aboutsummaryrefslogtreecommitdiff
path: root/src/tool/room_tool.rs
diff options
context:
space:
mode:
authorArne Dußin2020-12-15 00:46:54 +0100
committerArne Dußin2020-12-15 22:51:46 +0100
commit9799d3c6a8f0c242668203a1c70d7b6cfed3e855 (patch)
tree9116acbc886f680f82309a42b4e6147e65c1433b /src/tool/room_tool.rs
parent3bc690803fb59493ea8180fd630d65b3e26642d0 (diff)
downloadgraf_karto-9799d3c6a8f0c242668203a1c70d7b6cfed3e855.tar.gz
graf_karto-9799d3c6a8f0c242668203a1c70d7b6cfed3e855.zip
Refactor to make interaction between tools easier
Diffstat (limited to 'src/tool/room_tool.rs')
-rw-r--r--src/tool/room_tool.rs103
1 files changed, 0 insertions, 103 deletions
diff --git a/src/tool/room_tool.rs b/src/tool/room_tool.rs
deleted file mode 100644
index 6a283e3..0000000
--- a/src/tool/room_tool.rs
+++ /dev/null
@@ -1,103 +0,0 @@
-use super::Tool;
-use crate::button::Button;
-use crate::config::{RoomToolKeybindings, ToolKeybindings};
-use crate::dimension_indicator::DimensionIndicator;
-use crate::grid::{snap_to_grid, SNAP_SIZE};
-use crate::map_data::MapData;
-use crate::math::{Rect, Vec2};
-use crate::transform::Transform;
-use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-use raylib::ffi::Color;
-use raylib::RaylibHandle;
-
-pub struct RoomTool {
- keybindings: RoomToolKeybindings,
- /// The rectangle that is currently being drawn by the user. Once it is finished, it will be
- /// pushed into the room_rects.
- unfinished_rect: Option<(Vec2<f64>, Vec2<f64>)>,
- dimension_indicator: DimensionIndicator,
-}
-
-impl RoomTool {
- /// Create a new room tool where no rooms have been drawn yet.
- pub fn new(keybindings: RoomToolKeybindings) -> Self {
- Self {
- keybindings,
- unfinished_rect: None,
- dimension_indicator: DimensionIndicator::new(),
- }
- }
-}
-
-impl Tool for RoomTool {
- fn deactivate(&mut self) {
- self.unfinished_rect = None;
- self.dimension_indicator.clear_dimensions();
- }
-
- fn active_update(
- &mut self,
- map_data: &mut MapData,
- rl: &RaylibHandle,
- transform: &Transform,
- mouse_blocked: bool,
- ) {
- let mouse_pos_m = transform.point_px_to_m(&rl.get_mouse_position().into());
- // Update the currently drawn rectangle, if it exists, and also its dimension indicator.
- if let Some((ref pos1, ref mut pos2)) = &mut self.unfinished_rect {
- *pos2 = snap_to_grid(mouse_pos_m, SNAP_SIZE);
-
- self.dimension_indicator.update_dimensions(&[*pos1, *pos2]);
- }
-
- // Start or finish drawing the currently unfinished rectangle
- if self.keybindings.finish_draw.is_pressed(rl, mouse_blocked)
- && self.unfinished_rect.is_some()
- {
- let (pos1, pos2) = self.unfinished_rect.take().unwrap();
- self.dimension_indicator.clear_dimensions();
- map_data.rooms_mut().push(Rect::bounding_rect(pos1, pos2));
- } else if self.keybindings.start_draw.is_pressed(rl, mouse_blocked) {
- let snapped_mouse_pos = snap_to_grid(mouse_pos_m, SNAP_SIZE);
- self.unfinished_rect = Some((snapped_mouse_pos, snapped_mouse_pos))
- }
-
- if self.keybindings.abort_draw.is_pressed(rl, false) {
- self.unfinished_rect = None;
- }
- }
-
- fn draw(&self, map_data: &MapData, rld: &mut RaylibDrawHandle, transform: &Transform) {
- // Draw all finished rectangles.
- for &rect in map_data.rooms() {
- rld.draw_rectangle_rec(
- transform.rect_m_to_px(&rect),
- Color {
- r: 180,
- g: 180,
- b: 180,
- a: 255,
- },
- );
- }
-
- // Do the same for the unfinished rectangle
- 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,
- },
- );
-
- self.dimension_indicator.draw(rld, transform);
- }
- }
-
- fn activation_key(&self) -> Button {
- self.keybindings.activation_key()
- }
-}