mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Improved Rectangle, Line and Shape Tools (#106)
This commit is contained in:
@@ -247,7 +247,7 @@ impl Document {
|
||||
sides,
|
||||
style,
|
||||
} => {
|
||||
let s = Shape::new((x0, y0), (x0 - x1, y0 - y1), sides, style);
|
||||
let s = Shape::new((x0, y0), (x1, y1), sides, style);
|
||||
self.add_layer(&path, Layer::new(LayerDataTypes::Shape(s)), insert_index)?;
|
||||
|
||||
Some(vec![DocumentResponse::DocumentChanged])
|
||||
|
||||
@@ -7,14 +7,16 @@ use std::fmt::Write;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Shape {
|
||||
bounding_rect: kurbo::Rect,
|
||||
shape: shape_points::ShapePoints,
|
||||
style: style::PathStyle,
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
pub fn new(center: impl Into<kurbo::Point>, extent: impl Into<kurbo::Vec2>, sides: u8, style: style::PathStyle) -> Shape {
|
||||
pub fn new(p0: impl Into<kurbo::Point>, p1: impl Into<kurbo::Point>, sides: u8, style: style::PathStyle) -> Shape {
|
||||
Shape {
|
||||
shape: shape_points::ShapePoints::new(center, extent, sides),
|
||||
bounding_rect: kurbo::Rect::from_points(p0, p1),
|
||||
shape: shape_points::ShapePoints::new(kurbo::Point::new(0.5, 0.5), kurbo::Vec2::new(0.5, 0.0), sides),
|
||||
style,
|
||||
}
|
||||
}
|
||||
@@ -22,6 +24,15 @@ impl Shape {
|
||||
|
||||
impl LayerData for Shape {
|
||||
fn render(&mut self, svg: &mut String) {
|
||||
let _ = write!(svg, r#"<polygon points="{}" {} />"#, self.shape, self.style.render(),);
|
||||
let _ = write!(
|
||||
svg,
|
||||
r#"<polygon points="{}" transform="translate({} {}) scale({} {})" {} />"#,
|
||||
self.shape,
|
||||
self.bounding_rect.origin().x,
|
||||
self.bounding_rect.origin().y,
|
||||
self.bounding_rect.width(),
|
||||
self.bounding_rect.height(),
|
||||
self.style.render(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user