aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArne Dußin2021-01-08 16:08:09 +0100
committerArne Dußin2021-01-08 16:08:09 +0100
commitb8a9c3464a7ec4c60073fb4441129fa97b36442a (patch)
treed1147f7b017e7ff7c0fc4895501fe030b038780a /src
parent60327dd3ef85a263173e6275cb122c9191c030fe (diff)
downloadgraf_karto-b8a9c3464a7ec4c60073fb4441129fa97b36442a.tar.gz
graf_karto-b8a9c3464a7ec4c60073fb4441129fa97b36442a.zip
Fix CLI not capturing keyboard
This is not a very nice solution and is due to limitations of raylib. Since I want to change the way input is handled in the future this is an okay solution, but when overhauling the input needs to be changed.
Diffstat (limited to 'src')
-rw-r--r--src/cli/mod.rs5
-rw-r--r--src/editor.rs19
-rw-r--r--src/main.rs3
-rw-r--r--src/snapping.rs12
4 files changed, 25 insertions, 14 deletions
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index e96070f..eda274f 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -41,6 +41,11 @@ impl CLI {
}
}
+ /// Checks if the CLI is currently active. This means input to other things should be ignored.
+ pub fn active(&self) -> bool {
+ self.active
+ }
+
/// Handle input for the command line and perform any commands the user may want to run.
pub fn update(&mut self, rl: &mut RaylibHandle, editor: &mut Editor) {
/* Check if the CLI is currently active. If not and it should not be activated according to
diff --git a/src/editor.rs b/src/editor.rs
index 2cf2e41..abbc401 100644
--- a/src/editor.rs
+++ b/src/editor.rs
@@ -112,18 +112,21 @@ impl Editor {
transform: &Transform,
snapper: &Snapper,
mouse_blocked: bool,
+ keyboard_captured: bool,
) {
// Handle keybindings for tool change
- for (&tool_type, (_, activation_key)) in self.tools.iter() {
- if activation_key.is_pressed(rl, false) {
- // Don't do anything if the tool does not change.
- if tool_type == self.active {
+ if !keyboard_captured {
+ for (&tool_type, (_, activation_key)) in self.tools.iter() {
+ if activation_key.is_pressed(rl, false) {
+ // Don't do anything if the tool does not change.
+ if tool_type == self.active {
+ break;
+ }
+
+ // Activate the tool of which the key binding has been pressed.
+ self.set_active(tool_type);
break;
}
-
- // Activate the tool of which the key binding has been pressed.
- self.set_active(tool_type);
- break;
}
}
diff --git a/src/main.rs b/src/main.rs
index 105bb44..4d6f4ba 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -127,12 +127,13 @@ fn main() {
cli.update(&mut rl, &mut editor);
dimension_indicator.update(editor.map_mut(), &mut rl);
- snapper.update(&mut rl);
+ snapper.update(&mut rl, cli.active());
editor.update(
&mut rl,
&transform,
&snapper,
ToolSidebar::mouse_captured(screen_height as u16, last_mouse_pos.into()),
+ cli.active(),
);
// Drawing section
diff --git a/src/snapping.rs b/src/snapping.rs
index 325b62e..ceabf69 100644
--- a/src/snapping.rs
+++ b/src/snapping.rs
@@ -24,8 +24,8 @@ impl Snapper {
}
/// Update the grain according to the input the program receives.
- pub fn update(&mut self, rl: &mut RaylibHandle) {
- if !self.grain_gui.active() && rl.is_key_pressed(KeyboardKey::KEY_G) {
+ pub fn update(&mut self, rl: &mut RaylibHandle, keyboard_captured: bool) {
+ if !self.grain_gui.active() && rl.is_key_pressed(KeyboardKey::KEY_G) && !keyboard_captured {
self.grain_gui.set_active(true);
}
@@ -33,13 +33,15 @@ impl Snapper {
return;
}
- self.grain_gui.update(rl);
+ if !keyboard_captured {
+ self.grain_gui.update(rl);
+ }
- if rl.is_key_pressed(KeyboardKey::KEY_ENTER) {
+ if !keyboard_captured && rl.is_key_pressed(KeyboardKey::KEY_ENTER) {
self.grain_gui.set_active(false);
self.grain = self.grain_gui.value();
self.grain_gui.set_value(self.grain);
- } else if rl.is_key_pressed(KeyboardKey::KEY_ESCAPE) {
+ } else if !keyboard_captured && rl.is_key_pressed(KeyboardKey::KEY_ESCAPE) {
self.grain_gui.set_active(false);
self.grain_gui.set_value(self.grain);
}