diff options
| author | Arne Dußin | 2020-12-16 13:34:56 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-12-16 13:34:56 +0100 |
| commit | 82d11b7d3e15d8175accf7579db1fbe528fc6583 (patch) | |
| tree | be9a5601e99608966d4ccd146c3bfb3a70c7fc02 /src/editor.rs | |
| parent | 9799d3c6a8f0c242668203a1c70d7b6cfed3e855 (diff) | |
| download | graf_karto-82d11b7d3e15d8175accf7579db1fbe528fc6583.tar.gz graf_karto-82d11b7d3e15d8175accf7579db1fbe528fc6583.zip | |
Add constant for default colours and selection tool
Diffstat (limited to 'src/editor.rs')
| -rw-r--r-- | src/editor.rs | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/src/editor.rs b/src/editor.rs index bbe4f60..e6a2dcb 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -1,12 +1,12 @@ use crate::button::{Button, MouseButton}; use crate::config::Config; +use crate::grid::{snap_to_grid, SNAP_SIZE}; use crate::map::Map; use crate::tool::*; use crate::transform::Transform; use raylib::core::drawing::RaylibDrawHandle; use raylib::{RaylibHandle, RaylibThread}; use std::collections::HashMap; -use crate::grid::{snap_to_grid, SNAP_SIZE}; pub struct Editor { map: Map, @@ -14,7 +14,7 @@ pub struct Editor { /// itself. tools: HashMap<ToolType, (Box<dyn Tool>, Button)>, active: ToolType, - config: Config + config: Config, } impl Editor { @@ -56,6 +56,13 @@ impl Editor { config.tool_activation_keys.deletion, ), ); + tools.insert( + ToolType::SelectionTool, + ( + Box::new(SelectionTool::new()), + config.tool_activation_keys.selection, + ), + ); assert_eq!(ToolType::NumTools as usize, tools.len()); @@ -63,7 +70,7 @@ impl Editor { map, tools, active: ToolType::RectRoomTool, - config + config, } } @@ -123,23 +130,44 @@ impl Editor { active_tool.update(&self.map, &snapped_mouse_pos); // Handle common keybindings many of the tools have. - if self.config.tool_general_keys.place_single.is_pressed(rl, mouse_blocked) { + if self + .config + .tool_general_keys + .place_single + .is_pressed(rl, mouse_blocked) + { active_tool.place_single(&mut self.map, &snapped_mouse_pos); } - if self.config.tool_general_keys.finish.is_pressed(rl, mouse_blocked) { + if self + .config + .tool_general_keys + .finish + .is_pressed(rl, mouse_blocked) + { active_tool.finish(&mut self.map); } - if self.config.tool_general_keys.abort.is_pressed(rl, mouse_blocked) { + if self + .config + .tool_general_keys + .abort + .is_pressed(rl, mouse_blocked) + { active_tool.abort(); } // Handle custom keybindings in case the tool has any. let latest_button = if let Some(keyboard_key) = rl.get_key_pressed() { Some(Button::Keyboard(keyboard_key.into())) - } - else { - let mouse_buttons = [Button::Mouse(MouseButton::Left), Button::Mouse(MouseButton::Middle), Button::Mouse(MouseButton::Right)]; - mouse_buttons.iter().find(|button| button.is_pressed(rl, mouse_blocked)).copied() + } else { + let mouse_buttons = [ + Button::Mouse(MouseButton::Left), + Button::Mouse(MouseButton::Middle), + Button::Mouse(MouseButton::Right), + ]; + mouse_buttons + .iter() + .find(|button| button.is_pressed(rl, mouse_blocked)) + .copied() }; if let Some(latest_button) = latest_button { |
