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:
0HyperCube
2021-04-17 11:08:44 -07:00
committed by GitHub
parent c94c2b3373
commit b30e9ce3ba
9 changed files with 324 additions and 95 deletions
+20 -1
View File
@@ -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)?;