Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buggy version of adding a new lane next to selection #20
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use kay::{ID, Recipient, Actor, Individual, Swarm, ActorSystem, Fate, CreateWith}; | ||
use descartes::{Band, P2}; | ||
use ::core::geometry::{AnyShape}; | ||
|
||
use super::{LaneStroke, CurrentPlan, PlanControl}; | ||
|
||
#[derive(Actor, Compact, Clone)] | ||
pub struct LaneStrokeAddable{ | ||
_id: ID, | ||
stroke: LaneStroke | ||
} | ||
|
||
impl LaneStrokeAddable{ | ||
pub fn new(stroke: LaneStroke) -> Self { | ||
LaneStrokeAddable{ | ||
_id: ID::invalid(), | ||
stroke: stroke | ||
} | ||
} | ||
} | ||
|
||
use super::AddToUI; | ||
use ::core::ui::Add; | ||
|
||
impl Recipient<AddToUI> for LaneStrokeAddable { | ||
fn receive(&mut self, msg: &AddToUI) -> Fate {match *msg{ | ||
AddToUI => { | ||
::core::ui::UserInterface::id() << Add::Interactable3d( | ||
self.id(), | ||
AnyShape::Band(Band::new(self.stroke.path().clone(), 5.0)), | ||
3 | ||
); | ||
Fate::Live | ||
} | ||
}} | ||
} | ||
|
||
use super::ClearDraggables; | ||
use ::core::ui::Remove; | ||
|
||
impl Recipient<ClearDraggables> for LaneStrokeAddable { | ||
fn receive(&mut self, msg: &ClearDraggables) -> Fate {match *msg{ | ||
ClearDraggables => { | ||
::core::ui::UserInterface::id() << Remove::Interactable3d(self.id()); | ||
Fate::Die | ||
} | ||
}} | ||
} | ||
|
||
use ::core::ui::Event3d; | ||
|
||
impl Recipient<Event3d> for LaneStrokeAddable { | ||
fn receive(&mut self, msg: &Event3d) -> Fate {match *msg{ | ||
Event3d::HoverStarted{..} | Event3d::HoverOngoing{..} => { | ||
CurrentPlan::id() << PlanControl::AddStroke(self.stroke.clone()); | ||
Fate::Live | ||
}, | ||
Event3d::DragFinished{..} => { | ||
CurrentPlan::id() << PlanControl::Commit(true, P2::new(0.0, 0.0)); | ||
Fate::Live | ||
}, | ||
_ => Fate::Live | ||
}} | ||
} | ||
|
||
|
||
pub fn setup(system: &mut ActorSystem) { | ||
system.add_individual(Swarm::<LaneStrokeAddable>::new()); | ||
system.add_inbox::<CreateWith<LaneStrokeAddable, AddToUI>, Swarm<LaneStrokeAddable>>(); | ||
system.add_inbox::<ClearDraggables, Swarm<LaneStrokeAddable>>(); | ||
system.add_inbox::<Event3d, Swarm<LaneStrokeAddable>>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters