mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 02:38:13 +08:00
Implement fill tool (#254)
* Implement fill tool * Add fill tool shortcut * Add getters and setters to styles * Make fill tool act on the topmost layer clicked * Refactor fill operation * Refactor and unify selection tolerance * Add mark_as_dirty function * Fix getter names
This commit is contained in:
committed by
Keavon Chambers
parent
57b8ee0e86
commit
363b9c7ffa
@@ -227,6 +227,16 @@ impl Document {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mark_as_dirty(&mut self, path: &[LayerId]) -> Result<(), DocumentError> {
|
||||
let mut root = &mut self.root;
|
||||
root.cache_dirty = true;
|
||||
for id in path {
|
||||
root = root.as_folder_mut()?.layer_mut(*id).ok_or(DocumentError::LayerNotFound)?;
|
||||
root.cache_dirty = true;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Mutate the document by applying the `operation` to it. If the operation necessitates a
|
||||
/// reaction from the frontend, responses may be returned.
|
||||
pub fn handle_operation(&mut self, operation: Operation) -> Result<Option<Vec<DocumentResponse>>, DocumentError> {
|
||||
@@ -361,6 +371,12 @@ impl Document {
|
||||
let path = path.as_slice()[..path.len() - 1].to_vec();
|
||||
Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::FolderChanged { path }])
|
||||
}
|
||||
Operation::FillLayer { path, color } => {
|
||||
let layer = self.layer_mut(path).unwrap();
|
||||
layer.style.set_fill(layers::style::Fill::new(*color));
|
||||
self.mark_as_dirty(path)?;
|
||||
Some(vec![DocumentResponse::DocumentChanged])
|
||||
}
|
||||
};
|
||||
if !matches!(
|
||||
operation,
|
||||
|
||||
@@ -23,8 +23,6 @@ use crate::LayerId;
|
||||
pub use folder::Folder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const SELECTION_TOLERANCE: f64 = 5.0;
|
||||
|
||||
pub trait LayerData {
|
||||
fn render(&mut self, svg: &mut String, transform: glam::DAffine2, style: style::PathStyle);
|
||||
fn to_kurbo_path(&self, transform: glam::DAffine2, style: style::PathStyle) -> BezPath;
|
||||
|
||||
@@ -56,6 +56,24 @@ impl PathStyle {
|
||||
pub fn new(stroke: Option<Stroke>, fill: Option<Fill>) -> Self {
|
||||
Self { stroke, fill }
|
||||
}
|
||||
pub fn fill(&self) -> Option<Fill> {
|
||||
self.fill
|
||||
}
|
||||
pub fn stroke(&self) -> Option<Stroke> {
|
||||
self.stroke
|
||||
}
|
||||
pub fn set_fill(&mut self, fill: Fill) {
|
||||
self.fill = Some(fill);
|
||||
}
|
||||
pub fn set_stroke(&mut self, stroke: Stroke) {
|
||||
self.stroke = Some(stroke);
|
||||
}
|
||||
pub fn clear_fill(&mut self) {
|
||||
self.fill = None;
|
||||
}
|
||||
pub fn clear_stroke(&mut self) {
|
||||
self.stroke = None;
|
||||
}
|
||||
pub fn render(&self) -> String {
|
||||
format!(
|
||||
"{}{}",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
color::Color,
|
||||
layers::{style, Layer},
|
||||
LayerId,
|
||||
};
|
||||
@@ -71,4 +72,8 @@ pub enum Operation {
|
||||
ToggleVisibility {
|
||||
path: Vec<LayerId>,
|
||||
},
|
||||
FillLayer {
|
||||
path: Vec<LayerId>,
|
||||
color: Color,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user