| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgGA/EventQueue> |
|---|
| 15 | #include <osg/Notify> |
|---|
| 16 | |
|---|
| 17 | using namespace osgGA; |
|---|
| 18 | |
|---|
| 19 | EventQueue::EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation) |
|---|
| 20 | { |
|---|
| 21 | _useFixedMouseInputRange = false; |
|---|
| 22 | |
|---|
| 23 | _startTick = osg::Timer::instance()->getStartTick(); |
|---|
| 24 | |
|---|
| 25 | _accumulateEventState = new GUIEventAdapter(); |
|---|
| 26 | _accumulateEventState->setMouseYOrientation(mouseYOrientation); |
|---|
| 27 | |
|---|
| 28 | _firstTouchEmulatesMouse = true; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | EventQueue::~EventQueue() |
|---|
| 32 | { |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void EventQueue::clear() |
|---|
| 36 | { |
|---|
| 37 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 38 | _eventQueue.clear(); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | void EventQueue::setEvents(Events& events) |
|---|
| 43 | { |
|---|
| 44 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 45 | _eventQueue = events; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void EventQueue::appendEvents(Events& events) |
|---|
| 49 | { |
|---|
| 50 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 51 | _eventQueue.insert(_eventQueue.end(), events.begin(), events.end()); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void EventQueue::addEvent(GUIEventAdapter* event) |
|---|
| 55 | { |
|---|
| 56 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 57 | _eventQueue.push_back(event); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | bool EventQueue::takeEvents(Events& events) |
|---|
| 61 | { |
|---|
| 62 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 63 | if (!_eventQueue.empty()) |
|---|
| 64 | { |
|---|
| 65 | events.splice(events.end(), _eventQueue); |
|---|
| 66 | return true; |
|---|
| 67 | } |
|---|
| 68 | else |
|---|
| 69 | { |
|---|
| 70 | return false; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | bool EventQueue::takeEvents(Events& events, double cutOffTime) |
|---|
| 75 | { |
|---|
| 76 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 77 | if (!_eventQueue.empty()) |
|---|
| 78 | { |
|---|
| 79 | |
|---|
| 80 | Events::reverse_iterator ritr = _eventQueue.rbegin(); |
|---|
| 81 | for(; ritr != _eventQueue.rend() && ((*ritr)->getTime() > cutOffTime); ++ritr) {} |
|---|
| 82 | |
|---|
| 83 | if (ritr==_eventQueue.rend()) return false; |
|---|
| 84 | |
|---|
| 85 | for(Events::iterator itr = _eventQueue.begin(); |
|---|
| 86 | itr != ritr.base(); |
|---|
| 87 | ++itr) |
|---|
| 88 | { |
|---|
| 89 | events.push_back(*itr); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | double previousTime = cutOffTime; |
|---|
| 95 | for(Events::reverse_iterator itr = events.rbegin(); |
|---|
| 96 | itr != events.rend(); |
|---|
| 97 | ++itr) |
|---|
| 98 | { |
|---|
| 99 | if ((*itr)->getTime() > previousTime) |
|---|
| 100 | { |
|---|
| 101 | OSG_INFO<<"Reset event time from "<<(*itr)->getTime()<<" to "<<previousTime<<std::endl; |
|---|
| 102 | (*itr)->setTime(previousTime); |
|---|
| 103 | } |
|---|
| 104 | else |
|---|
| 105 | { |
|---|
| 106 | previousTime = (*itr)->getTime(); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | _eventQueue.erase(_eventQueue.begin(), ritr.base()); |
|---|
| 112 | |
|---|
| 113 | return true; |
|---|
| 114 | } |
|---|
| 115 | else |
|---|
| 116 | { |
|---|
| 117 | return false; |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | bool EventQueue::copyEvents(Events& events) const |
|---|
| 122 | { |
|---|
| 123 | OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); |
|---|
| 124 | if (!_eventQueue.empty()) |
|---|
| 125 | { |
|---|
| 126 | events.insert(events.end(),_eventQueue.begin(),_eventQueue.end()); |
|---|
| 127 | return true; |
|---|
| 128 | } |
|---|
| 129 | else |
|---|
| 130 | { |
|---|
| 131 | return false; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | void EventQueue::windowResize(int x, int y, int width, int height, double time) |
|---|
| 137 | { |
|---|
| 138 | _accumulateEventState->setWindowRectangle(x, y, width, height, !_useFixedMouseInputRange); |
|---|
| 139 | |
|---|
| 140 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 141 | event->setEventType(GUIEventAdapter::RESIZE); |
|---|
| 142 | event->setTime(time); |
|---|
| 143 | |
|---|
| 144 | addEvent(event); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | void EventQueue::penPressure(float pressure, double time) |
|---|
| 148 | { |
|---|
| 149 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 150 | event->setEventType(GUIEventAdapter::PEN_PRESSURE); |
|---|
| 151 | event->setPenPressure(pressure); |
|---|
| 152 | event->setTime(time); |
|---|
| 153 | |
|---|
| 154 | addEvent(event); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | void EventQueue::penOrientation(float tiltX, float tiltY, float rotation, double time) |
|---|
| 158 | { |
|---|
| 159 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 160 | event->setEventType(GUIEventAdapter::PEN_ORIENTATION); |
|---|
| 161 | event->setPenTiltX(tiltX); |
|---|
| 162 | event->setPenTiltY(tiltY); |
|---|
| 163 | event->setPenRotation(rotation); |
|---|
| 164 | event->setTime(time); |
|---|
| 165 | |
|---|
| 166 | addEvent(event); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | void EventQueue::penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time) |
|---|
| 170 | { |
|---|
| 171 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 172 | event->setEventType( (isEntering) ? GUIEventAdapter::PEN_PROXIMITY_ENTER : GUIEventAdapter::PEN_PROXIMITY_LEAVE); |
|---|
| 173 | event->setTabletPointerType(pt); |
|---|
| 174 | event->setTime(time); |
|---|
| 175 | |
|---|
| 176 | addEvent(event); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | void EventQueue::mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time) |
|---|
| 180 | { |
|---|
| 181 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 182 | event->setEventType(GUIEventAdapter::SCROLL); |
|---|
| 183 | event->setScrollingMotion(sm); |
|---|
| 184 | event->setTime(time); |
|---|
| 185 | |
|---|
| 186 | addEvent(event); |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | void EventQueue::mouseScroll2D(float x, float y, double time) |
|---|
| 190 | { |
|---|
| 191 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 192 | event->setEventType(GUIEventAdapter::SCROLL); |
|---|
| 193 | event->setScrollingMotionDelta(x,y); |
|---|
| 194 | event->setTime(time); |
|---|
| 195 | |
|---|
| 196 | addEvent(event); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | void EventQueue::mouseWarped(float x, float y) |
|---|
| 201 | { |
|---|
| 202 | _accumulateEventState->setX(x); |
|---|
| 203 | _accumulateEventState->setY(y); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | void EventQueue::mouseMotion(float x, float y, double time) |
|---|
| 208 | { |
|---|
| 209 | _accumulateEventState->setX(x); |
|---|
| 210 | _accumulateEventState->setY(y); |
|---|
| 211 | |
|---|
| 212 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 213 | event->setEventType(event->getButtonMask() ? GUIEventAdapter::DRAG : GUIEventAdapter::MOVE); |
|---|
| 214 | event->setTime(time); |
|---|
| 215 | |
|---|
| 216 | addEvent(event); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | void EventQueue::mouseButtonPress(float x, float y, unsigned int button, double time) |
|---|
| 220 | { |
|---|
| 221 | _accumulateEventState->setX(x); |
|---|
| 222 | _accumulateEventState->setY(y); |
|---|
| 223 | |
|---|
| 224 | switch(button) |
|---|
| 225 | { |
|---|
| 226 | case(1): |
|---|
| 227 | _accumulateEventState->setButtonMask(GUIEventAdapter::LEFT_MOUSE_BUTTON | _accumulateEventState->getButtonMask()); |
|---|
| 228 | break; |
|---|
| 229 | case(2): |
|---|
| 230 | _accumulateEventState->setButtonMask(GUIEventAdapter::MIDDLE_MOUSE_BUTTON | _accumulateEventState->getButtonMask()); |
|---|
| 231 | break; |
|---|
| 232 | case(3): |
|---|
| 233 | _accumulateEventState->setButtonMask(GUIEventAdapter::RIGHT_MOUSE_BUTTON | _accumulateEventState->getButtonMask()); |
|---|
| 234 | break; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 238 | event->setEventType(GUIEventAdapter::PUSH); |
|---|
| 239 | event->setTime(time); |
|---|
| 240 | |
|---|
| 241 | switch(button) |
|---|
| 242 | { |
|---|
| 243 | case(1): |
|---|
| 244 | event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); |
|---|
| 245 | break; |
|---|
| 246 | case(2): |
|---|
| 247 | event->setButton(GUIEventAdapter::MIDDLE_MOUSE_BUTTON); |
|---|
| 248 | break; |
|---|
| 249 | case(3): |
|---|
| 250 | event->setButton(GUIEventAdapter::RIGHT_MOUSE_BUTTON); |
|---|
| 251 | break; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | addEvent(event); |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | void EventQueue::mouseDoubleButtonPress(float x, float y, unsigned int button, double time) |
|---|
| 258 | { |
|---|
| 259 | _accumulateEventState->setX(x); |
|---|
| 260 | _accumulateEventState->setY(y); |
|---|
| 261 | |
|---|
| 262 | switch(button) |
|---|
| 263 | { |
|---|
| 264 | case(1): |
|---|
| 265 | _accumulateEventState->setButtonMask(GUIEventAdapter::LEFT_MOUSE_BUTTON | _accumulateEventState->getButtonMask()); |
|---|
| 266 | break; |
|---|
| 267 | case(2): |
|---|
| 268 | _accumulateEventState->setButtonMask(GUIEventAdapter::MIDDLE_MOUSE_BUTTON | _accumulateEventState->getButtonMask()); |
|---|
| 269 | break; |
|---|
| 270 | case(3): |
|---|
| 271 | _accumulateEventState->setButtonMask(GUIEventAdapter::RIGHT_MOUSE_BUTTON | _accumulateEventState->getButtonMask()); |
|---|
| 272 | break; |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 276 | event->setEventType(GUIEventAdapter::DOUBLECLICK); |
|---|
| 277 | event->setTime(time); |
|---|
| 278 | |
|---|
| 279 | switch(button) |
|---|
| 280 | { |
|---|
| 281 | case(1): |
|---|
| 282 | event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); |
|---|
| 283 | break; |
|---|
| 284 | case(2): |
|---|
| 285 | event->setButton(GUIEventAdapter::MIDDLE_MOUSE_BUTTON); |
|---|
| 286 | break; |
|---|
| 287 | case(3): |
|---|
| 288 | event->setButton(GUIEventAdapter::RIGHT_MOUSE_BUTTON); |
|---|
| 289 | break; |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | addEvent(event); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | void EventQueue::mouseButtonRelease(float x, float y, unsigned int button, double time) |
|---|
| 296 | { |
|---|
| 297 | _accumulateEventState->setX(x); |
|---|
| 298 | _accumulateEventState->setY(y); |
|---|
| 299 | |
|---|
| 300 | switch(button) |
|---|
| 301 | { |
|---|
| 302 | case(1): |
|---|
| 303 | _accumulateEventState->setButtonMask(~GUIEventAdapter::LEFT_MOUSE_BUTTON & _accumulateEventState->getButtonMask()); |
|---|
| 304 | break; |
|---|
| 305 | case(2): |
|---|
| 306 | _accumulateEventState->setButtonMask(~GUIEventAdapter::MIDDLE_MOUSE_BUTTON & _accumulateEventState->getButtonMask()); |
|---|
| 307 | break; |
|---|
| 308 | case(3): |
|---|
| 309 | _accumulateEventState->setButtonMask(~GUIEventAdapter::RIGHT_MOUSE_BUTTON & _accumulateEventState->getButtonMask()); |
|---|
| 310 | break; |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 314 | event->setEventType(GUIEventAdapter::RELEASE); |
|---|
| 315 | event->setTime(time); |
|---|
| 316 | |
|---|
| 317 | switch(button) |
|---|
| 318 | { |
|---|
| 319 | case(1): |
|---|
| 320 | event->setButton(GUIEventAdapter::LEFT_MOUSE_BUTTON); |
|---|
| 321 | break; |
|---|
| 322 | case(2): |
|---|
| 323 | event->setButton(GUIEventAdapter::MIDDLE_MOUSE_BUTTON); |
|---|
| 324 | break; |
|---|
| 325 | case(3): |
|---|
| 326 | event->setButton(GUIEventAdapter::RIGHT_MOUSE_BUTTON); |
|---|
| 327 | break; |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | addEvent(event); |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | void EventQueue::keyPress(int key, double time, int unmodifiedKey) |
|---|
| 334 | { |
|---|
| 335 | switch(key) |
|---|
| 336 | { |
|---|
| 337 | case(GUIEventAdapter::KEY_Shift_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_SHIFT | _accumulateEventState->getModKeyMask()); break; |
|---|
| 338 | case(GUIEventAdapter::KEY_Shift_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_SHIFT | _accumulateEventState->getModKeyMask()); break; |
|---|
| 339 | case(GUIEventAdapter::KEY_Control_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_CTRL | _accumulateEventState->getModKeyMask()); break; |
|---|
| 340 | case(GUIEventAdapter::KEY_Control_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_CTRL | _accumulateEventState->getModKeyMask()); break; |
|---|
| 341 | case(GUIEventAdapter::KEY_Meta_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_META | _accumulateEventState->getModKeyMask()); break; |
|---|
| 342 | case(GUIEventAdapter::KEY_Meta_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_META | _accumulateEventState->getModKeyMask()); break; |
|---|
| 343 | case(GUIEventAdapter::KEY_Alt_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_ALT | _accumulateEventState->getModKeyMask()); break; |
|---|
| 344 | case(GUIEventAdapter::KEY_Alt_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_ALT | _accumulateEventState->getModKeyMask()); break; |
|---|
| 345 | case(GUIEventAdapter::KEY_Super_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_SUPER | _accumulateEventState->getModKeyMask()); break; |
|---|
| 346 | case(GUIEventAdapter::KEY_Super_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_SUPER | _accumulateEventState->getModKeyMask()); break; |
|---|
| 347 | case(GUIEventAdapter::KEY_Hyper_L): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_LEFT_HYPER | _accumulateEventState->getModKeyMask()); break; |
|---|
| 348 | case(GUIEventAdapter::KEY_Hyper_R): _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_RIGHT_HYPER | _accumulateEventState->getModKeyMask()); break; |
|---|
| 349 | case(GUIEventAdapter::KEY_Caps_Lock): |
|---|
| 350 | { |
|---|
| 351 | if ((_accumulateEventState->getModKeyMask() & GUIEventAdapter::MODKEY_CAPS_LOCK)!=0) |
|---|
| 352 | _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_CAPS_LOCK & _accumulateEventState->getModKeyMask()); |
|---|
| 353 | else |
|---|
| 354 | _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_CAPS_LOCK | _accumulateEventState->getModKeyMask()); |
|---|
| 355 | break; |
|---|
| 356 | } |
|---|
| 357 | case(GUIEventAdapter::KEY_Num_Lock): |
|---|
| 358 | { |
|---|
| 359 | if ((_accumulateEventState->getModKeyMask() & GUIEventAdapter::MODKEY_NUM_LOCK)!=0) |
|---|
| 360 | _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_NUM_LOCK & _accumulateEventState->getModKeyMask()); |
|---|
| 361 | else |
|---|
| 362 | _accumulateEventState->setModKeyMask(GUIEventAdapter::MODKEY_NUM_LOCK | _accumulateEventState->getModKeyMask()); |
|---|
| 363 | break; |
|---|
| 364 | } |
|---|
| 365 | default: break; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 369 | event->setEventType(GUIEventAdapter::KEYDOWN); |
|---|
| 370 | event->setKey(key); |
|---|
| 371 | event->setUnmodifiedKey(unmodifiedKey); |
|---|
| 372 | event->setTime(time); |
|---|
| 373 | |
|---|
| 374 | addEvent(event); |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | void EventQueue::keyRelease(int key, double time, int unmodifiedKey) |
|---|
| 378 | { |
|---|
| 379 | switch(key) |
|---|
| 380 | { |
|---|
| 381 | case(GUIEventAdapter::KEY_Shift_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_SHIFT & _accumulateEventState->getModKeyMask()); break; |
|---|
| 382 | case(GUIEventAdapter::KEY_Shift_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_SHIFT & _accumulateEventState->getModKeyMask()); break; |
|---|
| 383 | case(GUIEventAdapter::KEY_Control_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_CTRL & _accumulateEventState->getModKeyMask()); break; |
|---|
| 384 | case(GUIEventAdapter::KEY_Control_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_CTRL & _accumulateEventState->getModKeyMask()); break; |
|---|
| 385 | case(GUIEventAdapter::KEY_Meta_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_META & _accumulateEventState->getModKeyMask()); break; |
|---|
| 386 | case(GUIEventAdapter::KEY_Meta_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_META & _accumulateEventState->getModKeyMask()); break; |
|---|
| 387 | case(GUIEventAdapter::KEY_Alt_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_ALT & _accumulateEventState->getModKeyMask()); break; |
|---|
| 388 | case(GUIEventAdapter::KEY_Alt_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_ALT & _accumulateEventState->getModKeyMask()); break; |
|---|
| 389 | case(GUIEventAdapter::KEY_Super_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_SUPER & _accumulateEventState->getModKeyMask()); break; |
|---|
| 390 | case(GUIEventAdapter::KEY_Super_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_SUPER & _accumulateEventState->getModKeyMask()); break; |
|---|
| 391 | case(GUIEventAdapter::KEY_Hyper_L): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_LEFT_HYPER & _accumulateEventState->getModKeyMask()); break; |
|---|
| 392 | case(GUIEventAdapter::KEY_Hyper_R): _accumulateEventState->setModKeyMask(~GUIEventAdapter::MODKEY_RIGHT_HYPER & _accumulateEventState->getModKeyMask()); break; |
|---|
| 393 | default: break; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 397 | event->setEventType(GUIEventAdapter::KEYUP); |
|---|
| 398 | event->setKey(key); |
|---|
| 399 | event->setUnmodifiedKey(unmodifiedKey); |
|---|
| 400 | event->setTime(time); |
|---|
| 401 | |
|---|
| 402 | addEvent(event); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | GUIEventAdapter* EventQueue::touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time) |
|---|
| 407 | { |
|---|
| 408 | if(_firstTouchEmulatesMouse) |
|---|
| 409 | { |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | _accumulateEventState->setButtonMask((1) | _accumulateEventState->getButtonMask()); |
|---|
| 413 | _accumulateEventState->setX(x); |
|---|
| 414 | _accumulateEventState->setY(y); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 418 | event->setEventType(GUIEventAdapter::PUSH); |
|---|
| 419 | event->setTime(time); |
|---|
| 420 | event->addTouchPoint(id, phase, x, y, 0); |
|---|
| 421 | |
|---|
| 422 | addEvent(event); |
|---|
| 423 | |
|---|
| 424 | return event; |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | GUIEventAdapter* EventQueue::touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time) |
|---|
| 429 | { |
|---|
| 430 | if(_firstTouchEmulatesMouse) |
|---|
| 431 | { |
|---|
| 432 | _accumulateEventState->setX(x); |
|---|
| 433 | _accumulateEventState->setY(y); |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 437 | event->setEventType(GUIEventAdapter::DRAG); |
|---|
| 438 | event->setTime(time); |
|---|
| 439 | event->addTouchPoint(id, phase, x, y, 0); |
|---|
| 440 | addEvent(event); |
|---|
| 441 | |
|---|
| 442 | return event; |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | GUIEventAdapter* EventQueue::touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count, double time) |
|---|
| 446 | { |
|---|
| 447 | if (_firstTouchEmulatesMouse) |
|---|
| 448 | { |
|---|
| 449 | _accumulateEventState->setButtonMask(~(1) & _accumulateEventState->getButtonMask()); |
|---|
| 450 | _accumulateEventState->setX(x); |
|---|
| 451 | _accumulateEventState->setY(y); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 455 | event->setEventType(GUIEventAdapter::RELEASE); |
|---|
| 456 | event->setTime(time); |
|---|
| 457 | event->addTouchPoint(id, phase, x, y, tap_count); |
|---|
| 458 | addEvent(event); |
|---|
| 459 | |
|---|
| 460 | return event; |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | void EventQueue::closeWindow(double time) |
|---|
| 465 | { |
|---|
| 466 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 467 | event->setEventType(GUIEventAdapter::CLOSE_WINDOW); |
|---|
| 468 | event->setTime(time); |
|---|
| 469 | |
|---|
| 470 | addEvent(event); |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | void EventQueue::quitApplication(double time) |
|---|
| 474 | { |
|---|
| 475 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 476 | event->setEventType(GUIEventAdapter::QUIT_APPLICATION); |
|---|
| 477 | event->setTime(time); |
|---|
| 478 | |
|---|
| 479 | addEvent(event); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | void EventQueue::frame(double time) |
|---|
| 484 | { |
|---|
| 485 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 486 | event->setEventType(GUIEventAdapter::FRAME); |
|---|
| 487 | event->setTime(time); |
|---|
| 488 | |
|---|
| 489 | addEvent(event); |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | GUIEventAdapter* EventQueue::createEvent() |
|---|
| 493 | { |
|---|
| 494 | if (_accumulateEventState.valid()) return new GUIEventAdapter(*_accumulateEventState.get()); |
|---|
| 495 | else return new GUIEventAdapter(); |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | void EventQueue::userEvent(osg::Referenced* userEventData, double time) |
|---|
| 499 | { |
|---|
| 500 | GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); |
|---|
| 501 | event->setEventType(GUIEventAdapter::USER); |
|---|
| 502 | event->setUserData(userEventData); |
|---|
| 503 | event->setTime(time); |
|---|
| 504 | |
|---|
| 505 | addEvent(event); |
|---|
| 506 | } |
|---|
| 507 | |
|---|