Skip to content

Commit 2d96eed

Browse files
0HyperCubeKeavon
authored andcommitted
Move artwork with artboard
1 parent 59327eb commit 2d96eed

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

demo-artwork/just-a-potted-cactus-v2.graphite

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

demo-artwork/valley-of-spires-v2.graphite

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn static_nodes() -> Vec<DocumentNodeBlueprint> {
258258
DocumentNodeBlueprint {
259259
name: "Artboard",
260260
category: "General",
261-
identifier: NodeImplementation::proto("graphene_core::ConstructArtboardNode<_, _, _, _>"),
261+
identifier: NodeImplementation::proto("graphene_core::ConstructArtboardNode<_, _, _, _, _>"),
262262
inputs: vec![
263263
DocumentInputType::value("Graphic Group", TaggedValue::GraphicGroup(GraphicGroup::EMPTY), true),
264264
DocumentInputType::value("Location", TaggedValue::IVec2(glam::IVec2::ZERO), false),
@@ -268,6 +268,7 @@ fn static_nodes() -> Vec<DocumentNodeBlueprint> {
268268
],
269269
outputs: vec![DocumentOutputType::new("Out", FrontendGraphDataType::Artboard)],
270270
properties: node_properties::artboard_properties,
271+
manual_composition: Some(concrete!(Footprint)),
271272
..Default::default()
272273
},
273274
DocumentNodeBlueprint {

node-graph/gcore/src/graphic_element.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::raster::{BlendMode, ImageFrame};
2+
use crate::transform::Footprint;
23
use crate::vector::VectorData;
34
use crate::{Color, Node};
45

@@ -136,15 +137,25 @@ fn to_graphic_element_data<Data: Into<GraphicElementData>>(graphic_element_data:
136137
graphic_element_data.into()
137138
}
138139

139-
pub struct ConstructArtboardNode<Location, Dimensions, Background, Clip> {
140+
pub struct ConstructArtboardNode<Contents, Location, Dimensions, Background, Clip> {
141+
contents: Contents,
140142
location: Location,
141143
dimensions: Dimensions,
142144
background: Background,
143145
clip: Clip,
144146
}
145147

146148
#[node_fn(ConstructArtboardNode)]
147-
fn construct_artboard(graphic_group: GraphicGroup, location: IVec2, dimensions: IVec2, background: Color, clip: bool) -> Artboard {
149+
async fn construct_artboard<Fut: Future<Output = GraphicGroup>>(
150+
mut footprint: Footprint,
151+
contents: impl Node<Footprint, Output = Fut>,
152+
location: IVec2,
153+
dimensions: IVec2,
154+
background: Color,
155+
clip: bool,
156+
) -> Artboard {
157+
footprint.transform = footprint.transform * DAffine2::from_translation(location.as_dvec2());
158+
let graphic_group = self.contents.eval(footprint).await;
148159
Artboard {
149160
graphic_group,
150161
location: location.min(location + dimensions),

node-graph/gcore/src/graphic_element/renderer.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,20 @@ impl GraphicElementRendered for Artboard {
284284
"g",
285285
|attributes| {
286286
attributes.push("class", "artboard");
287-
attributes.push("transform", format_transform_matrix(self.graphic_group.transform));
287+
attributes.push(
288+
"transform",
289+
format_transform_matrix(DAffine2::from_translation(self.location.as_dvec2()) * self.graphic_group.transform),
290+
);
288291
if self.clip {
289292
let id = format!("artboard-{}", generate_uuid());
290293
let selector = format!("url(#{id})");
291294
use std::fmt::Write;
292295
write!(
293296
&mut attributes.0.svg_defs,
294-
r##"<clipPath id="{id}"><rect x="{}" y="{}" width="{}" height="{}"/></clipPath>"##,
295-
self.location.x, self.location.y, self.dimensions.x, self.dimensions.y
297+
r##"<clipPath id="{id}"><rect x="0" y="0" width="{}" height="{}" transform="{}"/></clipPath>"##,
298+
self.dimensions.x,
299+
self.dimensions.y,
300+
format_transform_matrix(self.graphic_group.transform.inverse())
296301
)
297302
.unwrap();
298303
attributes.push("clip-path", selector);

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
844844
register_node!(graphene_core::ToGraphicElementData, input: ImageFrame<Color>, params: []),
845845
register_node!(graphene_core::ToGraphicElementData, input: GraphicGroup, params: []),
846846
register_node!(graphene_core::ToGraphicElementData, input: Artboard, params: []),
847-
register_node!(graphene_core::ConstructArtboardNode<_, _, _, _>, input: GraphicGroup, params: [glam::IVec2, glam::IVec2, Color, bool]),
847+
async_node!(graphene_core::ConstructArtboardNode<_, _, _, _, _>, input: Footprint, output: Artboard, fn_params: [Footprint => GraphicGroup, () => glam::IVec2, () => glam::IVec2, () => Color, () => bool]),
848848
];
849849
let mut map: HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> = HashMap::new();
850850
for (id, c, types) in node_types.into_iter().flatten() {

0 commit comments

Comments
 (0)