mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 04:38:11 +08:00
Add scaling by nudging with the Alt key (#990)
* update current progress working on issue#930 * Issue#930: features other than local scaling implemented * runs cargo fmt * issue930: implemented features(local scaling disregraded) update: merged master branch and solved coflicts * combined scaling and nudge feature * combined scaling and nudge feature * resolved issues when trying to scale below 1. pixel and other comments * reduce code complexity * reduce complexity * Improve code readability/idiomaticness * Add hints --------- Co-authored-by: Shiro <shiro@damedane.local> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Shiro
Keavon Chambers
parent
97b461377f
commit
77e69f4e5b
@@ -1,4 +1,5 @@
|
||||
use crate::messages::frontend::utility_types::{ExportBounds, FileType};
|
||||
use crate::messages::input_mapper::utility_types::input_keyboard::Key;
|
||||
use crate::messages::portfolio::document::utility_types::layer_panel::LayerMetadata;
|
||||
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis};
|
||||
use crate::messages::prelude::*;
|
||||
@@ -114,6 +115,8 @@ pub enum DocumentMessage {
|
||||
NudgeSelectedLayers {
|
||||
delta_x: f64,
|
||||
delta_y: f64,
|
||||
resize: Key,
|
||||
resize_opposite_corner: Key,
|
||||
},
|
||||
PasteImage {
|
||||
image: Image,
|
||||
|
||||
@@ -551,14 +551,45 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
NudgeSelectedLayers { delta_x, delta_y } => {
|
||||
NudgeSelectedLayers {
|
||||
delta_x,
|
||||
delta_y,
|
||||
resize,
|
||||
resize_opposite_corner,
|
||||
} => {
|
||||
self.backup(responses);
|
||||
|
||||
let opposite_corner = ipp.keyboard.key(resize_opposite_corner);
|
||||
let sign = if opposite_corner { -1. } else { 1. };
|
||||
|
||||
for path in self.selected_layers().map(|path| path.to_vec()) {
|
||||
let operation = DocumentOperation::TransformLayerInViewport {
|
||||
path,
|
||||
transform: DAffine2::from_translation((delta_x, delta_y).into()).to_cols_array(),
|
||||
// Nudge translation
|
||||
let transform = if !ipp.keyboard.key(resize) {
|
||||
Some(DAffine2::from_translation((delta_x, delta_y).into()).to_cols_array())
|
||||
}
|
||||
// Nudge resize
|
||||
else {
|
||||
self.document_legacy
|
||||
.viewport_bounding_box(&path, &render_data)
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|[existing_top_left, existing_bottom_right]| {
|
||||
let width = existing_bottom_right.x - existing_top_left.x;
|
||||
let height = existing_bottom_right.y - existing_top_left.y;
|
||||
|
||||
let new_width = (width + delta_x * sign).max(1.);
|
||||
let new_height = (height + delta_y * sign).max(1.);
|
||||
|
||||
let offset = DAffine2::from_translation(if opposite_corner { -existing_bottom_right } else { -existing_top_left });
|
||||
let scale = DAffine2::from_scale((new_width / width, new_height / height).into());
|
||||
|
||||
(offset.inverse() * scale * offset).to_cols_array()
|
||||
})
|
||||
};
|
||||
responses.push_back(operation.into());
|
||||
|
||||
if let Some(transform) = transform {
|
||||
responses.push_back(DocumentOperation::TransformLayerInViewport { path, transform }.into());
|
||||
}
|
||||
}
|
||||
responses.push_back(BroadcastEvent::DocumentIsDirty.into());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user