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