Board index FlightGear Development Canvas

[SOLVED] How to modify symbols in MapStructure layers

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.

[SOLVED] How to modify symbols in MapStructure layers

Postby clm76 » Sat Sep 17, 2016 7:44 am

Hello,

I'm learning MapStructure and MapStructureLayers and I paste this code (found in the wiki) in the nasal console :

Code: Select all
var MapStructure_demo = func() {
  var temp = {};
  temp.dlg = canvas.Window.new([600,400],"dialog");
  temp.canvas = temp.dlg.createCanvas().setColorBackground(1,1,1,0.5);
  temp.root = temp.canvas.createGroup();
  var TestMap = temp.root.createChild("map");
  TestMap.setController("Aircraft position");
  TestMap.setRange(25);

  TestMap.setTranslation(
                           temp.canvas.get("view[0]")/2,
                           temp.canvas.get("view[1]")/2
                        );
 
var r = func(name,vis=1,zindex=nil) return caller(0)[0];
 foreach(var type; [r('TFC'),r('APT'), r('VOR'), ] )
        TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);
};
MapStructure_demo();

It works well but … How to change color, symbol size and font size of APT and VOR ?
Last edited by clm76 on Thu Oct 27, 2016 7:51 pm, edited 1 time in total.
clm76
 
Posts: 149
Joined: Tue Oct 30, 2012 8:18 pm
Location: France - LFOH
Callsign: F-GCLM
Version: 2018.3.0
OS: Linux Mint 18.3

Re: How to modify symbols in MapStructure layers

Postby clm76 » Thu Oct 27, 2016 7:51 pm

clm76
 
Posts: 149
Joined: Tue Oct 30, 2012 8:18 pm
Location: France - LFOH
Callsign: F-GCLM
Version: 2018.3.0
OS: Linux Mint 18.3

Re: [SOLVED] How to modify symbols in MapStructure layers

Postby Hooray » Thu Oct 27, 2016 8:03 pm

yeah, thanks for your updates and help.

You can find more sophisticated examples in the Airbus style created by Artix, he also had to touch a bunch of MapStructure files to make that work.

The background info is here: http://wiki.flightgear.org/Canvas_MapStructure#Symbols

One important feature is the so called SymbolCache: http://wiki.flightgear.org/Canvas_MapStructure#Symbols

However, I don't think that artix actually used that (which is a pity, because Philosopher made sure to make it style-aware).


For a list of MapStructure files (meanwhile incomplete), see: http://wiki.flightgear.org/Canvas_MapStructure_Layers

Once you have found a layer that is not yet style-able, you need to encode style-able attributes using the relevant_keys vector.

For example, open the VOR.symbol file and see how it sets up a default style hash (df_style) here: https://sourceforge.net/p/flightgear/fg ... VOR.symbol

In the drawVOR callback it is then using those variables (as per the hash).

Finally, it creates a new cache entry using this:

Code: Select all
[/var cache = StyleableCacheable.new(
   name:name, draw_func: drawVOR,
   cache: SymbolCache32x32,
   draw_mode: SymbolCache.DRAW_CENTERED,
   relevant_keys: ["line_width", "color"],
);


The last line is particularly important.

My suggestion would be to review other files like that, and then add your findings to the wiki article - I will check what you have found and correct/add any missing info
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: 11354
Joined: Tue Mar 25, 2008 8:40 am

Re: [SOLVED] How to modify symbols in MapStructure layers

Postby Hooray » Thu Oct 27, 2016 8:08 pm

But like you said, some layers are still missing styling-support - which basically means identifying everything that is currently hard-coded but styling related (think colors, fonts, size, images/artwork) and replacing that with a variable, the same variable should be added to the df_style (default style) of the symbol, and then you need to set up a cache entry specifiying the symbol specific variables (e.g. color and fontsize), so that the styleable-cache can tell if it has a certain variant of a symbol or not

map-canvas.xml is a simple example, artix's Airbus style is more sophisticated.

Feel free to add screenshots to the wiki showing your changes
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: 11354
Joined: Tue Mar 25, 2008 8:40 am

Re: [SOLVED] How to modify symbols in MapStructure layers

Postby clm76 » Fri Oct 28, 2016 7:50 am

Feel free to add screenshots to the wiki showing your changes.
It's ok but I don't know how to change the screenshot !... :(
clm76
 
Posts: 149
Joined: Tue Oct 30, 2012 8:18 pm
Location: France - LFOH
Callsign: F-GCLM
Version: 2018.3.0
OS: Linux Mint 18.3

Re: [SOLVED] How to modify symbols in MapStructure layers

Postby Hooray » Fri Oct 28, 2016 6:04 pm

  • First, (after logging in) upload the new screenshot using the form at, copy the link that is shown to you afterwards: http://wiki.flightgear.org/Special:UploadWizard
  • Next, open the corresponding wiki article and navigate to the section that you'd like to edit, e.g.: http://wiki.flightgear.org/Canvas_Snipp ... re_Styling
  • Click the edit link, go to the line beginning with [[File: ... (e.g. [[File:Snippets-canvas-mapstructure-dialog.png|thumb|[[MapStructure]] layers shown in a Canvas GUI dialog]])
  • repace the link with the one you got in step #1
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: 11354
Joined: Tue Mar 25, 2008 8:40 am

Re: [SOLVED] How to modify symbols in MapStructure layers

Postby clm76 » Sat Oct 29, 2016 7:44 am

Thanks, done ! :)
clm76
 
Posts: 149
Joined: Tue Oct 30, 2012 8:18 pm
Location: France - LFOH
Callsign: F-GCLM
Version: 2018.3.0
OS: Linux Mint 18.3

Re: [SOLVED] How to modify symbols in MapStructure layers

Postby Hooray » Sat Oct 29, 2016 10:24 am

Thank you, that's looking good - my suggestion would be to always annotate the style hash to indicate what each key means (e.g. colors, size, line thickness).
I have also begun documenting the process to add styling support to other/new layers using the relevant_keys vector we previously talked about.
Like I said, there are much more sophisticated styling examples to be found in artix's Airbus style, which not only overrides certain style attrributes but even the draw callbacks themselves.

You can also specifcy custom SVG/raster images if you want to - so it's rather flexible actually, and gives you a fully functional "map" with roughly 30 lines of boilerplate code.

Besides, it would not be that much work to extend the canvas-nd.xml dialog to provide a mechanism that allows such things to be changed via the GUI - so that people would not necessarily have to hand-edit the styles file.
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: 11354
Joined: Tue Mar 25, 2008 8:40 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 0 guests