2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2004-08-02 17:11:31 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2004-08-02 17:11:31 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2004-08-02 17:11:31 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-08-02 17:11:31 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2006-03-08 22:09:47 +08:00
|
|
|
#include <osgGA/GUIEventAdapter>
|
2004-08-02 17:11:31 +08:00
|
|
|
|
|
|
|
using namespace osgGA;
|
|
|
|
|
2007-07-13 19:17:41 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
|
|
|
|
{
|
|
|
|
static osg::ref_ptr<GUIEventAdapter> s_eventState = new GUIEventAdapter;
|
|
|
|
return s_eventState;
|
|
|
|
}
|
|
|
|
|
2006-03-08 22:09:47 +08:00
|
|
|
GUIEventAdapter::GUIEventAdapter():
|
|
|
|
_eventType(NONE),
|
2006-09-26 00:25:53 +08:00
|
|
|
_windowX(0),
|
|
|
|
_windowY(0),
|
|
|
|
_windowWidth(1280),
|
|
|
|
_windowHeight(1024),
|
2006-03-08 22:09:47 +08:00
|
|
|
_key(0),
|
2011-01-28 00:23:48 +08:00
|
|
|
_unmodifiedKey(0),
|
2006-03-08 22:09:47 +08:00
|
|
|
_button(0),
|
2008-06-03 01:34:47 +08:00
|
|
|
_Xmin(-1.0),
|
2006-03-08 22:09:47 +08:00
|
|
|
_Xmax(1.0),
|
2008-06-03 01:34:47 +08:00
|
|
|
_Ymin(-1.0),
|
2006-03-08 22:09:47 +08:00
|
|
|
_Ymax(1.0),
|
2008-06-03 01:34:47 +08:00
|
|
|
_mx(0.0),
|
|
|
|
_my(0.0),
|
2006-03-08 22:09:47 +08:00
|
|
|
_buttonMask(0),
|
|
|
|
_modKeyMask(0),
|
2006-07-04 22:18:44 +08:00
|
|
|
_mouseYOrientation(Y_INCREASING_DOWNWARDS),
|
2009-05-15 00:08:12 +08:00
|
|
|
_scrolling(),
|
2010-11-23 01:30:44 +08:00
|
|
|
_tabletPen(),
|
|
|
|
_touchData(NULL)
|
2006-03-08 22:09:47 +08:00
|
|
|
{}
|
|
|
|
|
2007-05-19 21:39:55 +08:00
|
|
|
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
|
2013-10-25 22:54:15 +08:00
|
|
|
osgGA::Event(rhs,copyop),
|
2006-03-08 22:09:47 +08:00
|
|
|
_eventType(rhs._eventType),
|
2008-06-03 01:34:47 +08:00
|
|
|
_context(rhs._context),
|
2006-09-26 00:25:53 +08:00
|
|
|
_windowX(rhs._windowX),
|
|
|
|
_windowY(rhs._windowY),
|
|
|
|
_windowWidth(rhs._windowWidth),
|
|
|
|
_windowHeight(rhs._windowHeight),
|
2006-03-08 22:09:47 +08:00
|
|
|
_key(rhs._key),
|
2011-01-28 00:23:48 +08:00
|
|
|
_unmodifiedKey(rhs._unmodifiedKey),
|
2006-03-08 22:09:47 +08:00
|
|
|
_button(rhs._button),
|
|
|
|
_Xmin(rhs._Xmin),
|
|
|
|
_Xmax(rhs._Xmax),
|
|
|
|
_Ymin(rhs._Ymin),
|
|
|
|
_Ymax(rhs._Ymax),
|
|
|
|
_mx(rhs._mx),
|
|
|
|
_my(rhs._my),
|
|
|
|
_buttonMask(rhs._buttonMask),
|
|
|
|
_modKeyMask(rhs._modKeyMask),
|
2006-07-04 22:18:44 +08:00
|
|
|
_mouseYOrientation(rhs._mouseYOrientation),
|
2009-05-15 00:08:12 +08:00
|
|
|
_scrolling(rhs._scrolling),
|
2010-11-23 01:30:44 +08:00
|
|
|
_tabletPen(rhs._tabletPen),
|
|
|
|
_touchData(rhs._touchData)
|
2006-03-08 22:09:47 +08:00
|
|
|
{}
|
|
|
|
|
2004-08-02 17:11:31 +08:00
|
|
|
GUIEventAdapter::~GUIEventAdapter()
|
|
|
|
{
|
|
|
|
}
|
2006-03-08 22:09:47 +08:00
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange)
|
2006-09-26 00:25:53 +08:00
|
|
|
{
|
|
|
|
_windowX = x;
|
|
|
|
_windowY = y;
|
|
|
|
_windowWidth = width;
|
|
|
|
_windowHeight = height;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-09-26 00:25:53 +08:00
|
|
|
if (updateMouseRange)
|
|
|
|
{
|
2007-01-11 22:53:34 +08:00
|
|
|
setInputRange(0, 0, width, height);
|
2006-09-26 00:25:53 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-09-26 00:25:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ymax)
|
2006-03-08 22:09:47 +08:00
|
|
|
{
|
|
|
|
_Xmin = Xmin;
|
|
|
|
_Ymin = Ymin;
|
|
|
|
_Xmax = Xmax;
|
|
|
|
_Ymax = Ymax;
|
|
|
|
}
|
2008-04-11 21:28:09 +08:00
|
|
|
|
|
|
|
const osg::Matrix GUIEventAdapter::getPenOrientation() const
|
|
|
|
{
|
|
|
|
float xRad = osg::DegreesToRadians ( getPenTiltY() );
|
|
|
|
float yRad = osg::DegreesToRadians ( getPenTiltX() );
|
|
|
|
float zRad = osg::DegreesToRadians ( getPenRotation() );
|
|
|
|
osg::Matrix xrot = osg::Matrix::rotate ( xRad, osg::Vec3f(1.0f, 0.0f, 0.0f) );
|
|
|
|
osg::Matrix yrot = osg::Matrix::rotate ( yRad, osg::Vec3f(0.0f, 0.0f, 1.0f) );
|
|
|
|
osg::Matrix zrot = osg::Matrix::rotate ( zRad, osg::Vec3f(0.0f, 1.0f, 0.0f) );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-04-11 21:28:09 +08:00
|
|
|
return ( zrot * yrot * xrot );
|
|
|
|
}
|
2010-11-23 01:30:44 +08:00
|
|
|
|
|
|
|
void GUIEventAdapter::addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount)
|
|
|
|
{
|
|
|
|
if (!_touchData.valid()) {
|
|
|
|
_touchData = new TouchData();
|
|
|
|
setX(x);
|
|
|
|
setY(y);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-11-23 01:30:44 +08:00
|
|
|
_touchData->addTouchPoint(id, phase, x, y, tapCount);
|
|
|
|
}
|
2013-05-04 03:26:27 +08:00
|
|
|
|
|
|
|
void GUIEventAdapter::copyPointerDataFrom(const osgGA::GUIEventAdapter& sourceEvent)
|
|
|
|
{
|
|
|
|
setGraphicsContext(const_cast<osg::GraphicsContext*>(sourceEvent.getGraphicsContext()));
|
|
|
|
setX(sourceEvent.getX());
|
|
|
|
setY(sourceEvent.getY());
|
|
|
|
setInputRange(sourceEvent.getXmin(), sourceEvent.getYmin(), sourceEvent.getXmax(), sourceEvent.getYmax());
|
|
|
|
setButtonMask(sourceEvent.getButtonMask());
|
|
|
|
setMouseYOrientation(sourceEvent.getMouseYOrientation());
|
|
|
|
setPointerDataList(sourceEvent.getPointerDataList());
|
|
|
|
}
|