Skip to content

Commit

Permalink
Coloradjust transition (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Griwald authored Feb 5, 2024
1 parent eb3f9a6 commit 8856ad6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion h2d/domkit/BaseComponents.hx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,33 @@ class CustomParser extends domkit.CssValue.ValueParser {
}
}

public function transitionColorAdjust(col1: h3d.Matrix.ColorAdjust, col2: h3d.Matrix.ColorAdjust, t: Float) {
inline function defaultValues(col: h3d.Matrix.ColorAdjust) {
var c : h3d.Matrix.ColorAdjust = { saturation: 0, lightness: 0, hue: 0, contrast: 0, gain: { color: 0, alpha: 0 } };
if (col != null) {
if (col.saturation != null) c.saturation = col.saturation;
if (col.lightness != null) c.lightness = col.lightness;
if (col.hue != null) c.hue = col.hue;
if (col.contrast != null) c.contrast = col.contrast;
if (col.gain != null) c.gain = col.gain;
}
return c;
}

var col1 = defaultValues(col1);
var col2 = defaultValues(col2);
return {
saturation: hxd.Math.lerp(col1.saturation, col2.saturation, t),
lightness: hxd.Math.lerp(col1.lightness, col2.lightness, t),
hue: hxd.Math.lerp(col1.hue, col2.hue, t),
contrast: hxd.Math.lerp(col1.contrast, col2.contrast, t),
gain: {
color: transitionColor(col1.gain.color, col2.gain.color, t),
alpha: hxd.Math.lerp(col1.gain.alpha, col2.gain.alpha, t)
}
};
}

public function parseColorAdjust(value:CssValue) : h3d.Matrix.ColorAdjust {
if( value.match(VIdent("none")) )
return null;
Expand Down Expand Up @@ -578,7 +605,7 @@ class DrawableComp extends ObjectComp implements domkit.Component.ComponentDecl<

@:p(colorF) @:t(colorF) #if domkit_drawable_color var color #else var tint #end : h3d.Vector4;
@:p(auto) var smooth : Null<Bool>;
@:p(colorAdjust) var colorAdjust : Null<h3d.Matrix.ColorAdjust>;
@:p(colorAdjust) @:t(colorAdjust) var colorAdjust : Null<h3d.Matrix.ColorAdjust>;
@:p var tileWrap : Bool;

static function #if domkit_drawable_color set_color #else set_tint #end( o : h2d.Drawable, v ) {
Expand Down

0 comments on commit 8856ad6

Please sign in to comment.