aboutsummaryrefslogtreecommitdiff
path: root/src/tool
diff options
context:
space:
mode:
authorArne Dußin2020-12-16 13:34:56 +0100
committerArne Dußin2020-12-16 13:34:56 +0100
commit82d11b7d3e15d8175accf7579db1fbe528fc6583 (patch)
treebe9a5601e99608966d4ccd146c3bfb3a70c7fc02 /src/tool
parent9799d3c6a8f0c242668203a1c70d7b6cfed3e855 (diff)
downloadgraf_karto-82d11b7d3e15d8175accf7579db1fbe528fc6583.tar.gz
graf_karto-82d11b7d3e15d8175accf7579db1fbe528fc6583.zip
Add constant for default colours and selection tool
Diffstat (limited to 'src/tool')
-rw-r--r--src/tool/deletion_tool.rs16
-rw-r--r--src/tool/mod.rs3
-rw-r--r--src/tool/polygon_room_tool.rs30
-rw-r--r--src/tool/rect_room_tool.rs9
-rw-r--r--src/tool/selection_tool.rs63
5 files changed, 76 insertions, 45 deletions
diff --git a/src/tool/deletion_tool.rs b/src/tool/deletion_tool.rs
index ad3af1d..5ff3e6a 100644
--- a/src/tool/deletion_tool.rs
+++ b/src/tool/deletion_tool.rs
@@ -2,8 +2,8 @@ use super::Tool;
use crate::map::Map;
use crate::math::{Rect, Surface, Vec2};
use crate::transform::Transform;
+use crate::colours::DEFAULT_COLOURS;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-use raylib::ffi::Color;
pub struct DeletionTool {
deletion_rect: Option<(Vec2<f64>, Vec2<f64>)>,
@@ -38,22 +38,12 @@ impl Tool for DeletionTool {
let rect_px = transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2));
rld.draw_rectangle_rec(
rect_px,
- Color {
- r: 200,
- g: 150,
- b: 150,
- a: 50,
- },
+ DEFAULT_COLOURS.deletion_rect
);
rld.draw_rectangle_lines_ex(
rect_px,
4,
- Color {
- r: 200,
- g: 150,
- b: 150,
- a: 150,
- },
+ DEFAULT_COLOURS.deletion_rect_outline
);
}
}
diff --git a/src/tool/mod.rs b/src/tool/mod.rs
index 532572a..aeabf19 100644
--- a/src/tool/mod.rs
+++ b/src/tool/mod.rs
@@ -2,12 +2,14 @@ pub mod deletion_tool;
pub mod icon_tool;
pub mod polygon_room_tool;
pub mod rect_room_tool;
+pub mod selection_tool;
pub mod wall_tool;
pub use deletion_tool::DeletionTool;
pub use icon_tool::IconTool;
pub use polygon_room_tool::PolygonRoomTool;
pub use rect_room_tool::RectRoomTool;
+pub use selection_tool::SelectionTool;
pub use wall_tool::WallTool;
use crate::button::Button;
@@ -24,6 +26,7 @@ pub enum ToolType {
WallTool,
IconTool,
DeletionTool,
+ SelectionTool,
NumTools,
}
diff --git a/src/tool/polygon_room_tool.rs b/src/tool/polygon_room_tool.rs
index 4f8edce..1b079d2 100644
--- a/src/tool/polygon_room_tool.rs
+++ b/src/tool/polygon_room_tool.rs
@@ -2,8 +2,8 @@ use super::Tool;
use crate::map::Map;
use crate::math::{self, Polygon, PolygonError, Vec2};
use crate::transform::Transform;
+use crate::colours::DEFAULT_COLOURS;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-use raylib::ffi::Color;
struct UnfinishedPolygon {
pub corners: Vec<Vec2<f64>>,
@@ -103,12 +103,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&polygon.corners[0]),
transform.point_m_to_px(&polygon.working_corner),
transform.length_m_to_px(0.1) as f32,
- Color {
- r: 150,
- g: 200,
- b: 150,
- a: 255,
- },
+ DEFAULT_COLOURS.room_selected
);
} else if polygon.corners.len() == 2 {
// We have three valid corners, so we can draw a triangle.
@@ -116,12 +111,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&polygon.corners[0]),
transform.point_m_to_px(&polygon.corners[1]),
transform.point_m_to_px(&polygon.working_corner),
- Color {
- r: 150,
- g: 200,
- b: 150,
- a: 255,
- },
+ DEFAULT_COLOURS.room_selected
)
} else {
// A proper polygon can be drawn.
@@ -136,12 +126,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&triangle[0]),
transform.point_m_to_px(&triangle[1]),
transform.point_m_to_px(&triangle[2]),
- Color {
- r: 150,
- g: 200,
- b: 150,
- a: 255,
- },
+ DEFAULT_COLOURS.room_selected
)
}
} else if polygon.check_validity_completed().is_ok() {
@@ -153,12 +138,7 @@ impl Tool for PolygonRoomTool {
transform.point_m_to_px(&triangle[0]),
transform.point_m_to_px(&triangle[1]),
transform.point_m_to_px(&triangle[2]),
- Color {
- r: 150,
- g: 200,
- b: 150,
- a: 255,
- },
+ DEFAULT_COLOURS.room_selected
)
}
}
diff --git a/src/tool/rect_room_tool.rs b/src/tool/rect_room_tool.rs
index 3eb40aa..dfda495 100644
--- a/src/tool/rect_room_tool.rs
+++ b/src/tool/rect_room_tool.rs
@@ -2,8 +2,8 @@ use super::Tool;
use crate::map::Map;
use crate::math::{Rect, Vec2};
use crate::transform::Transform;
+use crate::colours::DEFAULT_COLOURS;
use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-use raylib::ffi::Color;
pub struct RectRoomTool {
/// The rectangle that is currently being drawn by the user. Once it is finished, it will be
@@ -35,12 +35,7 @@ impl Tool for RectRoomTool {
if let Some((pos1, pos2)) = self.unfinished_rect {
rld.draw_rectangle_rec(
transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2)),
- Color {
- r: 150,
- g: 200,
- b: 150,
- a: 255,
- },
+ DEFAULT_COLOURS.room_selected
);
}
}
diff --git a/src/tool/selection_tool.rs b/src/tool/selection_tool.rs
new file mode 100644
index 0000000..49efba9
--- /dev/null
+++ b/src/tool/selection_tool.rs
@@ -0,0 +1,63 @@
+use super::Tool;
+use crate::map::Map;
+use crate::math::{Rect, Surface, Vec2};
+use crate::transform::Transform;
+use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
+use crate::colours::DEFAULT_COLOURS;
+
+pub struct SelectionTool {
+ selection_rect: Option<(Vec2<f64>, Vec2<f64>)>,
+}
+
+impl SelectionTool {
+ pub fn new() -> Self {
+ Self {
+ selection_rect: None,
+ }
+ }
+}
+
+impl Tool for SelectionTool {
+ fn deactivate(&mut self) {
+ self.selection_rect = None;
+ }
+
+ fn update(&mut self, _map: &Map, mouse_pos_m: &Vec2<f64>) {
+ if let Some((_, ref mut pos2)) = &mut self.selection_rect {
+ *pos2 = *mouse_pos_m;
+ }
+ }
+
+ fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
+ if let Some((pos1, pos2)) = self.selection_rect {
+ let rect_px = transform.rect_m_to_px(&Rect::bounding_rect(pos1, pos2));
+ rld.draw_rectangle_rec(
+ rect_px,
+ DEFAULT_COLOURS.selection_rect
+ );
+ rld.draw_rectangle_lines_ex(
+ rect_px,
+ 4,
+ DEFAULT_COLOURS.selection_rect_outline
+ );
+ }
+ }
+
+ fn place_single(&mut self, map: &mut Map, mouse_pos_m: &Vec2<f64>) {
+ if let Some((pos1, pos2)) = self.selection_rect {
+ // Select all items on the map that are inside of the selection rectangle
+ let bounds = Rect::bounding_rect(pos1, pos2);
+ for element in map.elements_mut() {
+ // TODO: Make it possible to do this additively by custom keybinding.
+ element.set_selected(bounds.contains_rect(&element.bounding_rect()));
+ }
+ self.selection_rect = None;
+ } else {
+ self.selection_rect = Some((*mouse_pos_m, *mouse_pos_m));
+ }
+ }
+
+ fn abort(&mut self) {
+ self.selection_rect = None;
+ }
+}