Board index FlightGear Development Canvas

Getting a handle to an existing canvas and reusing it ?

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.

Getting a handle to an existing canvas and reusing it ?

Postby omega95 » Sun Aug 05, 2012 12:00 pm

Hooray wrote in Sun Aug 05, 2012 11:54 am:Do you now fully understand how this is working? Otherwise, maybe Tom can explain this a little better, after all he's written all that code! :)


As much as I understood, everything already works fine in the property tree, the only thing I'll have to do with nasal is to actually make that interface...

We can get the props using my_canvas.texture.getPath() ~ '/mouse/<required node>', play around with it and create click Handlers by running the function when the event is set to 1.

Btw, I have another small doubt here, let's say I have a canvas in fmcScreen placement or basically, this:

Code: Select all
var fmcScreen = canvas.new({
  "name": "fmcScreen",  # The name is optional but allow for easier identification
  "size": [1024, 1024], # Size of the underlying texture (should be a power of 2, required)
  "view": [1024, 1024],  # Virtual resolution (Defines the coordinate system of the canvas
                        # which will be stretched the size of the texture, required)
  "mipmapping": 0       # Enable mipmapping (optional)
});

fmcScreen.addPlacement({"node": "fmcScreen"});


Is there a way, I can load THIS canvas onto a canvas GUI? Like in the above example?
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 » Sun Aug 05, 2012 12:16 pm

Keep in mind that you want to have access to the instance of a class, i.e. the object, not just the class.
Once you implement an instrument like your CDU or FMC, you may very well want to be able to run multiple instruments at the same time (pilot, copilot) - currently, each instrument would be a separate instance in Nasal space, but also in the property tree.

Thus, you really only need to get a handle (i.e. the property tree path) to the instrument that you want to render and then also show it in the GUI, sort of like a "shared" canvas texture, that is used in multiple places - conceptually, there shouldn't really be any difference. Even if you were to render your FMC as an instrument, inside a GUI dialog, on the HUD or even as part of the livery - it's all already in the property tree.

Currently, placement is tied to each canvas, but Tom was planning to unify canvas-placement a little and decouple things.

In the meantime, you could explicitly communicate the path to your canvas texture, i.e. via the property tree, and then directly show the texture in a GUI window.
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: 11437
Joined: Tue Mar 25, 2008 8:40 am

Re: Changelog & Progress

Postby TheTom » Sun Aug 05, 2012 12:17 pm

omega95 wrote in Sun Aug 05, 2012 12:00 pm:Is there a way, I can load THIS canvas onto a canvas GUI? Like in the above example?

Add the following to canvas/gui.nas:
Code: Select all
  setCanvas: func(canvas_)
  {
    if( !isa(canvas_, canvas.Canvas) )
      return debug.warn("Not a canvas.Canvas");
     
    canvas_.addPlacement({type: "window", index: me._node.getIndex()});
  },


and then use
Code: Select all
dlg.setCanvas(fmcScreen);

I will push it later...
TheTom
 
Posts: 321
Joined: Sun Oct 09, 2011 10:20 am

Re: Changelog & Progress

Postby omega95 » Sun Aug 05, 2012 12:25 pm

Alright, that's awesome, I'll try that, but anyway, I was actually thinking if it's possible to load the fmcScreen canvas INTO a PART of another canvas. Like this, let's say I created a canvas that looks like this: (if you're able to create a canvas gui like in the above example, this should be sorta the same, just a little more work)

Image

I'd want to load the fmcScreen canvas into the black screen area in the above canvas.

And what about setting visibility of the dialog? I mean .show() and .hide()? :)
Last edited by omega95 on Sun Aug 05, 2012 12:30 pm, edited 1 time in total.
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 » Sun Aug 05, 2012 12:30 pm

I don't think this is currently possible directly. You may be able to work around this, by explicitly copying properties or using aliased properties (untested!). That being said, we talked a while ago about unifying the concept of images, so that non-vector images could not just be static images from the file system, but also other canvas textures - sort of like "nested" canvases, or rather cascading canvases.

The whole point is to implement multiple stages, with possibly shared stages of canvases, that can be reused for different purposes.
This would even make it possible to implement multiple identical instruments very efficiently, because canvas stages could be reused for different screens.

I don't think this will be available before image support has been added, but then it will be a fairly simple change, as it just involves getting a handle to another canvas and retrieving the texture.

Basically, this could work like "piping" on Unix/Linux, where canvases can be used as inputs and outputs for complex setups: http://wiki.flightgear.org/Canvas_Prope ... es_Pending

od_gauge is the underlying subsystem of the canvas, and it already has a method to get a texture, so reusing this in another canvas, shouldn't be too difficult actually. Input handling would be a different thing however - Tom has probably an idea on how this should work.

PS: We should really use a new thread for all these questions ... it's getting hard to follow this now!
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: 11437
Joined: Tue Mar 25, 2008 8:40 am

Re: Getting a handle to an existing canvas and reusing it ?

Postby Hooray » Mon Aug 06, 2012 10:04 am

Update: James just committed initial support for non-vector images to the canvas system: http://gitorious.org/fg/flightgear/comm ... 6801bb80ad

So, you'll probably be able to use non-vector images soon, including cascaded canvases, where you can specify canvas regions to include another, previously created, canvas.

Probably, the easiest option to use raster images, will be extending the SVG parser (svg.nas) so that it can map raster images to canvas images, that would allow us to use an SVG editor like Inscape.
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: 11437
Joined: Tue Mar 25, 2008 8:40 am

Re: Getting a handle to an existing canvas and reusing it ?

Postby Hooray » Thu Aug 09, 2012 7:04 pm

Another update, Tom now committed the changes to also supported "nested" canvases: http://gitorious.org/fg/flightgear/comm ... 253a7f9590

To see how this works in XML/Nasal space, see: http://gitorious.org/~tomprogs/fg/toms- ... bcf0d5e50e

PS: Obviously, you need to pull the latest changes and rebuild FG.
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: 11437
Joined: Tue Mar 25, 2008 8:40 am

Re: Getting a handle to an existing canvas and reusing it ?

Postby omega95 » Thu Aug 09, 2012 7:10 pm

Oh great! What about loading png (non-vector) images? And then ofcourse "clickability". :)
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: Getting a handle to an existing canvas and reusing it ?

Postby Hooray » Thu Aug 09, 2012 7:32 pm

yes, raster images are also supported now, and "clickability" also used to work previously ;-)
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: 11437
Joined: Tue Mar 25, 2008 8:40 am

Re: Getting a handle to an existing canvas and reusing it ?

Postby TheTom » Thu Aug 09, 2012 8:23 pm

Hooray wrote in Thu Aug 09, 2012 7:04 pm:To see how this works in XML/Nasal space, see: http://gitorious.org/~tomprogs/fg/toms- ... bcf0d5e50e

I have updated this commit. Now by default the whole image is used so it's gotten a bit shorter:
Code: Select all
root.createChild("image")
    .setFile("canvas://by-index/texture[0]")
    .setSize(240,180)
    .setTranslation(1,20);

If you have an instance of the canves to be displayed in a variable or now its id you can also do it with:
Code: Select all
var src = canvas.get("canvas-id");
root.createChild("image")
    .setFile( src.getPath() )
    .setSize(240,180)
    .setTranslation(1,20);


I'm currently working on "real" clickabilty...
TheTom
 
Posts: 321
Joined: Sun Oct 09, 2011 10:20 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest