GL Studio C++ Runtime API
events.h
Go to the documentation of this file.
1 /*! \file
2  \brief The standard Mouse and keyboard events and event structures
3 
4  \par Copyright Information
5 
6  Copyright (c) 2015 by The DiSTI Corporation.<br />
7  11301 Corporate Blvd., Suite 100<br />
8  Orlando, FL 32817<br />
9  USA<br />
10  <br />
11  All rights reserved.<br />
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America. Use, distribution,
38 duplication, or disclosure by the U. S. Government is subject to
39 "Restricted Rights" as set forth in DFARS 252.227-7014(c)(1)(ii).
40 */
41 #ifndef INCLUDED_DISTI_EVENTS_H
42 #define INCLUDED_DISTI_EVENTS_H
43 
44 #include "component_base.h"
45 #include "display.h"
46 #include "gls_include.h"
47 #include "group.h"
48 #include "timer.h"
49 #include <string>
50 
51 #ifdef __VXWORKS__
52 # include <cctype> //tolower
53 #endif
54 
55 namespace disti
56 {
57 /** Enumeration for event types */
58 typedef enum
59 {
60  EVENT_MOUSE, /**< A Mouse (or touch screen) event */
61  EVENT_KEYBOARD, /**< A Keyboard event */
62  EVENT_TIMER, /**< Unused */
63  EVENT_OBJECT, /**< An event emitted by an object */
64  EVENT_KEYBOARD_UP /**< A Keyboard up event (uses KeyboardEvent class) */
65 } EventType_e;
66 
67 /** Enumeration for mouse event types */
68 typedef enum
69 {
70  MOUSE_DOWN, /**< A Mouse button was pushed down */
71  MOUSE_UP, /**< A Mouse button was released */
72  MOUSE_MOVE, /**< The mouse moved */
73  MOUSE_DRAG, /**< The mouse moved while a button was held down */
74  MOUSE_LEAVE, /**< The mouse exited the object */
75  MOUSE_ENTER, /**< The mouse entered the object */
76  MOUSE_WHEEL_MINUS, /**< The mouse wheel was turned in the negative direction */
77  MOUSE_WHEEL_PLUS, /**< The mouse wheel was turned in the positive direction */
78  MOUSE_RECEIVE_MULTITOUCH, /**< Handle this event to receive input from multiple touches at the same time */
79  MOUSE_CANCEL, /**< Handle this event to interrupt the current mouse event */
81 
82 /** Enumeration for mouse buttons */
83 typedef enum
84 {
85  MOUSE_LBUTTON = 1, /**< Mask that matches only left mouse button */
86  MOUSE_MBUTTON = 2, /**< Mask that matches only middle mouse button */
87  MOUSE_RBUTTON = 4, /**< Mask that matches only right mouse button */
88  MOUSE_BUTTON_ANY = 7 /**< Mask that matches any mouse button */
90 
91 /** Enumeration for keyboard modifiers */
92 typedef enum
93 {
94  NONE_STATE = 0,
95  SHIFT_STATE = 0x00010000,
96  CAPS_LOCK_STATE = 0x00020000,
97  CTRL_STATE = 0x00040000,
98  ALT_STATE = 0x00080000,
99  NUM_LOCK_STATE = 0x00100000,
100  META_STATE = 0x00400000,
101  SCROLL_LOCK_STATE = 0x00800000,
102  BUTTON1_STATE = 0x01000000,
103  BUTTON2_STATE = 0x02000000,
104  BUTTON3_STATE = 0x04000000
106 
107 /** The base class for all user defined events.
108  * Each new class of event is assigned an event type.
109  * Each new event is assigned an event subtype
110  */
112 {
113 public:
114  unsigned short eventType; /**< Major event code. e.g., EVENT_MOUSE */
115  unsigned short eventSubtype; /**< Minor event code. e.g., MOUSE_DOWN */
116 
117  /** Default constructor */
119  : eventType( 0u )
120  , eventSubtype( 0u )
121  {
122  }
123 
124  /** Copy constructor */
125  DisplayEvent( const DisplayEvent& source )
126  : eventType( source.eventType )
127  , eventSubtype( source.eventSubtype )
128  {
129  }
130 
131  /** Virtual deconstructor to enable RTTI */
132  virtual ~DisplayEvent()
133  {
134  }
135 };
136 
137 /** An event with location fields */
139 {
140 public:
141  /** Location of the event in window coordinates
142  * x and y window coordinates in pixels.
143  * z is from 0.0 -> 1.0 and represents the depth.
144  * z == 0 is at the near cliping plane.
145  * z == 0.5 represents half way between near
146  * and far cliping planes.
147  */
149 
150  /** x,y,z of event in logical design coordinates */
152 
153  /** x,y,z of event in object DCS coordinates */
155 
156  // These references are included for backwards compatibility with GL Studio 2.1.
157  // They are simply references into the above vectors. New code should not use these!
158  float& x; /**< Reference to winLoc.x */
159  float& y; /**< Reference to winLoc.y */
160  float& z; /**< Reference to winLoc.z */
161 
162  float& lx; /**< Reference to lCoords.x */
163  float& ly; /**< Reference to lCoords.y */
164  float& lz; /**< Reference to lCoords.z */
165 
166  float& ox; /**< Reference to oCoords.x */
167  float& oy; /**< Reference to oCoords.y */
168  float& oz; /**< Reference to oCoords.z */
169 
170  /** Because of the use of the references, all automatically generated methods
171  * must be defined to allow for copying. */
172 
173  /** Default constructor */
175  : DisplayEvent()
176  , x( winLoc.x )
177  , y( winLoc.y )
178  , z( winLoc.z )
179  , lx( lCoords.x )
180  , ly( lCoords.y )
181  , lz( lCoords.z )
182  , ox( oCoords.x )
183  , oy( oCoords.y )
184  , oz( oCoords.z )
185  {
186  }
187 
188  /** Copy Constructor */
189  LocationEvent( const LocationEvent& source )
190  : DisplayEvent( source )
191  , winLoc( source.winLoc )
192  , lCoords( source.lCoords )
193  , oCoords( source.oCoords )
194  , x( winLoc.x )
195  , y( winLoc.y )
196  , z( winLoc.z )
197  , lx( lCoords.x )
198  , ly( lCoords.y )
199  , lz( lCoords.z )
200  , ox( oCoords.x )
201  , oy( oCoords.y )
202  , oz( oCoords.z )
203  {
204  }
205 
206  /** Assignment operator */
208  {
209  eventType = source.eventType;
210  eventSubtype = source.eventSubtype;
211  winLoc = source.winLoc;
212  lCoords = source.lCoords;
213  oCoords = source.oCoords;
214  return *this;
215  }
216 };
217 
218 /** A mouse event */
219 class MouseEvent : public LocationEvent
220 {
221 public:
222  /** Default Constructor */
224  : LocationEvent()
225  , buttonMask( 0u )
226  , clicks( 0u )
227  , modifiers( 0 )
228  , cursorID( 0u )
229  {
231  }
232 
233  /** Copy Constructor */
234  MouseEvent( const MouseEvent& source )
235  : LocationEvent( source )
236  , buttonMask( source.buttonMask )
237  , clicks( source.clicks )
238  , modifiers( source.modifiers )
239  , cursorID( source.cursorID )
240  {
241  }
242 
243  /** Copy Constructor from LocationEvent */
244  MouseEvent( const LocationEvent& source )
245  : LocationEvent( source )
246  , buttonMask( 0u )
247  , clicks( 0u )
248  , modifiers( 0 )
249  , cursorID( 0u )
250  {
252  }
253 
254  /** Assignment operator */
255  MouseEvent operator=( const MouseEvent& source )
256  {
257  LocationEvent::operator=( source );
258  buttonMask = source.buttonMask;
259  clicks = source.clicks;
260  modifiers = source.modifiers;
261  cursorID = source.cursorID;
262  return *this;
263  }
264 
265  unsigned char buttonMask; /**< bitfield: which button was pressed for this event */
266  unsigned char clicks; /**< Number of times a button was pressed */
267  int modifiers; /**< bitfield: which buttons or modifiers were depressed before event \sa SpecialKeyState_e */
268  unsigned int cursorID; /**< cursor id for multi-touch support */
269 };
270 
271 /** A keyboard event */
273 {
274 public:
275  /** Default Constructor */
277  : LocationEvent()
278  , keysym( 0 )
279  , event_text( 0 )
280  , modifiers( 0 )
281  {
282  }
283 
284  /** Copy Constructor */
285  KeyboardEvent( const KeyboardEvent& source )
286  : LocationEvent( source )
287  , keysym( source.keysym )
288  , event_text( source.event_text )
289  , modifiers( source.modifiers )
290  {
291  }
292 
293  /** Copy Constructor from LocationEvent*/
294  KeyboardEvent( const LocationEvent& source )
295  : LocationEvent( source )
296  , keysym( 0 )
297  , event_text( 0 )
298  , modifiers( 0 )
299  {
300  }
301 
302  /** Assignment operator */
304  {
305  LocationEvent::operator=( source );
306  keysym = source.keysym;
307  event_text = source.event_text;
308  modifiers = source.modifiers;
309  return *this;
310  }
311 
312  int keysym; /**< FLTK code for key that was pressed */
313  int event_text; /**< FLTK event text code for key that was pressed */
314  int modifiers; /**< bitfield: which modifiers or buttons were pressed \sa SpecialKeyState_e */
315 };
316 
317 /** The ObjectEvent class
318  * This event is intended to be emitted by objects, rather than by a mouse or keyboard.
319  */
320 class ObjectEvent : public DisplayEvent
321 {
322  DisplayObject* _initiator; /**< The display object that initiated the event */
323  char* _eventName; /**< String event name */
324  char* _eventData; /**< Any additional data for this event. A NULL terminated string */
325 
326 public:
327  ObjectEvent()
328  : DisplayEvent()
329  , _initiator( NULL )
330  , _eventName( NULL )
331  , _eventData( NULL )
332  {
334  }
335 
336  /** Create an ObjectEvent, setting the initator and event name
337  * \param initiator Pointer to the object that initated the event
338  * \param eventName Name of the event
339  * \param eventData Data of the event
340  */
341  ObjectEvent( DisplayObject* initiator, const char* eventName, const char* eventData = NULL )
342  : DisplayEvent()
343  , _initiator( initiator )
344  , _eventName( NULL )
345  , _eventData( NULL )
346  {
347  int size = (int)strlen( eventName ) + 1;
348  _eventName = new char[ size ];
349 #if defined( _WIN32 )
350  strcpy_s( _eventName, size, eventName );
351 #else
352  strcpy( _eventName, eventName );
353 #endif
354  if( eventData )
355  {
356  size = (int)strlen( eventData ) + 1;
357  _eventData = new char[ size ];
358 #if defined( _WIN32 )
359  strcpy_s( _eventData, size, eventData );
360 #else
361  strcpy( _eventData, eventData );
362 #endif
363  }
364 
366  }
367 
368  /** Create an ObjectEvent, setting the initator and event subtype
369  * \param initiator Pointer to the object that initated the event
370  * \param eventSubtypeArg The arbitrary event subtype
371  */
372  ObjectEvent( DisplayObject* initiator, unsigned short eventSubtypeArg )
373  : DisplayEvent()
374  , _initiator( initiator )
375  , _eventName( NULL )
376  , _eventData( NULL )
377  {
379  eventSubtype = eventSubtypeArg;
380  }
381 
382  virtual ~ObjectEvent()
383  {
384  delete[] _eventName;
385  _eventName = NULL;
386 
387  delete[] _eventData;
388  _eventData = NULL;
389  }
390 
391  /** \return Pointer to the object that initiated the event (may be NULL)
392  */
393  DisplayObject* Initiator() const { return _initiator; }
394 
395  /** Set which object initiated the event
396  * \param initiator Pointer to the object that initiated the event
397  */
398  void Initiator( DisplayObject* initiator ) { _initiator = initiator; }
399 
400  /** \return The name of the event
401  */
402  const char* EventName() const
403  {
404  if( _eventName )
405  {
406  return _eventName;
407  }
408  else
409  {
410  return "";
411  }
412  }
413 
414  /** Set the name of the event
415  * For CRT safety, this should only be called by the constructing code
416  * \param newName The name to set
417  */
418  void EventName( const char* newName )
419  {
420  delete[] _eventName;
421  _eventName = NULL;
422 
423  if( newName )
424  {
425  int size = (int)strlen( newName ) + 1;
426  _eventName = new char[ size ];
427 #if defined( _WIN32 )
428  strcpy_s( _eventName, size, newName );
429 #else
430  strcpy( _eventName, newName );
431 #endif
432  }
433  }
434 
435  /** \return The data of the event, NULL terminated
436  */
437  const char* EventData() const
438  {
439  if( _eventData )
440  {
441  return _eventData;
442  }
443  else
444  {
445  return "";
446  }
447  }
448 
449  /** Set the data of the event, NULL terminated.
450  * For CRT safety, this should only be called by the constructing code
451  * \param newData The name to set
452  */
453  void EventData( const char* newData )
454  {
455  delete[] _eventData;
456  _eventData = NULL;
457 
458  if( newData )
459  {
460  int size = (int)strlen( newData ) + 1;
461  _eventData = new char[ size ];
462 #if defined( _WIN32 )
463  strcpy_s( _eventData, size, newData );
464 #else
465  strcpy( _eventData, newData );
466 #endif
467  }
468  }
469 
470  /** return true if the name of this event matches the given name.
471  * \param eventName The name to compare
472  */
473  bool EventNameIs( const char* eventName ) const
474  {
475  if( !_eventName || !eventName )
476  {
477  return false;
478  }
479 
480  return ( 0 == strcmp( _eventName, eventName ) );
481  }
482 
483  /** return true if the name of this event matches the given name.
484  * \param eventData The name to compare
485  */
486  bool EventDataIs( const char* eventData ) const
487  {
488  if( !_eventData || !eventData )
489  {
490  return false;
491  }
492 
493  return ( 0 == strcmp( _eventData, eventData ) );
494  }
495 };
496 
497 /** Emits the specfied ObjectEvent */
498 inline void EmitObjectEvent( DisplayObject* self, ObjectEvent* event )
499 {
500  if( self->ParentGroup() )
501  {
502  self->ParentGroup()->handle( event );
503  }
504  else if( dynamic_cast<ComponentBase*>( self ) )
505  {
506  // Called when our ParentGroup is NULL and we are wrapped by an RSO Interface.
507  self->handle( event );
508  }
509 }
510 
511 /** Creates an ObjectEvent from the given NULL terminated strings and emits it */
512 inline void EmitObjectEvent( DisplayObject* self, const char* eventName, const char* eventData = NULL )
513 {
514  ObjectEvent temp( self, eventName, eventData );
515  EmitObjectEvent( self, &temp );
516 }
517 
518 /** \return true if the given DisplayEvent is an ObjectEvent and it's event name matches the given string.
519  * \param event The event to check
520  * \param eventName The eventName to compare
521  * \param eventData optional eventData to compare, if NULL, it will not be checked, otherwise, it will.
522  */
523 inline bool ObjectEventIs( DisplayEvent* event, const char* eventName, const char* eventData = NULL )
524 {
525  ObjectEvent* objEvent = dynamic_cast<ObjectEvent*>( event );
526  bool is = ( objEvent && objEvent->EventNameIs( eventName ) );
527  if( is && eventData )
528  {
529  is = objEvent->EventDataIs( eventData );
530  }
531  return is;
532 }
533 
534 /** Basic on event test, given the event and subevent enums. */
535 #define ON( event, subevent ) if( ( ev->eventType == ( event ) ) && ( ev->eventSubtype == ( subevent ) ) )
536 
537 /** On mouse button up event test, given the mouse button enum. */
538 #define ON_MOUSE_UP( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_UP ) && ( (btnMask)&mev->buttonMask ) )
539 
540 /** On mouse button down event test, given the mouse button enum. */
541 #define ON_MOUSE_DOWN( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_DOWN ) && ( (btnMask)&mev->buttonMask ) )
542 
543 /** On mouse button held during a drag event test, given the mouse button enum. */
544 #define ON_MOUSE_DRAG( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_DRAG ) && ( (btnMask)&mev->buttonMask ) )
545 
546 /** On keyboard key down event test, given the alpha numeric key to test. */
547 #define ON_KEY_DOWN( testKey ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, true, int( testKey ) ) )
548 
549 /** On keyboard key up event test, given the alpha numeric key to test. */
550 #define ON_KEY_UP( testKey ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, true, int( testKey ) ) )
551 
552 /** On keyboard key down with modifiers event test, given the alpha numeric key and modifiers to test. */
553 #define ON_KEY_DOWN_WITH_MODIFIER( testKey, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, true, int( testKey ), modifierMask ) )
554 
555 /** On keyboard key up with modifiers event test, given the alpha numeric key and modifiers to test. */
556 #define ON_KEY_UP_WITH_MODIFIER( testKey, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, true, int( testKey ), modifierMask ) )
557 
558 /** On keyboard key down event test, given the special key to test. */
559 #define ON_SPECIAL_KEY_DOWN( keySym ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, false, int( keySym ) ) )
560 
561 /** On keyboard key up event test, given the special key to test. */
562 #define ON_SPECIAL_KEY_UP( keySym ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, false, int( keySym ) ) )
563 
564 /** On keyboard key down with modifiers event test, given the special key and modifiers to test. */
565 #define ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( keySym, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, false, int( keySym ), modifierMask ) )
566 
567 /** On keyboard key up with modifiers event test, given the special key and modifiers to test. */
568 #define ON_SPECIAL_KEY_UP_WITH_MODIFIER( keySym, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, false, int( keySym ), modifierMask ) )
569 
570 /** On keyboard key down event test. */
571 #define ON_ANY_KEY_DOWN() if( ( ev->eventType == EVENT_KEYBOARD ) )
572 
573 /** On keyboard key up event test. */
574 #define ON_ANY_KEY_UP() if( ( ev->eventType == EVENT_KEYBOARD_UP ) )
575 
576 /** Examples:
577  * ON( EVENT_MOUSE, MOUSE_DOWN )
578  * {
579  * }
580  * ON_MOUSE_DOWN( MOUSE_LBUTTON )
581  * {
582  * }
583  * ON_KEY_DOWN( 'a' )
584  * {
585  * }
586  * ON_KEY_DOWN_WITH_MODIFIER( 'B', FL_SHIFT )
587  * {
588  * }
589  * ON_KEY_DOWN_WITH_MODIFIER( 'c', FL_SHIFT | FL_CTRL )
590  * {
591  * }
592  * ON_SPECIAL_KEY_DOWN( FL_KP+'1' )
593  * {
594  * }
595  * ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( FL_F+1, FL_CTRL )
596  * {
597  * }
598  * For a comprehensive list of keys and modifiers refer to Enumerations.H.
599  */
600 
601 inline bool OnKeyEvent( KeyboardEvent* kev, bool alphaNumeric, int key, int modifierMask = 0 )
602 {
603  bool keySuccess = false;
604 
605  if( alphaNumeric )
606  {
607  /** If CTRL is expected we need to look at keysym instead.
608  * Because CTRL changes the output of the key press to something unexpected
609  * we need to check against the key press action instead.
610  */
611  if( CTRL_STATE & modifierMask )
612  {
613  /** keysym is always lowercase */
614  key = std::tolower( key );
615  keySuccess = ( key == kev->keysym );
616  }
617  else
618  {
619  keySuccess = ( key == kev->event_text );
620  }
621  }
622  else
623  {
624  keySuccess = ( key == kev->keysym );
625  }
626 
627  /** Compare to zero to avoid performance warnings.
628  * Did we find the modifiers we're looking for (modifierMask) in the modifiers currently pressed (kev->modifiers)?
629  * OR Are we not looking for any modifiers AND none of the modifiers are currently pressed?
630  * (ignoring the lock state and mouse button modifiers)
631  */
632  bool modSuccess = ( 0 != ( modifierMask & kev->modifiers ) || ( 0 == modifierMask && 0 == ( int( SHIFT_STATE | CTRL_STATE | ALT_STATE | META_STATE ) & kev->modifiers ) ) );
633 
634  return ( keySuccess && modSuccess );
635 }
636 
637 template<class T>
638 /** Event Compressor */
639 class EventCompressor
640 {
641 public:
642  typedef DisplayObject* ( T::*EventSenderCbType )( DisplayEvent* ev );
643 
644 protected:
645  MouseEvent _lastCompressedEvent;
646  bool _lastEventWasCompressed;
647  EventSenderCbType _handleCb;
648  T* _objectPtr;
649  bool _sendingCompressed;
650  bool _active;
651 
652 public:
653  void Active( bool val ) { _active = val; }
654  bool Active() { return _active; }
655 
656  EventCompressor( T* objectPtr, EventSenderCbType cb )
657  : _lastEventWasCompressed( false )
658  , _handleCb( cb )
659  , _objectPtr( objectPtr )
660  , _sendingCompressed( false )
661  , _active( true )
662  {
663  }
664 
665  /** Returns true if event was compressed.
666  * Caller should stop processing this event if returns true
667  * Caller *MUST* call SendAnyCompressedEvents() before
668  * drawing to make sure any saved events are processed.
669  */
670  bool CompressEvent( const DisplayEvent& ev )
671  {
672  if( !_active || _sendingCompressed )
673  {
674  return false;
675  }
676 
677  bool compressed = false;
678  if( EVENT_MOUSE == ev.eventType && ( MOUSE_MOVE == ev.eventSubtype || MOUSE_DRAG == ev.eventSubtype ) )
679  {
680  MouseEvent* mev = (MouseEvent*)&ev;
681 
682  if( !_lastEventWasCompressed || ( _lastEventWasCompressed && _lastCompressedEvent.eventType == ev.eventType && _lastCompressedEvent.eventSubtype == ev.eventSubtype && _lastCompressedEvent.cursorID == mev->cursorID ) )
683  {
684  // Replace with this event, and don't send
685  _lastCompressedEvent = *mev;
686  _lastEventWasCompressed = true;
687  compressed = true;
688  }
689  }
690 
691  // If we did not compress the event, send any pending ones.
692  if( !compressed )
693  {
694  SendAnyCompressedEvents();
695  }
696  return compressed;
697  }
698 
699  void SendAnyCompressedEvents()
700  {
701  // Avoids infinite loop
702  if( _sendingCompressed )
703  {
704  return;
705  }
706 
707  if( _lastEventWasCompressed )
708  {
709  _sendingCompressed = true;
710  // Call the callback
711  ( _objectPtr->*( _handleCb ) )( &_lastCompressedEvent );
712  // The event is no longer valid
713  _sendingCompressed = false;
714 
715  _lastEventWasCompressed = false;
716  }
717  }
718 };
719 
720 } // namespace disti
721 
722 #endif // INCLUDED_DISTI_EVENTS_H
int keysym
Definition: events.h:312
unsigned short eventSubtype
Definition: events.h:115
Definition: events.h:86
Definition: events.h:320
unsigned short eventType
Definition: events.h:114
MouseButtonType_e
Definition: events.h:83
void EmitObjectEvent(DisplayObject *self, ObjectEvent *event)
Definition: events.h:498
float & x
Definition: events.h:158
float & z
Definition: events.h:160
The disti::ComponentBase class.
DisplayEvent(const DisplayEvent &source)
Definition: events.h:125
bool ObjectEventIs(DisplayEvent *event, const char *eventName, const char *eventData=NULL)
Definition: events.h:523
The disti::Group class. Implements groups of objects.
float & lx
Definition: events.h:162
Definition: events.h:272
Definition: events.h:73
float & ox
Definition: events.h:166
KeyboardEvent(const KeyboardEvent &source)
Definition: events.h:285
KeyboardEvent()
Definition: events.h:276
ObjectEvent(DisplayObject *initiator, unsigned short eventSubtypeArg)
Definition: events.h:372
Definition: events.h:70
LocationEvent()
Definition: events.h:174
bool OnKeyEvent(KeyboardEvent *kev, bool alphaNumeric, int key, int modifierMask=0)
Definition: events.h:601
Definition: display.h:98
MouseEvent(const MouseEvent &source)
Definition: events.h:234
SpecialKeyState_e
Definition: events.h:92
The disti::Timer class. An OS portable timing class.
int modifiers
Definition: events.h:314
Vector winLoc
Definition: events.h:148
Definition: events.h:138
A file for all GL Studio files to include.
MouseEventType_e
Definition: events.h:68
const char * EventName() const
Definition: events.h:402
Definition: events.h:85
Definition: events.h:77
The disti::DisplayObject class and global enumerations.
DisplayObject * Initiator() const
Definition: events.h:393
int modifiers
Definition: events.h:267
Definition: events.h:78
Definition: events.h:64
float & ly
Definition: events.h:163
Vector oCoords
Definition: events.h:154
KeyboardEvent operator=(const KeyboardEvent &source)
Definition: events.h:303
float & oy
Definition: events.h:167
unsigned int cursorID
Definition: events.h:268
Definition: events.h:60
Definition: events.h:71
EventType_e
Definition: events.h:58
Definition: events.h:61
void Initiator(DisplayObject *initiator)
Definition: events.h:398
Vector lCoords
Definition: events.h:151
Definition: events.h:111
Definition: events.h:62
unsigned char buttonMask
Definition: events.h:265
MouseEvent operator=(const MouseEvent &source)
Definition: events.h:255
bool EventDataIs(const char *eventData) const
Definition: events.h:486
float & y
Definition: events.h:159
float & oz
Definition: events.h:168
MouseEvent(const LocationEvent &source)
Definition: events.h:244
LocationEvent operator=(const LocationEvent &source)
Definition: events.h:207
Definition: events.h:88
DisplayEvent()
Definition: events.h:118
void EventData(const char *newData)
Definition: events.h:453
Definition: vertex.h:84
ObjectEvent(DisplayObject *initiator, const char *eventName, const char *eventData=NULL)
Definition: events.h:341
MouseEvent()
Definition: events.h:223
Definition: events.h:72
virtual ~DisplayEvent()
Definition: events.h:132
const char * EventData() const
Definition: events.h:437
Definition: events.h:79
KeyboardEvent(const LocationEvent &source)
Definition: events.h:294
Definition: events.h:75
unsigned char clicks
Definition: events.h:266
bool CompressEvent(const DisplayEvent &ev)
Definition: events.h:670
bool EventNameIs(const char *eventName) const
Definition: events.h:473
Definition: events.h:63
Definition: bmpimage.h:46
Definition: events.h:219
LocationEvent(const LocationEvent &source)
Definition: events.h:189
float & lz
Definition: events.h:164
void EventName(const char *newName)
Definition: events.h:418
int event_text
Definition: events.h:313
Definition: events.h:87
Definition: events.h:74
Definition: events.h:76