From cf0cbe3fd28b2099b580edc1714b4d68bf7183cd Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Fri, 20 Nov 2020 20:00:28 +0100 Subject: Add simple tool sidebar gui --- src/tool/deletion_tool.rs | 19 +++++++++++++++---- src/tool/icon_tool.rs | 18 ++++++++++++++---- src/tool/mod.rs | 10 ++++++++-- src/tool/room_tool.rs | 16 ++++++++++++---- src/tool/wall_tool.rs | 19 +++++++++++++++---- 5 files changed, 64 insertions(+), 18 deletions(-) (limited to 'src/tool') diff --git a/src/tool/deletion_tool.rs b/src/tool/deletion_tool.rs index bd80809..c313574 100644 --- a/src/tool/deletion_tool.rs +++ b/src/tool/deletion_tool.rs @@ -40,18 +40,29 @@ impl Tool for DeletionTool { self.deletion_rect = None; } - fn active_update(&mut self, map_data: &mut MapData, rl: &RaylibHandle, transform: &Transform) { + fn active_update( + &mut self, + map_data: &mut MapData, + rl: &RaylibHandle, + transform: &Transform, + mouse_blocked: bool, + ) { let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); if let Some((_, ref mut pos2)) = &mut self.deletion_rect { *pos2 = mouse_pos_m; } - if self.keybindings.do_delete.is_pressed(rl) && self.deletion_rect.is_some() { + if self.keybindings.do_delete.is_pressed(rl, mouse_blocked) && 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) { + } else if self + .keybindings + .start_selection + .is_pressed(rl, mouse_blocked) + { self.deletion_rect = Some((mouse_pos_m, mouse_pos_m)) - } else if self.keybindings.abort_deletion.is_pressed(rl) { + } else if self.keybindings.abort_deletion.is_pressed(rl, false) { self.deletion_rect = None; } } diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs index bd16de8..4b3a1eb 100644 --- a/src/tool/icon_tool.rs +++ b/src/tool/icon_tool.rs @@ -123,7 +123,13 @@ impl Tool for IconTool { self.active = false; } - fn active_update(&mut self, map: &mut MapData, rl: &RaylibHandle, transform: &Transform) { + fn active_update( + &mut self, + map: &mut MapData, + rl: &RaylibHandle, + transform: &Transform, + mouse_blocked: bool, + ) { // Update the position of the icon that should be drawn to the current mouse position. let snapped_mouse_pos_m = snap_to_grid( transform.point_px_to_m(rl.get_mouse_position().into()), @@ -132,15 +138,19 @@ impl Tool for IconTool { self.current_icon.position = snapped_mouse_pos_m; // Unwrap the current icon, since it is now definitely set, as we are in the active update. - if self.keybindings.next.is_pressed(rl) { + if self.keybindings.next.is_pressed(rl, mouse_blocked) { self.current_icon.icon_id = (self.current_icon.icon_id + 1) % self.icon_data.len(); } - if self.keybindings.rotate_clockwise.is_pressed(rl) { + if self + .keybindings + .rotate_clockwise + .is_pressed(rl, mouse_blocked) + { self.current_icon.rotation += 45.; } // Handle placing the icon on the map - if self.keybindings.place.is_pressed(rl) { + if self.keybindings.place.is_pressed(rl, mouse_blocked) { map.icons_mut().push(self.current_icon.clone()); } } diff --git a/src/tool/mod.rs b/src/tool/mod.rs index 3b9b845..e528b8f 100644 --- a/src/tool/mod.rs +++ b/src/tool/mod.rs @@ -14,7 +14,7 @@ use crate::transform::Transform; use raylib::core::drawing::RaylibDrawHandle; use raylib::RaylibHandle; -#[derive(Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] #[repr(u8)] pub enum ToolType { RoomTool, @@ -29,7 +29,13 @@ pub trait Tool { 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); + fn active_update( + &mut self, + map: &mut MapData, + rl: &RaylibHandle, + transform: &Transform, + mouse_blocked: bool, + ); fn draw(&self, _map: &MapData, _rld: &mut RaylibDrawHandle, _transform: &Transform) {} diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs index 3416596..c4a8b8c 100644 --- a/src/tool/room_tool.rs +++ b/src/tool/room_tool.rs @@ -35,7 +35,13 @@ impl Tool for RoomTool { self.dimension_indicator.clear_dimensions(); } - fn active_update(&mut self, map_data: &mut MapData, rl: &RaylibHandle, transform: &Transform) { + fn active_update( + &mut self, + map_data: &mut MapData, + rl: &RaylibHandle, + transform: &Transform, + mouse_blocked: bool, + ) { let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); // Update the currently drawn rectangle, if it exists, and also its dimension indicator. if let Some((ref pos1, ref mut pos2)) = &mut self.unfinished_rect { @@ -45,16 +51,18 @@ impl Tool for RoomTool { } // Start or finish drawing the currently unfinished rectangle - if self.keybindings.finish_draw.is_pressed(rl) && self.unfinished_rect.is_some() { + if self.keybindings.finish_draw.is_pressed(rl, mouse_blocked) + && self.unfinished_rect.is_some() + { let (pos1, pos2) = self.unfinished_rect.take().unwrap(); self.dimension_indicator.clear_dimensions(); map_data.rooms_mut().push(Rect::bounding_rect(pos1, pos2)); - } else if self.keybindings.start_draw.is_pressed(rl) { + } else if self.keybindings.start_draw.is_pressed(rl, mouse_blocked) { let snapped_mouse_pos = snap_to_grid(mouse_pos_m, SNAP_SIZE); self.unfinished_rect = Some((snapped_mouse_pos, snapped_mouse_pos)) } - if self.keybindings.abort_draw.is_pressed(rl) { + if self.keybindings.abort_draw.is_pressed(rl, false) { self.unfinished_rect = None; } } diff --git a/src/tool/wall_tool.rs b/src/tool/wall_tool.rs index 85079b0..2cc5b5d 100644 --- a/src/tool/wall_tool.rs +++ b/src/tool/wall_tool.rs @@ -28,22 +28,33 @@ impl Tool for WallTool { self.unfinished_wall = None; } - fn active_update(&mut self, map_data: &mut MapData, rl: &RaylibHandle, transform: &Transform) { + fn active_update( + &mut self, + map_data: &mut MapData, + rl: &RaylibHandle, + transform: &Transform, + mouse_blocked: bool, + ) { let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); if let Some((_, ref mut pos2)) = &mut self.unfinished_wall { *pos2 = snap_to_grid(mouse_pos_m, SNAP_SIZE); } - if self.keybindings.finish_segment.is_pressed(rl) && self.unfinished_wall.is_some() { + if self + .keybindings + .finish_segment + .is_pressed(rl, mouse_blocked) + && self.unfinished_wall.is_some() + { let (pos1, pos2) = self.unfinished_wall.unwrap(); map_data.walls_mut().push((pos1, pos2)); self.unfinished_wall = Some((pos2, pos2)); - } else if self.keybindings.start_wall.is_pressed(rl) { + } else if self.keybindings.start_wall.is_pressed(rl, mouse_blocked) { let snapped_mouse_pos = snap_to_grid(mouse_pos_m, SNAP_SIZE); self.unfinished_wall = Some((snapped_mouse_pos, snapped_mouse_pos)) } - if self.keybindings.abort_segment.is_pressed(rl) { + if self.keybindings.abort_segment.is_pressed(rl, false) { self.unfinished_wall = None; } } -- cgit v1.2.3-70-g09d2