root/OpenSceneGraph/trunk/src/osgGA/GUIEventAdapter.cpp @ 13890

Revision 13890, 3.8 kB (checked in by robert, 2 years ago)

Release OpenSceneGraph-3.5.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[13041]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
[3212]2 *
[13041]3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
[3212]5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
[13041]7 *
[3212]8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
[13041]10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[3212]11 * OpenSceneGraph Public License for more details.
12*/
13
[5032]14#include <osgGA/GUIEventAdapter>
[3212]15
16using namespace osgGA;
17
[7112]18
19osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
20{
21    static osg::ref_ptr<GUIEventAdapter> s_eventState = new GUIEventAdapter;
22    return s_eventState;
23}
24
[5032]25GUIEventAdapter::GUIEventAdapter():
[6046]26    _handled(false),
[5032]27    _eventType(NONE),
[5592]28    _windowX(0),
29    _windowY(0),
30    _windowWidth(1280),
31    _windowHeight(1024),
[5032]32    _key(0),
[12125]33    _unmodifiedKey(0),
[5032]34    _button(0),
[8398]35    _Xmin(-1.0),
[5032]36    _Xmax(1.0),
[8398]37    _Ymin(-1.0),
[5032]38    _Ymax(1.0),
[8398]39    _mx(0.0),
40    _my(0.0),
[5032]41    _buttonMask(0),
42    _modKeyMask(0),
[5234]43    _mouseYOrientation(Y_INCREASING_DOWNWARDS),
[10211]44    _scrolling(),
[11934]45    _tabletPen(),
46    _touchData(NULL)
[5032]47{}
48
[6699]49GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
[13890]50    osgGA::Event(rhs,copyop),
[6046]51    _handled(rhs._handled),
[5032]52    _eventType(rhs._eventType),
[8398]53    _context(rhs._context),
[5592]54    _windowX(rhs._windowX),
55    _windowY(rhs._windowY),
56    _windowWidth(rhs._windowWidth),
57    _windowHeight(rhs._windowHeight),
[5032]58    _key(rhs._key),
[12125]59    _unmodifiedKey(rhs._unmodifiedKey),
[5032]60    _button(rhs._button),
61    _Xmin(rhs._Xmin),
62    _Xmax(rhs._Xmax),
63    _Ymin(rhs._Ymin),
64    _Ymax(rhs._Ymax),
65    _mx(rhs._mx),
66    _my(rhs._my),
67    _buttonMask(rhs._buttonMask),
68    _modKeyMask(rhs._modKeyMask),
[5234]69    _mouseYOrientation(rhs._mouseYOrientation),
[10211]70    _scrolling(rhs._scrolling),
[11934]71    _tabletPen(rhs._tabletPen),
72    _touchData(rhs._touchData)
[5032]73{}
74
[3212]75GUIEventAdapter::~GUIEventAdapter()
76{
77}
[5032]78
[5863]79void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange)
[5032]80{
[5592]81    _windowX = x;
82    _windowY = y;
83    _windowWidth = width;
84    _windowHeight = height;
[13041]85
[5592]86    if (updateMouseRange)
87    {
[5961]88        setInputRange(0, 0, width, height);
[5592]89    }
[13041]90
[5592]91}
92
93void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ymax)
94{
[5032]95    _Xmin = Xmin;
96    _Ymin = Ymin;
97    _Xmax = Xmax;
98    _Ymax = Ymax;
99}
[8085]100
101const osg::Matrix GUIEventAdapter::getPenOrientation() const
102{
103    float xRad = osg::DegreesToRadians ( getPenTiltY() );
104    float yRad = osg::DegreesToRadians ( getPenTiltX() );
105    float zRad = osg::DegreesToRadians ( getPenRotation() );
106    osg::Matrix xrot = osg::Matrix::rotate ( xRad, osg::Vec3f(1.0f, 0.0f, 0.0f) );
107    osg::Matrix yrot = osg::Matrix::rotate ( yRad, osg::Vec3f(0.0f, 0.0f, 1.0f) );
108    osg::Matrix zrot = osg::Matrix::rotate ( zRad, osg::Vec3f(0.0f, 1.0f, 0.0f) );
[13041]109
[8085]110    return ( zrot * yrot * xrot );
111}
[11934]112
113void GUIEventAdapter::addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount)
114{
115    if (!_touchData.valid()) {
116        _touchData = new TouchData();
117        setX(x);
118        setY(y);
119    }
[13041]120
[11934]121    _touchData->addTouchPoint(id, phase, x, y, tapCount);
122}
[13376]123
124void GUIEventAdapter::copyPointerDataFrom(const osgGA::GUIEventAdapter& sourceEvent)
125{
126    setGraphicsContext(const_cast<osg::GraphicsContext*>(sourceEvent.getGraphicsContext()));
127    setX(sourceEvent.getX());
128    setY(sourceEvent.getY());
129    setInputRange(sourceEvent.getXmin(), sourceEvent.getYmin(), sourceEvent.getXmax(), sourceEvent.getYmax());
130    setButtonMask(sourceEvent.getButtonMask());
131    setMouseYOrientation(sourceEvent.getMouseYOrientation());
132    setPointerDataList(sourceEvent.getPointerDataList());
133}
Note: See TracBrowser for help on using the browser.