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 | _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 | |
---|
49 | GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop): |
---|
50 | osg::Object(rhs,copyop), |
---|
51 | _handled(rhs._handled), |
---|
52 | _eventType(rhs._eventType), |
---|
53 | _time(rhs._time), |
---|
54 | _context(rhs._context), |
---|
55 | _windowX(rhs._windowX), |
---|
56 | _windowY(rhs._windowY), |
---|
57 | _windowWidth(rhs._windowWidth), |
---|
58 | _windowHeight(rhs._windowHeight), |
---|
59 | _key(rhs._key), |
---|
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 | |
---|
75 | GUIEventAdapter::~GUIEventAdapter() |
---|
76 | { |
---|
77 | } |
---|
78 | |
---|
79 | void 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 | |
---|
93 | void 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 | |
---|
101 | const 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 | |
---|
113 | void 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 | } |
---|