diff options
Diffstat (limited to 'src/tool/room_tool.rs')
| -rw-r--r-- | src/tool/room_tool.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs index 0321ff3..09126c9 100644 --- a/src/tool/room_tool.rs +++ b/src/tool/room_tool.rs @@ -1,6 +1,7 @@ use super::Tool; +use crate::grid::snap_to_grid; use crate::map_data::MapData; -use crate::math::{self, Rect, Vec2}; +use crate::math::{Rect, Vec2}; use crate::transform::Transform; use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle}; use raylib::ffi::{Color, MouseButton}; @@ -26,11 +27,7 @@ impl Tool for RoomTool { 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 { - let snapped_mouse_pos = Vec2::new( - math::round(mouse_pos_m.x, 0.5), - math::round(mouse_pos_m.y, 0.5), - ); - *pos2 = snapped_mouse_pos; + *pos2 = snap_to_grid(mouse_pos_m, 0.5); } // Start or finish drawing the currently unfinished rectangle @@ -39,10 +36,7 @@ impl Tool for RoomTool { map_data.rooms_mut().push(Rect::bounding_rect(pos1, pos2)); self.unfinished_rect = None; } else { - let snapped_mouse_pos = Vec2::new( - math::round(mouse_pos_m.x, 0.5), - math::round(mouse_pos_m.y, 0.5), - ); + let snapped_mouse_pos = snap_to_grid(mouse_pos_m, 0.5); self.unfinished_rect = Some((snapped_mouse_pos, snapped_mouse_pos)) } } |
