aboutsummaryrefslogtreecommitdiff
path: root/src/tool/icon_tool.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tool/icon_tool.rs')
-rw-r--r--src/tool/icon_tool.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs
index 89a07e8..cf90056 100644
--- a/src/tool/icon_tool.rs
+++ b/src/tool/icon_tool.rs
@@ -1,3 +1,5 @@
+use crate::button::Button;
+use crate::config::{IconToolKeybindings, ToolKeybindings};
use crate::grid::snap_to_grid;
use crate::map_data::MapData;
use crate::math::Vec2;
@@ -34,6 +36,7 @@ pub struct IconInfo {
pub struct IconTool {
// TODO: support svg
+ keybindings: IconToolKeybindings,
/// The icon data, containing the image texture and the info for that image texture like the
/// scale the image actually has.
icon_data: Vec<(Texture2D, IconFileInfo)>,
@@ -43,7 +46,11 @@ pub struct IconTool {
}
impl IconTool {
- pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread) -> Self {
+ pub fn new(
+ rl: &mut RaylibHandle,
+ rlt: &RaylibThread,
+ keybindings: IconToolKeybindings,
+ ) -> Self {
/* Read all available icons from the icon directory. SVGs do not need any special scale
* file, but pixel-based file formats require a RON-file declaring what the scale of the
* picture is right beside them.
@@ -87,6 +94,7 @@ impl IconTool {
}
Self {
+ keybindings,
icon_data,
current_icon: None,
}
@@ -114,18 +122,16 @@ impl Tool for IconTool {
{
// Unwrap the current icon, since it is now definitely set, as we are in the active update.
let active_icon = self.current_icon.as_mut().unwrap();
- // Activate the next icon when pressing the icon tool key.
- if rl.is_key_pressed(KeyboardKey::KEY_I) {
+ if self.keybindings.next.is_pressed(rl) {
active_icon.icon_id = (active_icon.icon_id + 1) % self.icon_data.len();
}
- if rl.is_mouse_button_pressed(MouseButton::MOUSE_RIGHT_BUTTON) {
- // Rotate the currently active icon by a quarter rotation.
+ if self.keybindings.rotate_clockwise.is_pressed(rl) {
active_icon.rotation += 45.;
}
}
// Handle placing the icon on the map
- if rl.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
+ if self.keybindings.place.is_pressed(rl) {
map.icons_mut().push(self.current_icon.take().unwrap());
}
}
@@ -175,4 +181,8 @@ impl Tool for IconTool {
);
}
}
+
+ fn activation_key(&self) -> Button {
+ self.keybindings.activation_key()
+ }
}