mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Rename GradientStops to Gradient and the legacy Gradient/Fill structs to LegacyGradient/LegacyFill
This commit is contained in:
committed by
Dennis Kobert
parent
21eae1e2a1
commit
fd7f67b3e9
@@ -3,7 +3,7 @@ use core_types::list::List;
|
||||
use core_types::transform::Footprint;
|
||||
use core_types::{CacheHash, Color, Context, Ctx, DeriveCtx, ExtractAnimationTime, ExtractPointerPosition, ExtractRealTime};
|
||||
use glam::{DAffine2, DVec2};
|
||||
use graphic_types::vector_types::GradientStops;
|
||||
use graphic_types::vector_types::Gradient;
|
||||
use graphic_types::{Artboard, Graphic, Vector};
|
||||
use raster_types::{CPU, GPU, Raster};
|
||||
|
||||
@@ -80,7 +80,7 @@ fn quantize_real_time<T>(
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Artboard>,
|
||||
Context -> List<GradientStops>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<String>,
|
||||
Context -> List<f64>,
|
||||
Context -> (),
|
||||
@@ -120,7 +120,7 @@ fn quantize_animation_time<T>(
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Artboard>,
|
||||
Context -> List<GradientStops>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<String>,
|
||||
Context -> List<f64>,
|
||||
Context -> (),
|
||||
|
||||
@@ -3,7 +3,7 @@ use core_types::list::List;
|
||||
use core_types::{Color, ExtractVarArgs};
|
||||
use core_types::{Ctx, ExtractIndex, ExtractIndices, ExtractPosition};
|
||||
use glam::DVec2;
|
||||
use graphic_types::vector_types::GradientStops;
|
||||
use graphic_types::vector_types::Gradient;
|
||||
use graphic_types::{Graphic, Vector};
|
||||
use raster_types::{CPU, Raster};
|
||||
|
||||
@@ -40,7 +40,7 @@ fn read_color(ctx: impl Ctx + ExtractVarArgs) -> List<Color> {
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Context"), path(graphene_core::vector))]
|
||||
fn read_gradient(ctx: impl Ctx + ExtractVarArgs) -> List<GradientStops> {
|
||||
fn read_gradient(ctx: impl Ctx + ExtractVarArgs) -> List<Gradient> {
|
||||
let Ok(var_arg) = ctx.vararg(0) else { return Default::default() };
|
||||
let var_arg = var_arg as &dyn std::any::Any;
|
||||
|
||||
@@ -111,12 +111,12 @@ fn read_color_row_extent<C: Ctx + ExtractVarArgs>(_: &ReadColorRowNode, ctx: &C,
|
||||
|
||||
/// Rank-model vararg source: the mapped row's items as lanes, elements only.
|
||||
#[node_macro::node(category("Test"), extent_raw(read_gradient_row_extent))]
|
||||
pub fn read_gradient_row(ctx: impl Ctx + ExtractVarArgs + ExtractIndex) -> Result<IList<GradientStops>, Interrupt> {
|
||||
pub fn read_gradient_row(ctx: impl Ctx + ExtractVarArgs + ExtractIndex) -> Result<IList<Gradient>, Interrupt> {
|
||||
vararg_element(ctx)
|
||||
}
|
||||
|
||||
fn read_gradient_row_extent<C: Ctx + ExtractVarArgs>(_: &ReadGradientRowNode, ctx: &C, level: u8) -> GPoll<Extent> {
|
||||
vararg_lanes::<GradientStops>(ctx, level)
|
||||
vararg_lanes::<Gradient>(ctx, level)
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Context"), path(core_types::vector))]
|
||||
|
||||
@@ -13,7 +13,7 @@ use graphic_types::{ATTR_EDITOR_MERGED_LAYERS, Artboard, Vector};
|
||||
use raster_types::{CPU, GPU, Raster};
|
||||
|
||||
use vector_types::gradient::{GradientSpreadMethod, GradientType as GradientTypeValue};
|
||||
use vector_types::{GradientStop, GradientStops, ReferencePoint};
|
||||
use vector_types::{Gradient, GradientStop, ReferencePoint};
|
||||
|
||||
/// Resolves a signed index over `total` lanes: negatives count from the end,
|
||||
/// out of range resolves to nothing.
|
||||
@@ -100,7 +100,7 @@ fn omit_element_extent(list: ExtentIn<'_>, index: ValueIn<'_, f64>, level: Level
|
||||
pub fn extract_element<T: Clone + Default + Send + Sync + CacheHash + 'static>(
|
||||
_: impl Ctx,
|
||||
/// The `List` of data to extract from.
|
||||
#[implementations(String, f64, NodeId, Color, GradientStops, Vector, Raster<CPU>, Graphic, Artboard)]
|
||||
#[implementations(String, f64, NodeId, Color, Gradient, Vector, Raster<CPU>, Graphic, Artboard)]
|
||||
list: IList<T>,
|
||||
/// The index of the item to retrieve, starting from 0 for the first item. Negative indices count backwards from the end of the list, starting from -1 for the last item.
|
||||
index: SignedInteger,
|
||||
@@ -114,7 +114,7 @@ pub fn extract_element<T: Clone + Default + Send + Sync + CacheHash + 'static>(
|
||||
#[node_macro::node(category("General"))]
|
||||
fn map<Row: Clone + Send + Sync + CacheHash + 'static, T>(
|
||||
ctx: impl Ctx + DeriveCtx + ExtractIndex + InjectIndex + Copy,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Color, GradientStops, String)] content: IList<Row>,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Color, Gradient, String)] content: IList<Row>,
|
||||
mapped: impl Node<Context<'_>, Output = IList<T>>,
|
||||
) -> Result<IList<T>, Interrupt> {
|
||||
let mut remaining = ctx.index();
|
||||
@@ -429,9 +429,9 @@ fn extend_extent(base: ExtentIn<'_>, new: ExtentIn<'_>, level: LevelIn) -> GPoll
|
||||
#[node_macro::node(category(""))]
|
||||
pub fn legacy_layer_extend<T: Send + Clone>(
|
||||
_: impl Ctx,
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<GradientStops>)] base: List<T>,
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>)] base: List<T>,
|
||||
#[expose]
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<GradientStops>)]
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>)]
|
||||
new: List<T>,
|
||||
nested_node_path: List<NodeId>,
|
||||
) -> List<T> {
|
||||
@@ -458,7 +458,7 @@ pub fn legacy_layer_extend<T: Send + Clone>(
|
||||
#[node_macro::node(category("General"), extent(wrap_graphic_extent))]
|
||||
pub fn wrap_graphic<'e, T: Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, GradientStops, String)] content: IList<T>,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String)] content: IList<T>,
|
||||
) -> Result<IList<Graphic<'e>>, Interrupt> {
|
||||
let item = content.as_group_item();
|
||||
Ok(Graphic::Group(core_types::record::Group { row: None, content: item }))
|
||||
@@ -483,7 +483,7 @@ pub fn to_graphic<'e, T: graphic_types::graphic::IntoGraphicElement>(
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<GradientStops>,
|
||||
List<Gradient>,
|
||||
List<String>,
|
||||
)]
|
||||
content: T,
|
||||
@@ -503,14 +503,14 @@ pub fn to_graphic_element<'e, T: graphic_types::graphic::IntoGraphicElement>(
|
||||
Raster<CPU>,
|
||||
Raster<GPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
String,
|
||||
List<Graphic>,
|
||||
List<Vector>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<GradientStops>,
|
||||
List<Gradient>,
|
||||
List<String>,
|
||||
)]
|
||||
content: T,
|
||||
@@ -524,7 +524,7 @@ pub fn to_graphic_element<'e, T: graphic_types::graphic::IntoGraphicElement>(
|
||||
#[node_macro::node(category(""), extent(wrap_graphic_extent))]
|
||||
pub fn to_graphic_typed<'e, T: Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Vector, Raster<CPU>, Raster<GPU>, Color, GradientStops, String)] content: IList<T>,
|
||||
#[implementations(Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String)] content: IList<T>,
|
||||
) -> Result<IList<Graphic<'e>>, Interrupt> {
|
||||
let item = content.as_group_item();
|
||||
Ok(Graphic::Group(core_types::record::Group { row: None, content: item }))
|
||||
@@ -548,7 +548,7 @@ fn to_graphic_unit_extent(_content: core_types::extent::ValueIn<'_, ()>, _level:
|
||||
#[node_macro::node(category(""))]
|
||||
pub fn level_to_list<T: Clone + Send + Sync + CacheHash + dyn_any::StaticTypeSized>(
|
||||
_: impl Ctx,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, GradientStops, String)] value: IList<T>,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String)] value: IList<T>,
|
||||
_converter: (),
|
||||
) -> List<T> {
|
||||
let item = value.as_group_item();
|
||||
@@ -650,19 +650,19 @@ pub fn flatten_color<T: IntoGraphicList>(_: impl Ctx, #[implementations(List<Gra
|
||||
content.into_flattened_list()
|
||||
}
|
||||
|
||||
/// Converts a `Graphic[]` into a `GradientStops[]` by deeply flattening any gradient content it contains, and discarding any non-gradient content.
|
||||
/// Converts a `Graphic[]` into a `Gradient[]` by deeply flattening any gradient content it contains, and discarding any non-gradient content.
|
||||
#[node_macro::node(category("General"))]
|
||||
pub fn flatten_gradient<T: IntoGraphicList>(_: impl Ctx, #[implementations(List<Graphic>, List<GradientStops>)] content: T) -> List<GradientStops> {
|
||||
pub fn flatten_gradient<T: IntoGraphicList>(_: impl Ctx, #[implementations(List<Graphic>, List<Gradient>)] content: T) -> List<Gradient> {
|
||||
content.into_flattened_list()
|
||||
}
|
||||
|
||||
/// Constructs a gradient from a `Color[]`, where the colors are evenly distributed as gradient stops across the range from 0 to 1.
|
||||
#[node_macro::node(category("Color"))]
|
||||
fn colors_to_gradient(_: impl Ctx, colors: IList<Color>) -> GradientStops {
|
||||
fn colors_to_gradient(_: impl Ctx, colors: IList<Color>) -> Gradient {
|
||||
let stop = |position: f64, color: Color| GradientStop { position, midpoint: 0.5, color };
|
||||
match colors.len() {
|
||||
0 => GradientStops::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]),
|
||||
1 => GradientStops::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]),
|
||||
total => GradientStops::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))),
|
||||
0 => Gradient::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]),
|
||||
1 => Gradient::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]),
|
||||
total => Gradient::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use glam::DAffine2;
|
||||
use graphic_types::Vector;
|
||||
use graphic_types::graphic::Graphic;
|
||||
use raster_types::{CPU, Raster};
|
||||
use vector_types::{GradientStop, GradientStops};
|
||||
use vector_types::{Gradient, GradientStop};
|
||||
|
||||
/// Whether the walk can descend into a group: the run holds `Graphic`
|
||||
/// elements.
|
||||
@@ -113,12 +113,12 @@ fn wrap_extent(_content: ListIn<'_, Graphic>, _level: LevelIn) -> GPoll<Extent>
|
||||
/// Rank-model colors-to-gradient: the color level folds into one gradient
|
||||
/// with evenly spaced stops.
|
||||
#[node_macro::node(category("Test"))]
|
||||
fn to_gradient(_: impl Ctx, colors: IList<Color>) -> GradientStops {
|
||||
fn to_gradient(_: impl Ctx, colors: IList<Color>) -> Gradient {
|
||||
let stop = |position: f64, color: Color| GradientStop { position, midpoint: 0.5, color };
|
||||
match colors.len() {
|
||||
0 => GradientStops::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]),
|
||||
1 => GradientStops::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]),
|
||||
total => GradientStops::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))),
|
||||
0 => Gradient::new(vec![stop(0., Color::BLACK), stop(1., Color::BLACK)]),
|
||||
1 => Gradient::new(vec![stop(0., colors.get(0)), stop(1., colors.get(0))]),
|
||||
total => Gradient::new((0..total).map(|index| stop(index as f64 / (total - 1) as f64, colors.get(index)))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ pub(crate) fn vararg_row<Row: Clone + Send + Sync + 'static>(content: core_types
|
||||
#[node_macro::node(category("Test"))]
|
||||
fn map<Row: Clone + Send + Sync + core_types::CacheHash + 'static, T>(
|
||||
ctx: impl Ctx + DeriveCtx + ExtractIndex + InjectIndex + Copy,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Color, GradientStops, String)] content: IList<Row>,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Color, Gradient, String)] content: IList<Row>,
|
||||
mapped: impl Node<Context<'_>, Output = IList<T>>,
|
||||
) -> Result<IList<IList<T>>, Interrupt> {
|
||||
let mut remaining = ctx.index();
|
||||
@@ -159,7 +159,7 @@ fn map<Row: Clone + Send + Sync + core_types::CacheHash + 'static, T>(
|
||||
#[node_macro::node(category("Test"))]
|
||||
fn flat_map<Row: Clone + Send + Sync + core_types::CacheHash + 'static, T>(
|
||||
ctx: impl Ctx + DeriveCtx + ExtractIndex + InjectIndex + Copy,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Color, GradientStops, String)] content: IList<Row>,
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Color, Gradient, String)] content: IList<Row>,
|
||||
mapped: impl Node<Context<'_>, Output = IList<T>>,
|
||||
) -> Result<IList<T>, Interrupt> {
|
||||
let mut remaining = ctx.index();
|
||||
@@ -820,14 +820,14 @@ mod tests {
|
||||
let ctx = ContextImpl::root(&scope);
|
||||
|
||||
let layout = Layout::default().with_writes(1, record::element_write_hashed::<Color>(), &[]);
|
||||
let out = Layout::default().with_writes(0, record::element_write_hashed::<GradientStops>(), &[]);
|
||||
let out = Layout::default().with_writes(0, record::element_write_hashed::<Gradient>(), &[]);
|
||||
let build = |colors: Vec<Color>| install_flip(ToGradientNode::new(RecordSource::new(ColorSource { layout: layout.clone(), colors }, &layout, &layout), &layout), &out);
|
||||
let stops_of = |colors: Vec<Color>| {
|
||||
let node = build(colors);
|
||||
let GPoll::Final(record) = record::capture(&node, &ctx, &frames) else {
|
||||
panic!("expected a final record");
|
||||
};
|
||||
record.element::<GradientStops>()
|
||||
record.element::<Gradient>()
|
||||
};
|
||||
|
||||
let three = stops_of(vec![Color::BLACK, Color::WHITE, Color::BLACK]);
|
||||
|
||||
@@ -58,7 +58,7 @@ pub mod subpath {
|
||||
}
|
||||
|
||||
pub mod gradient {
|
||||
pub use vector_types::{GradientStop, GradientStops};
|
||||
pub use vector_types::{Gradient, GradientStop};
|
||||
}
|
||||
|
||||
pub mod transform {
|
||||
|
||||
@@ -33,7 +33,7 @@ use graphic_types::markers::EditorMergedLayers;
|
||||
use graphic_types::raster_types::Image;
|
||||
use graphic_types::raster_types::{CPU, Raster};
|
||||
#[cfg(target_family = "wasm")]
|
||||
use graphic_types::vector_types::gradient::GradientStops;
|
||||
use graphic_types::vector_types::gradient::Gradient;
|
||||
#[cfg(target_family = "wasm")]
|
||||
use rendering::{Render, RenderParams, RenderSvgSegmentList, SvgRender};
|
||||
use std::sync::Arc;
|
||||
@@ -212,7 +212,7 @@ async fn rasterize<T: Clone + Send + Sync + dyn_any::StaticTypeSized>(
|
||||
Raster<CPU>,
|
||||
Graphic,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
mut data: IList<T>,
|
||||
footprint: Footprint,
|
||||
|
||||
@@ -8,7 +8,7 @@ use graphic_types::raster_types::{CPU, Raster};
|
||||
use graphic_types::{Artboard, Graphic, Vector};
|
||||
use rendering::{Render, RenderMetadata, RenderOutputType as RenderOutputTypeRequest, RenderParams, SvgRender, SvgRenderOutput};
|
||||
use std::sync::Arc;
|
||||
use vector_types::GradientStops;
|
||||
use vector_types::Gradient;
|
||||
use wgpu_executor::RenderContext;
|
||||
|
||||
#[derive(Clone, dyn_any::DynAny)]
|
||||
@@ -60,7 +60,7 @@ fn render_intermediate<T: dyn_any::StaticTypeSized + 'static + Render + WasmNotS
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<GradientStops>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<String>,
|
||||
)]
|
||||
data: impl Node<Context<'_>, Output = T>,
|
||||
@@ -80,7 +80,7 @@ fn render_intermediate<T: dyn_any::StaticTypeSized + 'static + Render + WasmNotS
|
||||
#[node_macro::node(category(""))]
|
||||
fn render_intermediate_leveled<T: Clone + Send + Sync + core_types::CacheHash + dyn_any::StaticTypeSized + 'static>(
|
||||
ctx: impl Ctx + ExtractVarArgs + ExtractIndex + InjectIndex + Copy,
|
||||
#[implementations(Artboard, Graphic, Vector, Raster<CPU>, Color, GradientStops, String)] data: IList<T>,
|
||||
#[implementations(Artboard, Graphic, Vector, Raster<CPU>, Color, Gradient, String)] data: IList<T>,
|
||||
) -> Result<RenderIntermediate, Interrupt>
|
||||
where
|
||||
for<'a> core_types::record::RunView<'a, T>: Render,
|
||||
|
||||
@@ -11,7 +11,7 @@ use math_parser::value::{Number, Value};
|
||||
use num_traits::Pow;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use std::ops::{Add, Div, Mul, Rem, Sub};
|
||||
use vector_types::GradientStops;
|
||||
use vector_types::Gradient;
|
||||
use vector_types::markers::{GradientType as GradientTypeAttr, SpreadMethod as SpreadMethodAttr};
|
||||
|
||||
/// The struct that stores the context for the maths parser.
|
||||
@@ -819,25 +819,25 @@ fn hex_to_color(ctx: impl Ctx + ExtractIndex + InjectIndex + Copy, hex_code: Str
|
||||
|
||||
/// Constructs a gradient value which may be set to any sequence of color stops to represent the transition between colors.
|
||||
#[node_macro::node(category("Value"))]
|
||||
fn gradient_value(_: impl Ctx, _primary: (), gradient: GradientStops) -> GradientStops {
|
||||
fn gradient_value(_: impl Ctx, _primary: (), gradient: Gradient) -> Gradient {
|
||||
gradient
|
||||
}
|
||||
|
||||
/// Sets the type (linear or radial) of each gradient in the input list.
|
||||
#[node_macro::node(category("Color"))]
|
||||
fn gradient_type(_: impl Ctx, gradient: GradientStops, gradient_type: vector_types::GradientType) -> (GradientStops, Attr<GradientTypeAttr>) {
|
||||
fn gradient_type(_: impl Ctx, gradient: Gradient, gradient_type: vector_types::GradientType) -> (Gradient, Attr<GradientTypeAttr>) {
|
||||
(gradient, Attr(gradient_type))
|
||||
}
|
||||
|
||||
/// Sets how each gradient in the input list extends past its endpoints: Pad, Reflect, or Repeat.
|
||||
#[node_macro::node(category("Color"))]
|
||||
fn spread_method(_: impl Ctx, gradient: GradientStops, spread_method: vector_types::GradientSpreadMethod) -> (GradientStops, Attr<SpreadMethodAttr>) {
|
||||
fn spread_method(_: impl Ctx, gradient: Gradient, spread_method: vector_types::GradientSpreadMethod) -> (Gradient, Attr<SpreadMethodAttr>) {
|
||||
(gradient, Attr(spread_method))
|
||||
}
|
||||
|
||||
/// Gets the color at the specified position along the gradient, given a position from 0 (left) to 1 (right).
|
||||
#[node_macro::node(category("Color"))]
|
||||
fn sample_gradient(ctx: impl Ctx + ExtractIndex + InjectIndex + Copy, _primary: (), gradient: IList<GradientStops>, position: Fraction) -> Result<IList<Color>, Interrupt> {
|
||||
fn sample_gradient(ctx: impl Ctx + ExtractIndex + InjectIndex + Copy, _primary: (), gradient: IList<Gradient>, position: Fraction) -> Result<IList<Color>, Interrupt> {
|
||||
// An unwired gradient serves an empty level: no color
|
||||
if gradient.is_empty() || ctx.index() != 0 {
|
||||
return Err(GraphError::past_end().into());
|
||||
|
||||
@@ -7,7 +7,7 @@ use glam::{DAffine2, DVec2};
|
||||
use graphic_types::graphic::{GraphicLevel, PaintColumns, PaintReach, bake_paint_transforms, is_paint_present, set_paint_attribute, set_paint_attribute_at};
|
||||
use graphic_types::markers::{EditorMergedLayers, Fill, Stroke};
|
||||
use graphic_types::raster_types::{CPU, GPU, Raster};
|
||||
use graphic_types::vector_types::GradientStops;
|
||||
use graphic_types::vector_types::Gradient;
|
||||
use graphic_types::vector_types::gradient::{GradientSpreadMethod, GradientType};
|
||||
use graphic_types::vector_types::subpath::{ManipulatorGroup, Subpath};
|
||||
use graphic_types::vector_types::vector::PointId;
|
||||
@@ -283,7 +283,7 @@ fn color_paint_row(color: Color, mut attributes: core_types::list::ItemAttribute
|
||||
|
||||
/// A gradient row: an empty vector carrying the stops as its fill paint, the
|
||||
/// gradient keys moved onto the paint.
|
||||
fn gradient_paint_row(stops: GradientStops, mut attributes: core_types::list::ItemAttributeValues) -> Item<Vector> {
|
||||
fn gradient_paint_row(stops: Gradient, mut attributes: core_types::list::ItemAttributeValues) -> Item<Vector> {
|
||||
let mut gradient_paint = List::new_from_element(Graphic::Gradient(stops));
|
||||
if let Some(transform) = attributes.remove::<DAffine2>(ATTR_TRANSFORM) {
|
||||
gradient_paint.set_attribute(ATTR_TRANSFORM, 0, transform);
|
||||
@@ -409,7 +409,7 @@ fn flatten_group(out: &mut List<Vector>, group: &core_types::record::Group, comp
|
||||
out,
|
||||
(0..color.len()).filter_map(|i| Some(color_paint_row(*color.element(i)?, color.clone_item_attributes(i)))).collect(),
|
||||
);
|
||||
} else if let Some(gradient) = graphic_types::graphic::run_to_list::<GradientStops>(item) {
|
||||
} else if let Some(gradient) = graphic_types::graphic::run_to_list::<Gradient>(item) {
|
||||
push_rows(
|
||||
out,
|
||||
(0..gradient.len())
|
||||
|
||||
@@ -13,7 +13,7 @@ impl Adjust<Color> for Color {
|
||||
mod adjust_std {
|
||||
use super::*;
|
||||
use raster_types::{CPU, Raster};
|
||||
use vector_types::GradientStops;
|
||||
use vector_types::Gradient;
|
||||
|
||||
impl Adjust<Color> for Raster<CPU> {
|
||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
||||
@@ -22,7 +22,7 @@ mod adjust_std {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Adjust<Color> for GradientStops {
|
||||
impl Adjust<Color> for Gradient {
|
||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
||||
for color in self.color.iter_mut() {
|
||||
*color = map_fn(color);
|
||||
|
||||
@@ -14,7 +14,7 @@ use num_traits::float::Float;
|
||||
#[cfg(feature = "std")]
|
||||
use raster_types::{CPU, Raster};
|
||||
#[cfg(feature = "std")]
|
||||
use vector_types::GradientStops;
|
||||
use vector_types::Gradient;
|
||||
|
||||
// TODO: Implement the following:
|
||||
// Color Balance
|
||||
@@ -53,7 +53,7 @@ fn luminance<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::Cac
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -78,7 +78,7 @@ fn gamma_correction<T: Adjust<Color> + Clone + Send + Sync + no_std_types::conte
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -100,7 +100,7 @@ fn extract_channel<T: Adjust<Color> + Clone + Send + Sync + no_std_types::contex
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -124,7 +124,7 @@ fn make_opaque<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::C
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -146,7 +146,7 @@ fn brightness_contrast_classic<T: Adjust<Color> + Clone + Send + Sync + no_std_t
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -177,7 +177,7 @@ fn brightness_contrast<T: Adjust<Color> + Clone + Send + Sync + no_std_types::co
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -258,7 +258,7 @@ fn levels<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::CacheH
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
@@ -337,7 +337,7 @@ fn black_and_white<T: Adjust<Color> + Clone + Send + Sync + no_std_types::contex
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
@@ -420,7 +420,7 @@ fn hue_saturation<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -452,7 +452,7 @@ fn invert<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::CacheH
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -473,7 +473,7 @@ fn threshold<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::Cac
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
@@ -519,7 +519,7 @@ fn vibrance<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::Cach
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
@@ -721,7 +721,7 @@ fn channel_mixer<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context:
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
@@ -853,7 +853,7 @@ fn selective_color<T: Adjust<Color> + Clone + Send + Sync + no_std_types::contex
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
@@ -999,7 +999,7 @@ fn posterize<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::Cac
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
@@ -1028,7 +1028,7 @@ fn exposure<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context::Cach
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut input: T,
|
||||
|
||||
@@ -6,7 +6,7 @@ use no_std_types::registry::types::PercentageF32;
|
||||
#[cfg(feature = "std")]
|
||||
use raster_types::{CPU, Raster};
|
||||
#[cfg(feature = "std")]
|
||||
use vector_types::{GradientStop, GradientStops};
|
||||
use vector_types::{Gradient, GradientStop};
|
||||
|
||||
pub trait Blend<P: Pixel> {
|
||||
fn blend(&self, under: &Self, blend_fn: impl Fn(P, P) -> P) -> Self;
|
||||
@@ -36,7 +36,7 @@ mod blend_std {
|
||||
}
|
||||
}
|
||||
|
||||
impl Blend<Color> for GradientStops {
|
||||
impl Blend<Color> for Gradient {
|
||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||
let mut combined_stops = self.position.iter().chain(under.position.iter()).copied().collect::<Vec<_>>();
|
||||
combined_stops.dedup_by(|a, b| (*a - *b).abs() < 1e-6);
|
||||
@@ -47,7 +47,7 @@ mod blend_std {
|
||||
let color = blend_fn(over_color, under_color);
|
||||
GradientStop { position, midpoint: 0.5, color }
|
||||
});
|
||||
GradientStops::new(stops)
|
||||
Gradient::new(stops)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ fn mix<T: Blend<Color> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
over: T,
|
||||
@@ -119,7 +119,7 @@ fn mix<T: Blend<Color> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
under: T,
|
||||
@@ -135,7 +135,7 @@ fn color_overlay<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context:
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Not immediately shader compatible due to needing [`GradientStops`] as a param, which needs [`Vec`]
|
||||
//! Not immediately shader compatible due to needing [`Gradient`] as a param, which needs [`Vec`]
|
||||
|
||||
use crate::adjust::Adjust;
|
||||
use core_types::{Color, Ctx};
|
||||
use raster_types::{CPU, Raster};
|
||||
use vector_types::GradientStops;
|
||||
use vector_types::Gradient;
|
||||
|
||||
// Aims for interoperable compatibility with:
|
||||
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27grdm%27%20%3D%20Gradient%20Map
|
||||
@@ -14,10 +14,10 @@ fn gradient_map<T: Adjust<Color> + Clone + Send + Sync + core_types::CacheHash +
|
||||
#[implementations(
|
||||
Raster<CPU>,
|
||||
Color,
|
||||
GradientStops,
|
||||
Gradient,
|
||||
)]
|
||||
mut image: T,
|
||||
gradient: IList<GradientStops>,
|
||||
gradient: IList<Gradient>,
|
||||
reverse: bool,
|
||||
) -> T {
|
||||
if gradient.is_empty() {
|
||||
|
||||
@@ -9,7 +9,7 @@ use glam::{DAffine2, DMat2, DVec2};
|
||||
use graphic_types::Graphic;
|
||||
use graphic_types::Vector;
|
||||
use graphic_types::raster_types::{CPU, GPU, Raster};
|
||||
use vector_types::GradientStops;
|
||||
use vector_types::Gradient;
|
||||
|
||||
/// Applies the specified transform to each lane of the input, composing onto the lane's transform attribute.
|
||||
#[node_macro::node(category("Math: Transform"), extent(transform_extent))]
|
||||
@@ -97,7 +97,7 @@ fn replace_transform<T>(_: impl Ctx + InjectFootprint, (element, _content_transf
|
||||
// TODO: Figure out how this node should behave once #2982 is implemented.
|
||||
/// Obtains the transform of the first lane of the input, if present.
|
||||
#[node_macro::node(category("Math: Transform"), path(core_types::vector))]
|
||||
fn extract_transform<T: Clone + Send + Sync + CacheHash + 'static>(_: impl Ctx, #[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, GradientStops)] content: IList<T>) -> DAffine2 {
|
||||
fn extract_transform<T: Clone + Send + Sync + CacheHash + 'static>(_: impl Ctx, #[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient)] content: IList<T>) -> DAffine2 {
|
||||
match content.len() {
|
||||
0 => DAffine2::default(),
|
||||
_ => content.lane(0).attr::<TransformAttr>(),
|
||||
|
||||
@@ -37,14 +37,14 @@ use vector_types::vector::misc::{
|
||||
CentroidType, ExtrudeJoiningAlgorithm, HandleId, InterpolationDistribution, MergeByDistanceAlgorithm, PointSpacingType, RowsOrColumns, bezpath_from_manipulator_groups,
|
||||
bezpath_to_manipulator_groups, handles_to_segment, is_linear, point_to_dvec2, segment_to_handles,
|
||||
};
|
||||
use vector_types::vector::style::{GradientStops, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
use vector_types::vector::style::{Gradient, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
use vector_types::vector::{FillId, PointId, RegionId, SegmentDomain, SegmentId, StrokeId, VectorExt};
|
||||
use vector_types::{ATTR_GRADIENT_TYPE, ATTR_SPREAD_METHOD};
|
||||
use vector_types::{GradientSpreadMethod, GradientType};
|
||||
|
||||
/// The gradient color for one assign-colors position, replaying the
|
||||
/// randomized draws up to it.
|
||||
fn assign_color_at(gradient: &GradientStops, position: usize, length: usize, randomize: bool, seed: SeedValue, repeat_every: u32) -> Color {
|
||||
fn assign_color_at(gradient: &Gradient, position: usize, length: usize, randomize: bool, seed: SeedValue, repeat_every: u32) -> Color {
|
||||
let factor = match randomize {
|
||||
true => {
|
||||
let mut rng = rand::rngs::StdRng::seed_from_u64(seed.into());
|
||||
@@ -77,7 +77,7 @@ fn assign_colors<'e>(
|
||||
stroke: bool,
|
||||
/// The range of colors to select from.
|
||||
#[widget(ParsedWidgetOverride::Custom = "assign_colors_gradient")]
|
||||
gradient: IList<GradientStops>,
|
||||
gradient: IList<Gradient>,
|
||||
/// Whether to reverse the gradient.
|
||||
reverse: bool,
|
||||
/// Whether to randomize the color selection for each element from throughout the gradient.
|
||||
@@ -132,7 +132,7 @@ fn assign_colors_extent(
|
||||
content: ListIn<'_, Vector>,
|
||||
_fill: ValueIn<'_, bool>,
|
||||
_stroke: ValueIn<'_, bool>,
|
||||
_gradient: ListIn<'_, GradientStops>,
|
||||
_gradient: ListIn<'_, Gradient>,
|
||||
_reverse: ValueIn<'_, bool>,
|
||||
_randomize: ValueIn<'_, bool>,
|
||||
_seed: ValueIn<'_, SeedValue>,
|
||||
@@ -155,7 +155,7 @@ fn assign_colors_graphic<'e>(
|
||||
#[data] lane_offsets: std::sync::Arc<std::sync::Mutex<Option<LaneOffsets>>>,
|
||||
#[default(true)] fill: bool,
|
||||
stroke: bool,
|
||||
gradient: IList<GradientStops>,
|
||||
gradient: IList<Gradient>,
|
||||
reverse: bool,
|
||||
randomize: bool,
|
||||
seed: SeedValue,
|
||||
@@ -247,7 +247,7 @@ fn assign_colors_graphic_extent(
|
||||
content: ListIn<'_, Graphic>,
|
||||
_fill: ValueIn<'_, bool>,
|
||||
_stroke: ValueIn<'_, bool>,
|
||||
_gradient: ListIn<'_, GradientStops>,
|
||||
_gradient: ListIn<'_, Gradient>,
|
||||
_reverse: ValueIn<'_, bool>,
|
||||
_randomize: ValueIn<'_, bool>,
|
||||
_seed: ValueIn<'_, SeedValue>,
|
||||
@@ -322,7 +322,7 @@ fn fill<'e>(
|
||||
#[default(Color::BLACK)]
|
||||
fill: IList<Graphic<'static>>,
|
||||
_backup_color: IList<Color>,
|
||||
_backup_gradient: IList<GradientStops>,
|
||||
_backup_gradient: IList<Gradient>,
|
||||
_gradient_type: GradientType,
|
||||
_spread_method: GradientSpreadMethod,
|
||||
_transform: Option<DAffine2>,
|
||||
@@ -342,7 +342,7 @@ fn fill_graphic_leveled<'e>(
|
||||
(element, _content_fill): (Graphic<'static>, Attr<Fill>),
|
||||
#[default(Color::BLACK)] fill: IList<Graphic<'static>>,
|
||||
_backup_color: IList<Color>,
|
||||
_backup_gradient: IList<GradientStops>,
|
||||
_backup_gradient: IList<Gradient>,
|
||||
_gradient_type: GradientType,
|
||||
_spread_method: GradientSpreadMethod,
|
||||
_transform: Option<DAffine2>,
|
||||
@@ -2780,7 +2780,7 @@ fn morph_core(flattened: List<Vector>, snapshot: List<Graphic<'static>>, progres
|
||||
};
|
||||
|
||||
// This keeps the gradient metadata attributes, which ride the paint lane
|
||||
let gradient_paint = |metadata_source: &List<Graphic>, stops: GradientStops, transform: Option<DAffine2>| -> List<Graphic> {
|
||||
let gradient_paint = |metadata_source: &List<Graphic>, stops: Gradient, transform: Option<DAffine2>| -> List<Graphic> {
|
||||
let mut out = List::new_from_item(Item::from_parts(Graphic::Gradient(stops), metadata_source.clone_item_attributes(0)));
|
||||
if let Some(transform) = transform {
|
||||
out.set_attribute(ATTR_TRANSFORM, 0, transform);
|
||||
@@ -3666,7 +3666,7 @@ fn point_inside(_: impl Ctx, source: IList<Vector>, point: DVec2) -> bool {
|
||||
// TODO: Return u32, u64, or usize instead of f64 after #1621 is resolved and has allowed us to implement automatic type conversion in the node graph for nodes with generic type inputs.
|
||||
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
|
||||
#[node_macro::node(category("General"), path(graphene_core::vector))]
|
||||
fn count_elements<T: Clone + Send + Sync + CacheHash + 'static>(_: impl Ctx, #[implementations(Graphic, Artboard, Vector, Raster<CPU>, Color, GradientStops, String)] content: IList<T>) -> f64 {
|
||||
fn count_elements<T: Clone + Send + Sync + CacheHash + 'static>(_: impl Ctx, #[implementations(Graphic, Artboard, Vector, Raster<CPU>, Color, Gradient, String)] content: IList<T>) -> f64 {
|
||||
content.len() as f64
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user