Canvas event handling: Difference between revisions

Jump to navigation Jump to search
m
Use Nasal highlighter
(Event flow...)
m (Use Nasal highlighter)
Line 12: Line 12:
To receive events callback function can be added to elements on a Canvas as well as to the Canvas itself:
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="nasal">
canvas.addEventListener("<type>", <func>);
canvas.addEventListener("<type>", <func>);
canvas_element.addEventListener("<type>", <func>);
canvas_element.addEventListener("<type>", <func>);
Line 21: Line 21:
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:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var dlg = canvas.Window.new([152,74]);
var dlg = canvas.Window.new([152,74]);


Line 40: Line 40:
= Event classes =
= Event classes =


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var Event = {
var Event = {
   # Name of event type [read-only]
   # Name of event type [read-only]
Line 107: Line 107:
= Example Code =
= Example Code =
For the latest examples, please refer to [https://gitorious.org/~tomprogs/fg/toms-fgdata/commits/canvas-gui-demo Tom's canvas-gui-demo branch on gitorious]. This is also where you can find the following code in $FG_ROOT/Nasal/canvas/gui.nas (note that this example makes use of advanced Nasal concepts, such as anonymous functions, method chaining and lots of embedded/inline code):
For the latest examples, please refer to [https://gitorious.org/~tomprogs/fg/toms-fgdata/commits/canvas-gui-demo Tom's canvas-gui-demo branch on gitorious]. This is also where you can find the following code in $FG_ROOT/Nasal/canvas/gui.nas (note that this example makes use of advanced Nasal concepts, such as anonymous functions, method chaining and lots of embedded/inline code):
<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
# Canvas GUI demo
# Canvas GUI demo
#
#

Navigation menu