Hi Jeremy,
I don't know if this can be the ideal solution for you, but I can say what I
did in my engine. I got both "states" class and "event" class. I guess "events"
only are useful to osgWidgets, so I'll ignore "states" here (but they behave
quite the same).
All nodes that need to read/intercept an event derive from
"ControlEventHandler", and defines:
virtual bool handleEvent(blah blah blah) =0;
For instance, for a HUD/button/anything that waits for a key to be pushed:
virtual bool handleEvent(blah blah blah) {
if (it is my event) {
do something;
return true;
}
return false;
}
The return value (true or false) simply says if the event is "consumed" or not.
A consumed event will not be passed to other elements.
Of course, I got a special manipulator that stores "ControlEventHandlers", and
processes them all when it receives an event (derives from
osgGA::GUIEventHandler), by implementing a custom
virtual bool handle (const osgGA::GUIEventAdapter &ea,
osgGA::GUIActionAdapter &aa);
This is the main problem I guess: you have to use a special manipulator. Maybe
standard manipulators could have a kind of functionality-extention by the way
of callbacks or such?
Please note that for the mouse, my implementation only "sends" coordinates, but
changing this to a "mouseOver" event would be quite simple I guess. You could
provide a mehtod in your widgets that says if a mouse coordinate is over it or
not.
Hope it helps!
If you need some more info, you can mail me, mail the list, or look at the PVLE
documentation:
http://pvle.sourceforge.net/Doc/Html/classControlEventHandler.html (Abstract
class for handling events)
http://pvle.sourceforge.net/Doc/Html/classControlEvent.html (Event class)
or:
http://pvle.sourceforge.net/Doc/Html (doc root)
Sukender
PVLE - Lightweight cross-platform game engine - http://pvle.sourceforge.net/
Le Thu, 22 Jan 2009 20:23:15 +0100, Jeremy Moles <[email protected]> a
écrit:
> In osgWidget's current design, Widgets are notified of events such as
> mouseOver by a single ViewerEventHandler object that traverses a given
> root node and determines (or tries to :)) what kind of "thing" is going
> on. When I originally wrote this part of osgWidget, such was the limit
> of my knowldege...
>
> However, I would like to move to a more divorced system, in which each
> Drawable (Widget) or Node (Window) can use special UpdateCallback and
> NodeCallback objects so that they can simply "subscribe" to the events
> they're interested in.
>
> What I'm looking for are some ideas as to how I could best accomplish
> this.
>
> One possibility is that I could keep the osgWidget::ViewerEventHandlers
> that I currently have (MouseHandler, KeyboarHandler, etc.) except than
> instead of having them call the mouseOver methods on the Widgets
> directly they would simply set various state variables (mouse position,
> etc.) that the user could later query in their on NodeCallback or
> UpdateCallback functions.
>
> Does this make sense? Is this even a worthy endeavor? I get a lot of
> questions about how osgWidget "marries" the WindowManager+Event
> mechanism and the widgets it manages, so I'm looking for ways to break
> that up. The general idea is that I really want to use the OSG "update"
> traversal more, since right now I basically just have one object (the
> various ViewerEventHandlers) doing EVERYTHING on every object during
> their own update phase.
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org