mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 10:28:11 +08:00
Event broadcasting system (#692)
* broadcast system implemented but not everywhere * unused types * code review with keavon * - optional signal mappings - tool.rs simplification * Cleanup * reduced code duplication in `tool.rs` * ran cargo fmt * code review changes * fix merge error Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
c343aaa3ab
commit
a6c91204d6
@@ -6,7 +6,7 @@ use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::SnapHandler;
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::intersection::Quad;
|
||||
|
||||
@@ -41,6 +41,18 @@ pub enum ArtboardToolMessage {
|
||||
PointerUp,
|
||||
}
|
||||
|
||||
impl ToolMetadata for ArtboardTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"GeneralArtboardTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Artboard Tool".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Artboard
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for ArtboardTool {
|
||||
fn process_action(&mut self, action: ToolMessage, data: ToolActionHandlerData<'a>, responses: &mut VecDeque<Message>) {
|
||||
if action == ToolMessage::UpdateHints {
|
||||
@@ -66,6 +78,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for ArtboardTool
|
||||
|
||||
impl PropertyHolder for ArtboardTool {}
|
||||
|
||||
impl ToolTransition for ArtboardTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: Some(ArtboardToolMessage::DocumentIsDirty.into()),
|
||||
tool_abort: Some(ArtboardToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum ArtboardToolFsmState {
|
||||
Ready,
|
||||
@@ -168,7 +190,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
|
||||
let intersection = document.artboard_message_handler.artboards_graphene_document.intersects_quad_root(quad, font_cache);
|
||||
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
if let Some(intersection) = intersection.last() {
|
||||
tool_data.selected_board = Some(intersection[0]);
|
||||
|
||||
@@ -229,7 +251,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
.into(),
|
||||
);
|
||||
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
}
|
||||
}
|
||||
ArtboardToolFsmState::ResizingBounds
|
||||
@@ -257,7 +279,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
.into(),
|
||||
);
|
||||
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
|
||||
tool_data.drag_current = mouse_position + closest_move;
|
||||
}
|
||||
@@ -303,7 +325,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
.into(),
|
||||
);
|
||||
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
|
||||
ArtboardToolFsmState::Drawing
|
||||
}
|
||||
@@ -333,7 +355,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
bounds.original_transforms.clear();
|
||||
}
|
||||
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
|
||||
ArtboardToolFsmState::Ready
|
||||
}
|
||||
@@ -349,7 +371,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
(_, ArtboardToolMessage::DeleteSelected) => {
|
||||
if let Some(artboard) = tool_data.selected_board.take() {
|
||||
responses.push_back(ArtboardMessage::DeleteArtboard { artboard }.into());
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
}
|
||||
ArtboardToolFsmState::Ready
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::input::keyboard::{Key, MouseMotion};
|
||||
use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::layers::style;
|
||||
use graphene::Operation;
|
||||
@@ -36,6 +36,18 @@ pub enum EllipseToolMessage {
|
||||
},
|
||||
}
|
||||
|
||||
impl ToolMetadata for EllipseTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorEllipseTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Ellipse Tool (E)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Ellipse
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for EllipseTool {}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for EllipseTool {
|
||||
@@ -69,6 +81,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for EllipseTool
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for EllipseTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(EllipseToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum EllipseToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::input::keyboard::MouseMotion;
|
||||
use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::intersection::Quad;
|
||||
use graphene::layers::layer_info::LayerDataType;
|
||||
@@ -31,6 +31,18 @@ pub enum EyedropperToolMessage {
|
||||
RightMouseDown,
|
||||
}
|
||||
|
||||
impl ToolMetadata for EyedropperTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"GeneralEyedropperTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Eyedropper Tool (I)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Eyedropper
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for EyedropperTool {}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for EyedropperTool {
|
||||
@@ -57,6 +69,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for EyedropperTo
|
||||
advertise_actions!(EyedropperToolMessageDiscriminant; LeftMouseDown, RightMouseDown);
|
||||
}
|
||||
|
||||
impl ToolTransition for EyedropperTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(EyedropperToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum EyedropperToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::input::keyboard::MouseMotion;
|
||||
use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::intersection::Quad;
|
||||
use graphene::Operation;
|
||||
@@ -32,6 +32,18 @@ pub enum FillToolMessage {
|
||||
RightMouseDown,
|
||||
}
|
||||
|
||||
impl ToolMetadata for FillTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"GeneralFillTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Fill Tool (F)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Fill
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for FillTool {}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for FillTool {
|
||||
@@ -58,6 +70,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for FillTool {
|
||||
advertise_actions!(FillToolMessageDiscriminant; LeftMouseDown, RightMouseDown);
|
||||
}
|
||||
|
||||
impl ToolTransition for FillTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(FillToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum FillToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::input::keyboard::MouseMotion;
|
||||
use crate::layout::widgets::{Layout, LayoutGroup, NumberInput, PropertyHolder, Widget, WidgetCallback, WidgetHolder, WidgetLayout};
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo};
|
||||
use crate::viewport_tools::tool::{DocumentToolData, Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{DocumentToolData, Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::layers::style;
|
||||
use graphene::Operation;
|
||||
@@ -55,6 +55,18 @@ enum FreehandToolFsmState {
|
||||
Drawing,
|
||||
}
|
||||
|
||||
impl ToolMetadata for FreehandTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorFreehandTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Freehand Tool (N)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Freehand
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for FreehandTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -109,6 +121,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for FreehandTool
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for FreehandTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(FreehandToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FreehandToolFsmState {
|
||||
fn default() -> Self {
|
||||
FreehandToolFsmState::Ready
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::layout::widgets::{Layout, LayoutGroup, PropertyHolder, RadioEntryData
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::SnapHandler;
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::color::Color;
|
||||
use graphene::intersection::Quad;
|
||||
@@ -60,6 +60,18 @@ pub enum GradientOptionsUpdate {
|
||||
Type(GradientType),
|
||||
}
|
||||
|
||||
impl ToolMetadata for GradientTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"GeneralGradientTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Gradient Tool (H))".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Gradient
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for GradientTool {
|
||||
fn process_action(&mut self, action: ToolMessage, data: ToolActionHandlerData<'a>, responses: &mut VecDeque<Message>) {
|
||||
if action == ToolMessage::UpdateHints {
|
||||
@@ -284,6 +296,16 @@ impl SelectedGradient {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for GradientTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: Some(GradientToolMessage::DocumentIsDirty.into()),
|
||||
tool_abort: Some(GradientToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct GradientToolData {
|
||||
gradient_overlays: Vec<GradientOverlay>,
|
||||
@@ -332,7 +354,7 @@ impl Fsm for GradientToolFsmState {
|
||||
self
|
||||
}
|
||||
(GradientToolFsmState::Ready, GradientToolMessage::PointerDown) => {
|
||||
responses.push_back(ToolMessage::DocumentIsDirty.into());
|
||||
responses.push_back(BroadcastSignal::DocumentIsDirty.into());
|
||||
|
||||
let mouse = input.mouse.position;
|
||||
let tolerance = VECTOR_MANIPULATOR_ANCHOR_MARKER_SIZE.powi(2);
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::layout::widgets::{Layout, LayoutGroup, NumberInput, PropertyHolder, W
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::SnapHandler;
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::layers::style;
|
||||
use graphene::Operation;
|
||||
@@ -56,6 +56,18 @@ pub enum LineOptionsUpdate {
|
||||
LineWeight(f64),
|
||||
}
|
||||
|
||||
impl ToolMetadata for LineTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorLineTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Line Tool (L)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Line
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for LineTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -110,6 +122,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for LineTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for LineTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(LineToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum LineToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::input::keyboard::{Key, MouseMotion};
|
||||
use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use glam::DVec2;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -36,6 +36,18 @@ pub enum NavigateToolMessage {
|
||||
ZoomCanvasBegin,
|
||||
}
|
||||
|
||||
impl ToolMetadata for NavigateTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"GeneralNavigateTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Navigate Tool (Z)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Navigate
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for NavigateTool {}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for NavigateTool {
|
||||
@@ -69,6 +81,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for NavigateTool
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for NavigateTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(NavigateToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum NavigateToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::SnapHandler;
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
use crate::viewport_tools::vector_editor::shape_editor::ShapeEditor;
|
||||
|
||||
use graphene::intersection::Quad;
|
||||
@@ -42,6 +42,18 @@ pub enum PathToolMessage {
|
||||
},
|
||||
}
|
||||
|
||||
impl ToolMetadata for PathTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorPathTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Path Tool (A)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Path
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for PathTool {}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for PathTool {
|
||||
@@ -76,6 +88,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for PathTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for PathTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: Some(PathToolMessage::DocumentIsDirty.into()),
|
||||
tool_abort: Some(PathToolMessage::Abort.into()),
|
||||
selection_changed: Some(PathToolMessage::SelectionChanged.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum PathToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::layout::widgets::{Layout, LayoutGroup, NumberInput, PropertyHolder, W
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::SnapHandler;
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
use crate::viewport_tools::vector_editor::constants::ControlPointType;
|
||||
use crate::viewport_tools::vector_editor::shape_editor::ShapeEditor;
|
||||
use crate::viewport_tools::vector_editor::vector_shape::VectorShape;
|
||||
@@ -67,6 +67,18 @@ pub enum PenOptionsUpdate {
|
||||
LineWeight(f64),
|
||||
}
|
||||
|
||||
impl ToolMetadata for PenTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorPenTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Pen Tool (P)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Pen
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for PenTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -121,6 +133,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for PenTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for PenTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: Some(PenToolMessage::DocumentIsDirty.into()),
|
||||
tool_abort: Some(PenToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PenToolFsmState {
|
||||
fn default() -> Self {
|
||||
PenToolFsmState::Ready
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::input::keyboard::{Key, MouseMotion};
|
||||
use crate::layout::widgets::PropertyHolder;
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::layers::style;
|
||||
use graphene::Operation;
|
||||
@@ -69,6 +69,28 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for RectangleToo
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolMetadata for RectangleTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorRectangleTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Rectangle Tool (M)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Rectangle
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for RectangleTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(RectangleToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum RectangleToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::layout::widgets::{IconButton, Layout, LayoutGroup, PopoverButton, Pro
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::{self, SnapHandler};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData, ToolType};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
use graphene::boolean_ops::BooleanOperation;
|
||||
use graphene::document::Document;
|
||||
use graphene::intersection::Quad;
|
||||
@@ -56,6 +56,18 @@ pub enum SelectToolMessage {
|
||||
},
|
||||
}
|
||||
|
||||
impl ToolMetadata for SelectTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"GeneralSelectTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Select Tool (V)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Select
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for SelectTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -258,6 +270,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for SelectTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for SelectTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: Some(SelectToolMessage::DocumentIsDirty.into()),
|
||||
tool_abort: Some(SelectToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
enum SelectToolFsmState {
|
||||
Ready,
|
||||
@@ -317,6 +339,7 @@ impl Fsm for SelectToolFsmState {
|
||||
use SelectToolMessage::*;
|
||||
|
||||
if let ToolMessage::Select(event) = event {
|
||||
log::debug!("self: {:?}, even: {:?}", self, event);
|
||||
match (self, event) {
|
||||
(_, DocumentIsDirty) => {
|
||||
let mut buffer = Vec::new();
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::input::keyboard::{Key, MouseMotion};
|
||||
use crate::layout::widgets::{Layout, LayoutGroup, NumberInput, PropertyHolder, Widget, WidgetCallback, WidgetHolder, WidgetLayout};
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::layers::style;
|
||||
use graphene::Operation;
|
||||
@@ -54,6 +54,18 @@ pub enum ShapeOptionsUpdate {
|
||||
Vertices(u32),
|
||||
}
|
||||
|
||||
impl ToolMetadata for ShapeTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorShapeTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Shape Tool (Y)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Shape
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for ShapeTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -108,6 +120,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for ShapeTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for ShapeTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(ShapeToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum ShapeToolFsmState {
|
||||
Ready,
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::layout::widgets::{Layout, LayoutGroup, NumberInput, PropertyHolder, W
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::snapping::SnapHandler;
|
||||
use crate::viewport_tools::tool::{DocumentToolData, Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{DocumentToolData, Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::layers::style;
|
||||
use graphene::Operation;
|
||||
@@ -59,6 +59,18 @@ pub enum SplineOptionsUpdate {
|
||||
LineWeight(f64),
|
||||
}
|
||||
|
||||
impl ToolMetadata for SplineTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorSplineTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Spline Tool".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Spline
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for SplineTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -113,6 +125,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for SplineTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for SplineTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: None,
|
||||
tool_abort: Some(SplineToolMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SplineToolFsmState {
|
||||
fn default() -> Self {
|
||||
SplineToolFsmState::Ready
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::layout::layout_message::LayoutTarget;
|
||||
use crate::layout::widgets::{FontInput, Layout, LayoutGroup, NumberInput, PropertyHolder, Separator, SeparatorDirection, SeparatorType, Widget, WidgetCallback, WidgetHolder, WidgetLayout};
|
||||
use crate::message_prelude::*;
|
||||
use crate::misc::{HintData, HintGroup, HintInfo, KeysGroup};
|
||||
use crate::viewport_tools::tool::{Fsm, ToolActionHandlerData};
|
||||
use crate::viewport_tools::tool::{Fsm, SignalToMessageMap, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
|
||||
use graphene::intersection::Quad;
|
||||
use graphene::layers::style::{self, Fill, Stroke};
|
||||
@@ -70,6 +70,18 @@ pub enum TextOptionsUpdate {
|
||||
FontSize(u32),
|
||||
}
|
||||
|
||||
impl ToolMetadata for TextTool {
|
||||
fn icon_name(&self) -> String {
|
||||
"VectorTextTool".into()
|
||||
}
|
||||
fn tooltip(&self) -> String {
|
||||
"Text Tool (T)".into()
|
||||
}
|
||||
fn tool_type(&self) -> crate::viewport_tools::tool::ToolType {
|
||||
ToolType::Text
|
||||
}
|
||||
}
|
||||
|
||||
impl PropertyHolder for TextTool {
|
||||
fn properties(&self) -> Layout {
|
||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
|
||||
@@ -164,6 +176,16 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for TextTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolTransition for TextTool {
|
||||
fn signal_to_message_map(&self) -> SignalToMessageMap {
|
||||
SignalToMessageMap {
|
||||
document_dirty: Some(TextMessage::DocumentIsDirty.into()),
|
||||
tool_abort: Some(TextMessage::Abort.into()),
|
||||
selection_changed: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum TextToolFsmState {
|
||||
Ready,
|
||||
|
||||
Reference in New Issue
Block a user