mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 14:28:12 +08:00
Code cleanup and refactoring to enhance consistency (#1695)
- Move message handler payload data into structs
- Organize the file structure used by `editor/src/messages/portfolio/document` `/node_graph` and `/graph_operation`
- Make derive attributes use `serde::Serialize, serde::Deserialize` consistently instead of `use serde::{Deserialize, Serialize};` imports
- Various other code cleanup and refactoring
This commit is contained in:
@@ -17,7 +17,7 @@ pub struct ArtboardTool {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Artboard)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum ArtboardToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -50,8 +50,6 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Artboar
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use ArtboardToolFsmState::*;
|
||||
|
||||
let mut common = actions!(ArtboardToolMessageDiscriminant;
|
||||
DeleteSelected,
|
||||
NudgeSelected,
|
||||
@@ -59,7 +57,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Artboar
|
||||
);
|
||||
|
||||
let additional = match self.fsm_state {
|
||||
Ready => actions!(ArtboardToolMessageDiscriminant; PointerDown),
|
||||
ArtboardToolFsmState::Ready => actions!(ArtboardToolMessageDiscriminant; PointerDown),
|
||||
_ => actions!(ArtboardToolMessageDiscriminant; PointerUp, Abort),
|
||||
};
|
||||
common.extend(additional);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::resolve_document_node_type;
|
||||
use crate::messages::portfolio::document::node_graph::transform_utils::{get_current_normalized_pivot, get_current_transform};
|
||||
use crate::messages::portfolio::document::graph_operation::transform_utils::{get_current_normalized_pivot, get_current_transform};
|
||||
use crate::messages::portfolio::document::node_graph::document_node_types::resolve_document_node_type;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::tool::common_functionality::color_selector::{ToolColorOptions, ToolColorType};
|
||||
|
||||
@@ -13,7 +13,7 @@ use graphene_core::Color;
|
||||
|
||||
const BRUSH_MAX_SIZE: f64 = 5000.;
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Copy, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum DrawMode {
|
||||
Draw = 0,
|
||||
Erase,
|
||||
@@ -52,7 +52,7 @@ impl Default for BrushOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Brush)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum BrushToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -65,7 +65,7 @@ pub enum BrushToolMessage {
|
||||
UpdateOptions(BrushToolMessageOptionsUpdate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum BrushToolMessageOptionsUpdate {
|
||||
BlendMode(BlendMode),
|
||||
ChangeDiameter(f64),
|
||||
@@ -222,15 +222,13 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for BrushTo
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use BrushToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(BrushToolMessageDiscriminant;
|
||||
BrushToolFsmState::Ready => actions!(BrushToolMessageDiscriminant;
|
||||
DragStart,
|
||||
DragStop,
|
||||
UpdateOptions,
|
||||
),
|
||||
Drawing => actions!(BrushToolMessageDiscriminant;
|
||||
BrushToolFsmState::Drawing => actions!(BrushToolMessageDiscriminant;
|
||||
DragStop,
|
||||
PointerMove,
|
||||
Abort,
|
||||
|
||||
@@ -34,7 +34,7 @@ impl Default for EllipseToolOptions {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum EllipseOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -45,7 +45,7 @@ pub enum EllipseOptionsUpdate {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Ellipse)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum EllipseToolMessage {
|
||||
// Standard messages
|
||||
Overlays(OverlayContext),
|
||||
@@ -138,14 +138,12 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Ellipse
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use EllipseToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(EllipseToolMessageDiscriminant;
|
||||
EllipseToolFsmState::Ready => actions!(EllipseToolMessageDiscriminant;
|
||||
DragStart,
|
||||
PointerMove,
|
||||
),
|
||||
Drawing => actions!(EllipseToolMessageDiscriminant;
|
||||
EllipseToolFsmState::Drawing => actions!(EllipseToolMessageDiscriminant;
|
||||
DragStop,
|
||||
Abort,
|
||||
PointerMove,
|
||||
|
||||
@@ -8,7 +8,7 @@ pub struct EyedropperTool {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Eyedropper)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum EyedropperToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
|
||||
@@ -8,7 +8,7 @@ pub struct FillTool {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Fill)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum FillToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -42,14 +42,12 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for FillToo
|
||||
self.fsm_state.process_event(message, &mut (), tool_data, &(), responses, true);
|
||||
}
|
||||
fn actions(&self) -> ActionList {
|
||||
use FillToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(FillToolMessageDiscriminant;
|
||||
FillToolFsmState::Ready => actions!(FillToolMessageDiscriminant;
|
||||
FillPrimaryColor,
|
||||
FillSecondaryColor,
|
||||
),
|
||||
Filling => actions!(FillToolMessageDiscriminant;
|
||||
FillToolFsmState::Filling => actions!(FillToolMessageDiscriminant;
|
||||
PointerUp,
|
||||
Abort,
|
||||
),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::VectorDataModification;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::VectorDataModification;
|
||||
use crate::messages::portfolio::document::overlays::utility_functions::path_endpoint_overlays;
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
@@ -14,7 +14,6 @@ use graphene_core::Color;
|
||||
|
||||
use bezier_rs::ManipulatorGroup;
|
||||
use glam::DVec2;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FreehandTool {
|
||||
@@ -40,7 +39,7 @@ impl Default for FreehandOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Freehand)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum FreehandToolMessage {
|
||||
// Standard messages
|
||||
Overlays(OverlayContext),
|
||||
@@ -54,7 +53,7 @@ pub enum FreehandToolMessage {
|
||||
UpdateOptions(FreehandOptionsUpdate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum FreehandOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -149,14 +148,12 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Freehan
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use FreehandToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(FreehandToolMessageDiscriminant;
|
||||
FreehandToolFsmState::Ready => actions!(FreehandToolMessageDiscriminant;
|
||||
DragStart,
|
||||
DragStop,
|
||||
),
|
||||
Drawing => actions!(FreehandToolMessageDiscriminant;
|
||||
FreehandToolFsmState::Drawing => actions!(FreehandToolMessageDiscriminant;
|
||||
DragStop,
|
||||
PointerMove,
|
||||
Abort,
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct GradientOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Gradient)]
|
||||
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum GradientToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -37,7 +37,7 @@ pub enum GradientToolMessage {
|
||||
UpdateOptions(GradientOptionsUpdate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum GradientOptionsUpdate {
|
||||
Type(GradientType),
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::{self, IMAGINATE_NODE};
|
||||
use crate::messages::portfolio::document::node_graph::document_node_types::resolve_document_node_type;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_types::{new_image_network, IMAGINATE_NODE};
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::tool::common_functionality::resize::Resize;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use graph_craft::document::{generate_uuid, DocumentNodeMetadata, NodeId, NodeInput};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ImaginateTool {
|
||||
@@ -12,7 +13,7 @@ pub struct ImaginateTool {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Imaginate)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum ImaginateToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -35,13 +36,11 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Imagina
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use ImaginateToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(ImaginateToolMessageDiscriminant;
|
||||
ImaginateToolFsmState::Ready => actions!(ImaginateToolMessageDiscriminant;
|
||||
DragStart,
|
||||
),
|
||||
Drawing => actions!(ImaginateToolMessageDiscriminant;
|
||||
ImaginateToolFsmState::Drawing => actions!(ImaginateToolMessageDiscriminant;
|
||||
DragStop,
|
||||
Abort,
|
||||
Resize,
|
||||
@@ -107,17 +106,15 @@ impl Fsm for ImaginateToolFsmState {
|
||||
shape_data.layer = Some(LayerNodeIdentifier::new(NodeId(generate_uuid()), document.network()));
|
||||
responses.add(DocumentMessage::DeselectAllLayers);
|
||||
|
||||
use graph_craft::document::*;
|
||||
|
||||
// Utility function to offset the position of each consecutive node
|
||||
let mut pos = 8;
|
||||
let mut next_pos = || {
|
||||
pos += 8;
|
||||
graph_craft::document::DocumentNodeMetadata::position((pos, 4))
|
||||
DocumentNodeMetadata::position((pos, 4))
|
||||
};
|
||||
|
||||
// Get the node type for the Transform and Imaginate nodes
|
||||
let Some(transform_node_type) = crate::messages::portfolio::document::node_graph::resolve_document_node_type("Transform") else {
|
||||
let Some(transform_node_type) = resolve_document_node_type("Transform") else {
|
||||
warn!("Transform node should be in registry");
|
||||
return ImaginateToolFsmState::Drawing;
|
||||
};
|
||||
@@ -128,7 +125,7 @@ impl Fsm for ImaginateToolFsmState {
|
||||
let imaginate_node_id = NodeId(101);
|
||||
|
||||
// Create the network based on the Input -> Output passthrough default network
|
||||
let mut network = node_graph::new_image_network(16, imaginate_node_id);
|
||||
let mut network = new_image_network(16, imaginate_node_id);
|
||||
|
||||
// Insert the nodes into the default network
|
||||
network.nodes.insert(
|
||||
@@ -137,7 +134,7 @@ impl Fsm for ImaginateToolFsmState {
|
||||
);
|
||||
network.nodes.insert(
|
||||
imaginate_node_id,
|
||||
imaginate_node_type.to_document_node_default_inputs([Some(graph_craft::document::NodeInput::node(transform_node_id, 0))], next_pos()),
|
||||
imaginate_node_type.to_document_node_default_inputs([Some(NodeInput::node(transform_node_id, 0))], next_pos()),
|
||||
);
|
||||
responses.add(NodeGraphMessage::ShiftNode { node_id: imaginate_node_id });
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::consts::LINE_ROTATE_SNAP_ANGLE;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
|
||||
@@ -34,7 +35,7 @@ impl Default for LineOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Line)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum LineToolMessage {
|
||||
// Standard messages
|
||||
Overlays(OverlayContext),
|
||||
@@ -49,7 +50,7 @@ pub enum LineToolMessage {
|
||||
UpdateOptions(LineOptionsUpdate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum LineOptionsUpdate {
|
||||
LineWeight(f64),
|
||||
StrokeColor(Option<Color>),
|
||||
|
||||
@@ -25,5 +25,4 @@ pub mod tool_prelude {
|
||||
pub use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
|
||||
|
||||
pub use glam::{DAffine2, DVec2};
|
||||
pub use serde::{Deserialize, Serialize};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct NavigateTool {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Navigate)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum NavigateToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -45,10 +45,8 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Navigat
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use NavigateToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(NavigateToolMessageDiscriminant;
|
||||
NavigateToolFsmState::Ready => actions!(NavigateToolMessageDiscriminant;
|
||||
TranslateCanvasBegin,
|
||||
RotateCanvasBegin,
|
||||
ZoomCanvasBegin,
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct PathTool {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Path)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum PathToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -174,10 +174,8 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
|
||||
|
||||
// Different actions depending on state may be wanted:
|
||||
fn actions(&self) -> ActionList {
|
||||
use PathToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(PathToolMessageDiscriminant;
|
||||
PathToolFsmState::Ready => actions!(PathToolMessageDiscriminant;
|
||||
FlipSmoothSharp,
|
||||
MouseDown,
|
||||
Delete,
|
||||
@@ -188,7 +186,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
|
||||
BreakPath,
|
||||
DeleteAndBreakPath,
|
||||
),
|
||||
Dragging => actions!(PathToolMessageDiscriminant;
|
||||
PathToolFsmState::Dragging => actions!(PathToolMessageDiscriminant;
|
||||
Escape,
|
||||
RightClick,
|
||||
FlipSmoothSharp,
|
||||
@@ -198,7 +196,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
|
||||
BreakPath,
|
||||
DeleteAndBreakPath,
|
||||
),
|
||||
DrawingBox => actions!(PathToolMessageDiscriminant;
|
||||
PathToolFsmState::DrawingBox => actions!(PathToolMessageDiscriminant;
|
||||
FlipSmoothSharp,
|
||||
DragStop,
|
||||
PointerMove,
|
||||
@@ -209,7 +207,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
|
||||
Escape,
|
||||
RightClick,
|
||||
),
|
||||
InsertPoint => actions!(PathToolMessageDiscriminant;
|
||||
PathToolFsmState::InsertPoint => actions!(PathToolMessageDiscriminant;
|
||||
Enter,
|
||||
MouseDown,
|
||||
PointerMove,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::consts::LINE_ROTATE_SNAP_ANGLE;
|
||||
use crate::messages::portfolio::document::node_graph::VectorDataModification;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::VectorDataModification;
|
||||
use crate::messages::portfolio::document::overlays::utility_functions::path_overlays;
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
@@ -41,7 +41,7 @@ impl Default for PenOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Pen)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum PenToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -68,7 +68,7 @@ enum PenToolFsmState {
|
||||
PlacingAnchor,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum PenOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -217,12 +217,10 @@ impl PenToolData {
|
||||
let first_or_last = if from_start { manipulator_groups.first() } else { manipulator_groups.last() };
|
||||
let Some(last_handle) = first_or_last else { return };
|
||||
let id = last_handle.id;
|
||||
let modification = VectorDataModification::SetManipulatorColinearHandlesState { id, colinear: false };
|
||||
|
||||
// Stop the handles on the first point from being colinear
|
||||
responses.add(GraphOperationMessage::Vector {
|
||||
layer,
|
||||
modification: VectorDataModification::SetManipulatorColinearHandlesState { id, colinear: false },
|
||||
});
|
||||
responses.add(GraphOperationMessage::Vector { layer, modification });
|
||||
}
|
||||
|
||||
fn create_new_path(
|
||||
|
||||
@@ -39,7 +39,7 @@ impl Default for PolygonOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Polygon)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum PolygonToolMessage {
|
||||
// Standard messages
|
||||
Overlays(OverlayContext),
|
||||
@@ -54,13 +54,13 @@ pub enum PolygonToolMessage {
|
||||
UpdateOptions(PolygonOptionsUpdate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Copy, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum PolygonType {
|
||||
Convex = 0,
|
||||
Star = 1,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum PolygonOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -182,14 +182,12 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Polygon
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use PolygonToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(PolygonToolMessageDiscriminant;
|
||||
PolygonToolFsmState::Ready => actions!(PolygonToolMessageDiscriminant;
|
||||
DragStart,
|
||||
PointerMove,
|
||||
),
|
||||
Drawing => actions!(PolygonToolMessageDiscriminant;
|
||||
PolygonToolFsmState::Drawing => actions!(PolygonToolMessageDiscriminant;
|
||||
DragStop,
|
||||
Abort,
|
||||
PointerMove,
|
||||
|
||||
@@ -34,7 +34,7 @@ impl Default for RectangleToolOptions {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum RectangleOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -45,7 +45,7 @@ pub enum RectangleOptionsUpdate {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Rectangle)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum RectangleToolMessage {
|
||||
// Standard messages
|
||||
Overlays(OverlayContext),
|
||||
@@ -127,14 +127,12 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Rectang
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use RectangleToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(RectangleToolMessageDiscriminant;
|
||||
RectangleToolFsmState::Ready => actions!(RectangleToolMessageDiscriminant;
|
||||
DragStart,
|
||||
PointerMove,
|
||||
),
|
||||
Drawing => actions!(RectangleToolMessageDiscriminant;
|
||||
RectangleToolFsmState::Drawing => actions!(RectangleToolMessageDiscriminant;
|
||||
DragStop,
|
||||
Abort,
|
||||
PointerMove,
|
||||
|
||||
@@ -4,6 +4,7 @@ use super::tool_prelude::*;
|
||||
use crate::application::generate_uuid;
|
||||
use crate::consts::{ROTATE_SNAP_ANGLE, SELECTION_TOLERANCE};
|
||||
use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis};
|
||||
@@ -31,12 +32,12 @@ pub struct SelectOptions {
|
||||
nested_selection_behavior: NestedSelectionBehavior,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum SelectOptionsUpdate {
|
||||
NestedSelectionBehavior(NestedSelectionBehavior),
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, Hash, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum NestedSelectionBehavior {
|
||||
#[default]
|
||||
Deepest,
|
||||
@@ -52,7 +53,7 @@ impl fmt::Display for NestedSelectionBehavior {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub struct SelectToolPointerKeys {
|
||||
pub axis_align: Key,
|
||||
pub snap_angle: Key,
|
||||
@@ -61,7 +62,7 @@ pub struct SelectToolPointerKeys {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Select)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum SelectToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -204,8 +205,6 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SelectT
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use SelectToolFsmState::*;
|
||||
|
||||
let mut common = actions!(SelectToolMessageDiscriminant;
|
||||
PointerMove,
|
||||
Abort,
|
||||
@@ -214,7 +213,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SelectT
|
||||
);
|
||||
|
||||
let additional = match self.fsm_state {
|
||||
Ready { .. } => actions!(SelectToolMessageDiscriminant; DragStart),
|
||||
SelectToolFsmState::Ready { .. } => actions!(SelectToolMessageDiscriminant; DragStart),
|
||||
_ => actions!(SelectToolMessageDiscriminant; DragStop),
|
||||
};
|
||||
common.extend(additional);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::consts::DRAG_THRESHOLD;
|
||||
use crate::messages::portfolio::document::node_graph::VectorDataModification;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::VectorDataModification;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
|
||||
use crate::messages::tool::common_functionality::color_selector::{ToolColorOptions, ToolColorType};
|
||||
@@ -36,7 +36,7 @@ impl Default for SplineOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Spline)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum SplineToolMessage {
|
||||
// Standard messages
|
||||
CanvasTransformed,
|
||||
@@ -60,7 +60,7 @@ enum SplineToolFsmState {
|
||||
Drawing,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum SplineOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -148,17 +148,15 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SplineT
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use SplineToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(SplineToolMessageDiscriminant;
|
||||
SplineToolFsmState::Ready => actions!(SplineToolMessageDiscriminant;
|
||||
Undo,
|
||||
DragStart,
|
||||
DragStop,
|
||||
Confirm,
|
||||
Abort,
|
||||
),
|
||||
Drawing => actions!(SplineToolMessageDiscriminant;
|
||||
SplineToolFsmState::Drawing => actions!(SplineToolMessageDiscriminant;
|
||||
DragStop,
|
||||
PointerMove,
|
||||
Confirm,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use super::tool_prelude::*;
|
||||
use crate::application::generate_uuid;
|
||||
use crate::consts::{DEFAULT_FONT_FAMILY, DEFAULT_FONT_STYLE};
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||
use crate::messages::tool::common_functionality::color_selector::{ToolColorOptions, ToolColorType};
|
||||
@@ -41,7 +42,7 @@ impl Default for TextOptions {
|
||||
}
|
||||
|
||||
#[impl_message(Message, ToolMessage, Text)]
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum TextToolMessage {
|
||||
// Standard messages
|
||||
Abort,
|
||||
@@ -57,7 +58,7 @@ pub enum TextToolMessage {
|
||||
UpdateOptions(TextOptionsUpdate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub enum TextOptionsUpdate {
|
||||
FillColor(Option<Color>),
|
||||
FillColorType(ToolColorType),
|
||||
@@ -163,13 +164,11 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for TextToo
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
use TextToolFsmState::*;
|
||||
|
||||
match self.fsm_state {
|
||||
Ready => actions!(TextToolMessageDiscriminant;
|
||||
TextToolFsmState::Ready => actions!(TextToolMessageDiscriminant;
|
||||
Interact,
|
||||
),
|
||||
Editing => actions!(TextToolMessageDiscriminant;
|
||||
TextToolFsmState::Editing => actions!(TextToolMessageDiscriminant;
|
||||
Interact,
|
||||
Abort,
|
||||
CommitText,
|
||||
|
||||
Reference in New Issue
Block a user