diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas index bd42c061d..d24a9478b 100644 --- a/Nasal/canvas/api.nas +++ b/Nasal/canvas/api.nas @@ -1066,34 +1066,3 @@ var getDesktop = func() { return Group.new(_getDesktopGhost()); }; - -# ------------------------------------------------------------------------------ -# Show warnings if API used with too old version of FlightGear without Canvas -# support (Wrapped in anonymous function do not polute the canvas namespace) - -(func { -var legacy_dir = getprop("/sim/fg-root") ~ "/Nasal/canvas"; -var version_str = getprop("/sim/version/flightgear"); -if( string.scanf(version_str, "%u.%u.%u", var fg_version = []) < 1 ) - debug.warn("Canvas: Error parsing flightgear version (" ~ version_str ~ ")"); -else -{ - if( fg_version[0] < 2 - or (fg_version[0] == 2 and fg_version[1] < 8) ) - { - debug.warn("Canvas: FlightGear version too old (" ~ version_str ~ ")"); - gui.popupTip - ( - "FlightGear v2.8.0 or newer needed for Canvas support!", - 600, - {button: {legend: "Ok", binding: {command: "dialog-close"}}} - ); - } - - # Load support for older versions of FlightGear (TODO generalize :) ) - if( fg_version[0] == 2 and fg_version[1] == 8 ) - io.load_nasal(legacy_dir ~ "/api.nas.2.8", "canvas"); -} - -Canvas.property_root = props.globals.getNode("canvas/by-index", 1); -})(); diff --git a/Nasal/canvas/api.nas.2.8 b/Nasal/canvas/api.nas.2.8 deleted file mode 100644 index c9921f479..000000000 --- a/Nasal/canvas/api.nas.2.8 +++ /dev/null @@ -1,113 +0,0 @@ -# Canvas backward support for using 3.0 API with FlightGear 2.8 - -(func { - -# 2.8 uses multiple properties for representing a color. Also different names -# are used for the colors and no CSS syntax like #rrggbb are supported. -var color_components = ["red", "green", "blue", "alpha"]; -var setColorNodes = func(obj, name, color) -{ - if( size(color) == 1 ) - color = color[0]; - - if( typeof(color) != "vector" ) - debug.warn("Wrong type for color"); - else if( size(color) < 3 or size(color) > 4 ) - debug.warn("Color needs 3 or 4 values (RGB or RGBA)"); - else - { - var node = obj._node.getNode(name, 1); - for(var i = 0; i < size(color_components); i += 1) - node.getNode(color_components[i], 1) - .setDoubleValue( i < size(color) ? color[i] - : 1 ); # default alpha is 1 - } - - return obj; -}; - -Element.setColor = func setColorNodes(me, "color", arg); -Element.setColorFill = func { - setColorNodes(me, "color-fill", arg); - me.setBool("fill", 1); -}; -Path.setColor = Element.setColor; -Path.setColorFill = Element.setColorFill; -Text.setColor = Element.setColor; -Text.setColorFill = Element.setColorFill; - -# -Canvas.setColorBackground = func() -{ - me._node = me.texture; - setColorNodes(me, "color-background", arg); -}; - -# 2.8 uses multiple properties instead of a single string property -Canvas.setStrokeDashArray = func(pattern) -{ - me._node.removeChildren('stroke-dasharray'); - - if( typeof(pattern) == 'vector' ) - me._node.setValues({'stroke-dasharray': pattern}); - else - debug.warn("setStrokeDashArray: vector expected!"); - - 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. -# -# @note In 2.9+ this function is replaced by a C++ function. This -# implementation is just used as fallback for 2.8 and for usage -# in other programs. -canvas._newCanvasGhost = func() -{ - return makeCanvas( 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."); - -})();