mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Add Table<Color> as a graphical type (#3033)
* Reduce code duplication in bounding box impls on Table * Working Table<Color> rendering in the graph * Implement color and fix other rendering with Vello and polish
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::blending::AlphaBlending;
|
||||
use crate::bounds::BoundingBox;
|
||||
use crate::bounds::{BoundingBox, RenderBoundingBox};
|
||||
use crate::math::quad::Quad;
|
||||
use crate::raster_types::{CPU, GPU, Raster};
|
||||
use crate::table::{Table, TableRow};
|
||||
@@ -42,15 +42,16 @@ impl Artboard {
|
||||
}
|
||||
|
||||
impl BoundingBox for Artboard {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
let artboard_bounds = (transform * Quad::from_box([self.location.as_dvec2(), self.location.as_dvec2() + self.dimensions.as_dvec2()])).bounding_box();
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> RenderBoundingBox {
|
||||
let artboard_bounds = || (transform * Quad::from_box([self.location.as_dvec2(), self.location.as_dvec2() + self.dimensions.as_dvec2()])).bounding_box();
|
||||
|
||||
if self.clip {
|
||||
Some(artboard_bounds)
|
||||
} else {
|
||||
[self.content.bounding_box(transform, include_stroke), Some(artboard_bounds)]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.reduce(Quad::combine_bounds)
|
||||
return RenderBoundingBox::Rectangle(artboard_bounds());
|
||||
}
|
||||
|
||||
match self.content.bounding_box(transform, include_stroke) {
|
||||
RenderBoundingBox::Rectangle(content_bounds) => RenderBoundingBox::Rectangle(Quad::combine_bounds(content_bounds, artboard_bounds())),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,12 +89,6 @@ pub fn migrate_artboard<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Re
|
||||
})
|
||||
}
|
||||
|
||||
impl BoundingBox for Table<Artboard> {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
self.iter().filter_map(|row| row.element.bounding_box(transform, include_stroke)).reduce(Quad::combine_bounds)
|
||||
}
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
async fn create_artboard<T: Into<Table<Graphic>> + 'n>(
|
||||
ctx: impl ExtractAll + CloneVarArgs + Ctx,
|
||||
@@ -102,6 +97,7 @@ async fn create_artboard<T: Into<Table<Graphic>> + 'n>(
|
||||
Context -> Table<Vector>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> Table<Color>,
|
||||
Context -> DAffine2,
|
||||
)]
|
||||
content: impl Node<Context<'static>, Output = T>,
|
||||
|
||||
@@ -34,6 +34,13 @@ impl MultiplyAlpha for Table<Raster<CPU>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl MultiplyAlpha for Table<Color> {
|
||||
fn multiply_alpha(&mut self, factor: f64) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.opacity *= factor as f32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) trait MultiplyFill {
|
||||
fn multiply_fill(&mut self, factor: f64);
|
||||
@@ -64,6 +71,13 @@ impl MultiplyFill for Table<Raster<CPU>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl MultiplyFill for Table<Color> {
|
||||
fn multiply_fill(&mut self, factor: f64) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.fill *= factor as f32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait SetBlendMode {
|
||||
fn set_blend_mode(&mut self, blend_mode: BlendMode);
|
||||
@@ -90,6 +104,13 @@ impl SetBlendMode for Table<Raster<CPU>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl SetBlendMode for Table<Color> {
|
||||
fn set_blend_mode(&mut self, blend_mode: BlendMode) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.blend_mode = blend_mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait SetClip {
|
||||
fn set_clip(&mut self, clip: bool);
|
||||
@@ -116,6 +137,13 @@ impl SetClip for Table<Raster<CPU>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl SetClip for Table<Color> {
|
||||
fn set_clip(&mut self, clip: bool) {
|
||||
for row in self.iter_mut() {
|
||||
row.alpha_blending.clip = clip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Style"))]
|
||||
fn blend_mode<T: SetBlendMode>(
|
||||
@@ -124,6 +152,7 @@ fn blend_mode<T: SetBlendMode>(
|
||||
Table<Graphic>,
|
||||
Table<Vector>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Color>,
|
||||
)]
|
||||
mut value: T,
|
||||
blend_mode: BlendMode,
|
||||
@@ -140,6 +169,7 @@ fn opacity<T: MultiplyAlpha>(
|
||||
Table<Graphic>,
|
||||
Table<Vector>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Color>,
|
||||
)]
|
||||
mut value: T,
|
||||
#[default(100.)] opacity: Percentage,
|
||||
@@ -156,6 +186,7 @@ fn blending<T: SetBlendMode + MultiplyAlpha + MultiplyFill + SetClip>(
|
||||
Table<Graphic>,
|
||||
Table<Vector>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Color>,
|
||||
)]
|
||||
mut value: T,
|
||||
blend_mode: BlendMode,
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
use crate::Color;
|
||||
use glam::{DAffine2, DVec2};
|
||||
|
||||
#[derive(Clone, Copy, Default, Debug, PartialEq)]
|
||||
pub enum RenderBoundingBox {
|
||||
#[default]
|
||||
None,
|
||||
Infinite,
|
||||
Rectangle([DVec2; 2]),
|
||||
}
|
||||
|
||||
pub trait BoundingBox {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]>;
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> RenderBoundingBox;
|
||||
}
|
||||
|
||||
macro_rules! none_impl {
|
||||
($t:path) => {
|
||||
impl BoundingBox for $t {
|
||||
fn bounding_box(&self, _transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
None
|
||||
fn bounding_box(&self, _transform: DAffine2, _include_stroke: bool) -> RenderBoundingBox {
|
||||
RenderBoundingBox::None
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -20,5 +28,11 @@ none_impl!(bool);
|
||||
none_impl!(f32);
|
||||
none_impl!(f64);
|
||||
none_impl!(DVec2);
|
||||
none_impl!(Option<Color>);
|
||||
none_impl!(Vec<Color>);
|
||||
none_impl!(Option<Color>); // TODO: Remove this?
|
||||
none_impl!(Vec<Color>); // TODO: Remove this?
|
||||
|
||||
impl BoundingBox for Color {
|
||||
fn bounding_box(&self, _transform: DAffine2, _include_stroke: bool) -> RenderBoundingBox {
|
||||
RenderBoundingBox::Infinite
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::blending::AlphaBlending;
|
||||
use crate::bounds::BoundingBox;
|
||||
use crate::math::quad::Quad;
|
||||
use crate::bounds::{BoundingBox, RenderBoundingBox};
|
||||
use crate::raster_types::{CPU, GPU, Raster};
|
||||
use crate::table::{Table, TableRow};
|
||||
use crate::uuid::NodeId;
|
||||
@@ -17,11 +16,12 @@ pub enum Graphic {
|
||||
Vector(Table<Vector>),
|
||||
RasterCPU(Table<Raster<CPU>>),
|
||||
RasterGPU(Table<Raster<GPU>>),
|
||||
Color(Table<Color>),
|
||||
}
|
||||
|
||||
impl Default for Graphic {
|
||||
fn default() -> Self {
|
||||
Self::Graphic(Default::default())
|
||||
Self::Graphic(Table::new())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,48 @@ impl From<Table<Raster<GPU>>> for Table<Graphic> {
|
||||
}
|
||||
}
|
||||
|
||||
// Color
|
||||
impl From<Color> for Graphic {
|
||||
fn from(color: Color) -> Self {
|
||||
Graphic::Color(Table::new_from_element(color))
|
||||
}
|
||||
}
|
||||
impl From<Table<Color>> for Graphic {
|
||||
fn from(color: Table<Color>) -> Self {
|
||||
Graphic::Color(color)
|
||||
}
|
||||
}
|
||||
impl From<Color> for Table<Graphic> {
|
||||
fn from(color: Color) -> Self {
|
||||
Table::new_from_element(Graphic::Color(Table::new_from_element(color)))
|
||||
}
|
||||
}
|
||||
impl From<Table<Color>> for Table<Graphic> {
|
||||
fn from(color: Table<Color>) -> Self {
|
||||
Table::new_from_element(Graphic::Color(color))
|
||||
}
|
||||
}
|
||||
|
||||
// Option<Color>
|
||||
impl From<Option<Color>> for Graphic {
|
||||
fn from(color: Option<Color>) -> Self {
|
||||
if let Some(color) = color {
|
||||
Graphic::Color(Table::new_from_element(color))
|
||||
} else {
|
||||
Graphic::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Option<Color>> for Table<Graphic> {
|
||||
fn from(color: Option<Color>) -> Self {
|
||||
if let Some(color) = color {
|
||||
Table::new_from_element(Graphic::Color(Table::new_from_element(color)))
|
||||
} else {
|
||||
Table::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DAffine2
|
||||
impl From<DAffine2> for Graphic {
|
||||
fn from(_: DAffine2) -> Self {
|
||||
@@ -159,6 +201,7 @@ impl Graphic {
|
||||
Graphic::Graphic(graphic) => graphic.iter().all(|row| row.alpha_blending.clip),
|
||||
Graphic::RasterCPU(raster) => raster.iter().all(|row| row.alpha_blending.clip),
|
||||
Graphic::RasterGPU(raster) => raster.iter().all(|row| row.alpha_blending.clip),
|
||||
Graphic::Color(color) => color.iter().all(|row| row.alpha_blending.clip),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,28 +218,21 @@ impl Graphic {
|
||||
}
|
||||
|
||||
impl BoundingBox for Graphic {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> RenderBoundingBox {
|
||||
match self {
|
||||
Graphic::Vector(vector) => vector.bounding_box(transform, include_stroke),
|
||||
Graphic::RasterCPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||
Graphic::RasterGPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||
Graphic::Graphic(graphic) => graphic.bounding_box(transform, include_stroke),
|
||||
Graphic::Color(color) => color.bounding_box(transform, include_stroke),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BoundingBox for Table<Graphic> {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
self.iter()
|
||||
.filter_map(|element| element.element.bounding_box(transform * *element.transform, include_stroke))
|
||||
.reduce(Quad::combine_bounds)
|
||||
}
|
||||
}
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
async fn source_node_id<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>)] content: Table<I>,
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>)] content: Table<I>,
|
||||
node_path: Vec<NodeId>,
|
||||
) -> Table<I> {
|
||||
// Get the penultimate element of the node path, or None if the path is too short
|
||||
@@ -216,11 +252,11 @@ async fn source_node_id<I: 'n + Send + Clone>(
|
||||
async fn extend<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
/// The table whose rows will appear at the start of the extended table.
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>)]
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>)]
|
||||
base: Table<I>,
|
||||
/// The table whose rows will appear at the end of the extended table.
|
||||
#[expose]
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>)]
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>)]
|
||||
new: Table<I>,
|
||||
) -> Table<I> {
|
||||
let mut base = base;
|
||||
@@ -233,9 +269,9 @@ async fn extend<I: 'n + Send + Clone>(
|
||||
#[node_macro::node(category(""))]
|
||||
async fn legacy_layer_extend<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>)] base: Table<I>,
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>)] base: Table<I>,
|
||||
#[expose]
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>)]
|
||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>)]
|
||||
new: Table<I>,
|
||||
nested_node_path: Vec<NodeId>,
|
||||
) -> Table<I> {
|
||||
@@ -260,6 +296,9 @@ async fn wrap_graphic<T: Into<Graphic> + 'n>(
|
||||
Table<Vector>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Raster<GPU>>,
|
||||
Table<Color>,
|
||||
Color,
|
||||
Option<Color>,
|
||||
DAffine2,
|
||||
)]
|
||||
content: T,
|
||||
@@ -277,6 +316,9 @@ async fn to_graphic<T: Into<Table<Graphic>> + 'n>(
|
||||
Table<Vector>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Raster<GPU>>,
|
||||
Table<Color>,
|
||||
Color,
|
||||
Option<Color>,
|
||||
)]
|
||||
content: T,
|
||||
) -> Table<Graphic> {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use crate::Color;
|
||||
use crate::bounds::BoundingBox;
|
||||
use crate::bounds::{BoundingBox, RenderBoundingBox};
|
||||
use crate::math::quad::Quad;
|
||||
use crate::raster::Image;
|
||||
use crate::table::Table;
|
||||
use core::ops::Deref;
|
||||
use dyn_any::DynAny;
|
||||
use glam::{DAffine2, DVec2};
|
||||
@@ -199,17 +198,16 @@ mod gpu_common {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> BoundingBox for Table<Raster<T>>
|
||||
impl<T> BoundingBox for Raster<T>
|
||||
where
|
||||
Raster<T>: Storage,
|
||||
{
|
||||
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
self.iter()
|
||||
.filter(|row| !row.element.is_empty()) // Eliminate empty images
|
||||
.flat_map(|row| {
|
||||
let transform = transform * *row.transform;
|
||||
(transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())
|
||||
})
|
||||
.reduce(Quad::combine_bounds)
|
||||
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> RenderBoundingBox {
|
||||
if self.is_empty() || transform.matrix2.determinant() == 0. {
|
||||
return RenderBoundingBox::None;
|
||||
}
|
||||
|
||||
let unit_rectangle = Quad::from_box([DVec2::ZERO, DVec2::ONE]);
|
||||
RenderBoundingBox::Rectangle((transform * unit_rectangle).bounding_box())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ impl RenderComplexity for Graphic {
|
||||
Self::Vector(table) => table.render_complexity(),
|
||||
Self::RasterCPU(table) => table.render_complexity(),
|
||||
Self::RasterGPU(table) => table.render_complexity(),
|
||||
Self::Color(table) => table.render_complexity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +53,12 @@ impl RenderComplexity for Raster<GPU> {
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderComplexity for Color {
|
||||
fn render_complexity(&self) -> usize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderComplexity for String {}
|
||||
impl RenderComplexity for bool {}
|
||||
impl RenderComplexity for f32 {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::AlphaBlending;
|
||||
use crate::bounds::{BoundingBox, RenderBoundingBox};
|
||||
use crate::transform::ApplyTransform;
|
||||
use crate::uuid::NodeId;
|
||||
use crate::{AlphaBlending, math::quad::Quad};
|
||||
use dyn_any::StaticType;
|
||||
use glam::DAffine2;
|
||||
use std::hash::Hash;
|
||||
@@ -125,6 +126,28 @@ impl<T> Table<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BoundingBox> BoundingBox for Table<T> {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> RenderBoundingBox {
|
||||
let mut combined_bounds = None;
|
||||
|
||||
for row in self.iter() {
|
||||
match row.element.bounding_box(transform * *row.transform, include_stroke) {
|
||||
RenderBoundingBox::None => continue,
|
||||
RenderBoundingBox::Infinite => return RenderBoundingBox::Infinite,
|
||||
RenderBoundingBox::Rectangle(bounds) => match combined_bounds {
|
||||
Some(existing) => combined_bounds = Some(Quad::combine_bounds(existing, bounds)),
|
||||
None => combined_bounds = Some(bounds),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
match combined_bounds {
|
||||
Some(bounds) => RenderBoundingBox::Rectangle(bounds),
|
||||
None => RenderBoundingBox::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoIterator for Table<T> {
|
||||
type Item = TableRow<T>;
|
||||
type IntoIter = TableRowIter<T>;
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::Artboard;
|
||||
use crate::math::bbox::AxisAlignedBbox;
|
||||
pub use crate::vector::ReferencePoint;
|
||||
use core::f64;
|
||||
use glam::{DAffine2, DMat2, DVec2};
|
||||
use glam::{DAffine2, DMat2, DVec2, UVec2};
|
||||
|
||||
pub trait Transform {
|
||||
fn transform(&self) -> DAffine2;
|
||||
@@ -89,7 +89,7 @@ pub struct Footprint {
|
||||
/// Inverse of the transform which will be applied to the node output during the rendering process
|
||||
pub transform: DAffine2,
|
||||
/// Resolution of the target output area in pixels
|
||||
pub resolution: glam::UVec2,
|
||||
pub resolution: UVec2,
|
||||
/// Quality of the render, this may be used by caching nodes to decide if the cached render is sufficient
|
||||
pub quality: RenderQuality,
|
||||
}
|
||||
@@ -103,7 +103,7 @@ impl Default for Footprint {
|
||||
impl Footprint {
|
||||
pub const DEFAULT: Self = Self {
|
||||
transform: DAffine2::IDENTITY,
|
||||
resolution: glam::UVec2::new(1920, 1080),
|
||||
resolution: UVec2::new(1920, 1080),
|
||||
quality: RenderQuality::Full,
|
||||
};
|
||||
|
||||
@@ -112,7 +112,7 @@ impl Footprint {
|
||||
matrix2: DMat2::from_diagonal(DVec2::splat(f64::INFINITY)),
|
||||
translation: DVec2::ZERO,
|
||||
},
|
||||
resolution: glam::UVec2::new(0, 0),
|
||||
resolution: UVec2::ZERO,
|
||||
quality: RenderQuality::Full,
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::vector::Vector;
|
||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
|
||||
use core::f64;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use graphene_core_shaders::color::Color;
|
||||
|
||||
#[node_macro::node(category(""))]
|
||||
async fn transform<T: ApplyTransform + 'n + 'static>(
|
||||
@@ -43,7 +44,7 @@ async fn transform<T: ApplyTransform + 'n + 'static>(
|
||||
#[node_macro::node(category(""))]
|
||||
fn replace_transform<Data, TransformInput: Transform>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Table<Vector>, Table<Raster<CPU>>, Table<Graphic>)] mut data: Table<Data>,
|
||||
#[implementations(Table<Vector>, Table<Raster<CPU>>, Table<Graphic>, Table<Color>)] mut data: Table<Data>,
|
||||
#[implementations(DAffine2)] transform: TransformInput,
|
||||
) -> Table<Data> {
|
||||
for data_transform in data.iter_mut() {
|
||||
@@ -60,6 +61,7 @@ async fn extract_transform<T>(
|
||||
Table<Vector>,
|
||||
Table<Raster<CPU>>,
|
||||
Table<Raster<GPU>>,
|
||||
Table<Color>,
|
||||
)]
|
||||
vector: Table<T>,
|
||||
) -> DAffine2 {
|
||||
@@ -94,6 +96,7 @@ async fn boundless_footprint<T: 'n + 'static>(
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> Table<Color>,
|
||||
Context -> String,
|
||||
Context -> f64,
|
||||
)]
|
||||
@@ -112,6 +115,7 @@ async fn freeze_real_time<T: 'n + 'static>(
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Raster<GPU>>,
|
||||
Context -> Table<Color>,
|
||||
Context -> String,
|
||||
Context -> f64,
|
||||
)]
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::table::{Table, TableRowRef};
|
||||
use crate::vector::Vector;
|
||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, Graphic, OwnedContextImpl};
|
||||
use glam::DVec2;
|
||||
use graphene_core_shaders::color::Color;
|
||||
|
||||
#[node_macro::node(name("Instance on Points"), category("Instancing"), path(graphene_core::vector))]
|
||||
async fn instance_on_points<T: Into<Graphic> + Default + Send + Clone + 'static>(
|
||||
@@ -11,7 +12,8 @@ async fn instance_on_points<T: Into<Graphic> + Default + Send + Clone + 'static>
|
||||
#[implementations(
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Vector>,
|
||||
Context -> Table<Raster<CPU>>
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Color>,
|
||||
)]
|
||||
instance: impl Node<'n, Context<'static>, Output = Table<T>>,
|
||||
reverse: bool,
|
||||
@@ -52,7 +54,8 @@ async fn instance_repeat<T: Into<Graphic> + Default + Send + Clone + 'static>(
|
||||
#[implementations(
|
||||
Context -> Table<Graphic>,
|
||||
Context -> Table<Vector>,
|
||||
Context -> Table<Raster<CPU>>
|
||||
Context -> Table<Raster<CPU>>,
|
||||
Context -> Table<Color>,
|
||||
)]
|
||||
instance: impl Node<'n, Context<'static>, Output = Table<T>>,
|
||||
#[default(1)] count: u64,
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::algorithms::spline::{solve_spline_first_handle_closed, solve_spline_f
|
||||
use super::misc::{CentroidType, bezpath_from_manipulator_groups, bezpath_to_manipulator_groups, point_to_dvec2};
|
||||
use super::style::{Fill, Gradient, GradientStops, Stroke};
|
||||
use super::{PointId, SegmentDomain, SegmentId, StrokeId, Vector, VectorExt};
|
||||
use crate::bounds::BoundingBox;
|
||||
use crate::bounds::{BoundingBox, RenderBoundingBox};
|
||||
use crate::raster_types::{CPU, GPU, Raster};
|
||||
use crate::registry::types::{Angle, Fraction, IntegerCount, Length, Multiplier, Percentage, PixelLength, PixelSize, SeedValue};
|
||||
use crate::table::{Table, TableRow, TableRowMut};
|
||||
@@ -106,7 +106,7 @@ where
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("fill_properties"))]
|
||||
async fn fill<F: Into<Fill> + 'n + Send, V>(
|
||||
async fn fill<F: Into<Fill> + 'n + Send, V: VectorTableIterMut + 'n + Send>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Table<Vector>,
|
||||
@@ -116,7 +116,7 @@ async fn fill<F: Into<Fill> + 'n + Send, V>(
|
||||
Table<Graphic>,
|
||||
Table<Graphic>,
|
||||
Table<Graphic>,
|
||||
Table<Graphic>
|
||||
Table<Graphic>,
|
||||
)]
|
||||
/// The content with vector paths to apply the fill style to.
|
||||
mut content: V,
|
||||
@@ -135,10 +135,7 @@ async fn fill<F: Into<Fill> + 'n + Send, V>(
|
||||
fill: F,
|
||||
_backup_color: Option<Color>,
|
||||
_backup_gradient: Gradient,
|
||||
) -> V
|
||||
where
|
||||
V: VectorTableIterMut + 'n + Send,
|
||||
{
|
||||
) -> V {
|
||||
let fill: Fill = fill.into();
|
||||
for vector in content.vector_iter_mut() {
|
||||
let mut fill = fill.clone();
|
||||
@@ -219,7 +216,7 @@ where
|
||||
async fn repeat<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
// TODO: Implement other graphical types.
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>)] 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,
|
||||
@@ -255,7 +252,7 @@ async fn repeat<I: 'n + Send + Clone>(
|
||||
async fn circular_repeat<I: 'n + Send + Clone>(
|
||||
_: impl Ctx,
|
||||
// TODO: Implement other graphical types.
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>)] instance: Table<I>,
|
||||
angle_offset: Angle,
|
||||
#[unit(" px")]
|
||||
#[default(5)]
|
||||
@@ -291,7 +288,7 @@ async fn copy_to_points<I: 'n + Send + Clone>(
|
||||
points: Table<Vector>,
|
||||
#[expose]
|
||||
/// Artwork to be copied and placed at each point.
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>)]
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>)]
|
||||
instance: Table<I>,
|
||||
/// Minimum range of randomized sizes given to each instance.
|
||||
#[default(1)]
|
||||
@@ -366,7 +363,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<Graphic>, Table<Vector>, Table<Raster<CPU>>)] instance: Table<I>,
|
||||
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Color>)] content: Table<I>,
|
||||
#[default(ReferencePoint::Center)] relative_to_bounds: ReferencePoint,
|
||||
#[unit(" px")] offset: f64,
|
||||
#[range((-90., 90.))] angle: Angle,
|
||||
@@ -375,14 +372,12 @@ async fn mirror<I: 'n + Send + Clone>(
|
||||
where
|
||||
Table<I>: BoundingBox,
|
||||
{
|
||||
let mut result_table = Table::new();
|
||||
|
||||
// Normalize the direction vector
|
||||
let normal = DVec2::from_angle(angle.to_radians());
|
||||
|
||||
// The mirror reference is based on the bounding box (at least for now, until we have proper local layer origins)
|
||||
let Some(bounding_box) = instance.bounding_box(DAffine2::IDENTITY, false) else {
|
||||
return result_table;
|
||||
// The mirror reference may be based on the bounding box if an explicit reference point is chosen
|
||||
let RenderBoundingBox::Rectangle(bounding_box) = content.bounding_box(DAffine2::IDENTITY, false) else {
|
||||
return content;
|
||||
};
|
||||
|
||||
let reference_point_location = relative_to_bounds.point_in_bounding_box((bounding_box[0], bounding_box[1]).into());
|
||||
@@ -404,15 +399,17 @@ where
|
||||
reflection * DAffine2::from_translation(DVec2::from_angle(angle.to_radians()) * DVec2::splat(-offset))
|
||||
};
|
||||
|
||||
let mut result_table = Table::new();
|
||||
|
||||
// Add original instance depending on the keep_original flag
|
||||
if keep_original {
|
||||
for instance in instance.clone().into_iter() {
|
||||
for instance in content.clone().into_iter() {
|
||||
result_table.push(instance);
|
||||
}
|
||||
}
|
||||
|
||||
// Create and add mirrored instance
|
||||
for mut row in instance.into_iter() {
|
||||
for mut row in content.into_iter() {
|
||||
row.transform = reflected_transform * row.transform;
|
||||
result_table.push(row);
|
||||
}
|
||||
@@ -1901,7 +1898,7 @@ fn point_inside(_: impl Ctx, source: Table<Vector>, point: DVec2) -> bool {
|
||||
}
|
||||
|
||||
#[node_macro::node(category("General"), path(graphene_core::vector))]
|
||||
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>)] source: Table<I>) -> u64 {
|
||||
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>)] source: Table<I>) -> u64 {
|
||||
source.len() as u64
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::misc::dvec2_to_point;
|
||||
use super::style::{PathStyle, Stroke};
|
||||
pub use super::vector_attributes::*;
|
||||
pub use super::vector_modification::*;
|
||||
use crate::bounds::BoundingBox;
|
||||
use crate::bounds::{BoundingBox, RenderBoundingBox};
|
||||
use crate::math::quad::Quad;
|
||||
use crate::table::Table;
|
||||
use crate::transform::Transform;
|
||||
@@ -437,8 +437,9 @@ impl Vector {
|
||||
}
|
||||
|
||||
impl BoundingBox for Table<Vector> {
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||
self.iter()
|
||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> RenderBoundingBox {
|
||||
let bounds = self
|
||||
.iter()
|
||||
.flat_map(|row| {
|
||||
if !include_stroke {
|
||||
return row.element.bounding_box_with_transform(transform * *row.transform);
|
||||
@@ -455,7 +456,12 @@ impl BoundingBox for Table<Vector> {
|
||||
|
||||
row.element.bounding_box_with_transform(transform * *row.transform).map(|[a, b]| [a - offset, b + offset])
|
||||
})
|
||||
.reduce(Quad::combine_bounds)
|
||||
.reduce(Quad::combine_bounds);
|
||||
|
||||
match bounds {
|
||||
Some(bounds) => RenderBoundingBox::Rectangle(bounds),
|
||||
None => RenderBoundingBox::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user