Add initial tool settings messaging to backend

This commit is contained in:
Henry Sloan
2021-07-20 00:52:27 -04:00
parent 3203f7bcdf
commit 8e56a274fe
6 changed files with 98 additions and 50 deletions

View File

@@ -37,7 +37,7 @@ pub trait Fsm {
pub struct DocumentToolData {
pub primary_color: Color,
pub secondary_color: Color,
tool_settings: HashMap<ToolType, ToolSettings>,
pub tool_settings: HashMap<ToolType, ToolSettings>,
}
type SubToolMessageHandler = dyn for<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>>;

View File

@@ -4,7 +4,7 @@ use document_core::color::Color;
use crate::input::InputPreprocessor;
use crate::{
document::Document,
tool::{ToolFsmState, ToolType},
tool::{tool_settings::ToolSettings, ToolFsmState, ToolType},
};
use std::collections::VecDeque;
@@ -16,6 +16,7 @@ pub enum ToolMessage {
SelectSecondaryColor(Color),
SwapColors,
ResetColors,
SetToolSettings(ToolType, ToolSettings),
#[child]
Fill(FillMessage),
#[child]
@@ -89,6 +90,9 @@ impl MessageHandler<ToolMessage, (&Document, &InputPreprocessor)> for ToolMessag
.into(),
)
}
SetToolSettings(tool_type, tool_settings) => {
self.tool_state.document_tool_data.tool_settings.insert(tool_type, tool_settings);
}
message => {
let tool_type = match message {
Fill(_) => ToolType::Fill,
@@ -111,7 +115,7 @@ impl MessageHandler<ToolMessage, (&Document, &InputPreprocessor)> for ToolMessag
}
}
fn actions(&self) -> ActionList {
let mut list = actions!(ToolMessageDiscriminant; ResetColors, SwapColors, SelectTool);
let mut list = actions!(ToolMessageDiscriminant; ResetColors, SwapColors, SelectTool, SetToolSettings);
list.extend(self.tool_state.tool_data.active_tool().actions());
list
}

View File

@@ -71,6 +71,13 @@ impl Fsm for ShapeToolFsmState {
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;
}
}
};
responses.push_back(Operation::MountWorkingFolder { path: vec![] }.into());
Dragging