aboutsummaryrefslogtreecommitdiff
path: root/src/editor.rs
diff options
context:
space:
mode:
authorArne Dußin2020-11-20 20:00:28 +0100
committerArne Dußin2020-11-20 20:00:28 +0100
commitcf0cbe3fd28b2099b580edc1714b4d68bf7183cd (patch)
treeb03561c1ae7860cad247d089cb1ad728efa843ec /src/editor.rs
parentf62dabcb390d4808739745c050dfba8e2826b214 (diff)
downloadgraf_karto-cf0cbe3fd28b2099b580edc1714b4d68bf7183cd.tar.gz
graf_karto-cf0cbe3fd28b2099b580edc1714b4d68bf7183cd.zip
Add simple tool sidebar gui
Diffstat (limited to 'src/editor.rs')
-rw-r--r--src/editor.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/editor.rs b/src/editor.rs
index f8ee4bc..a2eb9c8 100644
--- a/src/editor.rs
+++ b/src/editor.rs
@@ -5,6 +5,7 @@ use crate::transform::Transform;
use raylib::core::drawing::RaylibDrawHandle;
use raylib::ffi::KeyboardKey;
use raylib::{RaylibHandle, RaylibThread};
+use std::mem;
pub struct Editor {
map_data: MapData,
@@ -33,21 +34,30 @@ impl Editor {
}
}
- pub fn update(&mut self, rl: &RaylibHandle, transform: &Transform) {
+ /// Get the currently active tool.
+ pub fn active(&self) -> ToolType {
+ unsafe { mem::transmute(self.active as u8) }
+ }
+
+ /// Set the currently active tool. Any process currently going on in a different tool will be
+ /// aborted.
+ pub fn set_active(&mut self, tool: ToolType) {
+ self.tools[self.active].deactivate();
+ self.active = tool as usize;
+ self.tools[self.active].activate();
+ }
+
+ pub fn update(&mut self, rl: &RaylibHandle, transform: &Transform, mouse_blocked: bool) {
// Handle keybindings for tool change
for (i, tool) in self.tools.iter().enumerate() {
- if tool.activation_key().is_pressed(rl) {
+ if tool.activation_key().is_pressed(rl, false) {
// Don't do anything if the tool does not change.
if i == self.active {
break;
}
- /* Deactivate the current tool and activate the tool, of which the keybinding has
- * been pressed.
- */
- self.tools[self.active].deactivate();
- self.active = i;
- self.tools[self.active].activate();
+ // Activate the tool of which the key binding has been pressed.
+ self.set_active(unsafe { mem::transmute(i as u8) });
break;
}
}
@@ -67,7 +77,7 @@ impl Editor {
tool.update(&self.map_data, rl, transform);
}
- self.tools[self.active].active_update(&mut self.map_data, rl, transform);
+ self.tools[self.active].active_update(&mut self.map_data, rl, transform, mouse_blocked);
}
pub fn draw_tools(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {