Canvas Image

From FlightGear wiki
Jump to: navigation, search


Additionally to the properties supported by every Canvas Element, Canvas Images support the following properties:


  • Version: FlightGear >= 3.1
  • Format: [<protocol>://]<path> (Supported protocols: canvas://, http://)
# Use file inside default search paths
img.set("src", "gui/dialogs/images/exit.png");

# Show canvas with index 3
img.set("src", "canvas://by-index/texture[3]");

# Download and show FlightGear logo
img.set("src", "");

# Show canvas available as object
img.set("src", my_canvas.getPath());




  • Format: <color> (#rrggbb, rbg(r,g,b), rgba(r,g,b,a) [r,g,b -> 0-255; a -> 0.0-1.0])
  • Default: #ffffff (white)

Image background color. Each pixel is modulated with the background color. If the image shall be displayed unchanged use white as background color.

# White with alpha of 0.5 (=half transparent)
img.set("fill", "rgba(255,255,255,0.5)");

# red completely opaque
img.set("fill", "#ff0000");


  • Format: [<number>%?]{1,4} fill?
  • Default: (empty) (disabled)

Image slicing (or scale-9, 9-slice) is a technique for dividing an image into nine regions. While scaling such an image the four corner regions will be shown undistorted, whereas the other regions are scaled to fit into the remaining parts. See the CSS3 border-image-slice property for more information.

# Top/bottom offset 10%, left/right offset 5%, fill center
img.set("slice", "10% 5% fill");

# All offsets 8 pixels, only draw border and do not fill center
img.set("slice", "8");

# Disable slicing
img.set("slice", "");


  • Format: [<number>%?]{1,4}
  • Default: (empty) (disabled)

Let the image extend outside its specified size. The areas extending outside the original dimensions are just drawn but not included in the bounding box, and therefore ignored for event handling and distance/margin calculations. This could be used, for example, to draw a shadow around an element which is ignored for handling events.

# Top outset 10%, left/right outset 5%, bottom outset 10 pixels
img.set("outset", "10% 5% 10");

# All offsets 8 pixels
img.set("outset", "8");

# Disable outset
img.set("outset", "");

file (deprecated)

  • Version: FlightGear <= 3.0

Same as src. Use src with FlightGear >= 3.1.