Canvas event handling: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 7: Line 7:


Listeners - simple Nasal functions - can be attached to every element inside the Canvas and the Canvas itself. Once a certain action - like moving the mouse or pressing a button - occurs the associated listeners are called. We can use this for example to detect whether the mouse has moved over an element or if a certain element has been clicked.
Listeners - simple Nasal functions - can be attached to every element inside the Canvas and the Canvas itself. Once a certain action - like moving the mouse or pressing a button - occurs the associated listeners are called. We can use this for example to detect whether the mouse has moved over an element or if a certain element has been clicked.
{{Note|{{FGCquote
  |Just keep in mind that there will be no support for mouseover/hover events.<br/>
Mouse clicks/wheel/drag work, but there is no support for mouse move in PUI/XML (CanvasWidget).
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=213533#p213533
    |title=<nowiki>Re: Using a PUI CanvasWidget as a Canvas.Window ?</nowiki>
    |author=<nowiki>TheTom</nowiki>
    |date=<nowiki>Thu Jun 26</nowiki>
  }}
}}
}}


= Listen for events =
= Listen for events =
Line 28: Line 17:
</syntaxhighlight>
</syntaxhighlight>


For each placement of a Canvas handling events can be enabled or disabled. A Canvas placed in a PUI widget or as standalone GUI window receives events by default, whereas Canvases placed onto the aircraft model or in the scenery do not receive any events by default.
For each placement of a Canvas handling events can be enabled or disabled. A Canvas placed in a PUI (old GUI) widget or as standalone GUI window receives events by default, whereas Canvases placed onto the aircraft model or in the scenery do not receive any events by default.
 
{{Note|The old [[Howto:Adding_a_canvas_to_a_GUI_dialog|PUI/XML GUI]] does not trigger any mouseover/hover events. Mouse clicks/wheel/drag are working as expected. For all other placements like on standalone Canvas windows and [[Howto:Add_a_2D_canvas_instrument_to_your_aircraft|3D models]] there is no such limitation.}}


For standalone GUI windows setting '''capture-events''' to ''0'' or ''1'' enables or disables handling of events respectively. For a Canvas placed onto a 3d model, setting ''capture-events'' inside the placement can be used to activate event handling:
For standalone GUI windows setting '''capture-events''' to ''0'' or ''1'' enables or disables handling of events respectively. For a Canvas placed onto a 3d model, setting ''capture-events'' inside the placement can be used to activate event handling:
166

edits

Navigation menu