Canvas event handling: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "Category:Canvas {{Template:Canvas Navigation}} The Canvas event handling system is heavily inspired by the [http://www.w3.org/TR/DOM-Level-3-Events/ DOM Event Model]. If ...")
 
No edit summary
Line 3: Line 3:


The Canvas event handling system is heavily inspired by the [http://www.w3.org/TR/DOM-Level-3-Events/ DOM Event Model]. If you have already worked with events in HTML and JavaScript most concepts of the Canvas event system should be already familiar to you.
The Canvas event handling system is heavily inspired by the [http://www.w3.org/TR/DOM-Level-3-Events/ DOM Event Model]. If you have already worked with events in HTML and JavaScript most concepts of the Canvas event system should be already familiar to you.
= Listen for events =
To receive events callback function can be added to elements on a Canvas as well as to the Canvas itself:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
canvas.addEventListener("<type>", <func>);
canvas.addEventListener("<type>", <func>);
canvas_element.addEventListener("<type>", <func>);
canvas_element.addEventListener("<type>", <func>);
</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 receive events by default, whereas Canvases placed onto the aircraft model or in the scenery do not receive any events by default.
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:
<syntaxhighlight lang="php">
var dlg = canvas.Window.new([152,74]);
# Disable event handling for this window. Events will pass through
# and can reach any window or also object covered by the window.
dlg.setBool("capture-events", 0);
# Place the canvas onto the PFD and enable receiving events
my_canvas.addPlacement({"node": "PFD-Screen", "capture-events": 1});
</syntaxhighlight>
</syntaxhighlight>


166

edits

Navigation menu