aboutsummaryrefslogtreecommitdiff
path: root/src/tool/room_tool.rs
diff options
context:
space:
mode:
authorArne Dußin2020-11-06 00:53:46 +0100
committerArne Dußin2020-11-06 00:53:46 +0100
commit625d00bb0e9a374e7ecf4b91fde599307199f3b6 (patch)
tree3dfdcc544c5b29f1f49d09a374d129bd825ade56 /src/tool/room_tool.rs
parent6d5db404416b93d22438efd45c7df7be2cc67d11 (diff)
downloadgraf_karto-625d00bb0e9a374e7ecf4b91fde599307199f3b6.tar.gz
graf_karto-625d00bb0e9a374e7ecf4b91fde599307199f3b6.zip
Add icon tool
Diffstat (limited to 'src/tool/room_tool.rs')
-rw-r--r--src/tool/room_tool.rs14
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))
}
}