Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update baseview and use the new mouse modifiers #9

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" }
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