mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Add time since pointerdown to input event handling (#4443)
Add event time to the editor pointer states The brush trace's hot core is position plus per-sample time, and the frame clock is too coarse for high-rate tablets: several samples share one timestamp and speed dynamics see dt = 0. The desktop stamps editor-routed pointer input with a monotonic arrival time since winit does not surface hardware timestamps; the web path can thread the PointerEvent timeStamp through later.
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::ui::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, PINCH_ZOOM_SPEED,
|
||||
use crate::wrapper::messages::{DesktopWrapperMessage, InputMessage, ModifierKeys, MouseKeys, PointerState, ScrollDelta};
|
||||
|
||||
pub(crate) struct InputState {
|
||||
start: Instant,
|
||||
viewport_info: Option<ViewportInfo>,
|
||||
pointer_lock_position: Option<PhysicalPosition<f64>>,
|
||||
modifier_keys: ModifierKeys,
|
||||
@@ -29,6 +30,7 @@ impl InputAction {
|
||||
impl InputState {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
start: Instant::now(),
|
||||
viewport_info: None,
|
||||
pointer_lock_position: None,
|
||||
modifier_keys: ModifierKeys::empty(),
|
||||
@@ -193,6 +195,7 @@ impl InputState {
|
||||
PointerState {
|
||||
editor_position: (self.pointer_position.x / self.scale(), self.pointer_position.y / self.scale()).into(),
|
||||
mouse_keys: self.pointer_keys,
|
||||
time: Some(self.start.elapsed().as_secs_f64() * 1000.),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ pub struct PointerState {
|
||||
pub position: ViewportPosition,
|
||||
pub mouse_keys: MouseKeys,
|
||||
pub scroll_delta: ScrollDelta,
|
||||
pub time: Option<f64>,
|
||||
pub pressure: Option<f64>,
|
||||
pub tilt: Option<DVec2>,
|
||||
pub twist: Option<f64>,
|
||||
@@ -77,6 +78,7 @@ pub struct EditorPointerState {
|
||||
pub editor_position: EditorPosition,
|
||||
pub mouse_keys: MouseKeys,
|
||||
pub scroll_delta: ScrollDelta,
|
||||
pub time: Option<f64>,
|
||||
pub pressure: Option<f64>,
|
||||
pub tilt: Option<DVec2>,
|
||||
pub twist: Option<f64>,
|
||||
@@ -101,6 +103,7 @@ impl EditorPointerState {
|
||||
position: (viewport.logical(self.editor_position) - viewport.offset()).into(),
|
||||
mouse_keys: self.mouse_keys,
|
||||
scroll_delta: self.scroll_delta,
|
||||
time: self.time,
|
||||
pressure: self.pressure,
|
||||
tilt: self.tilt,
|
||||
twist: self.twist,
|
||||
|
||||
@@ -16,6 +16,7 @@ pub struct InputPreprocessorMessageHandler {
|
||||
pub time: u64,
|
||||
pub keyboard: KeyStates,
|
||||
pub mouse: PointerState,
|
||||
pointer_down_time: f64,
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
@@ -144,6 +145,13 @@ impl InputPreprocessorMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
let raw_time = new_state.time.unwrap_or(self.time as f64);
|
||||
if self.mouse.mouse_keys == MouseKeys::empty() {
|
||||
self.pointer_down_time = raw_time;
|
||||
}
|
||||
let interacting = (self.mouse.mouse_keys | new_state.mouse_keys) != MouseKeys::empty();
|
||||
new_state.time = interacting.then_some(raw_time - self.pointer_down_time);
|
||||
|
||||
self.mouse = new_state;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user