-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColorBox.hx
82 lines (63 loc) · 1.78 KB
/
ColorBox.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package prefab;
import hrt.prefab.Context;
class ColorBox extends hrt.prefab.l3d.Box {
var color:Int;
public function new(?parent) {
super(parent);
type = "colorBox";
}
override function setColor(ctx:Context, color:Int) {
super.setColor(ctx, color);
#if !editor
if(ctx.local3d == null)
return;
var mesh = Std.downcast(ctx.local3d, h3d.scene.Mesh);
if(mesh != null)
mesh.material.color.setColor(color);
#end
}
override function save() {
var o:Dynamic = super.save();
// prepare to save our new property to the JSON file
o.color = color;
//
return o;
}
override public function load(v:Dynamic) {
super.load(v);
// load our new property from saved JSON file
color = v.color;
}
override function makeInstance(ctx:Context):Context {
var ret = super.makeInstance(ctx);
// apply our property
// add full alpha to the color
setColor(ctx, 255 << 24 | color);
return ret;
}
override function updateInstance( ctx: Context, ?propName : String ) {
super.updateInstance(ctx, propName);
// add full alpha to the color
setColor(ctx, 255 << 24 | color);
}
#if editor
override function edit( ctx : hide.prefab.EditContext ) {
super.edit(ctx);
var props = new hide.Element('
<div class="group" name="Parameters">
<dl>
<dt>Color</dt>
<dd><input type="color" field="color" /></dd>
</dl>
</div>'
);
ctx.properties.add(props, this, function(propName) {
ctx.onChange(this, propName);
});
}
override function getHideProps() : hide.prefab.HideProps {
return { icon : "square", name : "ColorBox" };
}
#end
static var _ = hrt.prefab.Library.register("colorBox", ColorBox);
}