166
edits
mNo edit summary |
(→Example Code: No need to manually create window decoration any more) |
||
Line 96: | Line 96: | ||
= 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"># Canvas GUI demo | <syntaxhighlight lang="php"> | ||
# Canvas GUI demo | |||
# | # | ||
# Shows an icon in the top-right corner which upon click opens a simple window | # Shows an icon in the top-right corner which upon click opens a simple window | ||
Line 104: | Line 105: | ||
removelistener(init_gui); | removelistener(init_gui); | ||
var dlg = canvas.Window.new([32,32]); | var dlg = canvas.Window.new([32,32]); | ||
dlg.setInt(" | dlg.setInt("tf/t[1]", 4) | ||
.setInt("right", 4); | .setInt("right", 4); | ||
var my_canvas = dlg.createCanvas() | |||
.setColorBackground(0,0,0,0); | .setColorBackground(0,0,0,0); | ||
var root = my_canvas.createGroup(); | |||
canvas.parsesvg(root, "gui/dialogs/images/icon-aircraft.svg"); | canvas.parsesvg(root, "gui/dialogs/images/icon-aircraft.svg"); | ||
my_canvas.addEventListener("click", func | my_canvas.addEventListener("click", func | ||
{ | { | ||
var dlg = canvas.Window.new([400,300], "dialog"); | |||
var my_canvas = dlg.createCanvas() | |||
.set("background", "#f2f1f0"); | |||
var root = my_canvas.createGroup(); | |||
root.addEventListener("click", func(e) { printf("click: screen(%.1f|%.1f) client(%.1f|%.1f) click count = %d", e.screenX, e.screenY, e.clientX, e.clientY, e.click_count); }); | |||
root.addEventListener("dblclick", func(e) { printf("dblclick: screen(%.1f|%.1f) client(%.1f|%.1f)", e.screenX, e.screenY, e.clientX, e.clientY); }); | |||
root.addEventListener("wheel", func(e) { printf("wheel: screen(%.1f|%.1f) client(%.1f|%.1f) %.1f", e.screenX, e.screenY, e.clientX, e.clientY, e.deltaY); }); | |||
var text = | |||
root.createChild("text") | |||
.setText("This could be used for building an 'Aircraft Help' dialog.\nYou can also #use it to play around with the new Canvas system :). β") | |||
.setTranslation(10, 30) | |||
.setAlignment("left-top") | |||
.setFontSize(14) | |||
.setFont("LiberationFonts/LiberationSans-Regular.ttf") | |||
.set("max-width", 380) | |||
.setColor(0,0,0); | |||
var text_move = | |||
root.createChild("text") | |||
.setText("Mouse moved over text...") | |||
.set("character-size", 15) | |||
.set("font", "LiberationFonts/LiberationSans-Bold.ttf") | |||
.set("alignment", "left-center") | |||
.setTranslation(20, 200) | |||
.set("fill", "#ff0000") | |||
.hide(); | |||
var visible_count = 0; | |||
text.addEventListener("mouseover", func text_move.show()); | |||
text.addEventListener("mouseout", func text_move.hide()); | |||
}); | }); | ||
}); | }); | ||
})(); | })(); | ||
</syntaxhighlight> | </syntaxhighlight> |
edits