Skip to content

Commit

Permalink
(G)rab, (R)otate, and (S)cale layers with hotkeys (#356)
Browse files Browse the repository at this point in the history
* Add handler and input mapping.

* Selecting transform type

* Add translation and axis constraints

* Remove unnecessary Key::

* Add rotation

* Centre pivot point for rotation

* Add scaling

* Select Tool bounding box now updates when transforming

* Add typing

* Shift to slow mouse movements

* Add snapping

* Refactor modifier keys

* Refactor to apply only 1 operation per frame

* Refactor to fix scale 0 issue

* Remove logging

* Avoid multiple decimol points in queue

* Add typing negative

* Add typing negative values

* Fix bounding box on apply/abort; fix some variable names

* Allow transform to daffine2 identity

* Revert previous operation when changing operation

* Remove repopulate transforms method

* Code readability tweaks

Co-authored-by: Keavon Chambers <[email protected]>
  • Loading branch information
0HyperCube and Keavon committed Aug 30, 2021
1 parent 4f87191 commit 134381f
Show file tree
Hide file tree
Showing 10 changed files with 610 additions and 3 deletions.
5 changes: 5 additions & 0 deletions editor/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub const VIEWPORT_SCROLL_RATE: f64 = 0.6;

pub const VIEWPORT_ROTATE_SNAP_INTERVAL: f64 = 15.;

// TRANSFORMING LAYER
pub const ROTATE_SNAP_ANGLE: f64 = 15.;
pub const SCALE_SNAP_INTERVAL: f64 = 0.1;
pub const SLOWING_DIVISOR: f64 = 10.;

// SELECT TOOL
pub const SELECTION_TOLERANCE: f64 = 1.;

Expand Down
8 changes: 8 additions & 0 deletions editor/src/document/document_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use log::warn;
use std::collections::VecDeque;

use super::movement_handler::{MovementMessage, MovementMessageHandler};
use super::transform_layer_handler::{TransformLayerMessage, TransformLayerMessageHandler};

type DocumentSave = (InternalDocument, HashMap<Vec<LayerId>, LayerData>);

Expand Down Expand Up @@ -63,6 +64,7 @@ pub struct DocumentMessageHandler {
pub name: String,
pub layer_data: HashMap<Vec<LayerId>, LayerData>,
movement_handler: MovementMessageHandler,
transform_layer_handler: TransformLayerMessageHandler,
}

impl Default for DocumentMessageHandler {
Expand All @@ -74,6 +76,7 @@ impl Default for DocumentMessageHandler {
name: String::from("Untitled Document"),
layer_data: vec![(vec![], LayerData::new(true))].into_iter().collect(),
movement_handler: MovementMessageHandler::default(),
transform_layer_handler: TransformLayerMessageHandler::default(),
}
}
}
Expand All @@ -83,6 +86,8 @@ impl Default for DocumentMessageHandler {
pub enum DocumentMessage {
#[child]
Movement(MovementMessage),
#[child]
TransformLayers(TransformLayerMessage),
DispatchOperation(Box<DocumentOperation>),
SetSelectedLayers(Vec<Vec<LayerId>>),
AddSelectedLayers(Vec<Vec<LayerId>>),
Expand Down Expand Up @@ -260,6 +265,7 @@ impl DocumentMessageHandler {
name,
layer_data: vec![(vec![], LayerData::new(true))].into_iter().collect(),
movement_handler: MovementMessageHandler::default(),
transform_layer_handler: TransformLayerMessageHandler::default(),
}
}

Expand Down Expand Up @@ -361,6 +367,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
use DocumentMessage::*;
match message {
Movement(message) => self.movement_handler.process_action(message, (layer_data(&mut self.layer_data, &[]), &self.document, ipp), responses),
TransformLayers(message) => self.transform_layer_handler.process_action(message, (&mut self.layer_data, &mut self.document, ipp), responses),
DeleteLayer(path) => responses.push_back(DocumentOperation::DeleteLayer { path }.into()),
StartTransaction => self.backup(),
RollbackTransaction => {
Expand Down Expand Up @@ -710,6 +717,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
common.extend(select);
}
common.extend(self.movement_handler.actions());
common.extend(self.transform_layer_handler.actions());
common
}
}
2 changes: 1 addition & 1 deletion editor/src/document/document_message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::input::InputPreprocessor;
use crate::message_prelude::*;
use graphene::layers::{Layer, LayerDataType};
use graphene::layers::Layer;
use graphene::{LayerId, Operation as DocumentOperation};
use log::warn;

Expand Down
3 changes: 3 additions & 0 deletions editor/src/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod document_file;
mod document_message_handler;
pub mod layer_panel;
mod movement_handler;
mod transform_layer_handler;

#[doc(inline)]
pub use document_file::LayerData;
Expand All @@ -12,3 +13,5 @@ pub use document_file::{AlignAggregate, AlignAxis, DocumentMessage, DocumentMess
pub use document_message_handler::{DocumentsMessage, DocumentsMessageDiscriminant, DocumentsMessageHandler};
#[doc(inline)]
pub use movement_handler::{MovementMessage, MovementMessageDiscriminant};
#[doc(inline)]
pub use transform_layer_handler::{TransformLayerMessage, TransformLayerMessageDiscriminant};
Loading

0 comments on commit 134381f

Please sign in to comment.