Canvas: MouseEvent now contains screen and client pos

This commit is contained in:
Thomas Geymayer
2012-12-08 14:59:29 +01:00
parent 24d2431522
commit a882263033
3 changed files with 27 additions and 19 deletions

View File

@@ -350,8 +350,8 @@ namespace canvas
//----------------------------------------------------------------------------
bool Canvas::handleMouseEvent(const MouseEventPtr& event)
{
_mouse_x = event->pos.x();
_mouse_y = event->pos.y();
_mouse_x = event->client_pos.x();
_mouse_y = event->client_pos.y();
_mouse_dx = event->delta.x();
_mouse_dy = event->delta.y();
_mouse_button = event->button;
@@ -365,7 +365,7 @@ namespace canvas
return false;
EventVisitor visitor( EventVisitor::TRAVERSE_DOWN,
event->getPos(),
event->getClientPos(),
event->getDelta() );
if( !_root_group->accept(visitor) )
return false;

View File

@@ -180,17 +180,21 @@ namespace canvas
// (eg. removed by another event handler)
continue;
if( mouse_event && event->type != Event::DRAG )
{
// TODO transform pos and delta for drag events. Maybe we should just
// store the global coordinates and convert to local coordinates
// on demand.
// Position and delta are specified in local coordinate system of
// current element
mouse_event->pos = it->local_pos;
mouse_event->delta = it->local_delta;
}
// TODO provide functions to convert position and delta to local
// coordinates on demand. Events shouldn't contain informations in
// local coordinates as they might differe between different elements
// receiving the same event.
// if( mouse_event && event->type != Event::DRAG )
// {
// // TODO transform pos and delta for drag events. Maybe we should just
// // store the global coordinates and convert to local coordinates
// // on demand.
//
// // Position and delta are specified in local coordinate system of
// // current element
// mouse_event->pos = it->local_pos;
// mouse_event->delta = it->local_delta;
// }
el->callListeners(event);

View File

@@ -38,19 +38,23 @@ namespace canvas
click_count(0)
{}
osg::Vec2f getPos() const { return pos; }
osg::Vec3f getPos3() const { return osg::Vec3f(pos, 0); }
osg::Vec2f getScreenPos() const { return screen_pos; }
osg::Vec2f getClientPos() const { return client_pos; }
osg::Vec2f getDelta() const { return delta; }
float getPosX() const { return pos.x(); }
float getPosY() const { return pos.y(); }
float getScreenX() const { return screen_pos.x(); }
float getScreenY() const { return screen_pos.y(); }
float getClientX() const { return client_pos.x(); }
float getClientY() const { return client_pos.y(); }
float getDeltaX() const { return delta.x(); }
float getDeltaY() const { return delta.y(); }
int getCurrentClickCount() const { return click_count; }
osg::Vec2f pos,
osg::Vec2f screen_pos, //<! Position in screen coordinates
client_pos, //<! Position in window/canvas coordinates
delta;
int button, //<! Button for this event
state, //<! Current button state