1
0
Fork 0
fgdata/Nasal/canvas/api/canvas.nas

75 lines
2.2 KiB
Text
Raw Normal View History

2020-04-27 07:44:19 +00:00
#-------------------------------------------------------------------------------
# Canvas
#-------------------------------------------------------------------------------
# Class for a canvas
# not to be confused with the namespace canvas (case sensitive!)
#
var Canvas = {
# private helper for wrapCanvas;
_new: func(canvas_ghost) {
var obj = {
parents: [Canvas, PropertyElement],
_node: props.wrapNode(canvas_ghost._node_ghost),
};
return obj;
},
2020-04-27 07:44:19 +00:00
# Place this canvas somewhere onto the object. Pass criterions for placement
# as a hash, eg:
#
# my_canvas.addPlacement({
# "texture": "EICAS.png",
# "node": "PFD-Screen",
# "parent": "Some parent name"
# });
#
# Note that we can choose whichever of the three filter criterions we use for
# matching the target object for our placement. If none of the three fields is
# given every texture of the model will be replaced.
addPlacement: func(vals) {
var placement = me._node.addChild("placement", 0, 0);
placement.setValues(vals);
return placement;
},
# Create a new group with the given name
#
# @param id Optional id/name for the group
createGroup: func(id = nil) {
return Group.new(me._createGroup(id));
},
# Get the group with the given name
getGroup: func(id) {
return Group.new(me._getGroup(id));
},
# Set the background color
#
# @param color Vector of 3 or 4 values in [0, 1]
setColorBackground: func {
me.set("background", _getColor(arg));
},
getColorBackground: func {
me.get("background");
},
# Get path of canvas to be used eg. in Image::setFile
getPath: func() {
return "canvas://by-index/texture["~me._node.getIndex()~"]";
},
# Destructor
#
# releases associated canvas and makes this object unusable
del: func {
# explicitly remove placement nodes. This should in principle not
# be required (since _node.remove() should also clean them up)
me._node.removeChildren("placement");
2020-04-27 07:44:19 +00:00
me._node.remove();
me.parents = nil; # ensure all ghosts get destroyed
}
};