mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Desktop: Support input from drawing tablets (#4354)
* Rename the editor mouse state types to Pointer* and the input_ modules * Add optional pen attributes to the editor pointer state types * Desktop: Send tablet pointer clicks to CEF as mouse clicks * Desktop: End pointer lock and pending window drags on any left-equivalent release * Desktop: Route pointer input carrying pen attributes directly to the editor * Desktop: Route wheel and pinch input inside the viewport directly to the editor * Desktop: Track double clicks on the direct editor route * Desktop: Move the pointer lock position into InputState * Restore the input state pointer position when pointer lock ends (review) * Fix pen input being swallowed by Windows resize helper * Update winit to 0.31.0-beta.2 from crates.io
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
use std::time::Duration;
|
||||
|
||||
pub const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(500);
|
||||
pub const MULTICLICK_ALLOWED_TRAVEL: usize = 4;
|
||||
|
||||
pub const SCROLL_LINE_HEIGHT: f64 = 40.;
|
||||
pub const SCROLL_LINE_WIDTH: f64 = 40.;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const SCROLL_SPEED_X: f64 = 3.;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const SCROLL_SPEED_Y: f64 = 3.;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub const SCROLL_SPEED_X: f64 = 1.;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub const SCROLL_SPEED_Y: f64 = 1.;
|
||||
|
||||
pub const PINCH_ZOOM_SPEED: f64 = 300.;
|
||||
|
||||
pub(crate) const RESOURCE_SCHEME: &str = "resources";
|
||||
pub(crate) const RESOURCE_DOMAIN: &str = "resources";
|
||||
|
||||
@@ -17,21 +35,3 @@ pub(crate) const HOST_SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub(crate) const IPC_BOOTSTRAP_PREFIX: &str = "art.graphite.Graphite.ipc.";
|
||||
|
||||
pub(crate) const SCROLL_LINE_HEIGHT: usize = 40;
|
||||
pub(crate) const SCROLL_LINE_WIDTH: usize = 40;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) const SCROLL_SPEED_X: f32 = 3.;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) const SCROLL_SPEED_Y: f32 = 3.;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) const SCROLL_SPEED_X: f32 = 1.;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) const SCROLL_SPEED_Y: f32 = 1.;
|
||||
|
||||
pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.;
|
||||
|
||||
pub(crate) const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(500);
|
||||
pub(crate) const MULTICLICK_ALLOWED_TRAVEL: usize = 4;
|
||||
|
||||
@@ -82,14 +82,16 @@ pub(crate) fn translate(input_state: &mut InputState, event: &WindowEvent) -> Ve
|
||||
}
|
||||
WindowEvent::PointerButton { state, button, position, .. } => {
|
||||
let mouse_button = match button {
|
||||
ButtonSource::Mouse(mouse_button) => mouse_button,
|
||||
_ => {
|
||||
return Vec::new(); // TODO: Handle touch input
|
||||
}
|
||||
ButtonSource::Mouse(mouse_button) => Some(*mouse_button),
|
||||
ButtonSource::TabletTool { button, .. } => (*button).into(),
|
||||
_ => None, // TODO: Handle touch input
|
||||
};
|
||||
let Some(mouse_button) = mouse_button else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
let _ = input_state.cursor_move(position);
|
||||
let click_count = input_state.mouse_input(mouse_button, state).into();
|
||||
let click_count = input_state.mouse_input(&mouse_button, state).into();
|
||||
let up = matches!(state, ElementState::Released);
|
||||
let button = match mouse_button {
|
||||
MouseButton::Left => MouseButtonKind::Left,
|
||||
@@ -110,8 +112,8 @@ pub(crate) fn translate(input_state: &mut InputState, event: &WindowEvent) -> Ve
|
||||
MouseScrollDelta::LineDelta(x, y) => (x * SCROLL_LINE_WIDTH as f32, y * SCROLL_LINE_HEIGHT as f32),
|
||||
MouseScrollDelta::PixelDelta(physical_position) => (physical_position.x as f32, physical_position.y as f32),
|
||||
};
|
||||
delta_x *= SCROLL_SPEED_X;
|
||||
delta_y *= SCROLL_SPEED_Y;
|
||||
delta_x *= SCROLL_SPEED_X as f32;
|
||||
delta_y *= SCROLL_SPEED_Y as f32;
|
||||
|
||||
vec![InputEvent::MouseWheel {
|
||||
data: input_state.mouse_data(),
|
||||
|
||||
@@ -22,6 +22,8 @@ mod resources;
|
||||
mod utility;
|
||||
mod view;
|
||||
|
||||
pub use consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y};
|
||||
|
||||
pub struct UiContext<S: Stage = Started> {
|
||||
inner: S::ContextData,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user