Library globals

Source canvas . api . canvas.nas

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#-------------------------------------------------------------------------------
# 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 {
        me._node.remove();
        me.parents = nil; # ensure all ghosts get destroyed
    }
};