mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Remove the 'Blending' node, moving clip into a new 'Clipping Mask' node and fill into the 'Opacity' node (#4085)
* Separate 'Clip' into its own node out from the removed 'Blending' node * Code review * Rename to Clipping Mask * Update Opacity node in demo art that use it * Use DIsplay not Debug for printing blend modes
This commit is contained in:
@@ -197,10 +197,11 @@ fn blend_mode<T: SetBlendMode>(
|
||||
content
|
||||
}
|
||||
|
||||
/// Modifies the opacity of the input graphics by multiplying the existing opacity by this percentage.
|
||||
/// This affects the transparency of the content (together with anything above which is clipped to it).
|
||||
/// Modifies the opacity and/or fill of the input graphics by multiplying the existing values by these percentages.
|
||||
/// Opacity affects the transparency of the content (together with anything above which is clipped to it).
|
||||
/// Fill affects the transparency of the content itself, independent of any content clipped to it.
|
||||
#[node_macro::node(category("Blending"))]
|
||||
fn opacity<T: MultiplyAlpha>(
|
||||
fn opacity<T: MultiplyAlpha + MultiplyFill>(
|
||||
_: impl Ctx,
|
||||
/// The layer stack that will be composited when rendering.
|
||||
#[implementations(
|
||||
@@ -211,19 +212,37 @@ fn opacity<T: MultiplyAlpha>(
|
||||
Table<GradientStops>,
|
||||
)]
|
||||
mut content: T,
|
||||
/// Whether the *Opacity* property is enabled, multiplying the existing opacity by the chosen percentage.
|
||||
#[widget(ParsedWidgetOverride::Hidden)]
|
||||
#[default(true)]
|
||||
has_opacity: bool,
|
||||
/// How visible the content should be, including any content clipped to it.
|
||||
/// Ranges from the default of 100% (fully opaque) to 0% (fully transparent).
|
||||
#[widget(ParsedWidgetOverride::Custom = "optional_percentage")]
|
||||
#[default(100.)]
|
||||
opacity: Percentage,
|
||||
/// Whether the *Fill* property is enabled, multiplying the existing fill by the chosen percentage.
|
||||
#[widget(ParsedWidgetOverride::Hidden)]
|
||||
has_fill: bool,
|
||||
/// How visible the content should be, independent of any content clipped to it.
|
||||
/// Ranges from 0% (fully transparent) to the default of 100% (fully opaque).
|
||||
#[widget(ParsedWidgetOverride::Custom = "optional_percentage")]
|
||||
#[default(100.)]
|
||||
fill: Percentage,
|
||||
) -> T {
|
||||
// TODO: Find a way to make this apply once to the table's parent (i.e. its item in its parent table or TableRow<T>) rather than applying to each item in its own table, which produces the undesired result
|
||||
content.multiply_alpha(opacity / 100.);
|
||||
if has_opacity {
|
||||
content.multiply_alpha(opacity / 100.);
|
||||
}
|
||||
if has_fill {
|
||||
content.multiply_fill(fill / 100.);
|
||||
}
|
||||
content
|
||||
}
|
||||
|
||||
/// Sets each of the blending properties at once. The blend mode determines how overlapping content is composited together. The opacity affects the transparency of the content (together with anything above which is clipped to it). The fill affects the transparency of the content itself, without affecting that of content clipped to it. The clip property determines whether the content inherits the alpha of the content beneath it.
|
||||
/// Sets whether the input graphics inherit the alpha of the content beneath them, "clipping" them to that content.
|
||||
#[node_macro::node(category("Blending"))]
|
||||
fn blending<T: SetBlendMode + MultiplyAlpha + MultiplyFill + SetClip>(
|
||||
fn clipping_mask<T: SetClip>(
|
||||
_: impl Ctx,
|
||||
/// The layer stack that will be composited when rendering.
|
||||
#[implementations(
|
||||
@@ -234,23 +253,10 @@ fn blending<T: SetBlendMode + MultiplyAlpha + MultiplyFill + SetClip>(
|
||||
Table<GradientStops>,
|
||||
)]
|
||||
mut content: T,
|
||||
/// The choice of equation that controls how brightness and color blends between overlapping pixels.
|
||||
blend_mode: BlendMode,
|
||||
/// How visible the content should be, including any content clipped to it.
|
||||
/// Ranges from the default of 100% (fully opaque) to 0% (fully transparent).
|
||||
#[default(100.)]
|
||||
opacity: Percentage,
|
||||
/// How visible the content should be, independent of any content clipped to it.
|
||||
/// Ranges from 0% (fully transparent) to 100% (fully opaque).
|
||||
#[default(100.)]
|
||||
fill: Percentage,
|
||||
/// Whether the content inherits the alpha of the content beneath it.
|
||||
clip: bool,
|
||||
) -> T {
|
||||
// TODO: Find a way to make this apply once to the table's parent (i.e. its item in its parent table or TableRow<T>) rather than applying to each item in its own table, which produces the undesired result
|
||||
content.set_blend_mode(blend_mode);
|
||||
content.multiply_alpha(opacity / 100.);
|
||||
content.multiply_fill(fill / 100.);
|
||||
content.set_clip(clip);
|
||||
content
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user