Board index FlightGear Development Canvas

Using nested canvases and raster images?

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Using nested canvases and raster images?

Postby omega95 » Wed Aug 15, 2012 11:00 am

TheTom wrote in Tue Aug 14, 2012 10:01 pm:Now window stacking and focus/raise behaviour is working and can be controlled with Nasal. Also recursive canvases are supported:


Is there a wiki documentation on loading png images to a canvas and canvas stacking?

I'll probably be making the digital display instruments (EADI and EHSI) on the ATR 72-500(C) on a canvas now, so I can use it from the cockpit panel AND in a movable gui. :mrgreen:

That way, you don't have to worry about small screen laptops.

The canvas map tool will also come in hand while making the EHSI.
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1223
Joined: Sat Jul 30, 2011 12:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: Changelog & Progress

Postby Hooray » Wed Aug 15, 2012 6:23 pm

omega95 wrote in Wed Aug 15, 2012 11:00 am:Is there a wiki documentation on loading png images to a canvas and canvas stacking?


Just take a look at Tom's canvas branch (fgroot/fgdata), see the stuff in menubar.xml: http://gitorious.org/fg/toms-fgdata/com ... bbd5db989c

Nested canvases with a static canvas path:
Code: Select all
root.createChild("image")
                                    .setFile("canvas://by-index/texture[0]")
                                    .setSize(240,180)
                                    .setTranslation(1,20);


Nested canvases using a path from another canvas dynamically:
Code: Select all
root.createChild("image")
                                    .setFile( someCanvas.getPath() )
                                    .setSize(240,180)
                                    .setTranslation(1,20);


And for raster images, you'll just need to set the file path to something in $FG_ROOT, i.e.

Code: Select all
root.createChild("image")
                                    .setFile( "/Textures/Splash1.png" )
                                    .setSize(240,180)
                                    .setTranslation(1,20);


EDIT: added a little howto to the wiki now: http://wiki.flightgear.org/Howto:Using_ ... d_canvases
EDIT2: Note that I only just got around to test this, all the earlier advice was based on reading the source code - but it turns out there's a minor issue at the moment, which prevents raster images from being loaded due to a check using resolve_resource_path(), sent a heads-up to Tom - so that he can check that
Last edited by Hooray on Wed Aug 15, 2012 8:44 pm, edited 1 time in total.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11430
Joined: Tue Mar 25, 2008 8:40 am

Re: Using nested canvases and raster images?

Postby TheTom » Wed Aug 15, 2012 8:40 pm

Hooray wrote in Wed Aug 15, 2012 6:23 pm:EDIT2: Note that I only just got around to test this, all the earlier advice was based on reading the source code - but it turns out there's a minor issue at the moment, which prevents raster images from being loaded due to a check using resolve_resource_path(), sent a heads-up to Tom - so that he can check that

You shouldn't use absolute paths and instead let the path be automatically resolved. Path are searched in the following directories in the following order:

  • Root directory of current aircraft (defined by /sim/aircraft-dir)
  • All aircraft directories if branch starts with Aircraft/
  • fg_data directory
TheTom
 
Posts: 321
Joined: Sun Oct 09, 2011 10:20 am

Re: Using nested canvases and raster images?

Postby Hooray » Wed Aug 15, 2012 8:46 pm

lol, that's too funny: the original code example that I posted here didn't even contain the getprop("/sim/fg-root") call at all - and neither did the wiki, I just "fixed" it automatically when testing the code ... And yes, everything's working now - sorry for the noise ... Like I told you: I even went as far as removing the check from the source code and directly used path instead of tpath because of this misunderstanding ... 15 minutes of my life, wasted :D

Thank you!

PS: Also fixed the source code in the wiki, too...
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11430
Joined: Tue Mar 25, 2008 8:40 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest