mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 07:28:11 +08:00
Add Shape Tool for drawing polygons (#75)
* ⬠ Add polygon drawing tool * 🔤 Minor fix of variable and function names * ❌ Remove stroke * ⌨️ Use N key as polygo tool shortcut. * ⌨️ Now using key Y for polygons. * ⌨️ The tooltip for the shortcut is fixed
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
pub mod operation;
|
||||
|
||||
pub use kurbo::{Circle, Line, Point, Rect};
|
||||
mod shape_points;
|
||||
pub use kurbo::{Circle, Line, Point, Rect, Vec2};
|
||||
pub use operation::Operation;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -9,6 +10,7 @@ pub enum LayerType {
|
||||
Circle(Circle),
|
||||
Rect(Rect),
|
||||
Line(Line),
|
||||
Shape(shape_points::ShapePoints),
|
||||
}
|
||||
|
||||
impl LayerType {
|
||||
@@ -24,6 +26,9 @@ impl LayerType {
|
||||
Self::Line(l) => {
|
||||
format!(r#"<line x1="{}" y1="{}" x2="{}" y2="{}" style="stroke: #fff;" />"#, l.p0.x, l.p0.y, l.p1.x, l.p1.y)
|
||||
}
|
||||
Self::Shape(s) => {
|
||||
format!(r#"<polygon points="{}" style="fill: #fff;" />"#, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,6 +225,20 @@ impl Document {
|
||||
|
||||
update_frontend(self.render());
|
||||
}
|
||||
Operation::AddShape {
|
||||
path,
|
||||
insert_index,
|
||||
x0,
|
||||
y0,
|
||||
x1,
|
||||
y1,
|
||||
sides,
|
||||
} => {
|
||||
let s = shape_points::ShapePoints::new(Point::new(x0, y0), Vec2 { x: x0 - x1, y: y0 - y1 }, sides);
|
||||
self.add_layer(&path, Layer::new(LayerType::Shape(s)), insert_index)?;
|
||||
|
||||
update_frontend(self.render());
|
||||
}
|
||||
Operation::DeleteLayer { path } => {
|
||||
self.delete(&path)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user