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

Revision 13890, 3.8 kB (checked in by robert, 4 days ago)

Added support for changing background colour of LineEdit? widget when focus changes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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
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.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgGA/GUIEventAdapter>
15
16using namespace osgGA;
17
18
19osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
20{
21    static osg::ref_ptr<GUIEventAdapter> s_eventState = new GUIEventAdapter;
22    return s_eventState;
23}
24
25GUIEventAdapter::GUIEventAdapter():
26    _handled(false),
27    _eventType(NONE),
28    _windowX(0),
29    _windowY(0),
30    _windowWidth(1280),
31    _windowHeight(1024),
32    _key(0),
33    _unmodifiedKey(0),
34    _button(0),
35    _Xmin(-1.0),
36    _Xmax(1.0),
37    _Ymin(-1.0),
38    _Ymax(1.0),
39    _mx(0.0),
40    _my(0.0),
41    _buttonMask(0),
42    _modKeyMask(0),
43    _mouseYOrientation(Y_INCREASING_DOWNWARDS),
44    _scrolling(),
45    _tabletPen(),
46    _touchData(NULL)
47{}
48
49GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
50    osgGA::Event(rhs,copyop),
51    _handled(rhs._handled),
52    _eventType(rhs._eventType),
53    _context(rhs._context),
54    _windowX(rhs._windowX),
55    _windowY(rhs._windowY),
56    _windowWidth(rhs._windowWidth),
57    _windowHeight(rhs._windowHeight),
58    _key(rhs._key),
59    _unmodifiedKey(rhs._unmodifiedKey),
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),
69    _mouseYOrientation(rhs._mouseYOrientation),
70    _scrolling(rhs._scrolling),
71    _tabletPen(rhs._tabletPen),
72    _touchData(rhs._touchData)
73{}
74
75GUIEventAdapter::~GUIEventAdapter()
76{
77}
78
79void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange)
80{
81    _windowX = x;
82    _windowY = y;
83    _windowWidth = width;
84    _windowHeight = height;
85
86    if (updateMouseRange)
87    {
88        setInputRange(0, 0, width, height);
89    }
90
91}
92
93void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ymax)
94{
95    _Xmin = Xmin;
96    _Ymin = Ymin;
97    _Xmax = Xmax;
98    _Ymax = Ymax;
99}
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) );
109
110    return ( zrot * yrot * xrot );
111}
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    }
120
121    _touchData->addTouchPoint(id, phase, x, y, tapCount);
122}
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.