2012-08-01 22:31:54 +00:00
|
|
|
#
|
2020-04-27 07:44:19 +00:00
|
|
|
# FlightGear canvas API
|
|
|
|
# Namespace: canvas
|
2012-08-01 22:31:54 +00:00
|
|
|
#
|
2020-04-27 07:44:19 +00:00
|
|
|
# Classes included:
|
|
|
|
# Transform
|
|
|
|
# Element
|
|
|
|
# Group
|
|
|
|
# Map
|
|
|
|
# Text
|
|
|
|
# Path
|
|
|
|
# Image
|
|
|
|
# Canvas
|
2012-08-01 22:31:54 +00:00
|
|
|
#
|
2020-04-27 07:44:19 +00:00
|
|
|
# see also gui.nas
|
|
|
|
var include_path = "Nasal/canvas/api/";
|
2012-11-04 13:25:36 +00:00
|
|
|
|
2020-04-27 07:44:19 +00:00
|
|
|
# log level for debug output
|
|
|
|
var _API_dbg_level = DEV_WARN;
|
2012-11-04 13:25:36 +00:00
|
|
|
|
2020-06-27 21:18:14 +00:00
|
|
|
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");
|
2020-06-27 21:29:11 +00:00
|
|
|
io.include(include_path~"svgcanvas.nas");
|
2012-08-05 21:43:43 +00:00
|
|
|
|
2012-08-01 22:31:54 +00:00
|
|
|
# Element factories used by #Group elements to create children
|
|
|
|
Group._element_factories = {
|
|
|
|
"group": Group.new,
|
2012-07-11 22:21:30 +00:00
|
|
|
"map": Map.new,
|
2012-08-01 22:31:54 +00:00
|
|
|
"text": Text.new,
|
2012-08-05 21:43:43 +00:00
|
|
|
"path": Path.new,
|
|
|
|
"image": Image.new
|
2012-08-01 22:31:54 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 07:44:19 +00:00
|
|
|
io.include(include_path~"canvas.nas");
|
2012-08-01 22:31:54 +00:00
|
|
|
|
2014-06-01 10:25:34 +00:00
|
|
|
# @param g Canvas ghost
|
2020-04-28 12:15:28 +00:00
|
|
|
var wrapCanvas = func(g) {
|
|
|
|
if (g != nil and g._impl == nil) {
|
|
|
|
g._impl = Canvas._new(g);
|
|
|
|
}
|
|
|
|
return g;
|
2012-11-18 22:28:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 22:31:54 +00:00
|
|
|
# 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)
|
|
|
|
{
|
2012-11-18 22:28:53 +00:00
|
|
|
var m = wrapCanvas(_newCanvasGhost());
|
2014-06-01 10:25:34 +00:00
|
|
|
m._node.setValues(vals);
|
2012-08-01 22:31:54 +00:00
|
|
|
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
|
2012-11-18 22:28:53 +00:00
|
|
|
var get = func(arg)
|
2012-08-01 22:31:54 +00:00
|
|
|
{
|
2012-11-18 22:28:53 +00:00
|
|
|
if( isa(arg, props.Node) )
|
|
|
|
var node = arg;
|
2020-05-05 18:13:06 +00:00
|
|
|
else if (ishash(arg))
|
2012-11-18 22:28:53 +00:00
|
|
|
var node = props.Node.new(arg);
|
2020-05-05 18:13:06 +00:00
|
|
|
else {
|
|
|
|
die("canvas.get: Invalid argument.");
|
|
|
|
}
|
2012-11-18 22:28:53 +00:00
|
|
|
|
2014-06-01 10:25:34 +00:00
|
|
|
return wrapCanvas(_getCanvasGhost(node._g));
|
2012-08-01 22:31:54 +00:00
|
|
|
};
|
2012-08-01 23:28:56 +00:00
|
|
|
|
2013-07-24 22:59:52 +00:00
|
|
|
var getDesktop = func()
|
|
|
|
{
|
|
|
|
return Group.new(_getDesktopGhost());
|
|
|
|
};
|
2023-01-06 10:57:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
var unload = func
|
|
|
|
{
|
|
|
|
unloadTooltips();
|
|
|
|
unloadErrorNotification();
|
2023-01-10 19:42:01 +00:00
|
|
|
unloadGUI();
|
2023-01-06 10:57:00 +00:00
|
|
|
logprint(LOG_INFO, "Unloaded canvas Nasal module");
|
2023-01-10 19:42:01 +00:00
|
|
|
};
|