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

88 lines
1.8 KiB
Text
Raw Normal View History

#
2020-04-27 07:44:19 +00:00
# FlightGear canvas API
# Namespace: canvas
#
2020-04-27 07:44:19 +00:00
# Classes included:
# Transform
# Element
# Group
# Map
# Text
# Path
# Image
# Canvas
#
2020-04-27 07:44:19 +00:00
# see also gui.nas
var include_path = "Nasal/canvas/api/";
2020-04-27 07:44:19 +00:00
# log level for debug output
var _API_dbg_level = DEV_WARN;
io.include(include_path~"colors.nas");
2020-04-27 07:44:19 +00:00
io.include(include_path~"helpers.nas");
io.include(include_path~"transform.nas");
io.include(include_path~"element.nas");
io.include(include_path~"group.nas");
io.include(include_path~"map.nas");
io.include(include_path~"text.nas");
io.include(include_path~"path.nas");
io.include(include_path~"image.nas");
io.include(include_path~"svgcanvas.nas");
2012-08-05 21:43:43 +00:00
# Element factories used by #Group elements to create children
Group._element_factories = {
"group": Group.new,
"map": Map.new,
"text": Text.new,
2012-08-05 21:43:43 +00:00
"path": Path.new,
"image": Image.new
};
2020-04-27 07:44:19 +00:00
io.include(include_path~"canvas.nas");
# @param g Canvas ghost
var wrapCanvas = func(g) {
if (g != nil and g._impl == nil) {
g._impl = Canvas._new(g);
}
return g;
}
# Create a new canvas. Pass parameters as hash, eg:
#
# var my_canvas = canvas.new({
# "name": "PFD-Test",
# "size": [512, 512],
# "view": [768, 1024],
# "mipmapping": 1
# });
var new = func(vals)
{
var m = wrapCanvas(_newCanvasGhost());
m._node.setValues(vals);
return m;
};
# Get the first existing canvas with the given name
#
# @param name Name of the canvas
# @return #Canvas, if canvas with #name exists
# nil, otherwise
var get = func(arg)
{
if( isa(arg, props.Node) )
var node = arg;
2020-05-05 18:13:06 +00:00
else if (ishash(arg))
var node = props.Node.new(arg);
2020-05-05 18:13:06 +00:00
else {
die("canvas.get: Invalid argument.");
}
return wrapCanvas(_getCanvasGhost(node._g));
};
var getDesktop = func()
{
return Group.new(_getDesktopGhost());
};