Skip to content

Commit

Permalink
Update baseview and use the new mouse modifiers
Browse files Browse the repository at this point in the history
Which should fix RustAudio/baseview#116 for
the use case of Shift+dragging a slider.
  • Loading branch information
robbert-vdh committed Sep 22, 2022
1 parent 679b8cd commit d30a639
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ opengl = ["egui_glow", "baseview/opengl"]
egui = "0.19"
egui_glow = { version = "0.19", optional = true }
keyboard-types = { version = "0.6.1", default-features = false }
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "b3712638bacb3fdf2883cb5aa3f6caed0e91ac8c" }
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "eae4033e7d2cc9c31ccaa2794d5d08eedf2f510c", features = ["opengl"] }
raw-window-handle = "0.4.2"
copypasta = "0.8"
copypasta = "0.8"
30 changes: 26 additions & 4 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use baseview::{
};
use copypasta::ClipboardProvider;
use egui::{pos2, vec2, Pos2, Rect, Rgba};
use keyboard_types::Modifiers;
use raw_window_handle::HasRawWindowHandle;
use std::time::Instant;

Expand Down Expand Up @@ -264,6 +265,13 @@ where
},
)
}

/// Update the pressed key modifiers when a mouse event has sent a new set of modifiers.
fn update_modifiers(&mut self, modifiers: &Modifiers) {
self.egui_input.modifiers.alt = !(*modifiers & Modifiers::ALT).is_empty();
self.egui_input.modifiers.shift = !(*modifiers & Modifiers::SHIFT).is_empty();
self.egui_input.modifiers.command = !(*modifiers & Modifiers::CONTROL).is_empty();
}
}

impl<State, U> WindowHandler for EguiWindow<State, U>
Expand Down Expand Up @@ -338,12 +346,19 @@ where
fn on_event(&mut self, _window: &mut Window, event: Event) -> EventStatus {
match &event {
baseview::Event::Mouse(event) => match event {
baseview::MouseEvent::CursorMoved { position } => {
baseview::MouseEvent::CursorMoved {
position,
modifiers,
} => {
self.update_modifiers(modifiers);

let pos = pos2(position.x as f32, position.y as f32);
self.mouse_pos = Some(pos);
self.egui_input.events.push(egui::Event::PointerMoved(pos));
}
baseview::MouseEvent::ButtonPressed(button) => {
baseview::MouseEvent::ButtonPressed { button, modifiers } => {
self.update_modifiers(modifiers);

if let Some(pos) = self.mouse_pos {
if let Some(button) = translate_mouse_button(*button) {
self.egui_input.events.push(egui::Event::PointerButton {
Expand All @@ -355,7 +370,9 @@ where
}
}
}
baseview::MouseEvent::ButtonReleased(button) => {
baseview::MouseEvent::ButtonReleased { button, modifiers } => {
self.update_modifiers(modifiers);

if let Some(pos) = self.mouse_pos {
if let Some(button) = translate_mouse_button(*button) {
self.egui_input.events.push(egui::Event::PointerButton {
Expand All @@ -367,7 +384,12 @@ where
}
}
}
baseview::MouseEvent::WheelScrolled(scroll_delta) => {
baseview::MouseEvent::WheelScrolled {
delta: scroll_delta,
modifiers,
} => {
self.update_modifiers(modifiers);

let mut delta = match scroll_delta {
baseview::ScrollDelta::Lines { x, y } => {
let points_per_scroll_line = 50.0; // Scroll speed decided by consensus: https://github.com/emilk/egui/issues/461
Expand Down

0 comments on commit d30a639

Please sign in to comment.