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 */
80 
81 /** Enumeration for mouse buttons */
82 typedef enum
83 {
84  MOUSE_LBUTTON = 1, /**< Mask that matches only left mouse button */
85  MOUSE_MBUTTON = 2, /**< Mask that matches only middle mouse button */
86  MOUSE_RBUTTON = 4, /**< Mask that matches only right mouse button */
87  MOUSE_BUTTON_ANY = 7 /**< Mask that matches any mouse button */
89 
90 /** Enumeration for keyboard modifiers */
91 typedef enum
92 {
93  NONE_STATE = 0,
94  SHIFT_STATE = 0x00010000,
95  CAPS_LOCK_STATE = 0x00020000,
96  CTRL_STATE = 0x00040000,
97  ALT_STATE = 0x00080000,
98  NUM_LOCK_STATE = 0x00100000,
99  META_STATE = 0x00400000,
100  SCROLL_LOCK_STATE = 0x00800000,
101  BUTTON1_STATE = 0x01000000,
102  BUTTON2_STATE = 0x02000000,
103  BUTTON3_STATE = 0x04000000
105 
106 /** The base class for all user defined events.
107  * Each new class of event is assigned an event type.
108  * Each new event is assigned an event subtype
109  */
111 {
112 public:
113  unsigned short eventType; /**< Major event code. e.g., EVENT_MOUSE */
114  unsigned short eventSubtype; /**< Minor event code. e.g., MOUSE_DOWN */
115 
116  /** Default constructor */
118  : eventType( 0u )
119  , eventSubtype( 0u )
120  {
121  }
122 
123  /** Copy constructor */
124  DisplayEvent( const DisplayEvent& source )
125  : eventType( source.eventType )
126  , eventSubtype( source.eventSubtype )
127  {
128  }
129 
130  /** Virtual deconstructor to enable RTTI */
131  virtual ~DisplayEvent()
132  {
133  }
134 };
135 
136 /** An event with location fields */
138 {
139 public:
140  /** Location of the event in window coordinates
141  * x and y window coordinates in pixels.
142  * z is from 0.0 -> 1.0 and represents the depth.
143  * z == 0 is at the near cliping plane.
144  * z == 0.5 represents half way between near
145  * and far cliping planes.
146  */
148 
149  /** x,y,z of event in logical design coordinates */
151 
152  /** x,y,z of event in object DCS coordinates */
154 
155  // These references are included for backwards compatibility with GL Studio 2.1.
156  // They are simply references into the above vectors. New code should not use these!
157  float& x; /**< Reference to winLoc.x */
158  float& y; /**< Reference to winLoc.y */
159  float& z; /**< Reference to winLoc.z */
160 
161  float& lx; /**< Reference to lCoords.x */
162  float& ly; /**< Reference to lCoords.y */
163  float& lz; /**< Reference to lCoords.z */
164 
165  float& ox; /**< Reference to oCoords.x */
166  float& oy; /**< Reference to oCoords.y */
167  float& oz; /**< Reference to oCoords.z */
168 
169  /** Because of the use of the references, all automatically generated methods
170  * must be defined to allow for copying. */
171 
172  /** Default constructor */
174  : DisplayEvent()
175  , x( winLoc.x )
176  , y( winLoc.y )
177  , z( winLoc.z )
178  , lx( lCoords.x )
179  , ly( lCoords.y )
180  , lz( lCoords.z )
181  , ox( oCoords.x )
182  , oy( oCoords.y )
183  , oz( oCoords.z )
184  {
185  }
186 
187  /** Copy Constructor */
188  LocationEvent( const LocationEvent& source )
189  : DisplayEvent( source )
190  , winLoc( source.winLoc )
191  , lCoords( source.lCoords )
192  , oCoords( source.oCoords )
193  , x( winLoc.x )
194  , y( winLoc.y )
195  , z( winLoc.z )
196  , lx( lCoords.x )
197  , ly( lCoords.y )
198  , lz( lCoords.z )
199  , ox( oCoords.x )
200  , oy( oCoords.y )
201  , oz( oCoords.z )
202  {
203  }
204 
205  /** Assignment operator */
207  {
208  eventType = source.eventType;
209  eventSubtype = source.eventSubtype;
210  winLoc = source.winLoc;
211  lCoords = source.lCoords;
212  oCoords = source.oCoords;
213  return *this;
214  }
215 };
216 
217 /** A mouse event */
218 class MouseEvent : public LocationEvent
219 {
220 public:
221  /** Default Constructor */
223  : LocationEvent()
224  , buttonMask( 0u )
225  , clicks( 0u )
226  , modifiers( 0 )
227  , cursorID( 0u )
228  {
230  }
231 
232  /** Copy Constructor */
233  MouseEvent( const MouseEvent& source )
234  : LocationEvent( source )
235  , buttonMask( source.buttonMask )
236  , clicks( source.clicks )
237  , modifiers( source.modifiers )
238  , cursorID( source.cursorID )
239  {
240  }
241 
242  /** Copy Constructor from LocationEvent */
243  MouseEvent( const LocationEvent& source )
244  : LocationEvent( source )
245  , buttonMask( 0u )
246  , clicks( 0u )
247  , modifiers( 0 )
248  , cursorID( 0u )
249  {
251  }
252 
253  /** Assignment operator */
254  MouseEvent operator=( const MouseEvent& source )
255  {
256  LocationEvent::operator=( source );
257  buttonMask = source.buttonMask;
258  clicks = source.clicks;
259  modifiers = source.modifiers;
260  cursorID = source.cursorID;
261  return *this;
262  }
263 
264  unsigned char buttonMask; /**< bitfield: which button was pressed for this event */
265  unsigned char clicks; /**< Number of times a button was pressed */
266  int modifiers; /**< bitfield: which buttons or modifiers were depressed before event \sa SpecialKeyState_e */
267  unsigned int cursorID; /**< cursor id for multi-touch support */
268 };
269 
270 /** A keyboard event */
272 {
273 public:
274  /** Default Constructor */
276  : LocationEvent()
277  , keysym( 0 )
278  , event_text( 0 )
279  , modifiers( 0 )
280  {
281  }
282 
283  /** Copy Constructor */
284  KeyboardEvent( const KeyboardEvent& source )
285  : LocationEvent( source )
286  , keysym( source.keysym )
287  , event_text( source.event_text )
288  , modifiers( source.modifiers )
289  {
290  }
291 
292  /** Copy Constructor from LocationEvent*/
293  KeyboardEvent( const LocationEvent& source )
294  : LocationEvent( source )
295  , keysym( 0 )
296  , event_text( 0 )
297  , modifiers( 0 )
298  {
299  }
300 
301  /** Assignment operator */
303  {
304  LocationEvent::operator=( source );
305  keysym = source.keysym;
306  event_text = source.event_text;
307  modifiers = source.modifiers;
308  return *this;
309  }
310 
311  int keysym; /**< FLTK code for key that was pressed */
312  int event_text; /**< FLTK event text code for key that was pressed */
313  int modifiers; /**< bitfield: which modifiers or buttons were pressed \sa SpecialKeyState_e */
314 };
315 
316 /** The ObjectEvent class
317  * This event is intended to be emitted by objects, rather than by a mouse or keyboard.
318  */
319 class ObjectEvent : public DisplayEvent
320 {
321  DisplayObject* _initiator; /**< The display object that initiated the event */
322  char* _eventName; /**< String event name */
323  char* _eventData; /**< Any additional data for this event. A NULL terminated string */
324 
325 public:
326  ObjectEvent()
327  : DisplayEvent()
328  , _initiator( NULL )
329  , _eventName( NULL )
330  , _eventData( NULL )
331  {
333  }
334 
335  /** Create an ObjectEvent, setting the initator and event name
336  * \param initiator Pointer to the object that initated the event
337  * \param eventName Name of the event
338  * \param eventData Data of the event
339  */
340  ObjectEvent( DisplayObject* initiator, const char* eventName, const char* eventData = NULL )
341  : DisplayEvent()
342  , _initiator( initiator )
343  , _eventName( NULL )
344  , _eventData( NULL )
345  {
346  int size = (int)strlen( eventName ) + 1;
347  _eventName = new char[ size ];
348 #if defined( _WIN32 )
349  strcpy_s( _eventName, size, eventName );
350 #else
351  strcpy( _eventName, eventName );
352 #endif
353  if( eventData )
354  {
355  size = (int)strlen( eventData ) + 1;
356  _eventData = new char[ size ];
357 #if defined( _WIN32 )
358  strcpy_s( _eventData, size, eventData );
359 #else
360  strcpy( _eventData, eventData );
361 #endif
362  }
363 
365  }
366 
367  /** Create an ObjectEvent, setting the initator and event subtype
368  * \param initiator Pointer to the object that initated the event
369  * \param eventSubtypeArg The arbitrary event subtype
370  */
371  ObjectEvent( DisplayObject* initiator, unsigned short eventSubtypeArg )
372  : DisplayEvent()
373  , _initiator( initiator )
374  , _eventName( NULL )
375  , _eventData( NULL )
376  {
378  eventSubtype = eventSubtypeArg;
379  }
380 
381  virtual ~ObjectEvent()
382  {
383  delete[] _eventName;
384  _eventName = NULL;
385 
386  delete[] _eventData;
387  _eventData = NULL;
388  }
389 
390  /** \return Pointer to the object that initiated the event (may be NULL)
391  */
392  DisplayObject* Initiator() const { return _initiator; }
393 
394  /** Set which object initiated the event
395  * \param initiator Pointer to the object that initiated the event
396  */
397  void Initiator( DisplayObject* initiator ) { _initiator = initiator; }
398 
399  /** \return The name of the event
400  */
401  const char* EventName() const
402  {
403  if( _eventName )
404  {
405  return _eventName;
406  }
407  else
408  {
409  return "";
410  }
411  }
412 
413  /** Set the name of the event
414  * For CRT safety, this should only be called by the constructing code
415  * \param newName The name to set
416  */
417  void EventName( const char* newName )
418  {
419  delete[] _eventName;
420  _eventName = NULL;
421 
422  if( newName )
423  {
424  int size = (int)strlen( newName ) + 1;
425  _eventName = new char[ size ];
426 #if defined( _WIN32 )
427  strcpy_s( _eventName, size, newName );
428 #else
429  strcpy( _eventName, newName );
430 #endif
431  }
432  }
433 
434  /** \return The data of the event, NULL terminated
435  */
436  const char* EventData() const
437  {
438  if( _eventData )
439  {
440  return _eventData;
441  }
442  else
443  {
444  return "";
445  }
446  }
447 
448  /** Set the data of the event, NULL terminated.
449  * For CRT safety, this should only be called by the constructing code
450  * \param newData The name to set
451  */
452  void EventData( const char* newData )
453  {
454  delete[] _eventData;
455  _eventData = NULL;
456 
457  if( newData )
458  {
459  int size = (int)strlen( newData ) + 1;
460  _eventData = new char[ size ];
461 #if defined( _WIN32 )
462  strcpy_s( _eventData, size, newData );
463 #else
464  strcpy( _eventData, newData );
465 #endif
466  }
467  }
468 
469  /** return true if the name of this event matches the given name.
470  * \param eventName The name to compare
471  */
472  bool EventNameIs( const char* eventName ) const
473  {
474  if( !_eventName || !eventName )
475  {
476  return false;
477  }
478 
479  return ( 0 == strcmp( _eventName, eventName ) );
480  }
481 
482  /** return true if the name of this event matches the given name.
483  * \param eventData The name to compare
484  */
485  bool EventDataIs( const char* eventData ) const
486  {
487  if( !_eventData || !eventData )
488  {
489  return false;
490  }
491 
492  return ( 0 == strcmp( _eventData, eventData ) );
493  }
494 };
495 
496 /** Emits the specfied ObjectEvent */
497 inline void EmitObjectEvent( DisplayObject* self, ObjectEvent* event )
498 {
499  if( self->ParentGroup() )
500  {
501  self->ParentGroup()->handle( event );
502  }
503  else if( dynamic_cast<ComponentBase*>( self ) )
504  {
505  // Called when our ParentGroup is NULL and we are wrapped by an RSO Interface.
506  self->handle( event );
507  }
508 }
509 
510 /** Creates an ObjectEvent from the given NULL terminated strings and emits it */
511 inline void EmitObjectEvent( DisplayObject* self, const char* eventName, const char* eventData = NULL )
512 {
513  ObjectEvent temp( self, eventName, eventData );
514  EmitObjectEvent( self, &temp );
515 }
516 
517 /** \return true if the given DisplayEvent is an ObjectEvent and it's event name matches the given string.
518  * \param event The event to check
519  * \param eventName The eventName to compare
520  * \param eventData optional eventData to compare, if NULL, it will not be checked, otherwise, it will.
521  */
522 inline bool ObjectEventIs( DisplayEvent* event, const char* eventName, const char* eventData = NULL )
523 {
524  ObjectEvent* objEvent = dynamic_cast<ObjectEvent*>( event );
525  bool is = ( objEvent && objEvent->EventNameIs( eventName ) );
526  if( is && eventData )
527  {
528  is = objEvent->EventDataIs( eventData );
529  }
530  return is;
531 }
532 
533 /** Basic on event test, given the event and subevent enums. */
534 #define ON( event, subevent ) if( ( ev->eventType == ( event ) ) && ( ev->eventSubtype == ( subevent ) ) )
535 
536 /** On mouse button up event test, given the mouse button enum. */
537 #define ON_MOUSE_UP( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_UP ) && ( (btnMask)&mev->buttonMask ) )
538 
539 /** On mouse button down event test, given the mouse button enum. */
540 #define ON_MOUSE_DOWN( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_DOWN ) && ( (btnMask)&mev->buttonMask ) )
541 
542 /** On mouse button held during a drag event test, given the mouse button enum. */
543 #define ON_MOUSE_DRAG( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_DRAG ) && ( (btnMask)&mev->buttonMask ) )
544 
545 /** On keyboard key down event test, given the alpha numeric key to test. */
546 #define ON_KEY_DOWN( testKey ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, true, int( testKey ) ) )
547 
548 /** On keyboard key up event test, given the alpha numeric key to test. */
549 #define ON_KEY_UP( testKey ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, true, int( testKey ) ) )
550 
551 /** On keyboard key down with modifiers event test, given the alpha numeric key and modifiers to test. */
552 #define ON_KEY_DOWN_WITH_MODIFIER( testKey, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, true, int( testKey ), modifierMask ) )
553 
554 /** On keyboard key up with modifiers event test, given the alpha numeric key and modifiers to test. */
555 #define ON_KEY_UP_WITH_MODIFIER( testKey, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, true, int( testKey ), modifierMask ) )
556 
557 /** On keyboard key down event test, given the special key to test. */
558 #define ON_SPECIAL_KEY_DOWN( keySym ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, false, int( keySym ) ) )
559 
560 /** On keyboard key up event test, given the special key to test. */
561 #define ON_SPECIAL_KEY_UP( keySym ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, false, int( keySym ) ) )
562 
563 /** On keyboard key down with modifiers event test, given the special key and modifiers to test. */
564 #define ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( keySym, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, false, int( keySym ), modifierMask ) )
565 
566 /** On keyboard key up with modifiers event test, given the special key and modifiers to test. */
567 #define ON_SPECIAL_KEY_UP_WITH_MODIFIER( keySym, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, false, int( keySym ), modifierMask ) )
568 
569 /** On keyboard key down event test. */
570 #define ON_ANY_KEY_DOWN() if( ( ev->eventType == EVENT_KEYBOARD ) )
571 
572 /** On keyboard key up event test. */
573 #define ON_ANY_KEY_UP() if( ( ev->eventType == EVENT_KEYBOARD_UP ) )
574 
575 /** Examples:
576  * ON( EVENT_MOUSE, MOUSE_DOWN )
577  * {
578  * }
579  * ON_MOUSE_DOWN( MOUSE_LBUTTON )
580  * {
581  * }
582  * ON_KEY_DOWN( 'a' )
583  * {
584  * }
585  * ON_KEY_DOWN_WITH_MODIFIER( 'B', FL_SHIFT )
586  * {
587  * }
588  * ON_KEY_DOWN_WITH_MODIFIER( 'c', FL_SHIFT | FL_CTRL )
589  * {
590  * }
591  * ON_SPECIAL_KEY_DOWN( FL_KP+'1' )
592  * {
593  * }
594  * ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( FL_F+1, FL_CTRL )
595  * {
596  * }
597  * For a comprehensive list of keys and modifiers refer to Enumerations.H.
598  */
599 
600 inline bool OnKeyEvent( KeyboardEvent* kev, bool alphaNumeric, int key, int modifierMask = 0 )
601 {
602  bool keySuccess = false;
603 
604  if( alphaNumeric )
605  {
606  /** If CTRL is expected we need to look at keysym instead.
607  * Because CTRL changes the output of the key press to something unexpected
608  * we need to check against the key press action instead.
609  */
610  if( CTRL_STATE & modifierMask )
611  {
612  /** keysym is always lowercase */
613  key = std::tolower( key );
614  keySuccess = ( key == kev->keysym );
615  }
616  else
617  {
618  keySuccess = ( key == kev->event_text );
619  }
620  }
621  else
622  {
623  keySuccess = ( key == kev->keysym );
624  }
625 
626  /** Compare to zero to avoid performance warnings.
627  * Did we find the modifiers we're looking for (modifierMask) in the modifiers currently pressed (kev->modifiers)?
628  * OR Are we not looking for any modifiers AND none of the modifiers are currently pressed?
629  * (ignoring the lock state and mouse button modifiers)
630  */
631  bool modSuccess = ( 0 != ( modifierMask & kev->modifiers ) || ( 0 == modifierMask && 0 == ( int( SHIFT_STATE | CTRL_STATE | ALT_STATE | META_STATE ) & kev->modifiers ) ) );
632 
633  return ( keySuccess && modSuccess );
634 }
635 
636 template<class T>
637 /** Event Compressor */
638 class EventCompressor
639 {
640 public:
641  typedef DisplayObject* ( T::*EventSenderCbType )( DisplayEvent* ev );
642 
643 protected:
644  MouseEvent _lastCompressedEvent;
645  bool _lastEventWasCompressed;
646  EventSenderCbType _handleCb;
647  T* _objectPtr;
648  bool _sendingCompressed;
649  bool _active;
650 
651 public:
652  void Active( bool val ) { _active = val; }
653  bool Active() { return _active; }
654 
655  EventCompressor( T* objectPtr, EventSenderCbType cb )
656  : _lastEventWasCompressed( false )
657  , _handleCb( cb )
658  , _objectPtr( objectPtr )
659  , _sendingCompressed( false )
660  , _active( true )
661  {
662  }
663 
664  /** Returns true if event was compressed.
665  * Caller should stop processing this event if returns true
666  * Caller *MUST* call SendAnyCompressedEvents() before
667  * drawing to make sure any saved events are processed.
668  */
669  bool CompressEvent( const DisplayEvent& ev )
670  {
671  if( !_active || _sendingCompressed )
672  {
673  return false;
674  }
675 
676  bool compressed = false;
677  if( EVENT_MOUSE == ev.eventType && ( MOUSE_MOVE == ev.eventSubtype || MOUSE_DRAG == ev.eventSubtype ) )
678  {
679  MouseEvent* mev = (MouseEvent*)&ev;
680 
681  if( !_lastEventWasCompressed || ( _lastEventWasCompressed && _lastCompressedEvent.eventType == ev.eventType && _lastCompressedEvent.eventSubtype == ev.eventSubtype && _lastCompressedEvent.cursorID == mev->cursorID ) )
682  {
683  // Replace with this event, and don't send
684  _lastCompressedEvent = *mev;
685  _lastEventWasCompressed = true;
686  compressed = true;
687  }
688  }
689 
690  // If we did not compress the event, send any pending ones.
691  if( !compressed )
692  {
693  SendAnyCompressedEvents();
694  }
695  return compressed;
696  }
697 
698  void SendAnyCompressedEvents()
699  {
700  // Avoids infinite loop
701  if( _sendingCompressed )
702  {
703  return;
704  }
705 
706  if( _lastEventWasCompressed )
707  {
708  _sendingCompressed = true;
709  // Call the callback
710  ( _objectPtr->*( _handleCb ) )( &_lastCompressedEvent );
711  // The event is no longer valid
712  _sendingCompressed = false;
713 
714  _lastEventWasCompressed = false;
715  }
716  }
717 };
718 
719 } // namespace disti
720 
721 #endif // INCLUDED_DISTI_EVENTS_H
int keysym
Definition: events.h:311
unsigned short eventSubtype
Definition: events.h:114
Definition: events.h:85
Definition: events.h:319
unsigned short eventType
Definition: events.h:113
MouseButtonType_e
Definition: events.h:82
void EmitObjectEvent(DisplayObject *self, ObjectEvent *event)
Definition: events.h:497
float & x
Definition: events.h:157
float & z
Definition: events.h:159
The disti::ComponentBase class.
DisplayEvent(const DisplayEvent &source)
Definition: events.h:124
bool ObjectEventIs(DisplayEvent *event, const char *eventName, const char *eventData=NULL)
Definition: events.h:522
The disti::Group class. Implements groups of objects.
float & lx
Definition: events.h:161
Definition: events.h:271
Definition: events.h:73
float & ox
Definition: events.h:165
KeyboardEvent(const KeyboardEvent &source)
Definition: events.h:284
KeyboardEvent()
Definition: events.h:275
ObjectEvent(DisplayObject *initiator, unsigned short eventSubtypeArg)
Definition: events.h:371
Definition: events.h:70
LocationEvent()
Definition: events.h:173
bool OnKeyEvent(KeyboardEvent *kev, bool alphaNumeric, int key, int modifierMask=0)
Definition: events.h:600
Definition: display.h:97
MouseEvent(const MouseEvent &source)
Definition: events.h:233
SpecialKeyState_e
Definition: events.h:91
The disti::Timer class. An OS portable timing class.
int modifiers
Definition: events.h:313
Vector winLoc
Definition: events.h:147
Definition: events.h:137
A file for all GL Studio files to include.
MouseEventType_e
Definition: events.h:68
const char * EventName() const
Definition: events.h:401
Definition: events.h:84
Definition: events.h:77
The disti::DisplayObject class and global enumerations.
DisplayObject * Initiator() const
Definition: events.h:392
int modifiers
Definition: events.h:266
Definition: events.h:78
Definition: events.h:64
float & ly
Definition: events.h:162
Vector oCoords
Definition: events.h:153
KeyboardEvent operator=(const KeyboardEvent &source)
Definition: events.h:302
float & oy
Definition: events.h:166
unsigned int cursorID
Definition: events.h:267
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:397
Vector lCoords
Definition: events.h:150
Definition: events.h:110
Definition: events.h:62
unsigned char buttonMask
Definition: events.h:264
MouseEvent operator=(const MouseEvent &source)
Definition: events.h:254
bool EventDataIs(const char *eventData) const
Definition: events.h:485
float & y
Definition: events.h:158
float & oz
Definition: events.h:167
MouseEvent(const LocationEvent &source)
Definition: events.h:243
LocationEvent operator=(const LocationEvent &source)
Definition: events.h:206
Definition: events.h:87
DisplayEvent()
Definition: events.h:117
void EventData(const char *newData)
Definition: events.h:452
Definition: vertex.h:83
ObjectEvent(DisplayObject *initiator, const char *eventName, const char *eventData=NULL)
Definition: events.h:340
MouseEvent()
Definition: events.h:222
Definition: events.h:72
virtual ~DisplayEvent()
Definition: events.h:131
const char * EventData() const
Definition: events.h:436
KeyboardEvent(const LocationEvent &source)
Definition: events.h:293
Definition: events.h:75
unsigned char clicks
Definition: events.h:265
bool CompressEvent(const DisplayEvent &ev)
Definition: events.h:669
bool EventNameIs(const char *eventName) const
Definition: events.h:472
Definition: events.h:63
Definition: bmpimage.h:46
Definition: events.h:218
LocationEvent(const LocationEvent &source)
Definition: events.h:188
float & lz
Definition: events.h:163
void EventName(const char *newName)
Definition: events.h:417
int event_text
Definition: events.h:312
Definition: events.h:86
Definition: events.h:74
Definition: events.h:76