mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 10:58:04 +08:00
Add shape side selection with JSON deserialization
This commit is contained in:
@@ -179,7 +179,7 @@ impl ToolType {
|
||||
ToolType::Select => ToolSettings::Select { append_mode: SelectAppendMode::New },
|
||||
ToolType::Ellipse => ToolSettings::Ellipse,
|
||||
ToolType::Shape => ToolSettings::Shape {
|
||||
shape: Shape::Polygon { vertices: 3 },
|
||||
shape_type: ShapeType::Polygon { vertices: 6 },
|
||||
},
|
||||
_ => todo!(),
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ToolSettings {
|
||||
Select { append_mode: SelectAppendMode },
|
||||
Ellipse,
|
||||
Shape { shape: Shape },
|
||||
Shape { shape_type: ShapeType },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub enum SelectAppendMode {
|
||||
New,
|
||||
Add,
|
||||
@@ -13,8 +15,8 @@ pub enum SelectAppendMode {
|
||||
Intersect,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Shape {
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ShapeType {
|
||||
Star { vertices: u32 },
|
||||
Polygon { vertices: u32 },
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::input::{mouse::ViewportPosition, InputPreprocessor};
|
||||
use crate::tool::{DocumentToolData, Fsm, ToolActionHandlerData};
|
||||
use crate::tool::{DocumentToolData, Fsm, ShapeType, ToolActionHandlerData, ToolSettings, ToolType};
|
||||
use crate::{document::Document, message_prelude::*};
|
||||
use document_core::{layers::style, Operation};
|
||||
use glam::{DAffine2, DVec2};
|
||||
@@ -70,13 +70,13 @@ impl Fsm for ShapeToolFsmState {
|
||||
data.drag_start = input.mouse.position;
|
||||
data.drag_current = input.mouse.position;
|
||||
|
||||
data.sides = 6;
|
||||
if let Some(tool_settings) = tool_data.tool_settings.get(&crate::tool::ToolType::Shape) {
|
||||
if let crate::tool::ToolSettings::Shape { shape } = tool_settings {
|
||||
if let crate::tool::Shape::Polygon { vertices } = shape {
|
||||
data.sides = *vertices as u8;
|
||||
}
|
||||
}
|
||||
data.sides = if let Some(&ToolSettings::Shape {
|
||||
shape_type: ShapeType::Polygon { vertices },
|
||||
}) = tool_data.tool_settings.get(&ToolType::Shape)
|
||||
{
|
||||
vertices as u8
|
||||
} else {
|
||||
6
|
||||
};
|
||||
|
||||
responses.push_back(Operation::MountWorkingFolder { path: vec![] }.into());
|
||||
|
||||
Reference in New Issue
Block a user