Board index FlightGear Development Canvas

addEventListener (was: Capturing and bubbling..)

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

addEventListener (was: Capturing and bubbling..)

Postby Kabuki » Thu Feb 07, 2013 9:13 pm

I have TheTom's canvas gui demo working. It's small enough that it's a good place to start reading code and understanding it. Keep up the good work!

I'm considering using it for my first attempt at a canvas HUD, and have run into a deal-killer, concerning the way it handles mouse events. It traps them and does not pass them along to the parent window. Sometimes you want it to, sometimes you don't. Most event oriented languages I've seen have some way of controlling the "bubbling" of events. Does Nasal have this?

To see why this is important, if you have a working demo of TheTom's demo Open the window, and right-click in the window. Nothing happens. Now right-click outside the window and you're in the mouse-as-stick mode: the pointer becomes a crosshair, and the movement is constrained. If the window's in the wrong place, you won't be able to move the pointer up to click on the close box. If the window's big enough it can trap your mouse. :twisted:

And although it appears as a crosshair, and is constrained, it is not controlling the stick. There's a multiple personality thing going on .

Most event-oriented programming languages have a way of controlling the bubbling of events. Do we have a way of doing that? Sometimes you want to trap them, sometimes you want to pass them on. In the case of something like a large, transparent HUD, you want it to mostly ignore them.

EDIT: I see now that addEventListner is a function new to canvas. Maybe it needs an additional parameter to specify whether events be passed on or trapped... ?
This is a family-friendly saloon. No talk stink.
Posts: 587
Joined: Fri Oct 23, 2009 11:21 pm
Location: Usually on the ground, always in the sky, except when underwater.
Callsign: Kabuki
Version: 3.0.0
OS: Windows 7

Re: addEventListener (was: Capturing and bubbling..)

Postby TheTom » Thu Feb 07, 2013 10:14 pm

Event bubbling only happens inside a single canvas, so it is not possible to let certain events pass through to another window (don't know if this is really needed). I've now pushed an update which prevents events from being captured by canvas windows if the mouse is in a non-pass-through mode (by default this are the view and control mode), so it shouldn't be trapped any more ;)

Also I've added an option which allows setting canvas windows completely invisible for events. Just set "capture-events" on the according window to false.
Posts: 322
Joined: Sun Oct 09, 2011 10:20 am

Return to Canvas

Who is online

Users browsing this forum: Google [Bot] and 1 guest