mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Add navigate tool (#441)
* Remove transformations from layerdata * Clean up snap rotate * Enable the navigate tool * Implement navigate tool Co-authored-by: otdavies <oliver@psyfer.io>
This commit is contained in:
committed by
Keavon Chambers
parent
7ab127c3ae
commit
d0dcc0e42f
@@ -1,6 +1,7 @@
|
||||
use crate::consts::VIEWPORT_ROTATE_SNAP_INTERVAL;
|
||||
pub use crate::document::layer_panel::*;
|
||||
use crate::document::DocumentMessage;
|
||||
use crate::input::keyboard::Key;
|
||||
use crate::message_prelude::*;
|
||||
use crate::{
|
||||
consts::{VIEWPORT_SCROLL_RATE, VIEWPORT_ZOOM_LEVELS, VIEWPORT_ZOOM_MOUSE_RATE, VIEWPORT_ZOOM_SCALE_MAX, VIEWPORT_ZOOM_SCALE_MIN, VIEWPORT_ZOOM_WHEEL_RATE},
|
||||
@@ -16,12 +17,10 @@ use std::collections::VecDeque;
|
||||
#[impl_message(Message, DocumentMessage, Movement)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum MovementMessage {
|
||||
MouseMove,
|
||||
MouseMove { snap_angle: Key },
|
||||
TranslateCanvasBegin,
|
||||
WheelCanvasTranslate { use_y_as_x: bool },
|
||||
RotateCanvasBegin { snap: bool },
|
||||
EnableSnapping,
|
||||
DisableSnapping,
|
||||
RotateCanvasBegin,
|
||||
ZoomCanvasBegin,
|
||||
TransformCanvasEnd,
|
||||
SetCanvasRotation(f64),
|
||||
@@ -101,16 +100,10 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
|
||||
self.translating = true;
|
||||
self.mouse_pos = ipp.mouse.position;
|
||||
}
|
||||
RotateCanvasBegin { snap } => {
|
||||
RotateCanvasBegin => {
|
||||
self.rotating = true;
|
||||
self.snap_rotate = snap;
|
||||
self.mouse_pos = ipp.mouse.position;
|
||||
}
|
||||
EnableSnapping => self.snap_rotate = true,
|
||||
DisableSnapping => {
|
||||
self.rotation = self.snapped_angle();
|
||||
self.snap_rotate = false
|
||||
}
|
||||
ZoomCanvasBegin => {
|
||||
self.zooming = true;
|
||||
self.mouse_pos = ipp.mouse.position;
|
||||
@@ -123,7 +116,7 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
|
||||
self.rotating = false;
|
||||
self.zooming = false;
|
||||
}
|
||||
MouseMove => {
|
||||
MouseMove { snap_angle } => {
|
||||
if self.translating {
|
||||
let delta = ipp.mouse.position - self.mouse_pos;
|
||||
let transformed_delta = document.root.transform.inverse().transform_vector2(delta);
|
||||
@@ -132,7 +125,15 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
self.create_document_transform(&ipp.viewport_bounds, responses);
|
||||
}
|
||||
|
||||
if self.rotating {
|
||||
let new_snap = ipp.keyboard.get(snap_angle as usize);
|
||||
// When disabling snap, keep the viewed rotation as it was previously.
|
||||
if !new_snap && self.snap_rotate {
|
||||
self.rotation = self.snapped_angle();
|
||||
}
|
||||
self.snap_rotate = new_snap;
|
||||
|
||||
let half_viewport = ipp.viewport_bounds.size() / 2.;
|
||||
let rotation = {
|
||||
let start_vec = self.mouse_pos - half_viewport;
|
||||
@@ -151,8 +152,8 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
|
||||
|
||||
let new = (self.scale * amount).clamp(VIEWPORT_ZOOM_SCALE_MIN, VIEWPORT_ZOOM_SCALE_MAX);
|
||||
self.scale = new;
|
||||
responses.push_back(FrontendMessage::SetCanvasZoom { new_zoom: self.scale }.into());
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(FrontendMessage::SetCanvasZoom { new_zoom: self.scale }.into());
|
||||
self.create_document_transform(&ipp.viewport_bounds, responses);
|
||||
}
|
||||
self.mouse_pos = ipp.mouse.position;
|
||||
@@ -213,11 +214,11 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
self.create_document_transform(&ipp.viewport_bounds, responses);
|
||||
}
|
||||
SetCanvasRotation(new) => {
|
||||
self.rotation = new;
|
||||
SetCanvasRotation(new_radians) => {
|
||||
self.rotation = new_radians;
|
||||
self.create_document_transform(&ipp.viewport_bounds, responses);
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(FrontendMessage::SetCanvasRotation { new_radians: new }.into());
|
||||
responses.push_back(FrontendMessage::SetCanvasRotation { new_radians }.into());
|
||||
}
|
||||
ZoomCanvasToFitAll => {
|
||||
if let Some([pos1, pos2]) = document.visible_layers_bounding_box() {
|
||||
@@ -272,13 +273,6 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
|
||||
TranslateCanvasByViewportFraction,
|
||||
);
|
||||
|
||||
if self.rotating {
|
||||
let snapping = actions!(MovementMessageDiscriminant;
|
||||
EnableSnapping,
|
||||
DisableSnapping,
|
||||
);
|
||||
common.extend(snapping);
|
||||
}
|
||||
if self.translating || self.rotating || self.zooming {
|
||||
let transforming = actions!(MovementMessageDiscriminant;
|
||||
TransformCanvasEnd,
|
||||
|
||||
Reference in New Issue
Block a user