4 # Usage: material.showDialog(<path>, [<title>], [<x>], [<y>]);
6 # the path should point to a property "directory" (usually set in
7 # the aircraft's *-set.xml file) that contains any of
8 # (shininess|transparency|texture) and (diffuse|ambient|specular|emission),
9 # whereby the latter four are directories containing any of
10 # (red|green|blue|factor|offset).
12 # If <title> is omitted or nil, then the last path component is used as title.
13 # If <x> and <y> are undefined, then the dialog is centered.
23 # <transparency>0.5</transparency>
24 # <texture>bar.rgb</texture>
28 # material.showDialog("/sim/model/foo/", "FOO");
32 # Of course, these properties are only used if a "material" animation
33 # references them via <*-prop> definition.
38 # <type>material</type>
39 # <object-name>foo</object-name>
40 # <property-base>/sim/model/foo</property-base>
42 # <red-prop>diffuse/red</red-prop>
43 # <green-prop>diffuse/green</green-prop>
44 # <blue-prop>diffuse/blue</blue-prop>
46 # <transparency-prop>transparency</transparency-prop>
47 # <texture-prop>texture</texture-prop>
53 var colorgroup = func(parent, name, base) {
54 var undef = func(color) { props.globals.getNode(base ~ name ~ "/" ~ color) == nil };
56 if (undef("red") and undef("green") and undef("blue")) {
61 parent.addChild("hrule").setColor(1, 1, 1, 0.5);
64 var grp = parent.addChild("group");
65 grp.set("layout", "vbox");
66 grp.addChild("text").set("label", name);
68 foreach (var color; ["red", "green", "blue", "factor"]) {
69 mat(parent, color, base ~ name ~ "/" ~ color, "%.3f");
71 mat(parent, "offset", base ~ name ~ "/" ~ "offset", "%.3f", -1.0, 1.0);
76 var mat = func(parent, name, path, format, min=nil, max=nil) {
77 if (props.globals.getNode(path) != nil) {
78 var grp = parent.addChild("group");
79 grp.set("layout", "hbox");
81 grp.addChild("empty").set("stretch", 1);
82 grp.addChild("text").set("label", name);
84 var slider = grp.addChild("slider");
85 slider.set("property", path);
86 slider.set("live", 1);
87 if (min != nil and max != nil) {
88 slider.set("min", min);
89 slider.set("max", max);
91 slider.setBinding("dialog-apply");
93 var number = grp.addChild("text");
94 number.set("label", "-0.123");
95 number.set("format", format);
96 number.set("property", path);
97 number.set("live", 1);
98 number.setColor(1, 0, 0);
103 var showDialog = func(base, title=nil, x=nil, y=nil) {
104 while (size(base) and substr(base, size(base) - 1, 1) == "/") {
105 base = substr(base, 0, size(base) - 1);
110 c = substr(b, size(b) - 1, 1);
111 if (c == "/") { break }
112 b = substr(b, 0, size(b) - 1);
113 parentdir = c ~ parentdir;
116 if (title == nil) var title = parentdir;
117 var name = "material-" ~ parentdir;
120 dialog = gui.Widget.new();
121 dialog.set("name", name);
122 if (x != nil) dialog.set("x", x);
123 if (y != nil) dialog.set("y", y);
124 dialog.set("layout", "vbox");
126 var titlebar = dialog.addChild("group");
127 titlebar.set("layout", "hbox");
128 var w = titlebar.addChild("text");
129 w.set("label", "object \"" ~ title ~ "\"");
130 titlebar.addChild("empty").set("stretch", 1);
132 w = titlebar.addChild("button");
133 w.set("pref-width", 16);
134 w.set("pref-height", 16);
139 w.setBinding("dialog-close");
142 h += colorgroup(dialog, "diffuse", base, h);
143 h += colorgroup(dialog, "ambient", base, h);
144 h += colorgroup(dialog, "emission", base, h);
145 h += colorgroup(dialog, "specular", base, h);
147 var undef = func(prop) { props.globals.getNode(base ~ prop) == nil };
148 if (!(undef("shininess") and undef("transparency/alpha") and undef("threshold"))) {
150 dialog.addChild("hrule").setColor(1, 1, 1, 0.5);
153 w = dialog.addChild("group");
154 w.set("layout", "hbox");
155 w.addChild("text").set("label", "misc");
157 mat(dialog, "shi", base ~ "shininess", "%.0f", 0.0, 128.0);
158 mat(dialog, "alpha", base ~ "transparency/alpha", "%.3f");
159 mat(dialog, "thresh", base ~ "threshold", "%.3f");
163 if (!undef("texture")) {
165 dialog.addChild("hrule").setColor(1, 1, 1, 0.5);
168 w = dialog.addChild("group");
169 w.set("layout", "hbox");
170 w.addChild("text").set("label", "texture");
172 w = dialog.addChild("input");
174 w.set("pref-width", 200);
175 w.set("property", base ~ "texture");
176 w.setBinding("dialog-apply");
178 dialog.addChild("empty").set("pref-height", "3");
180 dialog.setColor(0.6, 0.6, 0.6, 0.6);
182 fgcommand("dialog-new", dialog.prop());
183 gui.showDialog(name);