2013-07-27 09:54:41 +00:00
|
|
|
gui.Style = {
|
2014-06-17 15:13:13 +00:00
|
|
|
new: func(name, name_icon_theme)
|
2013-07-27 09:54:41 +00:00
|
|
|
{
|
|
|
|
var root_node = props.globals.getNode("/sim/gui/canvas", 1)
|
|
|
|
.addChild("style");
|
2014-06-17 15:13:13 +00:00
|
|
|
var gui_path = getprop("/sim/fg-root") ~ "/gui";
|
|
|
|
var style_path = gui_path ~ "/styles/" ~ name;
|
2013-07-27 09:54:41 +00:00
|
|
|
|
|
|
|
var m = {
|
|
|
|
parents: [gui.Style],
|
2014-06-17 15:13:13 +00:00
|
|
|
_path: style_path,
|
|
|
|
_dir_icons: gui_path ~ "/icons/" ~ name_icon_theme,
|
|
|
|
_node: io.read_properties(style_path ~ "/style.xml", root_node),
|
2023-01-24 18:49:32 +00:00
|
|
|
_colors: {},
|
|
|
|
_sizes: {}
|
2013-07-27 09:54:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# parse theme colors
|
|
|
|
var colors = m._node.getChild("colors");
|
|
|
|
if( colors != nil )
|
|
|
|
{
|
|
|
|
foreach(var color; colors.getChildren())
|
|
|
|
{
|
2023-01-24 18:49:32 +00:00
|
|
|
var tintNode = color.getChild("tint");
|
|
|
|
var shadeNode = color.getChild("shade");
|
|
|
|
var baseNode = color.getChild("base");
|
|
|
|
|
|
|
|
if (tintNode and baseNode) {
|
|
|
|
|
|
|
|
} elsif (shadeNode and baseNode) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
# todo : support a CSS style color as a direct text child,
|
|
|
|
# instead of seperate RGBA components
|
|
|
|
m._colors[ color.getName() ] = m._parseRGBANodes(color);
|
2013-07-27 09:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-24 18:49:32 +00:00
|
|
|
var sizes = m._node.getChild("sizes");
|
|
|
|
if (sizes) {
|
|
|
|
foreach(var sizeNode; sizes.getChildren()) {
|
|
|
|
var factorNode = sizeNode.getChild("factor");
|
|
|
|
var baseNode = sizeNode.getChild("base");
|
|
|
|
if (factorNode or baseNode) {
|
|
|
|
var f = factorNode.getValue() or 1.0;
|
|
|
|
m._sizes[sizeNode.getName()] = f * m.getSize(baseNode.getValue(), 1.0);
|
|
|
|
} else {
|
|
|
|
# simple literal value, easy
|
|
|
|
m._sizes[sizeNode.getName()] = sizeNode.getValue();
|
|
|
|
}
|
|
|
|
} # of sizes iteration
|
|
|
|
}
|
|
|
|
|
2013-07-27 09:54:41 +00:00
|
|
|
m._dir_decoration =
|
|
|
|
m._path ~ "/" ~ (m._node.getValue("folders/decoration") or "decoration");
|
|
|
|
m._dir_widgets =
|
|
|
|
m._path ~ "/" ~ (m._node.getValue("folders/widgets") or "widgets");
|
|
|
|
|
|
|
|
return m;
|
|
|
|
},
|
2023-01-24 18:49:32 +00:00
|
|
|
_parseRGBANodes: func(color)
|
|
|
|
{
|
|
|
|
var comp_names = ["red", "green", "blue", "alpha"];
|
|
|
|
var str = "rgba(";
|
|
|
|
for(var i = 0; i < size(comp_names); i += 1)
|
|
|
|
{
|
|
|
|
if( i > 0 )
|
|
|
|
str ~= ",";
|
|
|
|
var val = color.getValue(comp_names[i]);
|
|
|
|
if( val == nil )
|
|
|
|
val = 1;
|
|
|
|
if( i < 3 )
|
|
|
|
str ~= int(val * 255 + 0.5);
|
|
|
|
else
|
|
|
|
str ~= int(val * 100) / 100;
|
|
|
|
}
|
|
|
|
return str ~ ")";
|
|
|
|
},
|
|
|
|
|
2013-07-27 09:54:41 +00:00
|
|
|
getColor: func(name, def = "#00ffff")
|
|
|
|
{
|
|
|
|
return me._colors[name] or def;
|
2023-01-24 18:49:32 +00:00
|
|
|
},
|
|
|
|
getSize: func(name, def = 1.0)
|
|
|
|
{
|
|
|
|
return me._sizes[name] or def;
|
2013-07-27 09:54:41 +00:00
|
|
|
}
|
|
|
|
};
|