From 178d716232468e5ae3292f39ccc5abd9c147094e Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Tue, 10 Nov 2020 18:52:08 +0100 Subject: Add dimension indicator without direct value editing --- src/tool/room_tool.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/tool') diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs index 1bfb225..52748fc 100644 --- a/src/tool/room_tool.rs +++ b/src/tool/room_tool.rs @@ -1,6 +1,7 @@ use super::Tool; use crate::button::Button; use crate::config::{RoomToolKeybindings, ToolKeybindings}; +use crate::dimension_indicator::DimensionIndicator; use crate::grid::snap_to_grid; use crate::map_data::MapData; use crate::math::{Rect, Vec2}; @@ -14,6 +15,7 @@ pub struct RoomTool { /// The rectangle that is currently being drawn by the user. Once it is finished, it will be /// pushed into the room_rects. unfinished_rect: Option<(Vec2, Vec2)>, + dimension_indicator: DimensionIndicator, } impl RoomTool { @@ -22,6 +24,7 @@ impl RoomTool { Self { keybindings, unfinished_rect: None, + dimension_indicator: DimensionIndicator::new(), } } } @@ -29,9 +32,11 @@ impl RoomTool { impl Tool for RoomTool { fn active_update(&mut self, map_data: &mut MapData, rl: &RaylibHandle, transform: &Transform) { let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position().into()); - // Update the currently drawn rectangle, if it exists - if let Some((_, ref mut pos2)) = &mut self.unfinished_rect { + // 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 { *pos2 = snap_to_grid(mouse_pos_m, 0.5); + + self.dimension_indicator.update_dimensions(&[*pos1, *pos2]); } // Start or finish drawing the currently unfinished rectangle @@ -73,6 +78,8 @@ impl Tool for RoomTool { a: 255, }, ); + + self.dimension_indicator.draw(rld, transform); } } -- cgit v1.2.3-70-g09d2