1
0
Fork 0
fgdata/Nasal/canvas/api/canvas.nas
TheFGFSEagle 724fad6701 Fix placements not being removed when destroying a canvas
Canvas placements are being added / removed through a listener on "placement" node adds / removals on the canvas's node.
Previously, when the canvas's del method was called, the canvas's node was removed, but not its "placement" subnodes.
This caused the canvas to be destroyed without the placements being removed.
This in turn causes problems when setting up a canvas with the same placement(s).
This is fixed by this commit by removing the "placement" nodes separately before destroying the canvas.
2023-12-09 18:08:55 +00:00

74 lines
2.2 KiB
Text

#-------------------------------------------------------------------------------
# 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;
},
# 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");
me._node.remove();
me.parents = nil; # ensure all ghosts get destroyed
}
};