Use latest core API and fix FG 2.8 support
This commit is contained in:
parent
358d6fc754
commit
10c635752a
2 changed files with 67 additions and 40 deletions
|
@ -736,17 +736,10 @@ var Canvas = {
|
||||||
# @param id Optional id/name for the group
|
# @param id Optional id/name for the group
|
||||||
createGroup: func(id = nil)
|
createGroup: func(id = nil)
|
||||||
{
|
{
|
||||||
if( size(me.parents) >= 2 )
|
var ghost = me.parents[1].createGroup();
|
||||||
{
|
return {
|
||||||
var ghost = me.parents[1].createGroup();
|
parents: [ Group.new(props.wrapNode(ghost._node_ghost), id), ghost ]
|
||||||
return {
|
};
|
||||||
parents: [ Group.new(props.wrapNode(ghost._node_ghost), id),
|
|
||||||
ghost ]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
# Fallback for Canvas instances not based on a ghost
|
|
||||||
return Group.new([me.texture, "group"], id);
|
|
||||||
},
|
},
|
||||||
# Set the background color
|
# Set the background color
|
||||||
#
|
#
|
||||||
|
@ -759,6 +752,14 @@ var Canvas = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var wrapCanvas = func(canvas_ghost)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
parents: [Canvas, canvas_ghost],
|
||||||
|
texture: props.wrapNode(canvas_ghost._node_ghost)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
# Create a new canvas. Pass parameters as hash, eg:
|
# Create a new canvas. Pass parameters as hash, eg:
|
||||||
#
|
#
|
||||||
# var my_canvas = canvas.new({
|
# var my_canvas = canvas.new({
|
||||||
|
@ -769,11 +770,8 @@ var Canvas = {
|
||||||
# });
|
# });
|
||||||
var new = func(vals)
|
var new = func(vals)
|
||||||
{
|
{
|
||||||
var m = { parents: [Canvas, _newCanvasGhost()] };
|
var m = wrapCanvas(_newCanvasGhost());
|
||||||
|
|
||||||
m.texture = props.wrapNode(m._node_ghost);
|
|
||||||
m.texture.setValues(vals);
|
m.texture.setValues(vals);
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -782,30 +780,20 @@ var new = func(vals)
|
||||||
# @param name Name of the canvas
|
# @param name Name of the canvas
|
||||||
# @return #Canvas, if canvas with #name exists
|
# @return #Canvas, if canvas with #name exists
|
||||||
# nil, otherwise
|
# nil, otherwise
|
||||||
var get = func(name)
|
var get = func(arg)
|
||||||
{
|
{
|
||||||
var node_canvas = nil;
|
if( isa(arg, props.Node) )
|
||||||
if( isa(name, props.Node) )
|
var node = arg;
|
||||||
node_canvas = name;
|
else if( typeof(arg) == "hash" )
|
||||||
else if( typeof(name) == 'scalar' )
|
var node = props.Node.new(arg);
|
||||||
{
|
else
|
||||||
foreach(var c; Canvas.property_root.getChildren("texture"))
|
die("canvas.new: Invalid argument.");
|
||||||
{
|
|
||||||
if( c.getValue("name") == name )
|
|
||||||
node_canvas = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( node_canvas == nil )
|
var canvas_ghost = _getCanvasGhost(node._g);
|
||||||
{
|
if( canvas_ghost == nil )
|
||||||
debug.warn("Canvas not found: " ~ name);
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return wrapCanvas(canvas_ghost);
|
||||||
parents: [Canvas],
|
|
||||||
texture: node_canvas
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -22,7 +22,7 @@ var setColorNodes = func(obj, name, color)
|
||||||
.setDoubleValue( i < size(color) ? color[i]
|
.setDoubleValue( i < size(color) ? color[i]
|
||||||
: 1 ); # default alpha is 1
|
: 1 ); # default alpha is 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +56,16 @@ Canvas.setStrokeDashArray = func(pattern)
|
||||||
return me;
|
return me;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Create a canvas object from the given node. Used instead of ghost available
|
||||||
|
# in newer FG versions.
|
||||||
|
var makeCanvas = func(node)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
_node_ghost: node._g,
|
||||||
|
createGroup: func props.wrapNode(me._node_ghost).addChild("group", 0, 0)._g
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# Internal helper for creating a canvas.
|
# Internal helper for creating a canvas.
|
||||||
#
|
#
|
||||||
# @note In 2.9+ this function is replaced by a C++ function. This
|
# @note In 2.9+ this function is replaced by a C++ function. This
|
||||||
|
@ -63,10 +73,39 @@ Canvas.setStrokeDashArray = func(pattern)
|
||||||
# in other programs.
|
# in other programs.
|
||||||
canvas._newCanvasGhost = func()
|
canvas._newCanvasGhost = func()
|
||||||
{
|
{
|
||||||
return {
|
return makeCanvas( Canvas.property_root.addChild("texture", 0, 0) );
|
||||||
parents: [Canvas],
|
};
|
||||||
texture: Canvas.property_root.addChild("texture", 0, 0)
|
|
||||||
};
|
# Internal helper for retrieving an existing canvas.
|
||||||
|
#
|
||||||
|
canvas._getCanvasGhost = func(arg_ghost)
|
||||||
|
{
|
||||||
|
var arg = props.wrapNode(arg_ghost);
|
||||||
|
|
||||||
|
# get a canvas specified by its root node
|
||||||
|
if( Canvas.property_root.getPath() == arg.getParent().getPath() )
|
||||||
|
var node = Canvas.property_root.getChild("texture", arg.getIndex());
|
||||||
|
|
||||||
|
# get a canvas by its name
|
||||||
|
else if( (var name = arg.getChild("name")) != nil )
|
||||||
|
{
|
||||||
|
name = name.getValue();
|
||||||
|
var node = nil;
|
||||||
|
foreach(var c; Canvas.property_root.getChildren("texture"))
|
||||||
|
{
|
||||||
|
if( c.getValue("name") == name )
|
||||||
|
node_canvas = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# get a canvas by its index
|
||||||
|
else if( (var index = arg.getChild("index")) != nil )
|
||||||
|
var node = Canvas.property_root.getChild("texture", index.getValue());
|
||||||
|
|
||||||
|
if( node == nil )
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
return makeCanvas( node );
|
||||||
};
|
};
|
||||||
|
|
||||||
print("Canvas API: FlightGear 2.8 backward support loaded.");
|
print("Canvas API: FlightGear 2.8 backward support loaded.");
|
||||||
|
|
Loading…
Reference in a new issue