Board index FlightGear Development Canvas

Copying a canvas to another canvas ?

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.

Copying a canvas to another canvas ?

Postby omega95 » Sun Aug 05, 2012 3:38 pm

Hmm, does that mean I'll have the scrape the current canvas filler? The problem is that the FMC pages (I've done a LOT of work and it'd be difficult to track every bit) also change the contents inside the canvas, so I can't use an object for it, as the values in open in the module fmc.

Is there a script I can use to GET a canvas group contents and place it inside another canvas? Or something I can add to api.nas to use

var my_canvas = canvas.get(cmdarg());
var my_canvas.setGroup(fmc.group)


Or, is it possible to add a gui canvas element as a placement to a canvas? :)
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: Adding a canvas to an old XML dialog?

Postby TheTom » Sun Aug 05, 2012 4:16 pm

omega95 wrote in Sun Aug 05, 2012 3:38 pm:Is there a script I can use to GET a canvas group contents and place it inside another canvas? Or something I can add to api.nas to use

If your really can't place it in an object or store the active settings inside the property tree, you can just copy the according branch of the property tree to the other canvas (The canvas is fully controllable through the propery tree):

Code: Select all
# Create new element and copy sub branch from source node
var group = new_canvas.createGroup();
props.copy(old_group._node, group._node);

# copying also overrides the id so we need to set it again
group._node.getNode("id", 1).setValue("new-group-id");
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 11:20 am

Re: Adding a canvas to an old XML dialog?

Postby Hooray » Sun Aug 05, 2012 4:20 pm

actually, it wouldn't be too difficult to change CanvasWidget.cxx such that it could reuse an existing canvas - on the other hand, this module is going to be phased out soon, and Tom's suggestion is better in that it encourages a modular design.

Like I mentioned earlier, once you use a layered design, it shouldn't be too difficult to reuse your canvas object (Nasal) for different purposes, including cockpit instruments, but also GUI dialogs/widgets/windows.

Just try to think in terms of responsibilities and introduce another layer for each different responsibility, then you could also add a helper method to replicate a canvas in another texture, for use by the CanvasWidget

Once you think about it, it's really just a simple loop that copies a property tree branch to another location, so not really complicated.

EDIT: lol, same answer :-)
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Copying a canvas to another canvas ?

Postby omega95 » Sun Aug 05, 2012 4:28 pm

Lol, right, it'd be much easier when canvas supports layers but for now, I'm trying to get this on gui temporarily. Anyway, I have another question, let's say I create a nasal variable in an xml gui, how would I access it from the Console or anywhere else? Anyway, I was thinking of a continuous listener loop that copies props from the actual to new canvas, so what would I need to check to look for changes in the first group?

And can I scale the canvas down in the gui? The actual fmcScreen is of 1024x1024, but I want it to be shown as 400x320 in the GUI. :)
Merlion Virtual Airlines - the experience of a flight time...
Get high quality aircraft, airports, video tutorials or development tools from my hangar.
omega95
 
Posts: 1222
Joined: Sat Jul 30, 2011 1:59 am
Location: -unknown-
Callsign: MIA0001, OM-EGA
IRC name: omega95
Version: 2.12 git
OS: Ubuntu 13.04

Re: Copying a canvas to another canvas ?

Postby Hooray » Sun Aug 05, 2012 4:29 pm

@Tom:

From an API point of view, it might make sense to be able to temporarily disable a new canvas (e.g. while copying), so that most listeners are not invoked while the state is possibly inconsistent, and then explicitly re-enable updates (listeners) afterwards. This could also be useful for other use cases, where the state may not be valid, i.e. when using the canvas via the telnet or http clients. So that error messages would not be shown while copying.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Canvas

Who is online

Users browsing this forum: No registered users and 2 guests