diff options
| author | Arne Dußin | 2020-11-09 21:15:35 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-09 21:15:35 +0100 |
| commit | b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f (patch) | |
| tree | bb9de75363ade9f2f27ebdb60507dbefb36afc35 /src/tool/deletion_tool.rs | |
| parent | e08cb85528e6b72d5f3b2fbeb79b581fa7a4e461 (diff) | |
| download | graf_karto-b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f.tar.gz graf_karto-b06e0075bf4dfd51f8ad5df801f9c43fbd73df1f.zip | |
Add configuration options
Diffstat (limited to 'src/tool/deletion_tool.rs')
| -rw-r--r-- | src/tool/deletion_tool.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/tool/deletion_tool.rs b/src/tool/deletion_tool.rs index 142e0cb..6f5ac24 100644 --- a/src/tool/deletion_tool.rs +++ b/src/tool/deletion_tool.rs @@ -1,18 +1,22 @@ use super::Tool; +use crate::button::Button; +use crate::config::{DeletionToolKeybindings, ToolKeybindings}; use crate::map_data::MapData; use crate::math::{Rect, Vec2}; use crate::transform::Transform; use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle}; -use raylib::ffi::{Color, MouseButton}; +use raylib::ffi::Color; use raylib::RaylibHandle; pub struct DeletionTool { + keybindings: DeletionToolKeybindings, deletion_rect: Option<(Vec2<f32>, Vec2<f32>)>, } impl DeletionTool { - pub fn new() -> Self { + pub fn new(keybindings: DeletionToolKeybindings) -> Self { Self { + keybindings, deletion_rect: None, } } @@ -38,17 +42,12 @@ impl Tool for DeletionTool { *pos2 = mouse_pos_m; } - if rl.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) { - if let Some((pos1, pos2)) = self.deletion_rect { - Self::delete_rect(map_data, Rect::bounding_rect(pos1, pos2)); - self.deletion_rect = None; - } else { - self.deletion_rect = Some((mouse_pos_m, mouse_pos_m)) - } - } - - // Abort deletion. - if rl.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON) { + if self.keybindings.do_delete.is_pressed(rl) && self.deletion_rect.is_some() { + let (pos1, pos2) = self.deletion_rect.take().unwrap(); + Self::delete_rect(map_data, Rect::bounding_rect(pos1, pos2)); + } else if self.keybindings.start_selection.is_pressed(rl) { + self.deletion_rect = Some((mouse_pos_m, mouse_pos_m)) + } else if self.keybindings.abort_deletion.is_pressed(rl) { self.deletion_rect = None; } } @@ -77,4 +76,8 @@ impl Tool for DeletionTool { ); } } + + fn activation_key(&self) -> Button { + self.keybindings.activation_key() + } } |
