mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Rename GraphicElement -> Graphic and trait GraphicElementRendered -> Render (#2987)
This commit is contained in:
2
demo-artwork/changing-seasons.graphite
generated
2
demo-artwork/changing-seasons.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/isometric-fountain.graphite
generated
2
demo-artwork/isometric-fountain.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/marbled-mandelbrot.graphite
generated
2
demo-artwork/marbled-mandelbrot.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/painted-dreams.graphite
generated
2
demo-artwork/painted-dreams.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/parametric-dunescape.graphite
generated
2
demo-artwork/parametric-dunescape.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/procedural-string-lights.graphite
generated
2
demo-artwork/procedural-string-lights.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/red-dress.graphite
generated
2
demo-artwork/red-dress.graphite
generated
File diff suppressed because one or more lines are too long
2
demo-artwork/valley-of-spires.graphite
generated
2
demo-artwork/valley-of-spires.graphite
generated
File diff suppressed because one or more lines are too long
@@ -17,7 +17,7 @@ use graphene_std::text::{Font, TypesettingConfig};
|
||||
use graphene_std::vector::VectorData;
|
||||
use graphene_std::vector::style::{Fill, Stroke};
|
||||
use graphene_std::vector::{PointId, VectorModificationType};
|
||||
use graphene_std::{GraphicElement, NodeInputDecleration};
|
||||
use graphene_std::{Graphic, NodeInputDecleration};
|
||||
|
||||
#[derive(PartialEq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum TransformIn {
|
||||
@@ -303,7 +303,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
// TODO: Allow the path node to operate on Graphic Group data by utilizing the reference for each vector data in a group.
|
||||
if node_definition.identifier == "Path" {
|
||||
let layer_input_type = self.network_interface.input_type(&InputConnector::node(output_layer.to_node(), 1), &[]).0.nested_type().clone();
|
||||
if layer_input_type == concrete!(Table<GraphicElement>) {
|
||||
if layer_input_type == concrete!(Table<Graphic>) {
|
||||
let Some(flatten_path_definition) = resolve_document_node_type("Flatten Path") else {
|
||||
log::error!("Flatten Path does not exist in ModifyInputsContext::existing_node_id");
|
||||
return None;
|
||||
|
||||
@@ -26,7 +26,7 @@ use graphene_std::transform::{Footprint, ReferencePoint, Transform};
|
||||
use graphene_std::vector::VectorData;
|
||||
use graphene_std::vector::misc::{ArcType, CentroidType, GridType, MergeByDistanceAlgorithm, PointSpacingType};
|
||||
use graphene_std::vector::style::{Fill, FillChoice, FillType, GradientStops, GradientType, PaintOrder, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
use graphene_std::{GraphicElement, NodeInputDecleration};
|
||||
use graphene_std::{Graphic, NodeInputDecleration};
|
||||
|
||||
pub(crate) fn string_properties(text: &str) -> Vec<LayoutGroup> {
|
||||
let widget = TextLabel::new(text).widget_holder();
|
||||
@@ -185,7 +185,7 @@ pub(crate) fn property_from_type(
|
||||
// ====================
|
||||
Some(x) if x == TypeId::of::<Table<VectorData>>() => vector_data_widget(default_info).into(),
|
||||
Some(x) if x == TypeId::of::<Table<Raster<CPU>>>() || x == TypeId::of::<Table<Raster<GPU>>>() => raster_widget(default_info).into(),
|
||||
Some(x) if x == TypeId::of::<Table<GraphicElement>>() => group_widget(default_info).into(),
|
||||
Some(x) if x == TypeId::of::<Table<Graphic>>() => group_widget(default_info).into(),
|
||||
// ============
|
||||
// STRUCT TYPES
|
||||
// ============
|
||||
|
||||
@@ -6611,7 +6611,7 @@ struct InputTransientMetadata {
|
||||
fn migrate_output_names<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Vec<String>, D::Error> {
|
||||
use serde::Deserialize;
|
||||
|
||||
const REPLACEMENTS: [(&str, &str); 12] = [
|
||||
const REPLACEMENTS: &[(&str, &str)] = &[
|
||||
// Single to table data
|
||||
("VectorData", "Table<VectorData>"),
|
||||
("GraphicGroup", "Table<GraphicGroup>"),
|
||||
@@ -6622,11 +6622,13 @@ fn migrate_output_names<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Re
|
||||
("Instances<VectorData>", "Table<VectorData>"),
|
||||
("Instances<GraphicGroup>", "Table<GraphicGroup>"),
|
||||
("Instances<Image>", "Table<Image>"),
|
||||
("Instances<GraphicElement>", "Table<GraphicElement>"),
|
||||
("Instances<GraphicElement>", "Table<Graphic>"),
|
||||
("Table<GraphicElement>", "Table<Graphic>"),
|
||||
("Future<Instances<VectorData>>", "Future<Table<VectorData>>"),
|
||||
("Future<Instances<GraphicGroup>>", "Future<Table<GraphicGroup>>"),
|
||||
("Future<Instances<Image>>", "Future<Table<Image>>"),
|
||||
("Future<Instances<GraphicElement>>", "Future<Table<GraphicElement>>"),
|
||||
("Future<Instances<GraphicElement>>", "Future<Table<Graphic>>"),
|
||||
("Future<Table<GraphicElement>>", "Future<Table<Graphic>>"),
|
||||
];
|
||||
|
||||
let mut names = Vec::<String>::deserialize(deserializer)?;
|
||||
|
||||
@@ -39,7 +39,7 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
|
||||
},
|
||||
NodeReplacement {
|
||||
node: graphene_std::graphic_element::to_element::IDENTIFIER,
|
||||
aliases: &["graphene_core::ToGraphicElementNode"],
|
||||
aliases: &["graphene_core::ToGraphicElementNode", "graphene_core::graphic_element::ToElementNode"],
|
||||
},
|
||||
NodeReplacement {
|
||||
node: graphene_std::graphic_element::to_group::IDENTIFIER,
|
||||
|
||||
@@ -9,7 +9,7 @@ use graphene_std::memo::IORecord;
|
||||
use graphene_std::raster::Image;
|
||||
use graphene_std::table::Table;
|
||||
use graphene_std::vector::VectorData;
|
||||
use graphene_std::{Artboard, GraphicElement};
|
||||
use graphene_std::{Artboard, Graphic};
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -120,9 +120,9 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
|
||||
Some(io.output.layout_with_breadcrumb(data))
|
||||
} else if let Some(io) = introspected_data.downcast_ref::<IORecord<(), Table<VectorData>>>() {
|
||||
Some(io.output.layout_with_breadcrumb(data))
|
||||
} else if let Some(io) = introspected_data.downcast_ref::<IORecord<Context, Table<GraphicElement>>>() {
|
||||
} else if let Some(io) = introspected_data.downcast_ref::<IORecord<Context, Table<Graphic>>>() {
|
||||
Some(io.output.layout_with_breadcrumb(data))
|
||||
} else if let Some(io) = introspected_data.downcast_ref::<IORecord<(), Table<GraphicElement>>>() {
|
||||
} else if let Some(io) = introspected_data.downcast_ref::<IORecord<(), Table<Graphic>>>() {
|
||||
Some(io.output.layout_with_breadcrumb(data))
|
||||
} else {
|
||||
None
|
||||
@@ -148,9 +148,9 @@ trait TableRowLayout {
|
||||
fn compute_layout(&self, data: &mut LayoutData) -> Vec<LayoutGroup>;
|
||||
}
|
||||
|
||||
impl TableRowLayout for GraphicElement {
|
||||
impl TableRowLayout for Graphic {
|
||||
fn type_name() -> &'static str {
|
||||
"GraphicElement"
|
||||
"Graphic"
|
||||
}
|
||||
fn identifier(&self) -> String {
|
||||
match self {
|
||||
@@ -160,7 +160,7 @@ impl TableRowLayout for GraphicElement {
|
||||
Self::RasterDataGPU(_) => "RasterDataGPU".to_string(),
|
||||
}
|
||||
}
|
||||
// Don't put a breadcrumb for GraphicElement
|
||||
// Don't put a breadcrumb for Graphic
|
||||
fn layout_with_breadcrumb(&self, data: &mut LayoutData) -> Vec<LayoutGroup> {
|
||||
self.compute_layout(data)
|
||||
}
|
||||
@@ -168,8 +168,8 @@ impl TableRowLayout for GraphicElement {
|
||||
match self {
|
||||
Self::GraphicGroup(table) => table.layout_with_breadcrumb(data),
|
||||
Self::VectorData(table) => table.layout_with_breadcrumb(data),
|
||||
Self::RasterDataCPU(_) => label("Raster frame not supported"),
|
||||
Self::RasterDataGPU(_) => label("Raster frame not supported"),
|
||||
Self::RasterDataCPU(_) => label("Raster is not supported"),
|
||||
Self::RasterDataGPU(_) => label("Raster is not supported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use graph_craft::wasm_application_io::EditorPreferences;
|
||||
use graphene_std::application_io::TimingInformation;
|
||||
use graphene_std::application_io::{NodeGraphUpdateMessage, RenderConfig};
|
||||
use graphene_std::renderer::RenderSvgSegmentList;
|
||||
use graphene_std::renderer::{GraphicElementRendered, RenderParams, SvgRender};
|
||||
use graphene_std::renderer::{Render, RenderParams, SvgRender};
|
||||
use graphene_std::renderer::{RenderMetadata, format_transform_matrix};
|
||||
use graphene_std::text::FontCache;
|
||||
use graphene_std::transform::Footprint;
|
||||
@@ -321,7 +321,7 @@ impl NodeGraphExecutor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn debug_render(render_object: impl GraphicElementRendered, transform: DAffine2, responses: &mut VecDeque<Message>) {
|
||||
fn debug_render(render_object: impl Render, transform: DAffine2, responses: &mut VecDeque<Message>) {
|
||||
// Setup rendering
|
||||
let mut render = SvgRender::new();
|
||||
let render_params = RenderParams {
|
||||
|
||||
@@ -10,7 +10,7 @@ use graph_craft::{ProtoNodeIdentifier, concrete};
|
||||
use graphene_std::Context;
|
||||
use graphene_std::application_io::{ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
|
||||
use graphene_std::memo::IORecord;
|
||||
use graphene_std::renderer::{GraphicElementRendered, RenderParams, SvgRender};
|
||||
use graphene_std::renderer::{Render, RenderParams, SvgRender};
|
||||
use graphene_std::renderer::{RenderSvgSegmentList, SvgSegment};
|
||||
use graphene_std::table::{Table, TableRow};
|
||||
use graphene_std::text::FontCache;
|
||||
@@ -299,7 +299,7 @@ impl NodeRuntime {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Extract the monitor node's stored `GraphicElement` data.
|
||||
// Extract the monitor node's stored `Graphic` data.
|
||||
let Ok(introspected_data) = self.executor.introspect(monitor_node_path) else {
|
||||
// TODO: Fix the root of the issue causing the spam of this warning (this at least temporarily disables it in release builds)
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -308,7 +308,7 @@ impl NodeRuntime {
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Some(io) = introspected_data.downcast_ref::<IORecord<Context, graphene_std::GraphicElement>>() {
|
||||
if let Some(io) = introspected_data.downcast_ref::<IORecord<Context, graphene_std::Graphic>>() {
|
||||
Self::process_graphic_element(&mut self.thumbnail_renders, parent_network_node_id, &io.output, responses, update_thumbnails)
|
||||
} else if let Some(io) = introspected_data.downcast_ref::<IORecord<Context, graphene_std::Artboard>>() {
|
||||
Self::process_graphic_element(&mut self.thumbnail_renders, parent_network_node_id, &io.output, responses, update_thumbnails)
|
||||
@@ -323,12 +323,12 @@ impl NodeRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
// If this is `GraphicElement` data:
|
||||
// If this is `Graphic` data:
|
||||
// Regenerate click targets and thumbnails for the layers in the graph, modifying the state and updating the UI.
|
||||
fn process_graphic_element(
|
||||
thumbnail_renders: &mut HashMap<NodeId, Vec<SvgSegment>>,
|
||||
parent_network_node_id: NodeId,
|
||||
graphic_element: &impl GraphicElementRendered,
|
||||
graphic_element: &impl Render,
|
||||
responses: &mut VecDeque<FrontendMessage>,
|
||||
update_thumbnails: bool,
|
||||
) {
|
||||
@@ -352,7 +352,7 @@ impl NodeRuntime {
|
||||
|
||||
let bounds = graphic_element.bounding_box(DAffine2::IDENTITY, true);
|
||||
|
||||
// Render the thumbnail from a `GraphicElement` into an SVG string
|
||||
// Render the thumbnail from a `Graphic` into an SVG string
|
||||
let render_params = RenderParams {
|
||||
view_mode: ViewMode::Normal,
|
||||
culling_bounds: bounds,
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::table::{Table, TableRow};
|
||||
use crate::transform::TransformMut;
|
||||
use crate::uuid::NodeId;
|
||||
use crate::vector::VectorData;
|
||||
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicElement, OwnedContextImpl};
|
||||
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
|
||||
use dyn_any::DynAny;
|
||||
use glam::{DAffine2, DVec2, IVec2};
|
||||
use std::hash::Hash;
|
||||
@@ -14,7 +14,7 @@ use std::hash::Hash;
|
||||
/// Some [`ArtboardData`] with some optional clipping bounds that can be exported.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Artboard {
|
||||
pub graphic_group: Table<GraphicElement>,
|
||||
pub graphic_group: Table<Graphic>,
|
||||
pub label: String,
|
||||
pub location: IVec2,
|
||||
pub dimensions: IVec2,
|
||||
@@ -95,10 +95,10 @@ impl BoundingBox for Table<Artboard> {
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
async fn to_artboard<Data: Into<Table<GraphicElement>> + 'n>(
|
||||
async fn to_artboard<Data: Into<Table<Graphic>> + 'n>(
|
||||
ctx: impl ExtractAll + CloneVarArgs + Ctx,
|
||||
#[implementations(
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::raster_types::{CPU, Raster};
|
||||
use crate::registry::types::Percentage;
|
||||
use crate::table::Table;
|
||||
use crate::vector::VectorData;
|
||||
use crate::{BlendMode, Color, Ctx, GraphicElement};
|
||||
use crate::{BlendMode, Color, Ctx, Graphic};
|
||||
|
||||
pub(super) trait MultiplyAlpha {
|
||||
fn multiply_alpha(&mut self, factor: f64);
|
||||
@@ -20,7 +20,7 @@ impl MultiplyAlpha for Table<VectorData> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl MultiplyAlpha for Table<GraphicElement> {
|
||||
impl MultiplyAlpha for Table<Graphic> {
|
||||
fn multiply_alpha(&mut self, factor: f64) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.opacity *= factor as f32;
|
||||
@@ -50,7 +50,7 @@ impl MultiplyFill for Table<VectorData> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl MultiplyFill for Table<GraphicElement> {
|
||||
impl MultiplyFill for Table<Graphic> {
|
||||
fn multiply_fill(&mut self, factor: f64) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.fill *= factor as f32;
|
||||
@@ -76,7 +76,7 @@ impl SetBlendMode for Table<VectorData> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl SetBlendMode for Table<GraphicElement> {
|
||||
impl SetBlendMode for Table<Graphic> {
|
||||
fn set_blend_mode(&mut self, blend_mode: BlendMode) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.blend_mode = blend_mode;
|
||||
@@ -102,7 +102,7 @@ impl SetClip for Table<VectorData> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl SetClip for Table<GraphicElement> {
|
||||
impl SetClip for Table<Graphic> {
|
||||
fn set_clip(&mut self, clip: bool) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.clip = clip;
|
||||
@@ -121,7 +121,7 @@ impl SetClip for Table<Raster<CPU>> {
|
||||
fn blend_mode<T: SetBlendMode>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
)]
|
||||
@@ -137,7 +137,7 @@ fn blend_mode<T: SetBlendMode>(
|
||||
fn opacity<T: MultiplyAlpha>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
)]
|
||||
@@ -153,7 +153,7 @@ fn opacity<T: MultiplyAlpha>(
|
||||
fn blending<T: SetBlendMode + MultiplyAlpha + MultiplyFill + SetClip>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
)]
|
||||
|
||||
@@ -10,163 +10,163 @@ use dyn_any::DynAny;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use std::hash::Hash;
|
||||
|
||||
/// The possible forms of graphical content held in a Vec by the `elements` field of [`GraphicElement`].
|
||||
/// The possible forms of graphical content that can be rendered by the Render node into either an image or SVG syntax.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]
|
||||
pub enum GraphicElement {
|
||||
pub enum Graphic {
|
||||
/// Equivalent to the SVG <g> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g
|
||||
GraphicGroup(Table<GraphicElement>),
|
||||
GraphicGroup(Table<Graphic>),
|
||||
/// A vector shape, equivalent to the SVG <path> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
||||
VectorData(Table<VectorData>),
|
||||
RasterDataCPU(Table<Raster<CPU>>),
|
||||
RasterDataGPU(Table<Raster<GPU>>),
|
||||
}
|
||||
|
||||
impl Default for GraphicElement {
|
||||
impl Default for Graphic {
|
||||
fn default() -> Self {
|
||||
Self::GraphicGroup(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
// GraphicGroup
|
||||
impl From<Table<GraphicElement>> for GraphicElement {
|
||||
fn from(graphic_group: Table<GraphicElement>) -> Self {
|
||||
GraphicElement::GraphicGroup(graphic_group)
|
||||
impl From<Table<Graphic>> for Graphic {
|
||||
fn from(graphic_group: Table<Graphic>) -> Self {
|
||||
Graphic::GraphicGroup(graphic_group)
|
||||
}
|
||||
}
|
||||
|
||||
// VectorData
|
||||
impl From<VectorData> for GraphicElement {
|
||||
impl From<VectorData> for Graphic {
|
||||
fn from(vector_data: VectorData) -> Self {
|
||||
GraphicElement::VectorData(Table::new_from_element(vector_data))
|
||||
Graphic::VectorData(Table::new_from_element(vector_data))
|
||||
}
|
||||
}
|
||||
impl From<Table<VectorData>> for GraphicElement {
|
||||
impl From<Table<VectorData>> for Graphic {
|
||||
fn from(vector_data: Table<VectorData>) -> Self {
|
||||
GraphicElement::VectorData(vector_data)
|
||||
Graphic::VectorData(vector_data)
|
||||
}
|
||||
}
|
||||
impl From<VectorData> for Table<GraphicElement> {
|
||||
impl From<VectorData> for Table<Graphic> {
|
||||
fn from(vector_data: VectorData) -> Self {
|
||||
Table::new_from_element(GraphicElement::VectorData(Table::new_from_element(vector_data)))
|
||||
Table::new_from_element(Graphic::VectorData(Table::new_from_element(vector_data)))
|
||||
}
|
||||
}
|
||||
impl From<Table<VectorData>> for Table<GraphicElement> {
|
||||
impl From<Table<VectorData>> for Table<Graphic> {
|
||||
fn from(vector_data: Table<VectorData>) -> Self {
|
||||
Table::new_from_element(GraphicElement::VectorData(vector_data))
|
||||
Table::new_from_element(Graphic::VectorData(vector_data))
|
||||
}
|
||||
}
|
||||
|
||||
// Raster<CPU>
|
||||
impl From<Raster<CPU>> for GraphicElement {
|
||||
impl From<Raster<CPU>> for Graphic {
|
||||
fn from(raster_data: Raster<CPU>) -> Self {
|
||||
GraphicElement::RasterDataCPU(Table::new_from_element(raster_data))
|
||||
Graphic::RasterDataCPU(Table::new_from_element(raster_data))
|
||||
}
|
||||
}
|
||||
impl From<Table<Raster<CPU>>> for GraphicElement {
|
||||
impl From<Table<Raster<CPU>>> for Graphic {
|
||||
fn from(raster_data: Table<Raster<CPU>>) -> Self {
|
||||
GraphicElement::RasterDataCPU(raster_data)
|
||||
Graphic::RasterDataCPU(raster_data)
|
||||
}
|
||||
}
|
||||
impl From<Raster<CPU>> for Table<GraphicElement> {
|
||||
impl From<Raster<CPU>> for Table<Graphic> {
|
||||
fn from(raster_data: Raster<CPU>) -> Self {
|
||||
Table::new_from_element(GraphicElement::RasterDataCPU(Table::new_from_element(raster_data)))
|
||||
Table::new_from_element(Graphic::RasterDataCPU(Table::new_from_element(raster_data)))
|
||||
}
|
||||
}
|
||||
impl From<Table<Raster<CPU>>> for Table<GraphicElement> {
|
||||
impl From<Table<Raster<CPU>>> for Table<Graphic> {
|
||||
fn from(raster_data_table: Table<Raster<CPU>>) -> Self {
|
||||
Table::new_from_element(GraphicElement::RasterDataCPU(raster_data_table))
|
||||
Table::new_from_element(Graphic::RasterDataCPU(raster_data_table))
|
||||
}
|
||||
}
|
||||
|
||||
// Raster<GPU>
|
||||
impl From<Raster<GPU>> for GraphicElement {
|
||||
impl From<Raster<GPU>> for Graphic {
|
||||
fn from(raster_data: Raster<GPU>) -> Self {
|
||||
GraphicElement::RasterDataGPU(Table::new_from_element(raster_data))
|
||||
Graphic::RasterDataGPU(Table::new_from_element(raster_data))
|
||||
}
|
||||
}
|
||||
impl From<Table<Raster<GPU>>> for GraphicElement {
|
||||
impl From<Table<Raster<GPU>>> for Graphic {
|
||||
fn from(raster_data: Table<Raster<GPU>>) -> Self {
|
||||
GraphicElement::RasterDataGPU(raster_data)
|
||||
Graphic::RasterDataGPU(raster_data)
|
||||
}
|
||||
}
|
||||
impl From<Raster<GPU>> for Table<GraphicElement> {
|
||||
impl From<Raster<GPU>> for Table<Graphic> {
|
||||
fn from(raster_data: Raster<GPU>) -> Self {
|
||||
Table::new_from_element(GraphicElement::RasterDataGPU(Table::new_from_element(raster_data)))
|
||||
Table::new_from_element(Graphic::RasterDataGPU(Table::new_from_element(raster_data)))
|
||||
}
|
||||
}
|
||||
impl From<Table<Raster<GPU>>> for Table<GraphicElement> {
|
||||
impl From<Table<Raster<GPU>>> for Table<Graphic> {
|
||||
fn from(raster_data_table: Table<Raster<GPU>>) -> Self {
|
||||
Table::new_from_element(GraphicElement::RasterDataGPU(raster_data_table))
|
||||
Table::new_from_element(Graphic::RasterDataGPU(raster_data_table))
|
||||
}
|
||||
}
|
||||
|
||||
// DAffine2
|
||||
impl From<DAffine2> for GraphicElement {
|
||||
impl From<DAffine2> for Graphic {
|
||||
fn from(_: DAffine2) -> Self {
|
||||
GraphicElement::default()
|
||||
Graphic::default()
|
||||
}
|
||||
}
|
||||
impl From<DAffine2> for Table<GraphicElement> {
|
||||
impl From<DAffine2> for Table<Graphic> {
|
||||
fn from(_: DAffine2) -> Self {
|
||||
Table::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicElement {
|
||||
pub fn as_group(&self) -> Option<&Table<GraphicElement>> {
|
||||
impl Graphic {
|
||||
pub fn as_group(&self) -> Option<&Table<Graphic>> {
|
||||
match self {
|
||||
GraphicElement::GraphicGroup(group) => Some(group),
|
||||
Graphic::GraphicGroup(group) => Some(group),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_group_mut(&mut self) -> Option<&mut Table<GraphicElement>> {
|
||||
pub fn as_group_mut(&mut self) -> Option<&mut Table<Graphic>> {
|
||||
match self {
|
||||
GraphicElement::GraphicGroup(group) => Some(group),
|
||||
Graphic::GraphicGroup(group) => Some(group),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_vector_data(&self) -> Option<&Table<VectorData>> {
|
||||
match self {
|
||||
GraphicElement::VectorData(data) => Some(data),
|
||||
Graphic::VectorData(data) => Some(data),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_vector_data_mut(&mut self) -> Option<&mut Table<VectorData>> {
|
||||
match self {
|
||||
GraphicElement::VectorData(data) => Some(data),
|
||||
Graphic::VectorData(data) => Some(data),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_raster(&self) -> Option<&Table<Raster<CPU>>> {
|
||||
match self {
|
||||
GraphicElement::RasterDataCPU(raster) => Some(raster),
|
||||
Graphic::RasterDataCPU(raster) => Some(raster),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_raster_mut(&mut self) -> Option<&mut Table<Raster<CPU>>> {
|
||||
match self {
|
||||
GraphicElement::RasterDataCPU(raster) => Some(raster),
|
||||
Graphic::RasterDataCPU(raster) => Some(raster),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn had_clip_enabled(&self) -> bool {
|
||||
match self {
|
||||
GraphicElement::VectorData(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
GraphicElement::GraphicGroup(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
GraphicElement::RasterDataCPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
GraphicElement::RasterDataGPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
Graphic::VectorData(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
Graphic::GraphicGroup(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
Graphic::RasterDataCPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
Graphic::RasterDataGPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_reduce_to_clip_path(&self) -> bool {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data_table) => vector_data_table.iter_ref().all(|row| {
|
||||
Graphic::VectorData(vector_data_table) => vector_data_table.iter_ref().all(|row| {
|
||||
let style = &row.element.style;
|
||||
let alpha_blending = &row.alpha_blending;
|
||||
(alpha_blending.opacity > 1. - f32::EPSILON) && style.fill().is_opaque() && style.stroke().is_none_or(|stroke| !stroke.has_renderable_stroke())
|
||||
@@ -176,18 +176,18 @@ impl GraphicElement {
|
||||
}
|
||||
}
|
||||
|
||||
impl BoundingBox for GraphicElement {
|
||||
impl BoundingBox for Graphic {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
|
||||
GraphicElement::RasterDataCPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||
GraphicElement::RasterDataGPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
|
||||
Graphic::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
|
||||
Graphic::RasterDataCPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||
Graphic::RasterDataGPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BoundingBox for Table<GraphicElement> {
|
||||
impl BoundingBox for Table<Graphic> {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
self.iter_ref()
|
||||
.filter_map(|element| element.element.bounding_box(transform * *element.transform, include_stroke))
|
||||
@@ -198,8 +198,8 @@ impl BoundingBox for Table<GraphicElement> {
|
||||
#[node_macro::node(category(""))]
|
||||
async fn layer<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] mut stack: Table<I>,
|
||||
#[implementations(GraphicElement, VectorData, Raster<CPU>, Raster<GPU>)] element: I,
|
||||
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] mut stack: Table<I>,
|
||||
#[implementations(Graphic, VectorData, Raster<CPU>, Raster<GPU>)] element: I,
|
||||
node_path: Vec<NodeId>,
|
||||
) -> Table<I> {
|
||||
// Get the penultimate element of the node path, or None if the path is too short
|
||||
@@ -216,38 +216,38 @@ async fn layer<I: 'n + Send + Clone>(
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Debug"))]
|
||||
async fn to_element<Data: Into<GraphicElement> + 'n>(
|
||||
async fn to_element<Data: Into<Graphic> + 'n>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Raster<GPU>>,
|
||||
DAffine2,
|
||||
)]
|
||||
data: Data,
|
||||
) -> GraphicElement {
|
||||
) -> Graphic {
|
||||
data.into()
|
||||
}
|
||||
|
||||
#[node_macro::node(category("General"))]
|
||||
async fn to_group<Data: Into<Table<GraphicElement>> + 'n>(
|
||||
async fn to_group<Data: Into<Table<Graphic>> + 'n>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Raster<GPU>>,
|
||||
)]
|
||||
element: Data,
|
||||
) -> Table<GraphicElement> {
|
||||
) -> Table<Graphic> {
|
||||
element.into()
|
||||
}
|
||||
|
||||
#[node_macro::node(category("General"))]
|
||||
async fn flatten_group(_: impl Ctx, group: Table<GraphicElement>, fully_flatten: bool) -> Table<GraphicElement> {
|
||||
// TODO: Avoid mutable reference, instead return a new Table<GraphicElement>?
|
||||
fn flatten_group(output_group_table: &mut Table<GraphicElement>, current_group_table: Table<GraphicElement>, fully_flatten: bool, recursion_depth: usize) {
|
||||
async fn flatten_group(_: impl Ctx, group: Table<Graphic>, fully_flatten: bool) -> Table<Graphic> {
|
||||
// TODO: Avoid mutable reference, instead return a new Table<Graphic>?
|
||||
fn flatten_group(output_group_table: &mut Table<Graphic>, current_group_table: Table<Graphic>, fully_flatten: bool, recursion_depth: usize) {
|
||||
for current_row in current_group_table.iter_ref() {
|
||||
let current_element = current_row.element.clone();
|
||||
let reference = *current_row.source_node_id;
|
||||
@@ -256,7 +256,7 @@ async fn flatten_group(_: impl Ctx, group: Table<GraphicElement>, fully_flatten:
|
||||
|
||||
match current_element {
|
||||
// If we're allowed to recurse, flatten any GraphicGroups we encounter
|
||||
GraphicElement::GraphicGroup(mut current_element) if recurse => {
|
||||
Graphic::GraphicGroup(mut current_element) if recurse => {
|
||||
// Apply the parent group's transform to all child elements
|
||||
for graphic_element in current_element.iter_mut() {
|
||||
*graphic_element.transform = *current_row.transform * *graphic_element.transform;
|
||||
@@ -284,16 +284,16 @@ async fn flatten_group(_: impl Ctx, group: Table<GraphicElement>, fully_flatten:
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Vector"))]
|
||||
async fn flatten_vector(_: impl Ctx, group: Table<GraphicElement>) -> Table<VectorData> {
|
||||
// TODO: Avoid mutable reference, instead return a new Table<GraphicElement>?
|
||||
fn flatten_group(output_group_table: &mut Table<VectorData>, current_group_table: Table<GraphicElement>) {
|
||||
async fn flatten_vector(_: impl Ctx, group: Table<Graphic>) -> Table<VectorData> {
|
||||
// TODO: Avoid mutable reference, instead return a new Table<Graphic>?
|
||||
fn flatten_group(output_group_table: &mut Table<VectorData>, current_group_table: Table<Graphic>) {
|
||||
for current_graphic_element_row in current_group_table.iter_ref() {
|
||||
let current_element = current_graphic_element_row.element.clone();
|
||||
let reference = *current_graphic_element_row.source_node_id;
|
||||
|
||||
match current_element {
|
||||
// If we're allowed to recurse, flatten any GraphicGroups we encounter
|
||||
GraphicElement::GraphicGroup(mut current_element) => {
|
||||
Graphic::GraphicGroup(mut current_element) => {
|
||||
// Apply the parent group's transform to all child elements
|
||||
for graphic_element in current_element.iter_mut() {
|
||||
*graphic_element.transform = *current_graphic_element_row.transform * *graphic_element.transform;
|
||||
@@ -302,7 +302,7 @@ async fn flatten_vector(_: impl Ctx, group: Table<GraphicElement>) -> Table<Vect
|
||||
flatten_group(output_group_table, current_element);
|
||||
}
|
||||
// Handle any leaf elements we encounter, which can be either non-GraphicGroup elements or GraphicGroups that we don't want to flatten
|
||||
GraphicElement::VectorData(vector_table) => {
|
||||
Graphic::VectorData(vector_table) => {
|
||||
for current_vector_row in vector_table.iter_ref() {
|
||||
output_group_table.push(TableRow {
|
||||
element: current_vector_row.element.clone(),
|
||||
@@ -341,7 +341,7 @@ fn index<T: AtIndex + Clone + Default>(
|
||||
Vec<DVec2>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
)]
|
||||
collection: T,
|
||||
/// The index of the item to retrieve, starting from 0 for the first item.
|
||||
@@ -379,18 +379,18 @@ impl<T: Clone> AtIndex for Table<T> {
|
||||
}
|
||||
|
||||
// TODO: Eventually remove this migration document upgrade code
|
||||
pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Table<GraphicElement>, D::Error> {
|
||||
pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Table<Graphic>, D::Error> {
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DynAny, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub struct OldGraphicGroup {
|
||||
elements: Vec<(GraphicElement, Option<NodeId>)>,
|
||||
elements: Vec<(Graphic, Option<NodeId>)>,
|
||||
transform: DAffine2,
|
||||
alpha_blending: AlphaBlending,
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq, DynAny, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub struct GraphicGroup {
|
||||
elements: Vec<(GraphicElement, Option<NodeId>)>,
|
||||
elements: Vec<(Graphic, Option<NodeId>)>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@@ -428,10 +428,10 @@ pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D)
|
||||
}
|
||||
}
|
||||
graphic_group_table
|
||||
} else if let Ok(new_table) = serde_json::from_value::<Table<GraphicElement>>(value) {
|
||||
} else if let Ok(new_table) = serde_json::from_value::<Table<Graphic>>(value) {
|
||||
new_table
|
||||
} else {
|
||||
return Err(serde::de::Error::custom("Failed to deserialize Table<GraphicElement>"));
|
||||
return Err(serde::de::Error::custom("Failed to deserialize Table<Graphic>"));
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -41,7 +41,7 @@ pub use graphene_core_shaders::AsU32;
|
||||
pub use graphene_core_shaders::blending;
|
||||
pub use graphene_core_shaders::choice_type;
|
||||
pub use graphene_core_shaders::color;
|
||||
pub use graphic_element::GraphicElement;
|
||||
pub use graphic_element::Graphic;
|
||||
pub use memo::MemoHash;
|
||||
pub use num_traits;
|
||||
use std::any::TypeId;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::Artboard;
|
||||
use crate::Color;
|
||||
use crate::GraphicElement;
|
||||
use crate::Graphic;
|
||||
use crate::gradient::GradientStops;
|
||||
use crate::graphene_core::registry::types::TextArea;
|
||||
use crate::raster_types::{CPU, GPU, Raster};
|
||||
@@ -17,7 +17,7 @@ fn to_string<T: std::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f6
|
||||
#[node_macro::node(category("Text"))]
|
||||
fn serialize<T: serde::Serialize>(
|
||||
_: impl Ctx,
|
||||
#[implementations(String, bool, f64, u32, u64, DVec2, DAffine2, Color, Option<Color>, Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] value: T,
|
||||
#[implementations(String, bool, f64, u32, u64, DVec2, DAffine2, Color, Option<Color>, Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] value: T,
|
||||
) -> String {
|
||||
serde_json::to_string(&value).unwrap_or_else(|_| "Serialization Error".to_string())
|
||||
}
|
||||
@@ -61,10 +61,10 @@ async fn switch<T, C: Send + 'n + Clone>(
|
||||
Context -> DAffine2,
|
||||
Context -> Table<Artboard>,
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> GraphicElement,
|
||||
Context -> Graphic,
|
||||
Context -> Color,
|
||||
Context -> Option<Color>,
|
||||
Context -> GradientStops,
|
||||
@@ -82,10 +82,10 @@ async fn switch<T, C: Send + 'n + Clone>(
|
||||
Context -> DAffine2,
|
||||
Context -> Table<Artboard>,
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> GraphicElement,
|
||||
Context -> Graphic,
|
||||
Context -> Color,
|
||||
Context -> Option<Color>,
|
||||
Context -> GradientStops,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::raster_types::{CPU, GPU, Raster};
|
||||
use crate::table::Table;
|
||||
use crate::vector::VectorData;
|
||||
use crate::{Artboard, Color, GraphicElement};
|
||||
use crate::{Artboard, Color, Graphic};
|
||||
use glam::DVec2;
|
||||
|
||||
pub trait RenderComplexity {
|
||||
@@ -22,7 +22,7 @@ impl RenderComplexity for Artboard {
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderComplexity for GraphicElement {
|
||||
impl RenderComplexity for Graphic {
|
||||
fn render_complexity(&self) -> usize {
|
||||
match self {
|
||||
Self::GraphicGroup(table) => table.render_complexity(),
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::raster_types::{CPU, GPU, Raster};
|
||||
use crate::table::Table;
|
||||
use crate::transform::{ApplyTransform, Footprint, Transform};
|
||||
use crate::vector::VectorData;
|
||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, GraphicElement, OwnedContextImpl};
|
||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
|
||||
use core::f64;
|
||||
use glam::{DAffine2, DVec2};
|
||||
|
||||
@@ -13,7 +13,7 @@ async fn transform<T: ApplyTransform + 'n + 'static>(
|
||||
Context -> DAffine2,
|
||||
Context -> DVec2,
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
)]
|
||||
@@ -43,7 +43,7 @@ async fn transform<T: ApplyTransform + 'n + 'static>(
|
||||
#[node_macro::node(category(""))]
|
||||
fn replace_transform<Data, TransformInput: Transform>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<VectorData>, Table<Raster<CPU>>, Table<GraphicElement>)] mut data: Table<Data>,
|
||||
#[implementations(Table<VectorData>, Table<Raster<CPU>>, Table<Graphic>)] mut data: Table<Data>,
|
||||
#[implementations(DAffine2)] transform: TransformInput,
|
||||
) -> Table<Data> {
|
||||
for data_transform in data.iter_mut() {
|
||||
@@ -56,7 +56,7 @@ fn replace_transform<Data, TransformInput: Transform>(
|
||||
async fn extract_transform<T>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Raster<GPU>>,
|
||||
@@ -91,7 +91,7 @@ async fn boundless_footprint<T: 'n + 'static>(
|
||||
ctx: impl Ctx + CloneVarArgs + ExtractAll,
|
||||
#[implementations(
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> String,
|
||||
@@ -109,7 +109,7 @@ async fn freeze_real_time<T: 'n + 'static>(
|
||||
ctx: impl Ctx + CloneVarArgs + ExtractAll,
|
||||
#[implementations(
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> String,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use crate::raster_types::{CPU, Raster};
|
||||
use crate::table::{Table, TableRowRef};
|
||||
use crate::vector::VectorData;
|
||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, GraphicElement, OwnedContextImpl};
|
||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, Graphic, OwnedContextImpl};
|
||||
use glam::DVec2;
|
||||
|
||||
#[node_macro::node(name("Instance on Points"), category("Instancing"), path(graphene_core::vector))]
|
||||
async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
|
||||
async fn instance_on_points<T: Into<Graphic> + Default + Send + Clone + 'static>(
|
||||
ctx: impl ExtractAll + CloneVarArgs + Sync + Ctx,
|
||||
points: Table<VectorData>,
|
||||
#[implementations(
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<Raster<CPU>>
|
||||
)]
|
||||
@@ -47,10 +47,10 @@ async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + '
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
||||
async fn instance_repeat<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
|
||||
async fn instance_repeat<T: Into<Graphic> + Default + Send + Clone + 'static>(
|
||||
ctx: impl ExtractAll + CloneVarArgs + Ctx,
|
||||
#[implementations(
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<Raster<CPU>>
|
||||
)]
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::math::quad::Quad;
|
||||
use crate::table::Table;
|
||||
use crate::transform::Transform;
|
||||
use crate::vector::click_target::{ClickTargetType, FreePoint};
|
||||
use crate::{AlphaBlending, Color, GraphicElement};
|
||||
use crate::{AlphaBlending, Color, Graphic};
|
||||
pub use attributes::*;
|
||||
use bezier_rs::{BezierHandles, ManipulatorGroup};
|
||||
use core::borrow::Borrow;
|
||||
@@ -41,7 +41,7 @@ pub fn migrate_vector_data<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
|
||||
pub region_domain: RegionDomain,
|
||||
|
||||
// Used to store the upstream graphic group during destructive Boolean Operations (and other nodes with a similar effect) so that click targets can be preserved.
|
||||
pub upstream_graphic_group: Option<Table<GraphicElement>>,
|
||||
pub upstream_graphic_group: Option<Table<Graphic>>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@@ -89,7 +89,7 @@ pub struct VectorData {
|
||||
pub region_domain: RegionDomain,
|
||||
|
||||
// Used to store the upstream graphic group during destructive Boolean Operations (and other nodes with a similar effect) so that click targets can be preserved.
|
||||
pub upstream_graphic_group: Option<Table<GraphicElement>>,
|
||||
pub upstream_graphic_group: Option<Table<Graphic>>,
|
||||
}
|
||||
|
||||
impl Default for VectorData {
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::vector::misc::{MergeByDistanceAlgorithm, PointSpacingType, is_linear}
|
||||
use crate::vector::misc::{handles_to_segment, segment_to_handles};
|
||||
use crate::vector::style::{PaintOrder, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
use crate::vector::{FillId, RegionId};
|
||||
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicElement, OwnedContextImpl};
|
||||
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
|
||||
use bezier_rs::ManipulatorGroup;
|
||||
use core::f64::consts::PI;
|
||||
use core::hash::{Hash, Hasher};
|
||||
@@ -32,7 +32,7 @@ trait VectorDataTableIterMut {
|
||||
fn vector_iter_mut(&mut self) -> impl Iterator<Item = TableRowMut<'_, VectorData>>;
|
||||
}
|
||||
|
||||
impl VectorDataTableIterMut for Table<GraphicElement> {
|
||||
impl VectorDataTableIterMut for Table<Graphic> {
|
||||
fn vector_iter_mut(&mut self) -> impl Iterator<Item = TableRowMut<'_, VectorData>> {
|
||||
// Grab only the direct children
|
||||
self.iter_mut()
|
||||
@@ -50,7 +50,7 @@ impl VectorDataTableIterMut for Table<VectorData> {
|
||||
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector))]
|
||||
async fn assign_colors<T>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>)]
|
||||
#[implementations(Table<Graphic>, Table<VectorData>)]
|
||||
#[widget(ParsedWidgetOverride::Hidden)]
|
||||
/// The vector elements, or group of vector elements, to apply the fill and/or stroke style to.
|
||||
mut vector_group: T,
|
||||
@@ -115,10 +115,10 @@ async fn fill<F: Into<Fill> + 'n + Send, V>(
|
||||
Table<VectorData>,
|
||||
Table<VectorData>,
|
||||
Table<VectorData>,
|
||||
Table<GraphicElement>,
|
||||
Table<GraphicElement>,
|
||||
Table<GraphicElement>,
|
||||
Table<GraphicElement>
|
||||
Table<Graphic>,
|
||||
Table<Graphic>,
|
||||
Table<Graphic>,
|
||||
Table<Graphic>
|
||||
)]
|
||||
/// The vector elements, or group of vector elements, to apply the fill to.
|
||||
mut vector_data: V,
|
||||
@@ -157,7 +157,7 @@ where
|
||||
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("stroke_properties"))]
|
||||
async fn stroke<C: Into<Option<Color>> + 'n + Send, V>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<VectorData>, Table<VectorData>, Table<GraphicElement>, Table<GraphicElement>)]
|
||||
#[implementations(Table<VectorData>, Table<VectorData>, Table<Graphic>, Table<Graphic>)]
|
||||
/// The vector elements, or group of vector elements, to apply the stroke to.
|
||||
mut vector_data: Table<V>,
|
||||
#[implementations(
|
||||
@@ -220,8 +220,8 @@ where
|
||||
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
||||
async fn repeat<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
// TODO: Implement other GraphicElementRendered types.
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
// TODO: Implement other graphical types.
|
||||
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
#[default(100., 100.)]
|
||||
// TODO: When using a custom Properties panel layout in document_node_definitions.rs and this default is set, the widget weirdly doesn't show up in the Properties panel. Investigation is needed.
|
||||
direction: PixelSize,
|
||||
@@ -256,8 +256,8 @@ async fn repeat<I: 'n + Send + Clone>(
|
||||
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
||||
async fn circular_repeat<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
// TODO: Implement other GraphicElementRendered types.
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
// TODO: Implement other graphical types.
|
||||
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
angle_offset: Angle,
|
||||
#[unit(" px")]
|
||||
#[default(5)]
|
||||
@@ -293,7 +293,7 @@ async fn copy_to_points<I: 'n + Send + Clone>(
|
||||
points: Table<VectorData>,
|
||||
#[expose]
|
||||
/// Artwork to be copied and placed at each point.
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)]
|
||||
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)]
|
||||
instance: Table<I>,
|
||||
/// Minimum range of randomized sizes given to each instance.
|
||||
#[default(1)]
|
||||
@@ -368,7 +368,7 @@ async fn copy_to_points<I: 'n + Send + Clone>(
|
||||
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
||||
async fn mirror<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
#[default(ReferencePoint::Center)] relative_to_bounds: ReferencePoint,
|
||||
#[unit(" px")] offset: f64,
|
||||
#[range((-90., 90.))] angle: Angle,
|
||||
@@ -958,17 +958,17 @@ async fn solidify_stroke(_: impl Ctx, vector_data: Table<VectorData>) -> Table<V
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
||||
async fn flatten_path<I: 'n + Send>(_: impl Ctx, #[implementations(Table<GraphicElement>, Table<VectorData>)] graphic_group_input: Table<I>) -> Table<VectorData>
|
||||
async fn flatten_path<I: 'n + Send>(_: impl Ctx, #[implementations(Table<Graphic>, Table<VectorData>)] graphic_group_input: Table<I>) -> Table<VectorData>
|
||||
where
|
||||
GraphicElement: From<Table<I>>,
|
||||
Graphic: From<Table<I>>,
|
||||
{
|
||||
// A node based solution to support passing through vector data could be a network node with a cache node connected to
|
||||
// a Flatten Path connected to an if else node, another connection from the cache directly
|
||||
// To the if else node, and another connection from the cache to a matches type node connected to the if else node.
|
||||
fn flatten_group(graphic_group_table: &Table<GraphicElement>, output: &mut TableRowMut<VectorData>) {
|
||||
fn flatten_group(graphic_group_table: &Table<Graphic>, output: &mut TableRowMut<VectorData>) {
|
||||
for (group_index, current_element) in graphic_group_table.iter_ref().enumerate() {
|
||||
match current_element.element {
|
||||
GraphicElement::VectorData(vector_data_table) => {
|
||||
Graphic::VectorData(vector_data_table) => {
|
||||
// Loop through every row of the Table<VectorData> and concatenate each element's subpath into the output VectorData element.
|
||||
for (vector_index, row) in vector_data_table.iter_ref().enumerate() {
|
||||
let other = row.element;
|
||||
@@ -985,7 +985,7 @@ where
|
||||
output.element.style = row.element.style.clone();
|
||||
}
|
||||
}
|
||||
GraphicElement::GraphicGroup(graphic_group) => {
|
||||
Graphic::GraphicGroup(graphic_group) => {
|
||||
let mut graphic_group = graphic_group.clone();
|
||||
for row in graphic_group.iter_mut() {
|
||||
*row.transform = *current_element.transform * *row.transform;
|
||||
@@ -1005,7 +1005,7 @@ where
|
||||
};
|
||||
|
||||
// Flatten the graphic group input into the output VectorData element
|
||||
let base_graphic_group = Table::new_from_element(GraphicElement::from(graphic_group_input));
|
||||
let base_graphic_group = Table::new_from_element(Graphic::from(graphic_group_input));
|
||||
flatten_group(&base_graphic_group, &mut output);
|
||||
|
||||
// Return the single-row Table<VectorData> containing the flattened VectorData subpaths
|
||||
@@ -1911,7 +1911,7 @@ fn point_inside(_: impl Ctx, source: Table<VectorData>, point: DVec2) -> bool {
|
||||
}
|
||||
|
||||
#[node_macro::node(category("General"), path(graphene_core::vector))]
|
||||
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] source: Table<I>) -> u64 {
|
||||
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] source: Table<I>) -> u64 {
|
||||
source.len() as u64
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use graphene_core::table::{Table, TableRow, TableRowRef};
|
||||
use graphene_core::vector::algorithms::merge_by_distance::MergeByDistanceExt;
|
||||
use graphene_core::vector::style::Fill;
|
||||
use graphene_core::vector::{PointId, VectorData};
|
||||
use graphene_core::{Color, Ctx, GraphicElement};
|
||||
use graphene_core::{Color, Ctx, Graphic};
|
||||
pub use path_bool as path_bool_lib;
|
||||
use path_bool::{FillRule, PathBooleanOperation};
|
||||
use std::ops::Mul;
|
||||
@@ -32,10 +32,10 @@ pub enum BooleanOperation {
|
||||
|
||||
/// Combines the geometric forms of one or more closed paths into a new vector path that results from cutting or joining the paths by the chosen method.
|
||||
#[node_macro::node(category(""))]
|
||||
async fn boolean_operation<I: Into<Table<GraphicElement>> + 'n + Send + Clone>(
|
||||
async fn boolean_operation<I: Into<Table<Graphic>> + 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
/// The group of paths to perform the boolean operation on. Nested groups are automatically flattened.
|
||||
#[implementations(Table<GraphicElement>, Table<VectorData>)]
|
||||
#[implementations(Table<Graphic>, Table<VectorData>)]
|
||||
group_of_paths: I,
|
||||
/// Which boolean operation to perform on the paths.
|
||||
///
|
||||
@@ -221,12 +221,12 @@ fn difference<'a>(vector_data: impl DoubleEndedIterator<Item = TableRowRef<'a, V
|
||||
boolean_operation_on_vector_data_table(union.iter_ref().chain(std::iter::once(any_intersection.as_ref())), BooleanOperation::SubtractFront)
|
||||
}
|
||||
|
||||
fn flatten_vector_data(graphic_group_table: &Table<GraphicElement>) -> Table<VectorData> {
|
||||
fn flatten_vector_data(graphic_group_table: &Table<Graphic>) -> Table<VectorData> {
|
||||
graphic_group_table
|
||||
.iter_ref()
|
||||
.flat_map(|element| {
|
||||
match element.element.clone() {
|
||||
GraphicElement::VectorData(vector_data) => {
|
||||
Graphic::VectorData(vector_data) => {
|
||||
// Apply the parent group's transform to each element of vector data
|
||||
vector_data
|
||||
.iter()
|
||||
@@ -237,7 +237,7 @@ fn flatten_vector_data(graphic_group_table: &Table<GraphicElement>) -> Table<Vec
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
GraphicElement::RasterDataCPU(image) => {
|
||||
Graphic::RasterDataCPU(image) => {
|
||||
let make_row = |transform| {
|
||||
// Convert the image frame into a rectangular subpath with the image's transform
|
||||
let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
||||
@@ -253,7 +253,7 @@ fn flatten_vector_data(graphic_group_table: &Table<GraphicElement>) -> Table<Vec
|
||||
// Apply the parent group's transform to each element of raster data
|
||||
image.iter_ref().map(|row| make_row(*element.transform * *row.transform)).collect::<Vec<_>>()
|
||||
}
|
||||
GraphicElement::RasterDataGPU(image) => {
|
||||
Graphic::RasterDataGPU(image) => {
|
||||
let make_row = |transform| {
|
||||
// Convert the image frame into a rectangular subpath with the image's transform
|
||||
let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
||||
@@ -269,7 +269,7 @@ fn flatten_vector_data(graphic_group_table: &Table<GraphicElement>) -> Table<Vec
|
||||
// Apply the parent group's transform to each element of raster data
|
||||
image.iter_ref().map(|row| make_row(*element.transform * *row.transform)).collect::<Vec<_>>()
|
||||
}
|
||||
GraphicElement::GraphicGroup(mut graphic_group) => {
|
||||
Graphic::GraphicGroup(mut graphic_group) => {
|
||||
// Apply the parent group's transform to each element of inner group
|
||||
for sub_element in graphic_group.iter_mut() {
|
||||
*sub_element.transform = *element.transform * *sub_element.transform;
|
||||
|
||||
@@ -14,7 +14,7 @@ use graphene_core::transform::ReferencePoint;
|
||||
use graphene_core::uuid::NodeId;
|
||||
use graphene_core::vector::VectorData;
|
||||
use graphene_core::vector::style::Fill;
|
||||
use graphene_core::{Artboard, Color, GraphicElement, MemoHash, Node, Type};
|
||||
use graphene_core::{Artboard, Color, Graphic, MemoHash, Node, Type};
|
||||
use graphene_svg_renderer::RenderMetadata;
|
||||
use std::fmt::Display;
|
||||
use std::hash::Hash;
|
||||
@@ -180,13 +180,15 @@ tagged_value! {
|
||||
// ===========
|
||||
// TABLE TYPES
|
||||
// ===========
|
||||
GraphicElement(GraphicElement),
|
||||
#[serde(alias = "GraphicElement")]
|
||||
Graphic(Graphic),
|
||||
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphene_core::vector::migrate_vector_data"))] // TODO: Eventually remove this migration document upgrade code
|
||||
VectorData(Table<VectorData>),
|
||||
#[cfg_attr(target_family = "wasm", serde(alias = "ImageFrame", deserialize_with = "graphene_core::raster::image::migrate_image_frame"))] // TODO: Eventually remove this migration document upgrade code
|
||||
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphene_core::raster::image::migrate_image_frame"))] // TODO: Eventually remove this migration document upgrade code
|
||||
#[serde(alias = "ImageFrame")]
|
||||
RasterData(Table<Raster<CPU>>),
|
||||
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphene_core::graphic_element::migrate_graphic_group"))] // TODO: Eventually remove this migration document upgrade code
|
||||
GraphicGroup(Table<GraphicElement>),
|
||||
GraphicGroup(Table<Graphic>),
|
||||
#[cfg_attr(target_family = "wasm", serde(deserialize_with = "graphene_core::artboard::migrate_artboard_group"))] // TODO: Eventually remove this migration document upgrade code
|
||||
ArtboardGroup(Table<Artboard>),
|
||||
// ============
|
||||
|
||||
@@ -10,9 +10,9 @@ use graphene_core::raster_types::{CPU, Raster};
|
||||
use graphene_core::table::Table;
|
||||
use graphene_core::transform::Footprint;
|
||||
use graphene_core::vector::VectorData;
|
||||
use graphene_core::{Color, Context, Ctx, ExtractFootprint, GraphicElement, OwnedContextImpl, WasmNotSend};
|
||||
use graphene_core::{Color, Context, Ctx, ExtractFootprint, Graphic, OwnedContextImpl, WasmNotSend};
|
||||
use graphene_svg_renderer::RenderMetadata;
|
||||
use graphene_svg_renderer::{GraphicElementRendered, RenderParams, RenderSvgSegmentList, SvgRender, format_transform_matrix};
|
||||
use graphene_svg_renderer::{Render, RenderParams, RenderSvgSegmentList, SvgRender, format_transform_matrix};
|
||||
|
||||
#[cfg(target_family = "wasm")]
|
||||
use base64::Engine;
|
||||
@@ -139,7 +139,7 @@ fn decode_image(_: impl Ctx, data: Arc<[u8]>) -> Table<Raster<CPU>> {
|
||||
Table::new_from_element(Raster::new_cpu(image))
|
||||
}
|
||||
|
||||
fn render_svg(data: impl GraphicElementRendered, mut render: SvgRender, render_params: RenderParams, footprint: Footprint) -> RenderOutputType {
|
||||
fn render_svg(data: impl Render, mut render: SvgRender, render_params: RenderParams, footprint: Footprint) -> RenderOutputType {
|
||||
if !data.contains_artboard() && !render_params.hide_artboards {
|
||||
render.leaf_tag("rect", |attributes| {
|
||||
attributes.push("x", "0");
|
||||
@@ -166,13 +166,7 @@ fn render_svg(data: impl GraphicElementRendered, mut render: SvgRender, render_p
|
||||
|
||||
#[cfg(feature = "vello")]
|
||||
#[cfg_attr(not(target_family = "wasm"), allow(dead_code))]
|
||||
async fn render_canvas(
|
||||
render_config: RenderConfig,
|
||||
data: impl GraphicElementRendered,
|
||||
editor: &WasmEditorApi,
|
||||
surface_handle: Option<wgpu_executor::WgpuSurface>,
|
||||
render_params: RenderParams,
|
||||
) -> RenderOutputType {
|
||||
async fn render_canvas(render_config: RenderConfig, data: impl Render, editor: &WasmEditorApi, surface_handle: Option<wgpu_executor::WgpuSurface>, render_params: RenderParams) -> RenderOutputType {
|
||||
use graphene_application_io::{ImageTexture, SurfaceFrame};
|
||||
|
||||
let footprint = render_config.viewport;
|
||||
@@ -223,14 +217,14 @@ async fn rasterize<T: WasmNotSend + 'n>(
|
||||
#[implementations(
|
||||
Table<VectorData>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<GraphicElement>,
|
||||
Table<Graphic>,
|
||||
)]
|
||||
mut data: Table<T>,
|
||||
footprint: Footprint,
|
||||
surface_handle: Arc<graphene_application_io::SurfaceHandle<HtmlCanvasElement>>,
|
||||
) -> Table<Raster<CPU>>
|
||||
where
|
||||
Table<T>: GraphicElementRendered,
|
||||
Table<T>: Render,
|
||||
{
|
||||
use graphene_core::table::TableRow;
|
||||
|
||||
@@ -285,13 +279,13 @@ where
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
async fn render<'a: 'n, T: 'n + GraphicElementRendered + WasmNotSend>(
|
||||
async fn render<'a: 'n, T: 'n + Render + WasmNotSend>(
|
||||
render_config: RenderConfig,
|
||||
editor_api: impl Node<Context<'static>, Output = &'a WasmEditorApi>,
|
||||
#[implementations(
|
||||
Context -> Table<VectorData>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<GraphicElement>,
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Artboard>,
|
||||
Context -> Artboard,
|
||||
Context -> Option<Color>,
|
||||
|
||||
@@ -16,7 +16,7 @@ use graphene_core::uuid::{NodeId, generate_uuid};
|
||||
use graphene_core::vector::VectorData;
|
||||
use graphene_core::vector::click_target::{ClickTarget, FreePoint};
|
||||
use graphene_core::vector::style::{Fill, Stroke, StrokeAlign, ViewMode};
|
||||
use graphene_core::{Artboard, GraphicElement};
|
||||
use graphene_core::{Artboard, Graphic};
|
||||
use num_traits::Zero;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fmt::Write;
|
||||
@@ -212,7 +212,7 @@ pub struct RenderMetadata {
|
||||
}
|
||||
|
||||
// TODO: Rename to "Graphical"
|
||||
pub trait GraphicElementRendered: BoundingBox + RenderComplexity {
|
||||
pub trait Render: BoundingBox + RenderComplexity {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams);
|
||||
|
||||
#[cfg(feature = "vello")]
|
||||
@@ -234,7 +234,7 @@ pub trait GraphicElementRendered: BoundingBox + RenderComplexity {
|
||||
fn new_ids_from_hash(&mut self, _reference: Option<NodeId>) {}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Table<GraphicElement> {
|
||||
impl Render for Table<Graphic> {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
let mut iter = self.iter_ref().peekable();
|
||||
let mut mask_state = None;
|
||||
@@ -408,7 +408,7 @@ impl GraphicElementRendered for Table<GraphicElement> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Table<VectorData> {
|
||||
impl Render for Table<VectorData> {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
for row in self.iter_ref() {
|
||||
let multiplied_transform = *row.transform;
|
||||
@@ -811,7 +811,7 @@ impl GraphicElementRendered for Table<VectorData> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Artboard {
|
||||
impl Render for Artboard {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
if !render_params.hide_artboards {
|
||||
// Background
|
||||
@@ -907,7 +907,7 @@ impl GraphicElementRendered for Artboard {
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Table<Artboard> {
|
||||
impl Render for Table<Artboard> {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
for artboard in self.iter_ref() {
|
||||
artboard.element.render_svg(render, render_params);
|
||||
@@ -938,7 +938,7 @@ impl GraphicElementRendered for Table<Artboard> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Table<Raster<CPU>> {
|
||||
impl Render for Table<Raster<CPU>> {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
for row in self.iter_ref() {
|
||||
let image = row.element;
|
||||
@@ -1081,7 +1081,7 @@ impl GraphicElementRendered for Table<Raster<CPU>> {
|
||||
|
||||
const LAZY_ARC_VEC_ZERO_U8: LazyLock<Arc<Vec<u8>>> = LazyLock::new(|| Arc::new(Vec::new()));
|
||||
|
||||
impl GraphicElementRendered for Table<Raster<GPU>> {
|
||||
impl Render for Table<Raster<GPU>> {
|
||||
fn render_svg(&self, _render: &mut SvgRender, _render_params: &RenderParams) {
|
||||
log::warn!("tried to render texture as an svg");
|
||||
}
|
||||
@@ -1137,33 +1137,33 @@ impl GraphicElementRendered for Table<Raster<GPU>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for GraphicElement {
|
||||
impl Render for Graphic {
|
||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.render_svg(render, render_params),
|
||||
GraphicElement::RasterDataCPU(raster) => raster.render_svg(render, render_params),
|
||||
GraphicElement::RasterDataGPU(_raster) => (),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.render_svg(render, render_params),
|
||||
Graphic::VectorData(vector_data) => vector_data.render_svg(render, render_params),
|
||||
Graphic::RasterDataCPU(raster) => raster.render_svg(render, render_params),
|
||||
Graphic::RasterDataGPU(_raster) => (),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.render_svg(render, render_params),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "vello")]
|
||||
fn render_to_vello(&self, scene: &mut Scene, transform: DAffine2, context: &mut RenderContext, render_params: &RenderParams) {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.render_to_vello(scene, transform, context, render_params),
|
||||
GraphicElement::RasterDataCPU(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
||||
GraphicElement::RasterDataGPU(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.render_to_vello(scene, transform, context, render_params),
|
||||
Graphic::VectorData(vector_data) => vector_data.render_to_vello(scene, transform, context, render_params),
|
||||
Graphic::RasterDataCPU(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
||||
Graphic::RasterDataGPU(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.render_to_vello(scene, transform, context, render_params),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option<NodeId>) {
|
||||
if let Some(element_id) = element_id {
|
||||
match self {
|
||||
GraphicElement::GraphicGroup(_) => {
|
||||
Graphic::GraphicGroup(_) => {
|
||||
metadata.upstream_footprints.insert(element_id, footprint);
|
||||
}
|
||||
GraphicElement::VectorData(vector_data) => {
|
||||
Graphic::VectorData(vector_data) => {
|
||||
metadata.upstream_footprints.insert(element_id, footprint);
|
||||
// TODO: Find a way to handle more than one row of the graphical data table
|
||||
if let Some(vector_data) = vector_data.iter_ref().next() {
|
||||
@@ -1171,7 +1171,7 @@ impl GraphicElementRendered for GraphicElement {
|
||||
metadata.local_transforms.insert(element_id, *vector_data.transform);
|
||||
}
|
||||
}
|
||||
GraphicElement::RasterDataCPU(raster_frame) => {
|
||||
Graphic::RasterDataCPU(raster_frame) => {
|
||||
metadata.upstream_footprints.insert(element_id, footprint);
|
||||
|
||||
// TODO: Find a way to handle more than one row of images
|
||||
@@ -1179,7 +1179,7 @@ impl GraphicElementRendered for GraphicElement {
|
||||
metadata.local_transforms.insert(element_id, *image.transform);
|
||||
}
|
||||
}
|
||||
GraphicElement::RasterDataGPU(raster_frame) => {
|
||||
Graphic::RasterDataGPU(raster_frame) => {
|
||||
metadata.upstream_footprints.insert(element_id, footprint);
|
||||
|
||||
// TODO: Find a way to handle more than one row of images
|
||||
@@ -1191,37 +1191,37 @@ impl GraphicElementRendered for GraphicElement {
|
||||
}
|
||||
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.collect_metadata(metadata, footprint, element_id),
|
||||
GraphicElement::RasterDataCPU(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
||||
GraphicElement::RasterDataGPU(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.collect_metadata(metadata, footprint, element_id),
|
||||
Graphic::VectorData(vector_data) => vector_data.collect_metadata(metadata, footprint, element_id),
|
||||
Graphic::RasterDataCPU(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
||||
Graphic::RasterDataGPU(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.collect_metadata(metadata, footprint, element_id),
|
||||
}
|
||||
}
|
||||
|
||||
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.add_upstream_click_targets(click_targets),
|
||||
GraphicElement::RasterDataCPU(raster) => raster.add_upstream_click_targets(click_targets),
|
||||
GraphicElement::RasterDataGPU(raster) => raster.add_upstream_click_targets(click_targets),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.add_upstream_click_targets(click_targets),
|
||||
Graphic::VectorData(vector_data) => vector_data.add_upstream_click_targets(click_targets),
|
||||
Graphic::RasterDataCPU(raster) => raster.add_upstream_click_targets(click_targets),
|
||||
Graphic::RasterDataGPU(raster) => raster.add_upstream_click_targets(click_targets),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.add_upstream_click_targets(click_targets),
|
||||
}
|
||||
}
|
||||
|
||||
fn contains_artboard(&self) -> bool {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.contains_artboard(),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.contains_artboard(),
|
||||
GraphicElement::RasterDataCPU(raster) => raster.contains_artboard(),
|
||||
GraphicElement::RasterDataGPU(raster) => raster.contains_artboard(),
|
||||
Graphic::VectorData(vector_data) => vector_data.contains_artboard(),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.contains_artboard(),
|
||||
Graphic::RasterDataCPU(raster) => raster.contains_artboard(),
|
||||
Graphic::RasterDataGPU(raster) => raster.contains_artboard(),
|
||||
}
|
||||
}
|
||||
|
||||
fn new_ids_from_hash(&mut self, reference: Option<NodeId>) {
|
||||
match self {
|
||||
GraphicElement::VectorData(vector_data) => vector_data.new_ids_from_hash(reference),
|
||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.new_ids_from_hash(reference),
|
||||
GraphicElement::RasterDataCPU(_) => (),
|
||||
GraphicElement::RasterDataGPU(_) => (),
|
||||
Graphic::VectorData(vector_data) => vector_data.new_ids_from_hash(reference),
|
||||
Graphic::GraphicGroup(graphic_group) => graphic_group.new_ids_from_hash(reference),
|
||||
Graphic::RasterDataCPU(_) => (),
|
||||
Graphic::RasterDataGPU(_) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1240,7 +1240,7 @@ fn text_attributes(attributes: &mut SvgRenderAttrs) {
|
||||
attributes.push("font-size", "30");
|
||||
}
|
||||
|
||||
impl<P: Primitive> GraphicElementRendered for P {
|
||||
impl<P: Primitive> Render for P {
|
||||
fn render_svg(&self, render: &mut SvgRender, _render_params: &RenderParams) {
|
||||
render.parent_tag("text", text_attributes, |render| render.leaf_node(format!("{self}")));
|
||||
}
|
||||
@@ -1249,7 +1249,7 @@ impl<P: Primitive> GraphicElementRendered for P {
|
||||
fn render_to_vello(&self, _scene: &mut Scene, _transform: DAffine2, _context: &mut RenderContext, _render_params: &RenderParams) {}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Option<Color> {
|
||||
impl Render for Option<Color> {
|
||||
fn render_svg(&self, render: &mut SvgRender, _render_params: &RenderParams) {
|
||||
let Some(color) = self else {
|
||||
render.parent_tag("text", |_| {}, |render| render.leaf_node("Empty color"));
|
||||
@@ -1273,7 +1273,7 @@ impl GraphicElementRendered for Option<Color> {
|
||||
fn render_to_vello(&self, _scene: &mut Scene, _transform: DAffine2, _context: &mut RenderContext, _render_params: &RenderParams) {}
|
||||
}
|
||||
|
||||
impl GraphicElementRendered for Vec<Color> {
|
||||
impl Render for Vec<Color> {
|
||||
fn render_svg(&self, render: &mut SvgRender, _render_params: &RenderParams) {
|
||||
for (index, &color) in self.iter().enumerate() {
|
||||
render.leaf_tag("rect", |attributes| {
|
||||
|
||||
@@ -10,7 +10,7 @@ use graphene_core::{Cow, ProtoNodeIdentifier, Type};
|
||||
use graphene_core::{NodeIO, NodeIOTypes};
|
||||
use graphene_core::{fn_type_fut, future};
|
||||
use graphene_std::Context;
|
||||
use graphene_std::GraphicElement;
|
||||
use graphene_std::Graphic;
|
||||
#[cfg(feature = "gpu")]
|
||||
use graphene_std::any::DowncastBothNode;
|
||||
use graphene_std::any::{ComposeTypeErased, DynAnyNode, IntoTypeErasedNode};
|
||||
@@ -32,20 +32,20 @@ use wgpu_executor::{WgpuSurface, WindowHandle};
|
||||
fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeConstructor>> {
|
||||
let mut node_types: Vec<(ProtoNodeIdentifier, NodeConstructor, NodeIOTypes)> = vec![
|
||||
into_node!(from: Table<VectorData>, to: Table<VectorData>),
|
||||
into_node!(from: Table<VectorData>, to: GraphicElement),
|
||||
into_node!(from: Table<VectorData>, to: Table<GraphicElement>),
|
||||
into_node!(from: Table<GraphicElement>, to: Table<GraphicElement>),
|
||||
into_node!(from: Table<GraphicElement>, to: GraphicElement),
|
||||
into_node!(from: Table<VectorData>, to: Graphic),
|
||||
into_node!(from: Table<VectorData>, to: Table<Graphic>),
|
||||
into_node!(from: Table<Graphic>, to: Table<Graphic>),
|
||||
into_node!(from: Table<Graphic>, to: Graphic),
|
||||
into_node!(from: Table<Raster<CPU>>, to: Table<Raster<CPU>>),
|
||||
// into_node!(from: Table<Raster<CPU>>, to: Table<Raster<SRGBA8>>),
|
||||
into_node!(from: Table<Raster<CPU>>, to: GraphicElement),
|
||||
into_node!(from: Table<Raster<GPU>>, to: GraphicElement),
|
||||
into_node!(from: Table<Raster<CPU>>, to: Table<GraphicElement>),
|
||||
into_node!(from: Table<Raster<CPU>>, to: Graphic),
|
||||
into_node!(from: Table<Raster<GPU>>, to: Graphic),
|
||||
into_node!(from: Table<Raster<CPU>>, to: Table<Graphic>),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<Raster<CPU>>]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => ImageTexture]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<VectorData>]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<GraphicElement>]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => GraphicElement]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<Graphic>]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Graphic]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Artboard]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<Raster<CPU>>]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<Raster<GPU>>]),
|
||||
@@ -80,7 +80,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<VectorData>]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<Raster<CPU>>]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<GraphicElement>]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<Graphic>]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Vec<DVec2>]),
|
||||
#[cfg(feature = "gpu")]
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Arc<WasmSurfaceHandle>]),
|
||||
@@ -92,10 +92,10 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => f64]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => String]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => RenderOutput]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => GraphicElement]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Table<GraphicElement>]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Graphic]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Table<Graphic>]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Table<VectorData>]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Table<GraphicElement>]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Table<Graphic>]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => WgpuSurface]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => Option<WgpuSurface>]),
|
||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => ImageTexture]),
|
||||
|
||||
Reference in New Issue
Block a user