mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Fix transforms, Brush tool, and G/R/S (#1473)
* Transform fixes * Fix the desert artwork * Change artboard icon * Better handling when transforming brush strokes * Code review pass --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::raster::ImageFrame;
|
||||
use crate::text::FontCache;
|
||||
use crate::transform::{Footprint, Transform, TransformMut};
|
||||
use crate::vector::style::ViewMode;
|
||||
use crate::{Color, Node};
|
||||
|
||||
use dyn_any::{StaticType, StaticTypeSized};
|
||||
@@ -151,6 +152,7 @@ pub enum ExportFormat {
|
||||
pub struct RenderConfig {
|
||||
pub viewport: Footprint,
|
||||
pub export_format: ExportFormat,
|
||||
pub view_mode: ViewMode,
|
||||
}
|
||||
|
||||
pub struct EditorApi<'a, Io> {
|
||||
|
||||
@@ -284,6 +284,7 @@ impl GraphicElementRendered for Artboard {
|
||||
"g",
|
||||
|attributes| {
|
||||
attributes.push("class", "artboard");
|
||||
attributes.push("transform", format_transform_matrix(self.graphic_group.transform));
|
||||
if self.clip {
|
||||
let id = format!("artboard-{}", generate_uuid());
|
||||
let selector = format!("url(#{id})");
|
||||
@@ -298,8 +299,15 @@ impl GraphicElementRendered for Artboard {
|
||||
}
|
||||
},
|
||||
|render| {
|
||||
let old_opacity = render.opacity;
|
||||
render.opacity *= self.graphic_group.opacity;
|
||||
|
||||
// Contents
|
||||
self.graphic_group.render_svg(render, render_params);
|
||||
for element in self.graphic_group.iter() {
|
||||
render.blend_mode = element.blend_mode;
|
||||
element.graphic_element_data.render_svg(render, render_params);
|
||||
}
|
||||
render.opacity = old_opacity;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -349,6 +349,13 @@ impl<P: Hash + Pixel> Hash for ImageFrame<P> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Pixel> ImageFrame<P> {
|
||||
/// Compute the pivot in local space with the current transform applied
|
||||
pub fn local_pivot(&self, normalized_pivot: DVec2) -> DVec2 {
|
||||
self.transform.transform_point2(normalized_pivot)
|
||||
}
|
||||
}
|
||||
|
||||
/* This does not work because of missing specialization
|
||||
* so we have to manually implement this for now
|
||||
impl<S: Into<P> + Pixel, P: Pixel> From<Image<S>> for Image<P> {
|
||||
|
||||
@@ -37,11 +37,17 @@ impl<P: Pixel> Transform for ImageFrame<P> {
|
||||
fn transform(&self) -> DAffine2 {
|
||||
self.transform
|
||||
}
|
||||
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
|
||||
self.local_pivot(pivot)
|
||||
}
|
||||
}
|
||||
impl<P: Pixel> Transform for &ImageFrame<P> {
|
||||
fn transform(&self) -> DAffine2 {
|
||||
self.transform
|
||||
}
|
||||
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
|
||||
(*self).local_pivot(pivot)
|
||||
}
|
||||
}
|
||||
impl<P: Pixel> TransformMut for ImageFrame<P> {
|
||||
fn transform_mut(&mut self) -> &mut DAffine2 {
|
||||
@@ -69,8 +75,8 @@ impl Transform for GraphicElementData {
|
||||
GraphicElementData::VectorShape(vector_shape) => vector_shape.transform(),
|
||||
GraphicElementData::ImageFrame(image_frame) => image_frame.transform(),
|
||||
GraphicElementData::Text(_) => todo!("Transform of text"),
|
||||
GraphicElementData::GraphicGroup(_graphic_group) => DAffine2::IDENTITY,
|
||||
GraphicElementData::Artboard(_artboard) => DAffine2::IDENTITY,
|
||||
GraphicElementData::GraphicGroup(graphic_group) => graphic_group.transform(),
|
||||
GraphicElementData::Artboard(artboard) => artboard.graphic_group.transform(),
|
||||
}
|
||||
}
|
||||
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
|
||||
@@ -78,23 +84,17 @@ impl Transform for GraphicElementData {
|
||||
GraphicElementData::VectorShape(vector_shape) => vector_shape.local_pivot(pivot),
|
||||
GraphicElementData::ImageFrame(image_frame) => image_frame.local_pivot(pivot),
|
||||
GraphicElementData::Text(_) => todo!("Transform of text"),
|
||||
GraphicElementData::GraphicGroup(_graphic_group) => pivot,
|
||||
GraphicElementData::Artboard(_artboard) => pivot,
|
||||
GraphicElementData::GraphicGroup(graphic_group) => graphic_group.local_pivot(pivot),
|
||||
GraphicElementData::Artboard(artboard) => artboard.graphic_group.local_pivot(pivot),
|
||||
}
|
||||
}
|
||||
fn decompose_scale(&self) -> DVec2 {
|
||||
let standard = || {
|
||||
DVec2::new(
|
||||
self.transform().transform_vector2((1., 0.).into()).length(),
|
||||
self.transform().transform_vector2((0., 1.).into()).length(),
|
||||
)
|
||||
};
|
||||
match self {
|
||||
GraphicElementData::VectorShape(vector_shape) => vector_shape.decompose_scale(),
|
||||
GraphicElementData::ImageFrame(image_frame) => image_frame.decompose_scale(),
|
||||
GraphicElementData::Text(_) => todo!("Transform of text"),
|
||||
GraphicElementData::GraphicGroup(_graphic_group) => standard(),
|
||||
GraphicElementData::Artboard(_artboard) => standard(),
|
||||
GraphicElementData::GraphicGroup(graphic_group) => graphic_group.decompose_scale(),
|
||||
GraphicElementData::Artboard(artboard) => artboard.graphic_group.decompose_scale(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,8 +104,8 @@ impl TransformMut for GraphicElementData {
|
||||
GraphicElementData::VectorShape(vector_shape) => vector_shape.transform_mut(),
|
||||
GraphicElementData::ImageFrame(image_frame) => image_frame.transform_mut(),
|
||||
GraphicElementData::Text(_) => todo!("Transform of text"),
|
||||
GraphicElementData::GraphicGroup(_graphic_group) => todo!("Mutable transform of graphic group"),
|
||||
GraphicElementData::Artboard(_artboard) => todo!("Mutable transform of artboard"),
|
||||
GraphicElementData::GraphicGroup(graphic_group) => graphic_group.transform_mut(),
|
||||
GraphicElementData::Artboard(artboard) => artboard.graphic_group.transform_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user