// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#include "Canvas.hxx"
+#include "CanvasEventVisitor.hxx"
#include <simgear/canvas/MouseEvent.hxx>
-#include <simgear/misc/parse_color.hxx>
+#include <simgear/canvas/CanvasPlacement.hxx>
+#include <simgear/scene/util/parse_color.hxx>
#include <simgear/scene/util/RenderConstants.hxx>
#include <osg/Camera>
_dependent_canvases.erase(canvas);
}
+ //----------------------------------------------------------------------------
+ GroupPtr Canvas::createGroup(const std::string& name)
+ {
+ return boost::dynamic_pointer_cast<Group>
+ (
+ _root_group->createChild("group", name)
+ );
+ }
+
//----------------------------------------------------------------------------
void Canvas::enableRendering(bool force)
{
}
}
+ //----------------------------------------------------------------------------
+ naRef Canvas::addEventListener(const nasal::CallContext& ctx)
+ {
+ if( !_root_group.get() )
+ naRuntimeError(ctx.c, "Canvas: No root group!");
+
+ return _root_group->addEventListener(ctx);
+ }
+
//----------------------------------------------------------------------------
void Canvas::setSizeX(int sx)
{
}
//----------------------------------------------------------------------------
- bool Canvas::handleMouseEvent(const MouseEvent& event)
+ bool Canvas::handleMouseEvent(const MouseEventPtr& event)
{
- _mouse_x = event.x;
- _mouse_y = event.y;
- _mouse_dx = event.dx;
- _mouse_dy = event.dy;
- _mouse_button = event.button;
- _mouse_state = event.state;
- _mouse_mod = event.mod;
- _mouse_scroll = event.scroll;
+ _mouse_x = event->pos.x();
+ _mouse_y = event->pos.y();
+ _mouse_dx = event->delta.x();
+ _mouse_dy = event->delta.y();
+ _mouse_button = event->button;
+ _mouse_state = event->state;
+ _mouse_mod = event->mod;
+ //_mouse_scroll = event.scroll;
// Always set event type last because all listeners are attached to it
- _mouse_event = event.type;
+ _mouse_event = event->type;
- if( _root_group.get() )
- return _root_group->handleMouseEvent(event);
- else
+ if( !_root_group.get() )
return false;
+
+ EventVisitor visitor( EventVisitor::TRAVERSE_DOWN,
+ event->getPos(),
+ event->getDelta() );
+ if( !_root_group->accept(visitor) )
+ return false;
+
+ // TODO create special events like click/dblclick etc.
+
+ return visitor.propagateEvent(event);
}
//----------------------------------------------------------------------------
if( node->getParent()->getParent() == _node
&& node->getParent()->getNameString() == "placement" )
{
+ bool placement_dirty = false;
+ BOOST_FOREACH(Placements& placements, _placements)
+ {
+ BOOST_FOREACH(PlacementPtr& placement, placements)
+ {
+ // check if change can be directly handled by placement
+ if( placement->getProps() == node->getParent()
+ && !placement->childChanged(node) )
+ placement_dirty = true;
+ }
+ }
+
+ if( !placement_dirty )
+ return;
+
// prevent double updates...
for( size_t i = 0; i < _dirty_placements.size(); ++i )
{