aboutsummaryrefslogtreecommitdiff
path: root/src/gui/tool_sidebar.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-17 14:19:59 +0100
committerArne Dußin2021-01-17 14:19:59 +0100
commitb019d10df4080fdb0ab57445040d24f9b14abdac (patch)
tree268305b1024f8a15a88eb72f593fcfab0f0e8d61 /src/gui/tool_sidebar.rs
parentb58e965327deef14d6414a912bb6698c6f745ce9 (diff)
parent51b7747e62c189d430318c67368a5c84e50ece61 (diff)
downloadgraf_karto-b019d10df4080fdb0ab57445040d24f9b14abdac.tar.gz
graf_karto-b019d10df4080fdb0ab57445040d24f9b14abdac.zip
Merge branch 'master' into net
Diffstat (limited to 'src/gui/tool_sidebar.rs')
-rw-r--r--src/gui/tool_sidebar.rs42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/gui/tool_sidebar.rs b/src/gui/tool_sidebar.rs
index 78041e7..af6af74 100644
--- a/src/gui/tool_sidebar.rs
+++ b/src/gui/tool_sidebar.rs
@@ -3,7 +3,8 @@
// TODO: Currently, the keyboard shortcuts for tools are handled by the editor, but a lot speaks for
// them being handled by the ToolSidebar instead.
-use crate::math::{ExactSurface, Rect, Vec2};
+use crate::input::Input;
+use crate::math::Rect;
use crate::tool::ToolType;
use crate::Editor;
use raylib::core::texture::Texture2D;
@@ -17,37 +18,56 @@ pub const BUTTON_FILE: &str = "assets/button/tool_buttons.png";
/// Sidebar that renders and handles input for the tool activation buttons.
pub struct ToolSidebar {
button_texture: Texture2D,
+ bindings_id: usize,
+ panel_rect: Rect<u16>,
}
impl ToolSidebar {
/// Create a new tool sidebar. There should be only one sidebar per program instance.
- pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread) -> Self {
+ pub fn new(rl: &mut RaylibHandle, rlt: &RaylibThread, input: &mut Input) -> Self {
let button_texture = rl
.load_texture(rlt, BUTTON_FILE)
.expect("Could not read file containing tool icons.");
- Self { button_texture }
+ let panel_rect = Self::panel_rect(rl.get_screen_height() as u16);
+ let bindings_id = input.add_local_handler(panel_rect.clone());
+
+ Self {
+ button_texture,
+ bindings_id,
+ panel_rect,
+ }
}
- fn panel_rect(screen_height: u16) -> Rect<f32> {
+ fn panel_rect(screen_height: u16) -> Rect<u16> {
/* The width is currently hardcoded as 104, which is
* 64 (button-size) + 20 left gap + 20 right gap
*/
- Rect::new(0., 0., 104., screen_height as f32)
+ Rect::new(0, 0, 104, screen_height)
}
- /// Check if the mouse is currently being captured by this GUI-element. In that case,
- /// everything else that might want to access the mouse will be blocked.
- pub fn mouse_captured(screen_height: u16, mouse_pos: Vec2<f32>) -> bool {
- Self::panel_rect(screen_height).contains_point(&mouse_pos)
+ /// Update the state of the tool sidebar. Due to raylib limitations, this is not where the tools
+ /// are selected for the editor, which happens in draw.
+ pub fn update(&mut self, screen_height: u16, input: &mut Input) {
+ let new_panel_rect = Self::panel_rect(screen_height);
+ if new_panel_rect != self.panel_rect {
+ self.panel_rect = new_panel_rect;
+ input.set_binding_rect(self.bindings_id, self.panel_rect);
+ }
}
/// Draw the tool buttons and encasing panel. Because of the way raylib works, this also handles
/// clicking on tool buttons, which may be changed in the future, should a different gui be
/// chosen.
- pub fn draw(&self, screen_height: u16, rld: &mut impl RaylibDrawGui, editor: &mut Editor) {
- rld.gui_panel(Self::panel_rect(screen_height));
+ pub fn draw(&self, rld: &mut impl RaylibDrawGui, editor: &mut Editor) {
+ rld.gui_panel(Rect::new(
+ self.panel_rect.x as f32,
+ self.panel_rect.y as f32,
+ self.panel_rect.w as f32,
+ self.panel_rect.h as f32,
+ ));
+ // TODO: Update to new input system. Create buttons that integrate.
let mut active = editor.active();
for i in 0..ToolType::NumTools as usize {
let is_current_active = active as usize == i;