diff options
| author | Arne Dußin | 2020-10-30 23:28:40 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-10-30 23:28:40 +0100 |
| commit | c5b16dd0511997331b8cc8c3647fff95effbe8ec (patch) | |
| tree | f9077567ee46d70e4988e66086e47d07192f6aa3 /src/tool | |
| parent | 11faa70718c8304ac4e5b4a75e6aa1d573883955 (diff) | |
| download | graf_karto-c5b16dd0511997331b8cc8c3647fff95effbe8ec.tar.gz graf_karto-c5b16dd0511997331b8cc8c3647fff95effbe8ec.zip | |
Snap rooms to the grid
Diffstat (limited to 'src/tool')
| -rw-r--r-- | src/tool/room_tool.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs index 8288c97..6a9ad55 100644 --- a/src/tool/room_tool.rs +++ b/src/tool/room_tool.rs @@ -29,7 +29,11 @@ impl Tool for RoomTool { let mouse_pos_m = transform.point_px_to_m(rl.get_mouse_position()); // Update the currently drawn rectangle, if it exists if let Some((_, ref mut pos2)) = &mut self.unfinished_rect { - *pos2 = mouse_pos_m; + let snapped_mouse_pos = Vector2::new( + math::round(mouse_pos_m.x, 0.5), + math::round(mouse_pos_m.y, 0.5), + ); + *pos2 = snapped_mouse_pos; } // Start or finish drawing the currently unfinished rectangle @@ -38,7 +42,11 @@ impl Tool for RoomTool { self.room_rects.push(math::bounding_rect(pos1, pos2)); self.unfinished_rect = None; } else { - self.unfinished_rect = Some((mouse_pos_m, mouse_pos_m)) + let snapped_mouse_pos = Vector2::new( + math::round(mouse_pos_m.x, 0.5), + math::round(mouse_pos_m.y, 0.5), + ); + self.unfinished_rect = Some((snapped_mouse_pos, snapped_mouse_pos)) } } |
