Debian Codegraph @

Nasal/canvas/generic-canvas-map.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2 <!--
3 generic-canvas.map XML:
4 - to be used by dialogs and instruments to add a generic map (navaids, fixes, airports etc)
5 - with each feature put on a separate layer (canvas group)
6 - each layer being controllable via a boolean property
7
8 NOTE: This is still work in progress, and will be significantly refactored in the time to come
9
10 Current requirements: (these are subject to change)
11
12 Dialogs wanting to use this, MUST:
13
14 - set DIALOG_CANVAS in open block
15 - provide a helper function dialog_property(p) to return a property appended to the dialog root in /sim/gui/dialogs/FOO/
16 - to set up layer-checkboxes automatically, use canvas.GenericMap.setupGUICheckboxes(DIALOG_CANVAS, gui_group)
17
18 For example, add this to your dialogs Nasal/open block in "foo.xml":
19 var dialog_name = "foo";
20 var dialog_property = func(p) return "/sim/gui/dialogs/foo/"~p;
21 var DIALOG_CANVAS = gui.findElementByName(cmdarg(), "airport-selection");
22 canvas.GenericMap.setupGUICheckboxes(DIALOG_CANVAS, "canvas-control");
23
24 TODO: use a single "InitCanvasMapSupport();" helper
25
26 In the close block, you'll want to call "map.cleanup_listeners()" at the moment
27
28 -->
29 <PropertyList>
30 <!--FIXME: move somewhere else, this is GUI specific and not useful for canvas maps shown as instruments! -->
31 <checkbox-toggle-template>
32 <name></name>
33 <label></label>
34 <property></property>
35 <binding>
36 <command>dialog-apply</command>
37 <object-name></object-name>
38 </binding>
39 </checkbox-toggle-template>
40
41 <!-- will be procedurally added to the dialog -->
42 <zoom-template>
43 <button>
44 <name>zoomout</name>
45 <legend>-</legend>
46 <pref-width>22</pref-width>
47 <pref-height>22</pref-height>
48
49 <binding>
50 <command>property-adjust</command>
51 <property></property>
52 <min>0</min>
53 <step>-1</step>
54 </binding>
55 </button>
56
57 <text>
58 <label>MMMM</label>
59 <halign>center</halign>
60 <format>Zoom %d</format>
61 <property></property>
62 <live>true</live>
63 </text>
64
65 <button>
66 <name>zoomin</name>
67 <legend>+</legend>
68 <pref-width>22</pref-width>
69 <pref-height>22</pref-height>
70
71 <binding>
72 <command>property-adjust</command>
73 <property></property>
74 <step>1</step>
75 <max></max> <!-- FIXME: compute dynamically via Nasal size() or just a property-->
76 </binding>
77 </button>
78
79 <empty><stretch>true</stretch></empty>
80
81 </zoom-template>
82
83 <nasal>
84 <load><![CDATA[
85 var my_canvas = canvas.get(cmdarg());
86 my_canvas.setColorBackground(0.2, 0.5, 0.2, 0.5); #TODO: support customization in XML
87
88 var root = my_canvas.createGroup();
89 # the top level AirportMap element uses a "GenericMap" now:
90
91 #TODO: features should be procedurally enabled via params (WIP)
92 #TODO: use generic Map and instantiate via XML
93 var map = canvas.GenericMap.new(parent:root, name:dialog_name) # FIXME: We shouldn't be using AirportMap here:
94 # we need a high level wrapper that can instantiate
95 # all sorts of maps, not just AirportMaps
96 .setTranslation(300, 200) # TODO: move to Map class ctor!
97 .setupZoom( dialog:DIALOG_CANVAS ) # TODO: make zooming configurable for non GUI use
98 .pickupFeatures (DIALOG_CANVAS); # set up the features specified in the XML file
99
100 var offset = [0,0];
101 my_canvas.addEventListener("drag", func(e)
102 {
103 offset[0] += e.deltaX;
104 offset[1] += e.deltaY;
105 map.setTranslation(300 + offset[0], 200 + offset[1]);
106 });
107
108 my_canvas.addEventListener("wheel", func(e)
109 {
110 map.zoom_property.setIntValue(map.zoom_property.getValue() + e.deltaY );
111 });
112
113 canvas.run_callbacks(); # WORKAROUND to run dialog-specific init code -
114 # must be set up via register_callback() in the dialog's open block currently
115 ]]>
116 </load>
117 </nasal>
118 </PropertyList>