diff options
| author | Arne Dußin | 2021-01-17 13:33:04 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-01-17 13:33:04 +0100 |
| commit | 51b7747e62c189d430318c67368a5c84e50ece61 (patch) | |
| tree | 328be6230d392027eb106fd963b5ec97b9034f9f /src/tool | |
| parent | b1179849c28e50c39ac3c94af9dda86ee24beca0 (diff) | |
| download | graf_karto-input.tar.gz graf_karto-input.zip | |
Input revamp to make keybindings controlable.input
Diffstat (limited to 'src/tool')
| -rw-r--r-- | src/tool/icon_tool.rs | 21 | ||||
| -rw-r--r-- | src/tool/mod.rs | 4 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs index c9e671e..8b4afc0 100644 --- a/src/tool/icon_tool.rs +++ b/src/tool/icon_tool.rs @@ -1,8 +1,8 @@ //! Tool for creating icons. For explanation of icons, please see //! [the icon module](crate::map::icon). -use crate::button::Button; -use crate::config::IconToolKeys; +use crate::config::IconToolBinds; +use crate::input::Input; use crate::map::icon_renderer::IconRenderer; use crate::map::{Icon, Map, Mappable}; use crate::math::Vec2; @@ -13,7 +13,7 @@ use std::rc::Rc; /// The icon tool itself. pub struct IconTool { - keybindings: IconToolKeys, + keybindings: IconToolBinds, /// Saves whether the IconTool is the currently active tool or not. active: bool, /// The information of the icon that should be placed / is currently being placed, if it @@ -25,7 +25,7 @@ pub struct IconTool { impl IconTool { /// Create a new icon tool that renders icons with the provided icon renderer. There should only /// be one instance of the tool for the program, which should be created in the editor. - pub fn new(keybindings: IconToolKeys, renderer: Rc<IconRenderer>) -> Self { + pub fn new(keybindings: IconToolBinds, renderer: Rc<IconRenderer>) -> Self { Self { keybindings, active: false, @@ -58,15 +58,18 @@ impl Tool for IconTool { map.push_icon(self.current_icon.clone()); } - fn on_button_pressed(&mut self, _map: &mut Map, button: Button) { - if button == self.keybindings.next { + fn handle_custom_bindings(&mut self, _map: &mut Map, input: &mut Input) { + if input.poll_global(&self.keybindings.next) { self.current_icon.id = (self.current_icon.id + 1) % self.renderer.num_icons(); - } else if button == self.keybindings.previous { + } + if input.poll_global(&self.keybindings.previous) { self.current_icon.id = (self.current_icon.id + self.renderer.num_icons() - 1) % self.renderer.num_icons(); - } else if button == self.keybindings.rotate_clockwise { + } + if input.poll_global(&self.keybindings.rotate_clockwise) { self.current_icon.rotation += 45.; - } else if button == self.keybindings.rotate_counterclockwise { + } + if input.poll_global(&self.keybindings.rotate_counterclockwise) { self.current_icon.rotation -= 45.; } } diff --git a/src/tool/mod.rs b/src/tool/mod.rs index 4130244..b3fae80 100644 --- a/src/tool/mod.rs +++ b/src/tool/mod.rs @@ -20,7 +20,7 @@ pub use rect_room_tool::RectRoomTool; pub use selection_tool::SelectionTool; pub use wall_tool::WallTool; -use crate::button::Button; +use crate::input::Input; use crate::map::Map; use crate::math::Vec2; use crate::transform::Transform; @@ -82,5 +82,5 @@ pub trait Tool { /// 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) {} + fn handle_custom_bindings(&mut self, _map: &mut Map, _input: &mut Input) {} } |
