Improvements to the layer transform cage UX (#589)

* Allow input system to handle mousedown while dragging

* Fix abort

* Add apsect ratio

* Make comment more explicit

* Fix abort when dragging

* Constrain when dragging edge
This commit is contained in:
0HyperCube
2022-04-21 10:00:22 +01:00
committed by Keavon Chambers
parent 239aa03453
commit 2ace16df0f
5 changed files with 57 additions and 32 deletions
+17 -2
View File
@@ -254,7 +254,6 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for SelectTool {
match self.fsm_state {
Ready => actions!(SelectToolMessageDiscriminant; DragStart, PointerMove, EditLayer),
Dragging => actions!(SelectToolMessageDiscriminant; DragStop, PointerMove, EditLayer),
_ => actions!(SelectToolMessageDiscriminant; DragStop, PointerMove, Abort, EditLayer),
}
}
@@ -588,11 +587,27 @@ impl Fsm for SelectToolFsmState {
);
Ready
}
(Dragging, Abort) => {
data.snap_handler.cleanup(responses);
responses.push_back(DocumentMessage::Undo.into());
Ready
}
(_, Abort) => {
if let Some(path) = data.drag_box_overlay_layer.take() {
responses.push_front(DocumentMessage::Overlays(Operation::DeleteLayer { path }.into()).into())
};
if let Some(bounding_box_overlays) = data.bounding_box_overlays.take() {
if let Some(mut bounding_box_overlays) = data.bounding_box_overlays.take() {
let selected = data.layers_dragging.iter().collect::<Vec<_>>();
let mut selected = Selected::new(
&mut bounding_box_overlays.original_transforms,
&mut bounding_box_overlays.pivot,
&selected,
responses,
&document.graphene_document,
);
selected.revert_operation();
bounding_box_overlays.delete(responses);
}
@@ -8,7 +8,7 @@ use graphene::color::Color;
use graphene::layers::style::{self, Fill, Stroke};
use graphene::Operation;
use glam::{DAffine2, DVec2, Vec2Swizzles};
use glam::{DAffine2, DVec2};
/// Contains the edges that are being dragged along with the origional bounds
#[derive(Clone, Debug, Default)]
@@ -18,11 +18,22 @@ pub struct SelectedEdges {
bottom: bool,
left: bool,
right: bool,
// Aspect ratio in the form of width/height, so x:1 = width:height
aspect_ratio: f64,
}
impl SelectedEdges {
pub fn new(top: bool, bottom: bool, left: bool, right: bool, bounds: [DVec2; 2]) -> Self {
Self { top, bottom, left, right, bounds }
let size = (bounds[0] - bounds[1]).abs();
let aspect_ratio = size.x / size.y;
Self {
top,
bottom,
left,
right,
bounds,
aspect_ratio,
}
}
/// Calculate the pivot for the operation (the opposite point to the edge dragged)
@@ -67,8 +78,13 @@ impl SelectedEdges {
}
let mut size = max - min;
if constrain && ((self.top || self.bottom) && (self.left || self.right)) {
size = size.abs().max(size.abs().yx()) * size.signum();
if constrain {
size = match ((self.top || self.bottom), (self.left || self.right)) {
(true, true) => DVec2::new(size.x, size.x / self.aspect_ratio).abs().max(DVec2::new(size.y * self.aspect_ratio, size.y).abs()) * size.signum(),
(true, false) => DVec2::new(size.y * self.aspect_ratio, size.y),
(false, true) => DVec2::new(size.x, size.x / self.aspect_ratio),
_ => size,
};
}
if center {
if self.left || self.right {