Debian Codegraph @

Nasal/canvas/api/canvas.nas

raw
1 #-------------------------------------------------------------------------------
2 # Canvas
3 #-------------------------------------------------------------------------------
4 # Class for a canvas
5 # not to be confused with the namespace canvas (case sensitive!)
6 #
7 var Canvas = {
8 # private helper for wrapCanvas;
9 _new: func(canvas_ghost) {
10 var obj = {
11 parents: [Canvas, PropertyElement],
12 _node: props.wrapNode(canvas_ghost._node_ghost),
13 };
14 return obj;
15 },
16
17 # Place this canvas somewhere onto the object. Pass criterions for placement
18 # as a hash, eg:
19 #
20 # my_canvas.addPlacement({
21 # "texture": "EICAS.png",
22 # "node": "PFD-Screen",
23 # "parent": "Some parent name"
24 # });
25 #
26 # Note that we can choose whichever of the three filter criterions we use for
27 # matching the target object for our placement. If none of the three fields is
28 # given every texture of the model will be replaced.
29 addPlacement: func(vals) {
30 var placement = me._node.addChild("placement", 0, 0);
31 placement.setValues(vals);
32 return placement;
33 },
34
35 # Create a new group with the given name
36 #
37 # @param id Optional id/name for the group
38 createGroup: func(id = nil) {
39 return Group.new(me._createGroup(id));
40 },
41
42 # Get the group with the given name
43 getGroup: func(id) {
44 return Group.new(me._getGroup(id));
45 },
46
47 # Set the background color
48 #
49 # @param color Vector of 3 or 4 values in [0, 1]
50 setColorBackground: func {
51 me.set("background", _getColor(arg));
52 },
53
54 getColorBackground: func {
55 me.get("background");
56 },
57
58 # Get path of canvas to be used eg. in Image::setFile
59 getPath: func() {
60 return "canvas://by-index/texture["~me._node.getIndex()~"]";
61 },
62
63 # Destructor
64 #
65 # releases associated canvas and makes this object unusable
66 del: func {
67 # explicitly remove placement nodes. This should in principle not
68 # be required (since _node.remove() should also clean them up)
69 me._node.removeChildren("placement");
70
71 me._node.remove();
72 me.parents = nil; # ensure all ghosts get destroyed
73 }
74 };