GL Studio 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 
58 /** Enumeration for event types */
59 typedef enum
60 {
61  EVENT_MOUSE, /**< A Mouse (or touch screen) event */
62  EVENT_KEYBOARD, /**< A Keyboard event */
63  EVENT_TIMER, /**< Unused */
64  EVENT_OBJECT, /**< An event emitted by an object */
65  EVENT_KEYBOARD_UP /**< A Keyboard up event (uses KeyboardEvent class) */
66 } EventType_e;
67 
68 /** Enumeration for mouse event types */
69 typedef enum
70 {
71  MOUSE_DOWN, /**< A Mouse button was pushed down */
72  MOUSE_UP, /**< A Mouse button was released */
73  MOUSE_MOVE, /**< The mouse moved */
74  MOUSE_DRAG, /**< The mouse moved while a button was held down */
75  MOUSE_LEAVE, /**< The mouse exited the object */
76  MOUSE_ENTER, /**< The mouse entered the object */
77  MOUSE_WHEEL_MINUS, /**< The mouse wheel was turned in the negative direction */
78  MOUSE_WHEEL_PLUS, /**< The mouse wheel was turned in the positive direction */
79  MOUSE_RECEIVE_MULTITOUCH /**< Handle this event to receive input from multiple touches at the same time */
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; /**< # 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) && \
539 (ev->eventSubtype==MOUSE_UP) && ((btnMask) & mev->buttonMask))
540 
541 /** On mouse button down event test, given the mouse button enum. */
542 #define ON_MOUSE_DOWN(btnMask) if ((ev->eventType==EVENT_MOUSE) && \
543 (ev->eventSubtype==MOUSE_DOWN) && ((btnMask) & mev->buttonMask))
544 
545 /** On mouse button held during a drag event test, given the mouse button enum. */
546 #define ON_MOUSE_DRAG(btnMask) if ((ev->eventType==EVENT_MOUSE) && \
547 (ev->eventSubtype==MOUSE_DRAG) && ((btnMask) & mev->buttonMask))
548 
549 /** On keyboard key down event test, given the alpha numeric key to test. */
550 #define ON_KEY_DOWN(testKey) if ((ev->eventType==EVENT_KEYBOARD) && \
551 OnKeyEvent( kev, true, int(testKey) ))
552 
553 /** On keyboard key up event test, given the alpha numeric key to test. */
554 #define ON_KEY_UP(testKey) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
555 OnKeyEvent( kev, true, int(testKey) ))
556 
557 /** On keyboard key down with modifiers event test, given the alpha numeric key and modifiers to test. */
558 #define ON_KEY_DOWN_WITH_MODIFIER(testKey, modifierMask) if ((ev->eventType==EVENT_KEYBOARD) && \
559 OnKeyEvent( kev, true, int(testKey), modifierMask ))
560 
561 /** On keyboard key up with modifiers event test, given the alpha numeric key and modifiers to test. */
562 #define ON_KEY_UP_WITH_MODIFIER(testKey, modifierMask) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
563 OnKeyEvent( kev, true, int(testKey), modifierMask ))
564 
565 /** On keyboard key down event test, given the special key to test. */
566 #define ON_SPECIAL_KEY_DOWN(keySym) if ((ev->eventType==EVENT_KEYBOARD) && \
567 OnKeyEvent( kev, false, int(keySym) ))
568 
569 /** On keyboard key up event test, given the special key to test. */
570 #define ON_SPECIAL_KEY_UP(keySym) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
571 OnKeyEvent( kev, false, int(keySym) ))
572 
573 /** On keyboard key down with modifiers event test, given the special key and modifiers to test. */
574 #define ON_SPECIAL_KEY_DOWN_WITH_MODIFIER(keySym, modifierMask) if ((ev->eventType==EVENT_KEYBOARD) && \
575 OnKeyEvent( kev, false, int(keySym), modifierMask ))
576 
577 /** On keyboard key up with modifiers event test, given the special key and modifiers to test. */
578 #define ON_SPECIAL_KEY_UP_WITH_MODIFIER(keySym, modifierMask) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
579 OnKeyEvent( kev, false, int(keySym), modifierMask ))
580 
581 /** On keyboard key down event test. */
582 #define ON_ANY_KEY_DOWN() if ((ev->eventType==EVENT_KEYBOARD))
583 
584 /** On keyboard key up event test. */
585 #define ON_ANY_KEY_UP() if ((ev->eventType==EVENT_KEYBOARD_UP))
586 
587 /** Examples:
588  * ON( EVENT_MOUSE, MOUSE_DOWN )
589  * {
590  * }
591  * ON_MOUSE_DOWN( MOUSE_LBUTTON )
592  * {
593  * }
594  * ON_KEY_DOWN( 'a' )
595  * {
596  * }
597  * ON_KEY_DOWN_WITH_MODIFIER( 'B', FL_SHIFT )
598  * {
599  * }
600  * ON_KEY_DOWN_WITH_MODIFIER( 'c', FL_SHIFT | FL_CTRL )
601  * {
602  * }
603  * ON_SPECIAL_KEY_DOWN( FL_KP+'1' )
604  * {
605  * }
606  * ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( FL_F+1, FL_CTRL )
607  * {
608  * }
609  * For a comprehensive list of keys and modifiers refer to Enumerations.H.
610  */
611 
612 inline bool OnKeyEvent( KeyboardEvent* kev, bool alphaNumeric, int key, int modifierMask = 0 )
613 {
614  bool keySuccess = false;
615 
616  if( alphaNumeric )
617  {
618  /** If CTRL is expected we need to look at keysym instead.
619  * Because CTRL changes the output of the key press to something unexpected
620  * we need to check against the key press action instead.
621  */
622  if(CTRL_STATE & modifierMask)
623  {
624  /** keysym is always lowercase */
625  key = std::tolower( key );
626  keySuccess = ( key == kev->keysym );
627  }
628  else
629  {
630  keySuccess = ( key == kev->event_text );
631  }
632  }
633  else
634  {
635  keySuccess = ( key == kev->keysym );
636  }
637 
638  /** Compare to zero to avoid performance warnings.
639  * Did we find the modifiers we're looking for (modifierMask) in the modifiers currently pressed (kev->modifiers)?
640  * OR Are we not looking for any modifiers AND none of the modifiers are currently pressed?
641  * (ignoring the lock state and mouse button modifiers)
642  */
643  bool modSuccess = ( 0 != ( modifierMask & kev->modifiers ) || ( 0 == modifierMask && 0 == ( int( SHIFT_STATE | CTRL_STATE | ALT_STATE | META_STATE ) & kev->modifiers ) ) );
644 
645  return ( keySuccess && modSuccess );
646 }
647 
648 template <class T>
649 /** Event Compressor */
650 class EventCompressor
651 {
652 public:
653  typedef DisplayObject* (T::*EventSenderCbType)(DisplayEvent* ev);
654 
655 protected:
656  MouseEvent _lastCompressedEvent;
657  bool _lastEventWasCompressed;
658  EventSenderCbType _handleCb;
659  T* _objectPtr;
660  bool _sendingCompressed;
661  bool _active;
662 
663 public:
664  void Active( bool val ) { _active = val; }
665  bool Active() { return _active; }
666 
667  EventCompressor( T* objectPtr, EventSenderCbType cb ) :
668  _lastEventWasCompressed( false ),
669  _handleCb( cb ),
670  _objectPtr( objectPtr ),
671  _sendingCompressed( false ),
672  _active( true )
673  {
674  }
675 
676  /** Returns true if event was compressed.
677  * Caller should stop processing this event if returns true
678  * Caller *MUST* call SendAnyCompressedEvents() before
679  * drawing to make sure any saved events are processed.
680  */
681  bool CompressEvent( const DisplayEvent& ev )
682  {
683  if( !_active || _sendingCompressed )
684  {
685  return false;
686  }
687 
688  bool compressed = false;
689  if( EVENT_MOUSE == ev.eventType &&
690  ( MOUSE_MOVE == ev.eventSubtype ||
691  MOUSE_DRAG == ev.eventSubtype ) )
692  {
693  MouseEvent* mev = (MouseEvent*)&ev;
694 
695  if( !_lastEventWasCompressed ||
696  ( _lastEventWasCompressed &&
697  _lastCompressedEvent.eventType == ev.eventType &&
698  _lastCompressedEvent.eventSubtype == ev.eventSubtype &&
699  _lastCompressedEvent.cursorID == mev->cursorID ) )
700  {
701  // Replace with this event, and don't send
702  _lastCompressedEvent = *mev;
703  _lastEventWasCompressed = true;
704  compressed = true;
705  }
706  }
707 
708  // If we did not compress the event, send any pending ones.
709  if( !compressed )
710  {
711  SendAnyCompressedEvents();
712  }
713  return compressed;
714  }
715 
716  void SendAnyCompressedEvents()
717  {
718  // Avoids infinite loop
719  if( _sendingCompressed )
720  {
721  return;
722  }
723 
724  if( _lastEventWasCompressed )
725  {
726  _sendingCompressed = true;
727  // Call the callback
728  (_objectPtr->*(_handleCb))(&_lastCompressedEvent);
729  // The event is no longer valid
730  _sendingCompressed = false;
731 
732  _lastEventWasCompressed = false;
733  }
734  }
735 };
736 
737 } // namespace disti
738 
739 #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:74
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:71
LocationEvent()
Definition: events.h:174
bool OnKeyEvent(KeyboardEvent *kev, bool alphaNumeric, int key, int modifierMask=0)
Definition: events.h:612
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:69
const char * EventName() const
Definition: events.h:402
Definition: events.h:85
Definition: events.h:78
The disti::DisplayObject class and global enumerations.
DisplayObject * Initiator() const
Definition: events.h:393
int modifiers
Definition: events.h:267
Definition: events.h:79
Definition: events.h:65
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:61
Definition: events.h:72
EventType_e
Definition: events.h:59
Definition: events.h:62
void Initiator(DisplayObject *initiator)
Definition: events.h:398
Vector lCoords
Definition: events.h:151
Definition: events.h:111
Definition: events.h:63
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:73
virtual ~DisplayEvent()
Definition: events.h:132
const char * EventData() const
Definition: events.h:437
KeyboardEvent(const LocationEvent &source)
Definition: events.h:294
Definition: events.h:76
unsigned char clicks
Definition: events.h:266
bool CompressEvent(const DisplayEvent &ev)
Definition: events.h:681
bool EventNameIs(const char *eventName) const
Definition: events.h:473
Definition: events.h:64
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:75
Definition: events.h:77