Add viewing/editing layer names, add Blend Mode node, and clean up Layer node (#1489)

This commit is contained in:
Keavon Chambers
2023-12-07 15:10:47 -08:00
committed by GitHub
parent b7e304a708
commit 60a9c27bf1
43 changed files with 437 additions and 463 deletions

View File

@@ -90,15 +90,15 @@ pub enum BlendMode {
// Not supported by SVG, but we should someday support: Dissolve
// Darken group
Multiply,
Darken,
Multiply,
ColorBurn,
LinearBurn,
DarkerColor,
// Lighten group
Screen,
Lighten,
Screen,
ColorDodge,
LinearDodge,
LighterColor,
@@ -172,6 +172,7 @@ impl core::fmt::Display for BlendMode {
}
}
}
impl BlendMode {
/// Convert the enum to the CSS string for the blend mode.
/// [Read more](https://developer.mozilla.org/en-US/docs/Web/CSS/blend-mode#values)
@@ -206,6 +207,11 @@ impl BlendMode {
}
}
/// Renders the blend mode CSS style declaration.
pub fn render(&self) -> String {
format!(r#" mix-blend-mode: {};"#, self.to_svg_style_name())
}
/// List of all the blend modes in their conventional ordering and grouping.
pub fn list_modes_in_groups() -> [&'static [BlendMode]; 6] {
[
@@ -898,32 +904,55 @@ pub struct OpacityNode<O> {
}
#[node_macro::node_fn(OpacityNode)]
fn image_opacity(color: Color, opacity_multiplier: f32) -> Color {
fn opacity_node(color: Color, opacity_multiplier: f32) -> Color {
let opacity_multiplier = opacity_multiplier / 100.;
Color::from_rgbaf32_unchecked(color.r(), color.g(), color.b(), color.a() * opacity_multiplier)
}
#[node_macro::node_impl(OpacityNode)]
fn image_opacity(mut vector_data: VectorData, opacity_multiplier: f32) -> VectorData {
fn opacity_node(mut vector_data: VectorData, opacity_multiplier: f32) -> VectorData {
let opacity_multiplier = opacity_multiplier / 100.;
vector_data.style.opacity *= opacity_multiplier;
vector_data
}
#[node_macro::node_impl(OpacityNode)]
fn image_opacity(mut graphic_group: GraphicGroup, opacity_multiplier: f32) -> GraphicGroup {
fn opacity_node(mut graphic_group: GraphicGroup, opacity_multiplier: f32) -> GraphicGroup {
let opacity_multiplier = opacity_multiplier / 100.;
graphic_group.opacity *= opacity_multiplier;
graphic_group
}
#[derive(Debug, Clone, Copy)]
pub struct BlendModeNode<BM> {
blend_mode: BM,
}
#[node_macro::node_fn(BlendModeNode)]
fn blend_mode_node(mut vector_data: VectorData, blend_mode: BlendMode) -> VectorData {
vector_data.style.blend_mode = blend_mode;
vector_data
}
#[node_macro::node_impl(BlendModeNode)]
fn blend_mode_node(mut graphic_group: GraphicGroup, blend_mode: BlendMode) -> GraphicGroup {
graphic_group.blend_mode = blend_mode;
graphic_group
}
#[node_macro::node_impl(BlendModeNode)]
fn blend_mode_node(mut image_frame: ImageFrame<Color>, blend_mode: BlendMode) -> ImageFrame<Color> {
image_frame.blend_mode = blend_mode;
image_frame
}
#[derive(Debug, Clone, Copy)]
pub struct PosterizeNode<P> {
posterize_value: P,
}
// Based on http://www.axiomx.com/posterize.htm
// This algorithm is perfectly accurate.
// This algorithm produces fully accurate output in relation to the industry standard.
#[node_macro::node_fn(PosterizeNode)]
fn posterize(color: Color, posterize_value: f32) -> Color {
let color = color.to_gamma_srgb();

View File

@@ -250,7 +250,6 @@ fn map_node<P: Pixel>(input: (u32, u32), data: Vec<P>) -> Image<P> {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ImageFrame<P: Pixel> {
pub image: Image<P>,
// The transform that maps image space to layer space.
//
// Image space is unitless [0, 1] for both axes, with x axis positive
@@ -261,6 +260,7 @@ pub struct ImageFrame<P: Pixel> {
// positive going right and y axis positive going down, with the origin
// being an unspecified quantity.
pub transform: DAffine2,
pub blend_mode: BlendMode,
}
impl<P: Debug + Copy + Pixel> Sample for ImageFrame<P> {
@@ -312,6 +312,7 @@ impl<P: Copy + Pixel> ImageFrame<P> {
Self {
image: Image::empty(),
transform: DAffine2::ZERO,
blend_mode: BlendMode::Normal,
}
}
@@ -319,6 +320,7 @@ impl<P: Copy + Pixel> ImageFrame<P> {
Self {
image: Image::empty(),
transform: DAffine2::IDENTITY,
blend_mode: BlendMode::Normal,
}
}
@@ -379,6 +381,7 @@ impl From<ImageFrame<Color>> for ImageFrame<SRGBA8> {
height: image.image.height,
},
transform: image.transform,
blend_mode: BlendMode::Normal,
}
}
}
@@ -393,6 +396,7 @@ impl From<ImageFrame<SRGBA8>> for ImageFrame<Color> {
height: image.image.height,
},
transform: image.transform,
blend_mode: BlendMode::Normal,
}
}
}