Am 2012-07-31 18:49, schrieb James Turner:
> I was assuming I'd create a Nasal ghost for Canvas::Element, and another for 
> osgGA::Event, or a Canvas::Event if we need an explicit class. Then we need 
> some global Nasal C functions to map from a Canvas property node to the Nasal 
> ghost (i.e finding the underlying C++ canvas::Element).

What shall the ghost for the canvas::Element do? I think it would be
enough to have a set(event)handler(path, event_type/mask, cb) and
remove(event)handler function which work similar to the property
listener functions:

  sethandler('/canvas/texture[2]/group[3]', 'click', func(event) {
    print('click at ' ~ event.x ~ '|' ~ event.y);
  });

  or

  sethandler('/canvas/texture[2]/group[3]', 'mouse', func(event) {
    print('mouse event ' ~ event.type ~ ' at ' ~ event.x ~ '|' ~ event.y);
  });

I'm not really sure if we need to differentiate between different mouse
events already at C++ level or if just passing every mouse event is
sufficient.

Finding the acording canvas::Element is really easy as the first part of
the path can directly be compared to the canvas base path (see
canvas_mgr.cxx and property_based_mgr.cxx) and access the required
canvas by it's index (only possible with canvases) and afterwards
recursively checking for element name and index.

Can Nasal ghosts also be used with an inheritance hierarchy? Eg. having
an event base class and mouse, keybord, etc. events. Events may have
something in common, but eg. for mouse and keyboard most of the data
will be different.

> All of the above is only a few lines of code and I've been doing it for 
> FGPositioned recently - it's pretty easy. Once that's done we define the 
> 'addXYZCVallback' methods in C++, and have them capture an naFunctionRef for 
> the callbacks - again I've already done this and it works nicely. When the 
> C++ element receives an event it can check its registered callback list, wrap 
> the event in a ghost and run whichever callbacks apply.
> 
> If you want me to prototype some code for this, I am happy to do so!

Would be great :)

Tom

-- 
Thomas Geymayer  www.tomprogs.at / C-Forum und Tutorial: www.proggen.org
------------------------------------------------------------------------
      Student of Computer Science @ Graz University of Technology
------------------------------- Austria --------------------------------

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to