Rename Shape tool to Polygon tool

This commit is contained in:
Keavon Chambers 2023-08-01 01:28:14 -07:00
parent b9e49623a3
commit 2b05e1c270
15 changed files with 104 additions and 106 deletions

View File

@ -95,7 +95,7 @@ Spline Tool | <kbd> </kbd> | <kbd>P</kbd> |
Line Tool | <kbd>L</kbd> | <kbd>U</kbd> | <kbd>\\</kbd> | **<kbd>L</kbd>** | <kbd>P</kbd> | | |
Rectangle Tool | <kbd>M</kbd> | <kbd>U</kbd>/**<kbd>M</kbd>** | **<kbd>M</kbd>** | <kbd>R</kbd> | **<kbd>M</kbd>** | | |
Ellipse Tool | <kbd>E</kbd> | <kbd>U</kbd>/<kbd>M</kbd> | <kbd>L</kbd> | **<kbd>E</kbd>** | <kbd>M</kbd> | | |
Shape Tool | <kbd>Y</kbd> | <kbd>U</kbd> | | **<kbd>Y</kbd>** | | | |
Polygon Tool | <kbd>Y</kbd> | <kbd>U</kbd> | | **<kbd>Y</kbd>** | | | |
Text Tool | <kbd>T</kbd> | **<kbd>T</kbd>** | **<kbd>T</kbd>** | **<kbd>T</kbd>** | **<kbd>T</kbd>** | | |
Brush Tool | <kbd>B</kbd> | **<kbd>B</kbd>** | **<kbd>B</kbd>** | | **<kbd>B</kbd>** | | |
Heal Tool | <kbd>J</kbd> | **<kbd>J</kbd>** | | | | | |
@ -138,7 +138,7 @@ Excluding mouse inputs and modifier keys.
##### Ellipse Tool
##### Shape Tool
##### Polygon Tool
##### Text Tool

View File

@ -6,10 +6,8 @@ pub enum DocumentError {
LayerNotFound(Vec<LayerId>),
InvalidPath,
IndexOutOfBounds,
NotAFolder,
NonReorderableSelection,
NotFolder,
NotShape,
NotText,
NotNodeGraph,
NotLayer,
InvalidFile(String),
}

View File

@ -20,7 +20,7 @@ use std::fmt::Write;
pub enum LayerDataType {
/// A layer that wraps a [FolderLayer] struct.
Folder(FolderLayer),
/// A layer that wraps a [ShapeLayer] struct.
/// A layer that wraps a [ShapeLayer] struct. Still used by the overlays system, but will be removed in the future.
Shape(ShapeLayer),
/// A layer that wraps an [LayerLayer] struct.
Layer(LayerLayer),
@ -438,7 +438,7 @@ impl Layer {
pub fn as_folder_mut(&mut self) -> Result<&mut FolderLayer, DocumentError> {
match &mut self.data {
LayerDataType::Folder(f) => Ok(f),
_ => Err(DocumentError::NotAFolder),
_ => Err(DocumentError::NotFolder),
}
}
@ -461,7 +461,7 @@ impl Layer {
pub fn as_folder(&self) -> Result<&FolderLayer, DocumentError> {
match &self.data {
LayerDataType::Folder(f) => Ok(f),
_ => Err(DocumentError::NotAFolder),
_ => Err(DocumentError::NotFolder),
}
}
@ -470,7 +470,7 @@ impl Layer {
pub fn as_layer_network_mut(&mut self) -> Result<&mut graph_craft::document::NodeNetwork, DocumentError> {
match &mut self.data {
LayerDataType::Layer(layer) => Ok(&mut layer.network),
_ => Err(DocumentError::NotNodeGraph),
_ => Err(DocumentError::NotLayer),
}
}
@ -479,14 +479,14 @@ impl Layer {
pub fn as_layer_network(&self) -> Result<&graph_craft::document::NodeNetwork, DocumentError> {
match &self.data {
LayerDataType::Layer(layer) => Ok(&layer.network),
_ => Err(DocumentError::NotNodeGraph),
_ => Err(DocumentError::NotLayer),
}
}
pub fn as_layer(&self) -> Result<&LayerLayer, DocumentError> {
match &self.data {
LayerDataType::Layer(layer) => Ok(layer),
_ => Err(DocumentError::NotNodeGraph),
_ => Err(DocumentError::NotLayer),
}
}

View File

@ -3,8 +3,8 @@
//! Layers allow the user to mutate part of the document while leaving the rest unchanged.
//! There are currently these different types of layers:
//! * [Folder layers](folder_layer::FolderLayer), which encapsulate sub-layers
//! * [Shape layers](shape_layer::ShapeLayer), which contain generic SVG [`<path>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path)s
//! * [Layer layers](layer_layer::NodegraphLayer), which contain a node graph layer
//! * [Shape layers](shape_layer::ShapeLayer), which contain generic SVG [`<path>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path)s (deprecated but still used by the overlays system).
//! * [Layer layers](layer_layer::LayerLayer), which contain a node graph layer
//!
//! Refer to the module-level documentation for detailed information on each layer.
//!
@ -20,7 +20,7 @@ pub mod blend_mode;
pub mod folder_layer;
/// Contains the base [Layer](layer_info::Layer) type, an abstraction over the different types of layers.
pub mod layer_info;
/// Contains the [NodegraphLayer](nodegraph_layer::NodegraphLayer) type that contains a node graph.
/// Contains the [LayerLayer](nodegraph_layer::LayerLayer) type that contains a node graph.
pub mod layer_layer;
// TODO: Remove shape layers after rewriting the overlay system
/// Contains the [ShapeLayer](shape_layer::ShapeLayer) type, a generic SVG element defined using Bezier paths.

View File

@ -282,7 +282,7 @@ mod test {
editor.draw_rect(100., 200., 300., 400.);
editor.select_primary_color(Color::BLUE);
editor.draw_shape(10., 1200., 1300., 400.);
editor.draw_polygon(10., 1200., 1300., 400.);
editor.select_primary_color(Color::GREEN);
editor.draw_ellipse(104., 1200., 1300., 400.);

View File

@ -159,12 +159,12 @@ pub fn default_mapping() -> Mapping {
entry!(KeyDown(Escape); action_dispatch=EllipseToolMessage::Abort),
entry!(PointerMove; refresh_keys=[Alt, Shift], action_dispatch=EllipseToolMessage::Resize { center: Alt, lock_ratio: Shift }),
//
// ShapeToolMessage
entry!(KeyDown(Lmb); action_dispatch=ShapeToolMessage::DragStart),
entry!(KeyUp(Lmb); action_dispatch=ShapeToolMessage::DragStop),
entry!(KeyDown(Rmb); action_dispatch=ShapeToolMessage::Abort),
entry!(KeyDown(Escape); action_dispatch=ShapeToolMessage::Abort),
entry!(PointerMove; refresh_keys=[Alt, Shift], action_dispatch=ShapeToolMessage::Resize { center: Alt, lock_ratio: Shift }),
// PolygonToolMessage
entry!(KeyDown(Lmb); action_dispatch=PolygonToolMessage::DragStart),
entry!(KeyUp(Lmb); action_dispatch=PolygonToolMessage::DragStop),
entry!(KeyDown(Rmb); action_dispatch=PolygonToolMessage::Abort),
entry!(KeyDown(Escape); action_dispatch=PolygonToolMessage::Abort),
entry!(PointerMove; refresh_keys=[Alt, Shift], action_dispatch=PolygonToolMessage::Resize { center: Alt, lock_ratio: Shift }),
//
// LineToolMessage
entry!(KeyDown(Lmb); action_dispatch=LineToolMessage::DragStart),
@ -253,7 +253,7 @@ pub fn default_mapping() -> Mapping {
entry!(KeyDown(KeyL); action_dispatch=ToolMessage::ActivateToolLine),
entry!(KeyDown(KeyM); action_dispatch=ToolMessage::ActivateToolRectangle),
entry!(KeyDown(KeyE); action_dispatch=ToolMessage::ActivateToolEllipse),
entry!(KeyDown(KeyY); action_dispatch=ToolMessage::ActivateToolShape),
entry!(KeyDown(KeyY); action_dispatch=ToolMessage::ActivateToolPolygon),
entry!(KeyDown(KeyB); action_dispatch=ToolMessage::ActivateToolBrush),
entry!(KeyDown(KeyX); modifiers=[Shift, Accel], action_dispatch=ToolMessage::ResetColors),
entry!(KeyDown(KeyX); modifiers=[Shift], action_dispatch=ToolMessage::SwapColors),

View File

@ -44,9 +44,9 @@ pub use crate::messages::tool::tool_messages::line_tool::{LineToolMessage, LineT
pub use crate::messages::tool::tool_messages::navigate_tool::{NavigateToolMessage, NavigateToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::path_tool::{PathToolMessage, PathToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::pen_tool::{PenToolMessage, PenToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::polygon_tool::{PolygonToolMessage, PolygonToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::rectangle_tool::{RectangleToolMessage, RectangleToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::select_tool::{SelectToolMessage, SelectToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::shape_tool::{ShapeToolMessage, ShapeToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::spline_tool::{SplineToolMessage, SplineToolMessageDiscriminant};
pub use crate::messages::tool::tool_messages::text_tool::{TextToolMessage, TextToolMessageDiscriminant};

View File

@ -56,7 +56,7 @@ pub enum ToolMessage {
Ellipse(EllipseToolMessage),
#[remain::unsorted]
#[child]
Shape(ShapeToolMessage),
Polygon(PolygonToolMessage),
#[remain::unsorted]
#[child]
Text(TextToolMessage),
@ -117,7 +117,7 @@ pub enum ToolMessage {
#[remain::unsorted]
ActivateToolEllipse,
#[remain::unsorted]
ActivateToolShape,
ActivateToolPolygon,
#[remain::unsorted]
ActivateToolBrush,

View File

@ -67,7 +67,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
#[remain::unsorted]
ToolMessage::ActivateToolEllipse => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Ellipse }),
#[remain::unsorted]
ToolMessage::ActivateToolShape => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Shape }),
ToolMessage::ActivateToolPolygon => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Polygon }),
#[remain::unsorted]
ToolMessage::ActivateToolBrush => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Brush }),
@ -282,7 +282,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
ActivateToolLine,
ActivateToolRectangle,
ActivateToolEllipse,
ActivateToolShape,
ActivateToolPolygon,
ActivateToolBrush,
ActivateToolImaginate,

View File

@ -11,8 +11,8 @@ pub mod line_tool;
pub mod navigate_tool;
pub mod path_tool;
pub mod pen_tool;
pub mod polygon_tool;
pub mod rectangle_tool;
pub mod select_tool;
pub mod shape_tool;
pub mod spline_tool;
pub mod text_tool;

View File

@ -15,13 +15,13 @@ use glam::DVec2;
use serde::{Deserialize, Serialize};
#[derive(Default)]
pub struct ShapeTool {
fsm_state: ShapeToolFsmState,
tool_data: ShapeToolData,
options: ShapeOptions,
pub struct PolygonTool {
fsm_state: PolygonToolFsmState,
tool_data: PolygonToolData,
options: PolygonOptions,
}
pub struct ShapeOptions {
pub struct PolygonOptions {
line_weight: f64,
fill: ToolColorOptions,
stroke: ToolColorOptions,
@ -29,7 +29,7 @@ pub struct ShapeOptions {
primitive_shape_type: PrimitiveShapeType,
}
impl Default for ShapeOptions {
impl Default for PolygonOptions {
fn default() -> Self {
Self {
vertices: 5,
@ -42,9 +42,9 @@ impl Default for ShapeOptions {
}
#[remain::sorted]
#[impl_message(Message, ToolMessage, Shape)]
#[impl_message(Message, ToolMessage, Polygon)]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
pub enum ShapeToolMessage {
pub enum PolygonToolMessage {
// Standard messages
#[remain::unsorted]
Abort,
@ -58,7 +58,7 @@ pub enum ShapeToolMessage {
center: Key,
lock_ratio: Key,
},
UpdateOptions(ShapeOptionsUpdate),
UpdateOptions(PolygonOptionsUpdate),
}
#[derive(PartialEq, Copy, Clone, Debug, Serialize, Deserialize, specta::Type)]
@ -69,7 +69,7 @@ pub enum PrimitiveShapeType {
#[remain::sorted]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
pub enum ShapeOptionsUpdate {
pub enum PolygonOptionsUpdate {
FillColor(Option<Color>),
FillColorType(ToolColorType),
LineWeight(f64),
@ -80,15 +80,15 @@ pub enum ShapeOptionsUpdate {
WorkingColors(Option<Color>, Option<Color>),
}
impl ToolMetadata for ShapeTool {
impl ToolMetadata for PolygonTool {
fn icon_name(&self) -> String {
"VectorShapeTool".into()
"VectorPolygonTool".into()
}
fn tooltip(&self) -> String {
"Shape Tool".into()
"Polygon Tool".into()
}
fn tool_type(&self) -> crate::messages::tool::utility_types::ToolType {
ToolType::Shape
ToolType::Polygon
}
}
@ -99,14 +99,14 @@ fn create_sides_widget(vertices: u32) -> WidgetHolder {
.min(3.)
.max(1000.)
.mode(NumberInputMode::Increment)
.on_update(|number_input: &NumberInput| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::Vertices(number_input.value.unwrap() as u32)).into())
.on_update(|number_input: &NumberInput| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::Vertices(number_input.value.unwrap() as u32)).into())
.widget_holder()
}
fn create_star_option_widget(primitive_shape_type: PrimitiveShapeType) -> WidgetHolder {
let entries = vec![
RadioEntryData::new("Polygon").on_update(move |_| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::PrimitiveShapeType(PrimitiveShapeType::Polygon)).into()),
RadioEntryData::new("Star").on_update(move |_| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::PrimitiveShapeType(PrimitiveShapeType::Star)).into()),
RadioEntryData::new("Polygon").on_update(move |_| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::PrimitiveShapeType(PrimitiveShapeType::Polygon)).into()),
RadioEntryData::new("Star").on_update(move |_| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::PrimitiveShapeType(PrimitiveShapeType::Star)).into()),
];
RadioInput::new(entries).selected_index(primitive_shape_type as u32).widget_holder()
}
@ -116,11 +116,11 @@ fn create_weight_widget(line_weight: f64) -> WidgetHolder {
.unit(" px")
.label("Weight")
.min(0.)
.on_update(|number_input: &NumberInput| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::LineWeight(number_input.value.unwrap())).into())
.on_update(|number_input: &NumberInput| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::LineWeight(number_input.value.unwrap())).into())
.widget_holder()
}
impl LayoutHolder for ShapeTool {
impl LayoutHolder for PolygonTool {
fn layout(&self) -> Layout {
let mut widgets = vec![
create_star_option_widget(self.options.primitive_shape_type),
@ -133,9 +133,9 @@ impl LayoutHolder for ShapeTool {
widgets.append(&mut self.options.fill.create_widgets(
"Fill",
true,
|_| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::FillColor(None)).into(),
|color_type: ToolColorType| WidgetCallback::new(move |_| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::FillColorType(color_type.clone())).into()),
|color: &ColorInput| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::FillColor(color.value)).into(),
|_| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::FillColor(None)).into(),
|color_type: ToolColorType| WidgetCallback::new(move |_| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::FillColorType(color_type.clone())).into()),
|color: &ColorInput| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::FillColor(color.value)).into(),
));
widgets.push(Separator::new(SeparatorType::Section).widget_holder());
@ -143,9 +143,9 @@ impl LayoutHolder for ShapeTool {
widgets.append(&mut self.options.stroke.create_widgets(
"Stroke",
true,
|_| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::StrokeColor(None)).into(),
|color_type: ToolColorType| WidgetCallback::new(move |_| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::StrokeColorType(color_type.clone())).into()),
|color: &ColorInput| ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::StrokeColor(color.value)).into(),
|_| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::StrokeColor(None)).into(),
|color_type: ToolColorType| WidgetCallback::new(move |_| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::StrokeColorType(color_type.clone())).into()),
|color: &ColorInput| PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::StrokeColor(color.value)).into(),
));
widgets.push(Separator::new(SeparatorType::Unrelated).widget_holder());
widgets.push(create_weight_widget(self.options.line_weight));
@ -153,24 +153,24 @@ impl LayoutHolder for ShapeTool {
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
}
}
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for ShapeTool {
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PolygonTool {
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
if let ToolMessage::Shape(ShapeToolMessage::UpdateOptions(action)) = message {
if let ToolMessage::Polygon(PolygonToolMessage::UpdateOptions(action)) = message {
match action {
ShapeOptionsUpdate::Vertices(vertices) => self.options.vertices = vertices,
ShapeOptionsUpdate::PrimitiveShapeType(primitive_shape_type) => self.options.primitive_shape_type = primitive_shape_type,
ShapeOptionsUpdate::FillColor(color) => {
PolygonOptionsUpdate::Vertices(vertices) => self.options.vertices = vertices,
PolygonOptionsUpdate::PrimitiveShapeType(primitive_shape_type) => self.options.primitive_shape_type = primitive_shape_type,
PolygonOptionsUpdate::FillColor(color) => {
self.options.fill.custom_color = color;
self.options.fill.color_type = ToolColorType::Custom;
}
ShapeOptionsUpdate::FillColorType(color_type) => self.options.fill.color_type = color_type,
ShapeOptionsUpdate::LineWeight(line_weight) => self.options.line_weight = line_weight,
ShapeOptionsUpdate::StrokeColor(color) => {
PolygonOptionsUpdate::FillColorType(color_type) => self.options.fill.color_type = color_type,
PolygonOptionsUpdate::LineWeight(line_weight) => self.options.line_weight = line_weight,
PolygonOptionsUpdate::StrokeColor(color) => {
self.options.stroke.custom_color = color;
self.options.stroke.color_type = ToolColorType::Custom;
}
ShapeOptionsUpdate::StrokeColorType(color_type) => self.options.stroke.color_type = color_type,
ShapeOptionsUpdate::WorkingColors(primary, secondary) => {
PolygonOptionsUpdate::StrokeColorType(color_type) => self.options.stroke.color_type = color_type,
PolygonOptionsUpdate::WorkingColors(primary, secondary) => {
self.options.stroke.primary_working_color = primary;
self.options.stroke.secondary_working_color = secondary;
self.options.fill.primary_working_color = primary;
@ -187,13 +187,13 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for ShapeTo
}
fn actions(&self) -> ActionList {
use ShapeToolFsmState::*;
use PolygonToolFsmState::*;
match self.fsm_state {
Ready => actions!(ShapeToolMessageDiscriminant;
Ready => actions!(PolygonToolMessageDiscriminant;
DragStart,
),
Drawing => actions!(ShapeToolMessageDiscriminant;
Drawing => actions!(PolygonToolMessageDiscriminant;
DragStop,
Abort,
Resize,
@ -202,31 +202,31 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for ShapeTo
}
}
impl ToolTransition for ShapeTool {
impl ToolTransition for PolygonTool {
fn event_to_message_map(&self) -> EventToMessageMap {
EventToMessageMap {
tool_abort: Some(ShapeToolMessage::Abort.into()),
working_color_changed: Some(ShapeToolMessage::WorkingColorChanged.into()),
tool_abort: Some(PolygonToolMessage::Abort.into()),
working_color_changed: Some(PolygonToolMessage::WorkingColorChanged.into()),
..Default::default()
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
enum ShapeToolFsmState {
enum PolygonToolFsmState {
#[default]
Ready,
Drawing,
}
#[derive(Clone, Debug, Default)]
struct ShapeToolData {
struct PolygonToolData {
data: Resize,
}
impl Fsm for ShapeToolFsmState {
type ToolData = ShapeToolData;
type ToolOptions = ShapeOptions;
impl Fsm for PolygonToolFsmState {
type ToolData = PolygonToolData;
type ToolOptions = PolygonOptions;
fn transition(
self,
@ -242,18 +242,18 @@ impl Fsm for ShapeToolFsmState {
tool_options: &Self::ToolOptions,
responses: &mut VecDeque<Message>,
) -> Self {
use ShapeToolFsmState::*;
use ShapeToolMessage::*;
use PolygonToolFsmState::*;
use PolygonToolMessage::*;
let shape_data = &mut tool_data.data;
let polygon_data = &mut tool_data.data;
if let ToolMessage::Shape(event) = event {
if let ToolMessage::Polygon(event) = event {
match (self, event) {
(Ready, DragStart) => {
shape_data.start(responses, document, input, render_data);
polygon_data.start(responses, document, input, render_data);
responses.add(DocumentMessage::StartTransaction);
let layer_path = document.get_path_for_new_layer();
shape_data.path = Some(layer_path.clone());
polygon_data.path = Some(layer_path.clone());
let subpath = match tool_options.primitive_shape_type {
PrimitiveShapeType::Polygon => bezier_rs::Subpath::new_regular_polygon(DVec2::ZERO, tool_options.vertices as u64, 1.),
@ -275,27 +275,27 @@ impl Fsm for ShapeToolFsmState {
Drawing
}
(state, Resize { center, lock_ratio }) => {
if let Some(message) = shape_data.calculate_transform(responses, document, input, center, lock_ratio, false) {
if let Some(message) = polygon_data.calculate_transform(responses, document, input, center, lock_ratio, false) {
responses.add(message);
}
state
}
(Drawing, DragStop) => {
input.mouse.finish_transaction(shape_data.viewport_drag_start(document), responses);
shape_data.cleanup(responses);
input.mouse.finish_transaction(polygon_data.viewport_drag_start(document), responses);
polygon_data.cleanup(responses);
Ready
}
(Drawing, Abort) => {
responses.add(DocumentMessage::AbortTransaction);
shape_data.cleanup(responses);
polygon_data.cleanup(responses);
Ready
}
(_, WorkingColorChanged) => {
responses.add(ShapeToolMessage::UpdateOptions(ShapeOptionsUpdate::WorkingColors(
responses.add(PolygonToolMessage::UpdateOptions(PolygonOptionsUpdate::WorkingColors(
Some(global_tool_data.primary_color),
Some(global_tool_data.secondary_color),
)));
@ -310,12 +310,12 @@ impl Fsm for ShapeToolFsmState {
fn update_hints(&self, responses: &mut VecDeque<Message>) {
let hint_data = match self {
ShapeToolFsmState::Ready => HintData(vec![HintGroup(vec![
HintInfo::mouse(MouseMotion::LmbDrag, "Draw Shape"),
PolygonToolFsmState::Ready => HintData(vec![HintGroup(vec![
HintInfo::mouse(MouseMotion::LmbDrag, "Draw Polygon"),
HintInfo::keys([Key::Shift], "Constrain 1:1 Aspect").prepend_plus(),
HintInfo::keys([Key::Alt], "From Center").prepend_plus(),
])]),
ShapeToolFsmState::Drawing => HintData(vec![HintGroup(vec![HintInfo::keys([Key::Shift], "Constrain 1:1 Aspect"), HintInfo::keys([Key::Alt], "From Center")])]),
PolygonToolFsmState::Drawing => HintData(vec![HintGroup(vec![HintInfo::keys([Key::Shift], "Constrain 1:1 Aspect"), HintInfo::keys([Key::Alt], "From Center")])]),
};
responses.add(FrontendMessage::UpdateInputHints { hint_data });

View File

@ -348,7 +348,7 @@ pub enum ToolType {
Line,
Rectangle,
Ellipse,
Shape,
Polygon,
Text,
// Raster tool group
@ -388,7 +388,7 @@ fn list_tools_in_groups() -> Vec<Vec<ToolAvailability>> {
ToolAvailability::Available(Box::<line_tool::LineTool>::default()),
ToolAvailability::Available(Box::<rectangle_tool::RectangleTool>::default()),
ToolAvailability::Available(Box::<ellipse_tool::EllipseTool>::default()),
ToolAvailability::Available(Box::<shape_tool::ShapeTool>::default()),
ToolAvailability::Available(Box::<polygon_tool::PolygonTool>::default()),
ToolAvailability::Available(Box::<text_tool::TextTool>::default()),
],
vec![
@ -423,7 +423,7 @@ pub fn tool_message_to_tool_type(tool_message: &ToolMessage) -> ToolType {
ToolMessage::Line(_) => ToolType::Line,
ToolMessage::Rectangle(_) => ToolType::Rectangle,
ToolMessage::Ellipse(_) => ToolType::Ellipse,
ToolMessage::Shape(_) => ToolType::Shape,
ToolMessage::Polygon(_) => ToolType::Polygon,
ToolMessage::Text(_) => ToolType::Text,
// Raster tool group
@ -460,7 +460,7 @@ pub fn tool_type_to_activate_tool_message(tool_type: ToolType) -> ToolMessageDis
ToolType::Line => ToolMessageDiscriminant::ActivateToolLine,
ToolType::Rectangle => ToolMessageDiscriminant::ActivateToolRectangle,
ToolType::Ellipse => ToolMessageDiscriminant::ActivateToolEllipse,
ToolType::Shape => ToolMessageDiscriminant::ActivateToolShape,
ToolType::Polygon => ToolMessageDiscriminant::ActivateToolPolygon,
ToolType::Text => ToolMessageDiscriminant::ActivateToolText,
// Raster tool group
@ -582,14 +582,14 @@ mod tool_crash_on_layer_delete_tests {
use test_case::test_case;
#[test_case(ToolType::Pen; "while using pen tool")]
#[test_case(ToolType::Freehand; "while using freehand tool")]
#[test_case(ToolType::Spline; "while using spline tool")]
#[test_case(ToolType::Line; "while using line tool")]
#[test_case(ToolType::Rectangle; "while using rectangle tool")]
#[test_case(ToolType::Ellipse; "while using ellipse tool")]
#[test_case(ToolType::Shape; "while using shape tool")]
#[test_case(ToolType::Path; "while using path tool")]
#[test_case(ToolType::Pen; "while using Pen tool")]
#[test_case(ToolType::Freehand; "while using Freehand tool")]
#[test_case(ToolType::Spline; "while using Spline tool")]
#[test_case(ToolType::Line; "while using Line tool")]
#[test_case(ToolType::Rectangle; "while using Rectangle tool")]
#[test_case(ToolType::Ellipse; "while using Ellipse tool")]
#[test_case(ToolType::Polygon; "while using Polygon tool")]
#[test_case(ToolType::Path; "while using Path tool")]
fn should_not_crash_when_layer_is_deleted(tool: ToolType) {
set_uuid_seed(0);
let mut test_editor = Editor::new();

View File

@ -15,7 +15,7 @@ pub trait EditorTestUtils {
fn new_document(&mut self);
fn draw_rect(&mut self, x1: f64, y1: f64, x2: f64, y2: f64);
fn draw_shape(&mut self, x1: f64, y1: f64, x2: f64, y2: f64);
fn draw_polygon(&mut self, x1: f64, y1: f64, x2: f64, y2: f64);
fn draw_ellipse(&mut self, x1: f64, y1: f64, x2: f64, y2: f64);
/// Select given tool and drag it from (x1, y1) to (x2, y2)
@ -52,8 +52,8 @@ impl EditorTestUtils for Editor {
self.drag_tool(ToolType::Rectangle, x1, y1, x2, y2);
}
fn draw_shape(&mut self, x1: f64, y1: f64, x2: f64, y2: f64) {
self.drag_tool(ToolType::Shape, x1, y1, x2, y2);
fn draw_polygon(&mut self, x1: f64, y1: f64, x2: f64, y2: f64) {
self.drag_tool(ToolType::Polygon, x1, y1, x2, y2);
}
fn draw_ellipse(&mut self, x1: f64, y1: f64, x2: f64, y2: f64) {

View File

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 273 B

View File

@ -251,7 +251,7 @@ import VectorLineTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-
import VectorPathTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-path-tool.svg";
import VectorPenTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-pen-tool.svg";
import VectorRectangleTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-rectangle-tool.svg";
import VectorShapeTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-shape-tool.svg";
import VectorPolygonTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-polygon-tool.svg";
import VectorSplineTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-spline-tool.svg";
import VectorTextTool from "@graphite-frontend/assets/icon-24px-two-tone/vector-text-tool.svg";
@ -276,7 +276,7 @@ const TWO_TONE_24PX = {
VectorPathTool: { svg: VectorPathTool, size: 24 },
VectorPenTool: { svg: VectorPenTool, size: 24 },
VectorRectangleTool: { svg: VectorRectangleTool, size: 24 },
VectorShapeTool: { svg: VectorShapeTool, size: 24 },
VectorPolygonTool: { svg: VectorPolygonTool, size: 24 },
VectorSplineTool: { svg: VectorSplineTool, size: 24 },
VectorTextTool: { svg: VectorTextTool, size: 24 },
} as const;