diff --git a/hide/comp/PropsEditor.hx b/hide/comp/PropsEditor.hx index 4e8d72a7..8c3bf492 100644 --- a/hide/comp/PropsEditor.hx +++ b/hide/comp/PropsEditor.hx @@ -518,11 +518,14 @@ class PropsField extends Component { propagateValueChange = (value, isTemp) -> { var f = resolveField(); + isTempChange = isTemp; f.gradient.value = value; f.gradient.onChange(isTemp); }; - gradient.onChange = function(shouldUndo : Bool) { + gradient.onChange = function(temp : Bool) { + isTempChange = temp; + var shouldUndo = !temp; if (shouldUndo) { var setVal = function(val, undo) { var f = resolveField(); @@ -549,7 +552,8 @@ class PropsField extends Component { } else { current = gradient.value; setFieldValue(current); - onChange(false); + var f = resolveField(); + f.onChange(false); } } case "model": diff --git a/hrt/prefab/l2d/Gradient.hx b/hrt/prefab/l2d/Gradient.hx new file mode 100644 index 00000000..ca77dd58 --- /dev/null +++ b/hrt/prefab/l2d/Gradient.hx @@ -0,0 +1,73 @@ +package hrt.prefab.l2d; + +class Gradient extends Object2D { + @:s var gradient: hrt.impl.Gradient.GradientData = hrt.impl.Gradient.getDefaultGradientData(); + @:s var dx: Float; + @:s var dy: Float; + + override function makeObject(parent2d:h2d.Object):h2d.Object { + var bmp = new h2d.Bitmap(null, parent2d); + bmp.smooth = true; + return bmp; + } + + override function updateInstance(?propName : String ) { + super.updateInstance(propName); + var bmp = (cast local2d : h2d.Bitmap); + bmp.visible = visible; + if (bmp.tile == null) { + bmp.tile = h2d.Tile.fromTexture(hrt.impl.Gradient.textureFromData(gradient)); + bmp.tile.setSize(64,64); + } else { + @:privateAccess bmp.tile.setTexture(hrt.impl.Gradient.textureFromData(gradient)); + } + + var cRatio = Bitmap.getCenterRatio(dx,dy); + bmp.tile.setCenterRatio(cRatio[0], cRatio[1]); + + #if editor + var int = Std.downcast(bmp.getChildAt(0),h2d.Interactive); + if( int != null ) { + int.width = bmp.tile.width; + int.height = bmp.tile.height; + int.x = bmp.tile.dx; + int.y = bmp.tile.dy; + } + #end + } + + #if editor + + override function makeInteractive():h2d.Interactive { + if(local2d == null) + return null; + var bmp = cast(local2d, h2d.Bitmap); + var int = new h2d.Interactive(bmp.tile.width, bmp.tile.height); + bmp.addChildAt(int, 0); + int.propagateEvents = true; + int.x = bmp.tile.dx; + int.y = bmp.tile.dy; + return int; + } + + + override function edit( ctx : hide.prefab.EditContext ) { + super.edit(ctx); + ctx.properties.add(new hide.Element('
+
+
Gradient
+
Bg Pivot DX
+
Bg Pivot DY
+
'), this, function(pname) { + ctx.onChange(this, pname); + }); + } + + override function getHideProps() : hide.prefab.HideProps { + return { icon : "eyedropper", name : "Gradient" }; + } + + #end + + static var _ = Prefab.register("gradient", Gradient); +} \ No newline at end of file