aboutsummaryrefslogtreecommitdiff
path: root/src/tool/deletion_tool.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-27 14:01:50 +0100
committerArne Dußin2021-02-02 22:16:15 +0100
commitf92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch)
tree20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/tool/deletion_tool.rs
parentc60a6d07efb120724b308e29e8e70f27c87c952d (diff)
downloadgraf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz
graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/tool/deletion_tool.rs')
-rw-r--r--src/tool/deletion_tool.rs75
1 files changed, 0 insertions, 75 deletions
diff --git a/src/tool/deletion_tool.rs b/src/tool/deletion_tool.rs
deleted file mode 100644
index da2090b..0000000
--- a/src/tool/deletion_tool.rs
+++ /dev/null
@@ -1,75 +0,0 @@
-//! A meta tool for selecting parts of a map and removing them in a single operation.
-//!
-//! The user can draw a rectangle, which currently must have it's side parallel to the x and y-axes
-//! of the world. With the first node placement, the mode is started, while the second placement would
-//! finish the process and delete all elements that are *completely* contained in the rectangle
-//! (partially contained items are not deleted) or abort it, in which case the selection is removed
-//! and nothing is deleted.
-
-use super::Tool;
-use crate::colours::DEFAULT_COLOURS;
-use crate::map::Map;
-use crate::math::{ExactSurface, Rect, Vec2};
-use crate::transform::Transform;
-use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-
-/// The deletion tool itself.
-pub struct DeletionTool {
- deletion_rect: Option<(Vec2<f64>, Vec2<f64>)>,
-}
-
-impl DeletionTool {
- /// Create a new deletion tool, there should only be one deletion tool and it should be created
- /// by the editor.
- #[allow(clippy::new_without_default)]
- pub fn new() -> Self {
- Self {
- deletion_rect: None,
- }
- }
-}
-
-fn delete_rect((pos1, pos2): (&Vec2<f64>, &Vec2<f64>), map: &mut Map) {
- let bounds = Rect::bounding_rect(*pos1, *pos2);
- map.retain(|e| !bounds.contains_rect(&e.bounding_rect()));
-}
-
-impl Tool for DeletionTool {
- fn deactivate(&mut self) {
- self.deletion_rect = None;
- }
-
- fn update(&mut self, _map: &Map, mouse_pos_m: &Vec2<f64>) {
- if let Some((_, ref mut pos2)) = &mut self.deletion_rect {
- *pos2 = *mouse_pos_m;
- }
- }
-
- fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
- if let Some((pos1, pos2)) = self.deletion_rect {
- let rect_px = transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2));
- rld.draw_rectangle_rec(rect_px, DEFAULT_COLOURS.deletion_rect);
- rld.draw_rectangle_lines_ex(rect_px, 4, DEFAULT_COLOURS.deletion_rect_outline);
- }
- }
-
- fn place_single(&mut self, map: &mut Map, mouse_pos_m: &Vec2<f64>) {
- if let Some((pos1, pos2)) = self.deletion_rect {
- delete_rect((&pos1, &pos2), map);
- self.deletion_rect = None;
- } else {
- self.deletion_rect = Some((*mouse_pos_m, *mouse_pos_m));
- }
- }
-
- fn finish(&mut self, map: &mut Map) {
- if let Some((pos1, pos2)) = self.deletion_rect {
- delete_rect((&pos1, &pos2), map);
- self.deletion_rect = None;
- }
- }
-
- fn abort(&mut self) {
- self.deletion_rect = None;
- }
-}