1 | |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | #include <osgGA/GUIEventAdapter> |
---|
15 | |
---|
16 | using namespace osgGA; |
---|
17 | |
---|
18 | |
---|
19 | osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState() |
---|
20 | { |
---|
21 | static osg::ref_ptr<GUIEventAdapter> s_eventState = new GUIEventAdapter; |
---|
22 | return s_eventState; |
---|
23 | } |
---|
24 | |
---|
25 | GUIEventAdapter::GUIEventAdapter(): |
---|
26 | _handled(false), |
---|
27 | _eventType(NONE), |
---|
28 | _time(0.0), |
---|
29 | _windowX(0), |
---|
30 | _windowY(0), |
---|
31 | _windowWidth(1280), |
---|
32 | _windowHeight(1024), |
---|
33 | _key(0), |
---|
34 | _unmodifiedKey(0), |
---|
35 | _button(0), |
---|
36 | _Xmin(-1.0), |
---|
37 | _Xmax(1.0), |
---|
38 | _Ymin(-1.0), |
---|
39 | _Ymax(1.0), |
---|
40 | _mx(0.0), |
---|
41 | _my(0.0), |
---|
42 | _buttonMask(0), |
---|
43 | _modKeyMask(0), |
---|
44 | _mouseYOrientation(Y_INCREASING_DOWNWARDS), |
---|
45 | _scrolling(), |
---|
46 | _tabletPen(), |
---|
47 | _touchData(NULL) |
---|
48 | {} |
---|
49 | |
---|
50 | GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop): |
---|
51 | osg::Object(rhs,copyop), |
---|
52 | _handled(rhs._handled), |
---|
53 | _eventType(rhs._eventType), |
---|
54 | _time(rhs._time), |
---|
55 | _context(rhs._context), |
---|
56 | _windowX(rhs._windowX), |
---|
57 | _windowY(rhs._windowY), |
---|
58 | _windowWidth(rhs._windowWidth), |
---|
59 | _windowHeight(rhs._windowHeight), |
---|
60 | _key(rhs._key), |
---|
61 | _unmodifiedKey(rhs._unmodifiedKey), |
---|
62 | _button(rhs._button), |
---|
63 | _Xmin(rhs._Xmin), |
---|
64 | _Xmax(rhs._Xmax), |
---|
65 | _Ymin(rhs._Ymin), |
---|
66 | _Ymax(rhs._Ymax), |
---|
67 | _mx(rhs._mx), |
---|
68 | _my(rhs._my), |
---|
69 | _buttonMask(rhs._buttonMask), |
---|
70 | _modKeyMask(rhs._modKeyMask), |
---|
71 | _mouseYOrientation(rhs._mouseYOrientation), |
---|
72 | _scrolling(rhs._scrolling), |
---|
73 | _tabletPen(rhs._tabletPen), |
---|
74 | _touchData(rhs._touchData) |
---|
75 | {} |
---|
76 | |
---|
77 | GUIEventAdapter::~GUIEventAdapter() |
---|
78 | { |
---|
79 | } |
---|
80 | |
---|
81 | void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange) |
---|
82 | { |
---|
83 | _windowX = x; |
---|
84 | _windowY = y; |
---|
85 | _windowWidth = width; |
---|
86 | _windowHeight = height; |
---|
87 | |
---|
88 | if (updateMouseRange) |
---|
89 | { |
---|
90 | setInputRange(0, 0, width, height); |
---|
91 | } |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ymax) |
---|
96 | { |
---|
97 | _Xmin = Xmin; |
---|
98 | _Ymin = Ymin; |
---|
99 | _Xmax = Xmax; |
---|
100 | _Ymax = Ymax; |
---|
101 | } |
---|
102 | |
---|
103 | const osg::Matrix GUIEventAdapter::getPenOrientation() const |
---|
104 | { |
---|
105 | float xRad = osg::DegreesToRadians ( getPenTiltY() ); |
---|
106 | float yRad = osg::DegreesToRadians ( getPenTiltX() ); |
---|
107 | float zRad = osg::DegreesToRadians ( getPenRotation() ); |
---|
108 | osg::Matrix xrot = osg::Matrix::rotate ( xRad, osg::Vec3f(1.0f, 0.0f, 0.0f) ); |
---|
109 | osg::Matrix yrot = osg::Matrix::rotate ( yRad, osg::Vec3f(0.0f, 0.0f, 1.0f) ); |
---|
110 | osg::Matrix zrot = osg::Matrix::rotate ( zRad, osg::Vec3f(0.0f, 1.0f, 0.0f) ); |
---|
111 | |
---|
112 | return ( zrot * yrot * xrot ); |
---|
113 | } |
---|
114 | |
---|
115 | void GUIEventAdapter::addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount) |
---|
116 | { |
---|
117 | if (!_touchData.valid()) { |
---|
118 | _touchData = new TouchData(); |
---|
119 | setX(x); |
---|
120 | setY(y); |
---|
121 | } |
---|
122 | |
---|
123 | _touchData->addTouchPoint(id, phase, x, y, tapCount); |
---|
124 | } |
---|