From 51b7747e62c189d430318c67368a5c84e50ece61 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Sun, 17 Jan 2021 13:33:04 +0100 Subject: Input revamp to make keybindings controlable. --- src/main.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4d6f4ba..3c582d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,16 +21,17 @@ #[macro_use] extern crate log; -pub mod button; pub mod cli; pub mod colours; pub mod config; pub mod editor; pub mod grid; pub mod gui; +pub mod input; pub mod map; pub mod math; pub mod snapping; +pub mod stable_vec; pub mod svg; pub mod tool; pub mod transform; @@ -41,6 +42,7 @@ use config::Config; use editor::Editor; use float_cmp::F64Margin; use gui::{DimensionIndicator, ToolSidebar}; +use input::Input; use raylib::prelude::*; use snapping::Snapper; use std::ffi::CString; @@ -96,11 +98,13 @@ fn main() { &CString::new(GUI_STYLE).expect("Could not create C string from style file name"), )); + let mut input = Input::new(&rl); + config::register_bindings(&config, &mut input); let mut editor = Editor::new(&mut rl, &thread, config); let mut dimension_indicator = DimensionIndicator::new(); - let tool_sidebar = ToolSidebar::new(&mut rl, &thread); + let mut tool_sidebar = ToolSidebar::new(&mut rl, &thread, &mut input); let mut snapper = Snapper::default(); - let mut cli = CLI::new(); + let mut cli = CLI::new(&mut input); let mut transform = Transform::new(); let mut last_mouse_pos = rl.get_mouse_position(); @@ -108,6 +112,8 @@ fn main() { let screen_width = rl.get_screen_width(); let screen_height = rl.get_screen_height(); + input.update(&mut rl); + // Move the canvas together with the mouse if rl.is_mouse_button_down(MouseButton::MOUSE_MIDDLE_BUTTON) { transform.move_by_px(&(rl.get_mouse_position() - last_mouse_pos).into()); @@ -125,16 +131,11 @@ fn main() { ); } - cli.update(&mut rl, &mut editor); + cli.update(&mut editor, &mut input); dimension_indicator.update(editor.map_mut(), &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(), - ); + editor.update(&mut rl, &transform, &snapper, &mut input); + tool_sidebar.update(screen_height as u16, &mut input); // Drawing section { @@ -144,7 +145,7 @@ fn main() { editor.map().draw(&mut d, &transform); editor.draw_tools(&mut d, &transform); - tool_sidebar.draw(screen_height as u16, &mut d, &mut editor); + tool_sidebar.draw(&mut d, &mut editor); snapper.draw(&mut d); gui::position_indicator_draw(&mut d, last_mouse_pos.into(), &transform, &snapper); dimension_indicator.draw(&mut d, &transform); -- cgit v1.2.3-70-g09d2