Skip to content

Commit a182a73

Browse files
authored
Extract gbrush (#2784)
1 parent 602d7e8 commit a182a73

File tree

18 files changed

+85
-30
lines changed

18 files changed

+85
-30
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"frontend/wasm",
66
"frontend/src-tauri",
77
"node-graph/gapplication-io",
8+
"node-graph/gbrush",
89
"node-graph/gcore",
910
"node-graph/gstd",
1011
"node-graph/gmath-nodes",
@@ -25,6 +26,7 @@ members = [
2526
default-members = [
2627
"editor",
2728
"frontend/wasm",
29+
"node-graph/gbrush",
2830
"node-graph/gcore",
2931
"node-graph/gstd",
3032
"node-graph/gmath-nodes",
@@ -46,6 +48,7 @@ preprocessor = { path = "node-graph/preprocessor"}
4648
math-parser = { path = "libraries/math-parser" }
4749
path-bool = { path = "libraries/path-bool" }
4850
graphene-application-io = { path = "node-graph/gapplication-io" }
51+
graphene-brush = { path = "node-graph/gbrush" }
4952
graphene-core = { path = "node-graph/gcore" }
5053
graphene-math-nodes = { path = "node-graph/gmath-nodes" }
5154
graphene-path-bool = { path = "node-graph/gpath-bool" }

editor/src/messages/portfolio/document/graph_operation/graph_operation_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use bezier_rs::Subpath;
66
use glam::{DAffine2, DVec2, IVec2};
77
use graph_craft::document::NodeId;
88
use graphene_std::Artboard;
9+
use graphene_std::brush::brush_stroke::BrushStroke;
910
use graphene_std::raster::BlendMode;
1011
use graphene_std::raster_types::{CPU, RasterDataTable};
1112
use graphene_std::text::{Font, TypesettingConfig};
1213
use graphene_std::vector::PointId;
1314
use graphene_std::vector::VectorModificationType;
14-
use graphene_std::vector::brush_stroke::BrushStroke;
1515
use graphene_std::vector::style::{Fill, Stroke};
1616

1717
#[impl_message(Message, DocumentMessage, GraphOperation)]

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use graph_craft::concrete;
99
use graph_craft::document::value::TaggedValue;
1010
use graph_craft::document::{NodeId, NodeInput};
1111
use graphene_std::Artboard;
12+
use graphene_std::brush::brush_stroke::BrushStroke;
1213
use graphene_std::raster::BlendMode;
1314
use graphene_std::raster_types::{CPU, RasterDataTable};
1415
use graphene_std::text::{Font, TypesettingConfig};
15-
use graphene_std::vector::brush_stroke::BrushStroke;
1616
use graphene_std::vector::style::{Fill, Stroke};
1717
use graphene_std::vector::{PointId, VectorModificationType};
1818
use graphene_std::vector::{VectorData, VectorDataTable};

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use graph_craft::ProtoNodeIdentifier;
1616
use graph_craft::concrete;
1717
use graph_craft::document::value::*;
1818
use graph_craft::document::*;
19+
use graphene_std::brush::brush_cache::BrushCache;
1920
use graphene_std::extract_xy::XY;
20-
use graphene_std::raster::brush_cache::BrushCache;
2121
use graphene_std::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
2222
use graphene_std::raster_types::{CPU, RasterDataTable};
2323
use graphene_std::text::{Font, TypesettingConfig};
@@ -1032,7 +1032,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
10321032
nodes: vec![DocumentNode {
10331033
inputs: vec![
10341034
NodeInput::network(concrete!(RasterDataTable<CPU>), 0),
1035-
NodeInput::network(concrete!(Vec<graphene_std::vector::brush_stroke::BrushStroke>), 1),
1035+
NodeInput::network(concrete!(Vec<brush::brush_stroke::BrushStroke>), 1),
10361036
NodeInput::network(concrete!(BrushCache), 2),
10371037
],
10381038
manual_composition: Some(concrete!(Context)),

editor/src/messages/portfolio/document_migration.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ const REPLACEMENTS: &[(&str, &str)] = &[
147147
("graphene_std::raster::MaskImageNode", "graphene_std::raster::MaskNode"),
148148
("graphene_core::vector::FlattenVectorElementsNode", "graphene_core::vector::FlattenPathNode"),
149149
("graphene_std::vector::BooleanOperationNode", "graphene_path_bool::BooleanOperationNode"),
150+
// brush
151+
("graphene_std::brush::BrushStampGeneratorNode", "graphene_brush::brush::BrushStampGeneratorNode"),
152+
("graphene_std::brush::BlitNode", "graphene_brush::brush::BlitNode"),
153+
("graphene_std::brush::BrushNode", "graphene_brush::brush::BrushNode"),
150154
];
151155

152156
pub fn document_migration_string_preprocessing(document_serialized_content: String) -> String {

editor/src/messages/tool/tool_messages/brush_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::messages::tool::common_functionality::color_selector::{ToolColorOptio
88
use graph_craft::document::NodeId;
99
use graph_craft::document::value::TaggedValue;
1010
use graphene_std::Color;
11+
use graphene_std::brush::brush_stroke::{BrushInputSample, BrushStroke, BrushStyle};
1112
use graphene_std::raster::BlendMode;
12-
use graphene_std::vector::brush_stroke::{BrushInputSample, BrushStroke, BrushStyle};
1313

1414
const BRUSH_MAX_SIZE: f64 = 5000.;
1515

node-graph/gbrush/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "graphene-brush"
3+
version = "0.1.0"
4+
edition = "2024"
5+
description = "graphene brush"
6+
authors = ["Graphite Authors <[email protected]>"]
7+
license = "MIT OR Apache-2.0"
8+
9+
[features]
10+
default = ["serde"]
11+
serde = ["dep:serde"]
12+
13+
[dependencies]
14+
# Local dependencies
15+
dyn-any = { workspace = true }
16+
graphene-core = { workspace = true }
17+
graphene-raster-nodes = { workspace = true }
18+
node-macro = { workspace = true }
19+
20+
# Workspace dependencies
21+
glam = { workspace = true }
22+
23+
# Optional workspace dependencies
24+
serde = { workspace = true, optional = true, features = ["derive"] }
25+
26+
[dev-dependencies]
27+
# Workspace dependencies
28+
tokio = { workspace = true }

node-graph/gstd/src/brush.rs renamed to node-graph/gbrush/src/brush.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
use crate::brush_cache::BrushCache;
2+
use crate::brush_stroke::{BrushStroke, BrushStyle};
13
use glam::{DAffine2, DVec2};
2-
use graph_craft::generic::FnNode;
3-
use graph_craft::proto::FutureWrapperNode;
4+
use graphene_core::blending::BlendMode;
45
use graphene_core::bounds::BoundingBox;
6+
use graphene_core::color::{Alpha, Color, Pixel, Sample};
7+
use graphene_core::generic::FnNode;
58
use graphene_core::instances::Instance;
69
use graphene_core::math::bbox::{AxisAlignedBbox, Bbox};
7-
use graphene_core::raster::brush_cache::BrushCache;
10+
use graphene_core::raster::BitmapMut;
811
use graphene_core::raster::image::Image;
9-
use graphene_core::raster::{Alpha, BitmapMut, BlendMode, Color, Pixel, Sample};
1012
use graphene_core::raster_types::{CPU, Raster, RasterDataTable};
13+
use graphene_core::registry::FutureWrapperNode;
1114
use graphene_core::transform::Transform;
1215
use graphene_core::value::ClonedNode;
13-
use graphene_core::vector::brush_stroke::{BrushStroke, BrushStyle};
14-
use graphene_core::{Ctx, GraphicElement, Node};
16+
use graphene_core::{Ctx, Node};
1517
use graphene_raster_nodes::adjustments::blend_colors;
1618
use graphene_raster_nodes::std_nodes::{empty_image, extend_image_to_bounds};
1719

@@ -50,7 +52,7 @@ impl<P: Pixel + Alpha> Sample for BrushStampGenerator<P> {
5052
return None;
5153
};
5254

53-
use graphene_core::raster::Channel;
55+
use graphene_core::color::Channel;
5456
Some(self.color.multiplied_alpha(P::AlphaChannel::from_linear(result)))
5557
}
5658
}
@@ -78,7 +80,6 @@ fn brush_stamp_generator(#[unit(" px")] diameter: f64, color: Color, hardness: f
7880
fn blit<BlendFn>(mut target: RasterDataTable<CPU>, texture: Raster<CPU>, positions: Vec<DVec2>, blend_mode: BlendFn) -> RasterDataTable<CPU>
7981
where
8082
BlendFn: for<'any_input> Node<'any_input, (Color, Color), Output = Color>,
81-
GraphicElement: From<Raster<CPU>>,
8283
{
8384
if positions.is_empty() {
8485
return target;
@@ -392,7 +393,7 @@ mod test {
392393
(),
393394
RasterDataTable::<CPU>::new(Raster::new_cpu(Image::<Color>::default())),
394395
vec![BrushStroke {
395-
trace: vec![crate::vector::brush_stroke::BrushInputSample { position: DVec2::ZERO }],
396+
trace: vec![crate::brush_stroke::BrushInputSample { position: DVec2::ZERO }],
396397
style: BrushStyle {
397398
color: Color::BLACK,
398399
diameter: 20.,

node-graph/gcore/src/raster/brush_cache.rs renamed to node-graph/gbrush/src/brush_cache.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::instances::Instance;
2-
use crate::raster_types::CPU;
3-
use crate::raster_types::Raster;
4-
use crate::vector::brush_stroke::BrushStroke;
5-
use crate::vector::brush_stroke::BrushStyle;
1+
use crate::brush_stroke::BrushStroke;
2+
use crate::brush_stroke::BrushStyle;
63
use dyn_any::DynAny;
4+
use graphene_core::instances::Instance;
5+
use graphene_core::raster_types::CPU;
6+
use graphene_core::raster_types::Raster;
77
use std::collections::HashMap;
88
use std::hash::Hash;
99
use std::sync::Arc;
@@ -15,11 +15,11 @@ struct BrushCacheImpl {
1515
prev_input: Vec<BrushStroke>,
1616

1717
// The strokes that have been fully processed and blended into the background.
18-
#[serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance")]
18+
#[serde(deserialize_with = "graphene_core::raster::image::migrate_image_frame_instance")]
1919
background: Instance<Raster<CPU>>,
20-
#[serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance")]
20+
#[serde(deserialize_with = "graphene_core::raster::image::migrate_image_frame_instance")]
2121
blended_image: Instance<Raster<CPU>>,
22-
#[serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance")]
22+
#[serde(deserialize_with = "graphene_core::raster::image::migrate_image_frame_instance")]
2323
last_stroke_texture: Instance<Raster<CPU>>,
2424

2525
// A cache for brush textures.

0 commit comments

Comments
 (0)