/
lane_stroke_selectable.rs
81 lines (70 loc) · 2.46 KB
/
lane_stroke_selectable.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use kay::{ID, Recipient, Actor, Individual, Swarm, ActorSystem, Fate, CreateWith};
use descartes::{Band, Curve, Into2d};
use ::core::geometry::{CPath, AnyShape};
use super::{SelectableStrokeRef, CurrentPlan, PlanControl};
#[derive(Actor, Compact, Clone)]
pub struct LaneStrokeSelectable{
_id: ID,
stroke_ref: SelectableStrokeRef,
path: CPath
}
impl LaneStrokeSelectable{
pub fn new(stroke_ref: SelectableStrokeRef, path: CPath) -> Self {
LaneStrokeSelectable{
_id: ID::invalid(),
stroke_ref: stroke_ref,
path: path
}
}
}
use super::AddToUI;
use ::core::ui::Add;
impl Recipient<AddToUI> for LaneStrokeSelectable {
fn receive(&mut self, msg: &AddToUI) -> Fate {match *msg{
AddToUI => {
::core::ui::UserInterface::id() << Add::Interactable3d(
self.id(),
AnyShape::Band(Band::new(self.path.clone(), 2.5)),
1
);
Fate::Live
}
}}
}
use super::ClearSelectables;
use ::core::ui::Remove;
impl Recipient<ClearSelectables> for LaneStrokeSelectable {
fn receive(&mut self, msg: &ClearSelectables) -> Fate {match *msg{
ClearSelectables::One(stroke_ref_to_clear) => {
if self.stroke_ref == stroke_ref_to_clear {
::core::ui::UserInterface::id() << Remove::Interactable3d(self.id());
Fate::Die
} else {
Fate::Live
}
},
ClearSelectables::All(()) => {
::core::ui::UserInterface::id() << Remove::Interactable3d(self.id());
Fate::Die
}
}}
}
use ::core::ui::Event3d;
impl Recipient<Event3d> for LaneStrokeSelectable {
fn receive(&mut self, msg: &Event3d) -> Fate {match *msg{
Event3d::DragOngoing{from, to} => {
if let (Some(selection_start), Some(selection_end)) =
(self.path.project(from.into_2d()), self.path.project(to.into_2d())) {
CurrentPlan::id() << PlanControl::Select(self.stroke_ref, selection_start, selection_end);
}
Fate::Live
},
_ => Fate::Live
}}
}
pub fn setup(system: &mut ActorSystem) {
system.add_individual(Swarm::<LaneStrokeSelectable>::new());
system.add_inbox::<CreateWith<LaneStrokeSelectable, AddToUI>, Swarm<LaneStrokeSelectable>>();
system.add_inbox::<ClearSelectables, Swarm<LaneStrokeSelectable>>();
system.add_inbox::<Event3d, Swarm<LaneStrokeSelectable>>();
}