diff options
| author | Arne Dußin | 2020-12-15 00:46:54 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-12-15 22:51:46 +0100 |
| commit | 9799d3c6a8f0c242668203a1c70d7b6cfed3e855 (patch) | |
| tree | 9116acbc886f680f82309a42b4e6147e65c1433b /src/tool/mod.rs | |
| parent | 3bc690803fb59493ea8180fd630d65b3e26642d0 (diff) | |
| download | graf_karto-9799d3c6a8f0c242668203a1c70d7b6cfed3e855.tar.gz graf_karto-9799d3c6a8f0c242668203a1c70d7b6cfed3e855.zip | |
Refactor to make interaction between tools easier
Diffstat (limited to 'src/tool/mod.rs')
| -rw-r--r-- | src/tool/mod.rs | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/tool/mod.rs b/src/tool/mod.rs index f503d2b..532572a 100644 --- a/src/tool/mod.rs +++ b/src/tool/mod.rs @@ -1,25 +1,25 @@ pub mod deletion_tool; pub mod icon_tool; pub mod polygon_room_tool; -pub mod room_tool; +pub mod rect_room_tool; pub mod wall_tool; pub use deletion_tool::DeletionTool; pub use icon_tool::IconTool; pub use polygon_room_tool::PolygonRoomTool; -pub use room_tool::RoomTool; +pub use rect_room_tool::RectRoomTool; pub use wall_tool::WallTool; use crate::button::Button; -use crate::map_data::MapData; +use crate::map::Map; +use crate::math::Vec2; use crate::transform::Transform; use raylib::core::drawing::RaylibDrawHandle; -use raylib::RaylibHandle; -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] #[repr(u8)] pub enum ToolType { - RoomTool, + RectRoomTool, PolygonRoomTool, WallTool, IconTool, @@ -28,19 +28,33 @@ pub enum ToolType { } pub trait Tool { + /// Code that needs to be called when this Tool is activated or reactivated goes here. fn activate(&mut self) {} + /// Cleanup that needs to be done when the user switches from this tool to something else goes here. fn deactivate(&mut self) {} - fn update(&mut self, _map: &MapData, _rl: &RaylibHandle, _transform: &Transform) {} - fn active_update( - &mut self, - map: &mut MapData, - rl: &RaylibHandle, - transform: &Transform, - mouse_blocked: bool, - ); + /// Called on each frame when this tool is active. + fn update(&mut self, map: &Map, mouse_pos_m: &Vec2<f64>); - fn draw(&self, _map: &MapData, _rld: &mut RaylibDrawHandle, _transform: &Transform) {} + /// Draw the contents of this tool. + // TODO: Maybe make this tool mappable? This might make it easier to make things resizable while + // it's still being drawn. + fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform); - fn activation_key(&self) -> Button; + /// Generic keybinding. + /// Code to place a single node for this tool. + fn place_single(&mut self, _map: &mut Map, _mouse_pos_m: &Vec2<f64>) {} + + /// Generic keybinding. + /// Code to finish whatever one is doing with this tool currently and trying to apply the + /// changes to the map data. + fn finish(&mut self, _map: &mut Map) {} + + /// Generic keybinding. + /// Stop whatever one is doing with this tool and do not apply any changes to the map data. + fn abort(&mut self) {} + + /// If there are any additional keybindings that need to be handled by this tool, these can be + /// handled here. + fn on_button_pressed(&mut self, _map: &mut Map, _button: Button) {} } |
