mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-18 18:38:05 +08:00
Implement tool messaging and shape flipping (#288)
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::{
|
||||
};
|
||||
use document_core::layers::Layer;
|
||||
use document_core::{DocumentResponse, LayerId, Operation as DocumentOperation};
|
||||
use glam::DAffine2;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use log::warn;
|
||||
|
||||
use crate::document::Document;
|
||||
@@ -55,6 +55,7 @@ pub enum DocumentMessage {
|
||||
SetCanvasRotation(f64),
|
||||
NudgeSelectedLayers(f64, f64),
|
||||
ReorderSelectedLayers(i32),
|
||||
FlipLayer(Vec<LayerId>, bool, bool),
|
||||
}
|
||||
|
||||
impl From<DocumentOperation> for DocumentMessage {
|
||||
@@ -594,6 +595,18 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||
responses.push_back(DocumentMessage::SelectLayers(selected_layer_paths).into());
|
||||
}
|
||||
}
|
||||
FlipLayer(path, flip_horizontal, flip_vertical) => {
|
||||
if let Ok(layer) = self.active_document_mut().document.layer_mut(&path) {
|
||||
let scale = DVec2::new(if flip_horizontal { -1. } else { 1. }, if flip_vertical { -1. } else { 1. });
|
||||
responses.push_back(
|
||||
DocumentOperation::SetLayerTransform {
|
||||
path,
|
||||
transform: (layer.transform * DAffine2::from_scale(scale)).to_cols_array(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
message => todo!("document_action_handler does not implement: {}", message.to_discriminant().global_name()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use document_core::layers::style::Fill;
|
||||
use document_core::layers::style::Stroke;
|
||||
use document_core::Operation;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::input::{mouse::ViewportPosition, InputPreprocessor};
|
||||
use crate::tool::{DocumentToolData, Fsm, ToolActionHandlerData};
|
||||
@@ -16,12 +17,15 @@ pub struct Select {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Select)]
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum SelectMessage {
|
||||
DragStart,
|
||||
DragStop,
|
||||
MouseMove,
|
||||
Abort,
|
||||
|
||||
FlipHorizontal,
|
||||
FlipVertical,
|
||||
}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Select {
|
||||
@@ -121,6 +125,22 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
Ready
|
||||
}
|
||||
(_, FlipHorizontal) => {
|
||||
let selected_layers = document.layer_data.iter().filter_map(|(path, data)| data.selected.then(|| path.clone()));
|
||||
for path in selected_layers {
|
||||
responses.push_back(DocumentMessage::FlipLayer(path, true, false).into());
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
(_, FlipVertical) => {
|
||||
let selected_layers = document.layer_data.iter().filter_map(|(path, data)| data.selected.then(|| path.clone()));
|
||||
for path in selected_layers {
|
||||
responses.push_back(DocumentMessage::FlipLayer(path, false, true).into());
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
_ => self,
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user