GL Studio C++ Runtime API
events.h
Go to the documentation of this file.
1/// \file events.h
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/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<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.
38
39#ifndef INCLUDED_DISTI_EVENTS_H
40#define INCLUDED_DISTI_EVENTS_H
41
42#include "component_base.h"
43#include "display.h"
44#include "gls_include.h"
45#include "group.h"
46#include "timer.h"
47#include <string>
48
49#ifdef __VXWORKS__
50# include <cctype> //tolower
51#endif
52
53namespace disti
54{
55/** Enumeration for event types */
56typedef enum
57{
58 EVENT_MOUSE, /**< A Mouse (or touch screen) event */
59 EVENT_KEYBOARD, /**< A Keyboard event */
60 EVENT_TIMER, /**< Unused */
61 EVENT_OBJECT, /**< An event emitted by an object */
62 EVENT_KEYBOARD_UP /**< A Keyboard up event (uses KeyboardEvent class) */
64
65/** Enumeration for mouse event types */
66typedef enum
67{
68 MOUSE_DOWN, /**< A Mouse button was pushed down */
69 MOUSE_UP, /**< A Mouse button was released */
70 MOUSE_MOVE, /**< The mouse moved */
71 MOUSE_DRAG, /**< The mouse moved while a button was held down */
72 MOUSE_LEAVE, /**< The mouse exited the object */
73 MOUSE_ENTER, /**< The mouse entered the object */
74 MOUSE_WHEEL_MINUS, /**< The mouse wheel was turned in the negative direction */
75 MOUSE_WHEEL_PLUS, /**< The mouse wheel was turned in the positive direction */
76 MOUSE_RECEIVE_MULTITOUCH, /**< Handle this event to receive input from multiple touches at the same time */
77 MOUSE_CANCEL, /**< Handle this event to interrupt the current mouse event */
78 MOUSE_DOUBLE /**< A Mouse button was pushed down twice */
80
81/** Enumeration for mouse buttons */
82typedef 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 */
91typedef 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{
112public:
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 /// \param source The event to copy from.
125 DisplayEvent( const DisplayEvent& source )
126 : eventType( source.eventType )
127 , eventSubtype( source.eventSubtype )
128 {
129 }
130
131 /** Virtual deconstructor to enable RTTI */
133 {
134 }
135};
136
137/** An event with location fields */
139{
140public:
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 /// \param source The event to copy from.
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
208 /// \param source The event to copy from.
209 /// \return The resulting event (this).
211 {
212 eventType = source.eventType;
213 eventSubtype = source.eventSubtype;
214 winLoc = source.winLoc;
215 lCoords = source.lCoords;
216 oCoords = source.oCoords;
217 return *this;
218 }
219};
220
221/** A mouse event */
223{
224public:
225 /** Default Constructor */
227 : LocationEvent()
228 , buttonMask( 0u )
229 , clicks( 0u )
230 , modifiers( 0 )
231 , cursorID( 0u )
232 {
234 }
235
236 /// Copy Constructor
237 /// \param source The event to copy from.
238 MouseEvent( const MouseEvent& source )
239 : LocationEvent( source )
240 , buttonMask( source.buttonMask )
241 , clicks( source.clicks )
242 , modifiers( source.modifiers )
243 , cursorID( source.cursorID )
244 {
245 }
246
247 /// Copy Constructor from LocationEvent
248 /// \param source The event to copy from.
249 MouseEvent( const LocationEvent& source )
250 : LocationEvent( source )
251 , buttonMask( 0u )
252 , clicks( 0u )
253 , modifiers( 0 )
254 , cursorID( 0u )
255 {
257 }
258
259 /// Assignment operator
260 /// \param source The event to copy from.
261 /// \return The resulting event (this).
263 {
264 LocationEvent::operator=( source );
265 buttonMask = source.buttonMask;
266 clicks = source.clicks;
267 modifiers = source.modifiers;
268 cursorID = source.cursorID;
269 return *this;
270 }
271
272 unsigned char buttonMask; /**< bitfield: which button was pressed for this event */
273 unsigned char clicks; /**< Number of times a button was pressed */
274 int modifiers; /**< bitfield: which buttons or modifiers were depressed before event \sa SpecialKeyState_e */
275 unsigned int cursorID; /**< cursor id for multi-touch support */
276};
277
278/** A keyboard event */
280{
281public:
282 /// Default Constructor
284 : LocationEvent()
285 , keysym( 0 )
286 , event_text( 0 )
287 , modifiers( 0 )
288 {
289 }
290
291 /// Copy Constructor
292 /// \param source The event to copy from.
294 : LocationEvent( source )
295 , keysym( source.keysym )
296 , event_text( source.event_text )
297 , modifiers( source.modifiers )
298 {
299 }
300
301 /// Copy Constructor from LocationEvent
302 /// \param source The event to copy from.
304 : LocationEvent( source )
305 , keysym( 0 )
306 , event_text( 0 )
307 , modifiers( 0 )
308 {
309 }
310
311 /// Assignment operator
312 /// \param source The event to copy from.
313 /// \return The resulting event (this).
315 {
316 LocationEvent::operator=( source );
317 keysym = source.keysym;
318 event_text = source.event_text;
319 modifiers = source.modifiers;
320 return *this;
321 }
322
323 int keysym; /**< FLTK code for key that was pressed */
324 int event_text; /**< FLTK event text code for key that was pressed */
325 int modifiers; /**< bitfield: which modifiers or buttons were pressed \sa SpecialKeyState_e */
326};
327
328/** The ObjectEvent class
329 * This event is intended to be emitted by objects, rather than by a mouse or keyboard.
330 */
332{
333 DisplayObject* _initiator; /**< The display object that initiated the event */
334 char* _eventName; /**< String event name */
335 char* _eventData; /**< Any additional data for this event. A NULL terminated string */
336
337public:
339 : DisplayEvent()
340 , _initiator( NULL )
341 , _eventName( NULL )
342 , _eventData( NULL )
343 {
345 }
346
347 /** Create an ObjectEvent, setting the initator and event name
348 * \param initiator Pointer to the object that initated the event
349 * \param eventName Name of the event
350 * \param eventData Data of the event
351 */
352 ObjectEvent( DisplayObject* initiator, const char* eventName, const char* eventData = NULL )
353 : DisplayEvent()
354 , _initiator( initiator )
355 , _eventName( NULL )
356 , _eventData( NULL )
357 {
358 int size = (int)strlen( eventName ) + 1;
359 _eventName = new char[ size ];
360#if defined( _WIN32 )
361 strcpy_s( _eventName, size, eventName );
362#else
363 strcpy( _eventName, eventName );
364#endif
365 if( eventData )
366 {
367 size = (int)strlen( eventData ) + 1;
368 _eventData = new char[ size ];
369#if defined( _WIN32 )
370 strcpy_s( _eventData, size, eventData );
371#else
372 strcpy( _eventData, eventData );
373#endif
374 }
375
377 }
378
379 /** Create an ObjectEvent, setting the initator and event subtype
380 * \param initiator Pointer to the object that initated the event
381 * \param eventSubtypeArg The arbitrary event subtype
382 */
383 ObjectEvent( DisplayObject* initiator, unsigned short eventSubtypeArg )
384 : DisplayEvent()
385 , _initiator( initiator )
386 , _eventName( NULL )
387 , _eventData( NULL )
388 {
390 eventSubtype = eventSubtypeArg;
391 }
392
393 virtual ~ObjectEvent()
394 {
395 delete[] _eventName;
396 _eventName = NULL;
397
398 delete[] _eventData;
399 _eventData = NULL;
400 }
401
402 /** \return Pointer to the object that initiated the event (may be NULL)
403 */
404 DisplayObject* Initiator() const { return _initiator; }
405
406 /** Set which object initiated the event
407 * \param initiator Pointer to the object that initiated the event
408 */
409 void Initiator( DisplayObject* initiator ) { _initiator = initiator; }
410
411 /** \return The name of the event
412 */
413 const char* EventName() const
414 {
415 if( _eventName )
416 {
417 return _eventName;
418 }
419 else
420 {
421 return "";
422 }
423 }
424
425 /** Set the name of the event
426 * For CRT safety, this should only be called by the constructing code
427 * \param newName The name to set
428 */
429 void EventName( const char* newName )
430 {
431 delete[] _eventName;
432 _eventName = NULL;
433
434 if( newName )
435 {
436 int size = (int)strlen( newName ) + 1;
437 _eventName = new char[ size ];
438#if defined( _WIN32 )
439 strcpy_s( _eventName, size, newName );
440#else
441 strcpy( _eventName, newName );
442#endif
443 }
444 }
445
446 /** \return The data of the event, NULL terminated
447 */
448 const char* EventData() const
449 {
450 if( _eventData )
451 {
452 return _eventData;
453 }
454 else
455 {
456 return "";
457 }
458 }
459
460 /** Set the data of the event, NULL terminated.
461 * For CRT safety, this should only be called by the constructing code
462 * \param newData The name to set
463 */
464 void EventData( const char* newData )
465 {
466 delete[] _eventData;
467 _eventData = NULL;
468
469 if( newData )
470 {
471 int size = (int)strlen( newData ) + 1;
472 _eventData = new char[ size ];
473#if defined( _WIN32 )
474 strcpy_s( _eventData, size, newData );
475#else
476 strcpy( _eventData, newData );
477#endif
478 }
479 }
480
481 /// \param eventName The name to compare.
482 /// \return True if the name of this event matches the given name.
483 bool EventNameIs( const char* eventName ) const
484 {
485 if( !_eventName || !eventName )
486 {
487 return false;
488 }
489
490 return ( 0 == strcmp( _eventName, eventName ) );
491 }
492
493 /// \param eventData The name to compare.
494 /// \return True if the name of this event matches the given name.
495 bool EventDataIs( const char* eventData ) const
496 {
497 if( !_eventData || !eventData )
498 {
499 return false;
500 }
501
502 return ( 0 == strcmp( _eventData, eventData ) );
503 }
504};
505
506/// Emits the specfied ObjectEvent.
507/// \param self The object emitting the event.
508/// \param event A complete ObjectEvent object to emit.
509inline void EmitObjectEvent( DisplayObject* self, ObjectEvent* event )
510{
511 if( self->ParentGroup() )
512 {
513 self->ParentGroup()->handle( event );
514 }
515 else if( dynamic_cast<ComponentBase*>( self ) )
516 {
517 // Called when our ParentGroup is NULL and we are wrapped by an RSO Interface.
518 self->handle( event );
519 }
520}
521
522/// Creates an ObjectEvent from the given NULL terminated strings and emits it.
523/// \param self The object emitting the event.
524/// \param eventName The name of the event e.g. "StateChanged".
525/// \param eventData Optional additional user data.
526inline void EmitObjectEvent( DisplayObject* self, const char* eventName, const char* eventData = NULL )
527{
528 ObjectEvent temp( self, eventName, eventData );
529 EmitObjectEvent( self, &temp );
530}
531
532/** \return true if the given DisplayEvent is an ObjectEvent and it's event name matches the given string.
533 * \param event The event to check
534 * \param eventName The eventName to compare
535 * \param eventData optional eventData to compare, if NULL, it will not be checked, otherwise, it will.
536 */
537inline bool ObjectEventIs( DisplayEvent* event, const char* eventName, const char* eventData = NULL )
538{
539 ObjectEvent* objEvent = dynamic_cast<ObjectEvent*>( event );
540 bool is = ( objEvent && objEvent->EventNameIs( eventName ) );
541 if( is && eventData )
542 {
543 is = objEvent->EventDataIs( eventData );
544 }
545 return is;
546}
547
548/** Basic on event test, given the event and subevent enums. */
549#define ON( event, subevent ) if( ( ev->eventType == ( event ) ) && ( ev->eventSubtype == ( subevent ) ) )
550
551/** On mouse button up event test, given the mouse button enum. */
552#define ON_MOUSE_UP( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_UP ) && ( (btnMask)&mev->buttonMask ) )
553
554/** On mouse button down event test, given the mouse button enum. */
555#define ON_MOUSE_DOWN( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_DOWN ) && ( (btnMask)&mev->buttonMask ) )
556
557/** On mouse button held during a drag event test, given the mouse button enum. */
558#define ON_MOUSE_DRAG( btnMask ) if( ( ev->eventType == EVENT_MOUSE ) && ( ev->eventSubtype == MOUSE_DRAG ) && ( (btnMask)&mev->buttonMask ) )
559
560/** On keyboard key down event test, given the alpha numeric key to test. */
561#define ON_KEY_DOWN( testKey ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, true, int( testKey ) ) )
562
563/** On keyboard key up event test, given the alpha numeric key to test. */
564#define ON_KEY_UP( testKey ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, true, int( testKey ) ) )
565
566/** On keyboard key down with modifiers event test, given the alpha numeric key and modifiers to test. */
567#define ON_KEY_DOWN_WITH_MODIFIER( testKey, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, true, int( testKey ), modifierMask ) )
568
569/** On keyboard key up with modifiers event test, given the alpha numeric key and modifiers to test. */
570#define ON_KEY_UP_WITH_MODIFIER( testKey, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, true, int( testKey ), modifierMask ) )
571
572/** On keyboard key down event test, given the special key to test. */
573#define ON_SPECIAL_KEY_DOWN( keySym ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, false, int( keySym ) ) )
574
575/** On keyboard key up event test, given the special key to test. */
576#define ON_SPECIAL_KEY_UP( keySym ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, false, int( keySym ) ) )
577
578/** On keyboard key down with modifiers event test, given the special key and modifiers to test. */
579#define ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( keySym, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD ) && OnKeyEvent( kev, false, int( keySym ), modifierMask ) )
580
581/** On keyboard key up with modifiers event test, given the special key and modifiers to test. */
582#define ON_SPECIAL_KEY_UP_WITH_MODIFIER( keySym, modifierMask ) if( ( ev->eventType == EVENT_KEYBOARD_UP ) && OnKeyEvent( kev, false, int( keySym ), modifierMask ) )
583
584/** On keyboard key down event test. */
585#define ON_ANY_KEY_DOWN() if( ( ev->eventType == EVENT_KEYBOARD ) )
586
587/** On keyboard key up event test. */
588#define ON_ANY_KEY_UP() if( ( ev->eventType == EVENT_KEYBOARD_UP ) )
589
590/** Examples:
591 * ON( EVENT_MOUSE, MOUSE_DOWN )
592 * {
593 * }
594 * ON_MOUSE_DOWN( MOUSE_LBUTTON )
595 * {
596 * }
597 * ON_KEY_DOWN( 'a' )
598 * {
599 * }
600 * ON_KEY_DOWN_WITH_MODIFIER( 'B', FL_SHIFT )
601 * {
602 * }
603 * ON_KEY_DOWN_WITH_MODIFIER( 'c', FL_SHIFT | FL_CTRL )
604 * {
605 * }
606 * ON_SPECIAL_KEY_DOWN( FL_KP+'1' )
607 * {
608 * }
609 * ON_SPECIAL_KEY_DOWN_WITH_MODIFIER( FL_F+1, FL_CTRL )
610 * {
611 * }
612 * For a comprehensive list of keys and modifiers refer to Enumerations.H.
613 */
614
615/// A convenience function to compare a KeyboardEvent against a particular keyboard key / modifier combo.
616/// \param kev The KeyboardEvent to check.
617/// \param alphaNumeric Whether or not to try to compare to kev->event_text versus kev->keysym.
618/// \param key The key to look for in the event.
619/// \param modifierMask Any modifiers to look for in the event.
620/// \return True if the incoming key event matches the other incoming parameters.
621inline bool OnKeyEvent( KeyboardEvent* kev, bool alphaNumeric, int key, int modifierMask = 0 )
622{
623 bool keySuccess = false;
624
625 if( alphaNumeric )
626 {
627 /** If CTRL is expected we need to look at keysym instead.
628 * Because CTRL changes the output of the key press to something unexpected
629 * we need to check against the key press action instead.
630 */
631 if( CTRL_STATE & modifierMask )
632 {
633 /** keysym is always lowercase */
634 key = std::tolower( key );
635 keySuccess = ( key == kev->keysym );
636 }
637 else
638 {
639 keySuccess = ( key == kev->event_text );
640 }
641 }
642 else
643 {
644 keySuccess = ( key == kev->keysym );
645 }
646
647 /** Compare to zero to avoid performance warnings.
648 * Did we find the modifiers we're looking for (modifierMask) in the modifiers currently pressed (kev->modifiers)?
649 * OR Are we not looking for any modifiers AND none of the modifiers are currently pressed?
650 * (ignoring the lock state and mouse button modifiers)
651 */
652 bool modSuccess = ( 0 != ( modifierMask & kev->modifiers ) || ( 0 == modifierMask && 0 == ( int( SHIFT_STATE | CTRL_STATE | ALT_STATE | META_STATE ) & kev->modifiers ) ) );
653
654 return ( keySuccess && modSuccess );
655}
656
657template<class T>
658/** Event Compressor */
660{
661public:
662 typedef DisplayObject* ( T::*EventSenderCbType )( DisplayEvent* ev ); ///< Typedef for a event callback function pointer.
663
664protected:
665 MouseEvent _lastCompressedEvent; ///< The result of event compression, i.e. what all the other events boiled down to.
666 bool _lastEventWasCompressed; ///< If true, the event we're passing along was compressed.
667 EventSenderCbType _handleCb; ///< The callback function that will process this event.
668 T* _objectPtr; ///< The object containing the callback function.
669 bool _sendingCompressed; ///< Flag set to avoid compressing an already compressed event (infinite loop).
670 bool _active; ///< If active, events will be compressed, i.e. multiple MOUSE_DRAG will be boiled down to one equivalent MOUSE_DRAG.
671
672public:
673 /// Set the current active state for event compression.
674 /// \param val The new active state to set.
675 void Active( bool val ) { _active = val; }
676
677 /// \return The current active state of event compression.
678 bool Active() { return _active; }
679
680 /// Construct a new EventCompressor object to compress events for the given object.
681 /// \param objectPtr The object to receive compressed events, contains the callback function.
682 /// \param cb The callback function to receive compressed events.
684 : _lastEventWasCompressed( false )
685 , _handleCb( cb )
686 , _objectPtr( objectPtr )
687 , _sendingCompressed( false )
688 , _active( true )
689 {
690 }
691
692 /// Caller should stop processing this event if returns true
693 /// Caller *MUST* call SendAnyCompressedEvents() before
694 /// drawing to make sure any saved events are processed.
695 /// \param ev The event to compress.
696 /// \return True if event was compressed.
697 bool CompressEvent( const DisplayEvent& ev )
698 {
700 {
701 return false;
702 }
703
704 bool compressed = false;
705 if( EVENT_MOUSE == ev.eventType && ( MOUSE_MOVE == ev.eventSubtype || MOUSE_DRAG == ev.eventSubtype ) )
706 {
707 MouseEvent* mev = (MouseEvent*)&ev;
708
710 {
711 // Replace with this event, and don't send
714 compressed = true;
715 }
716 }
717
718 // If we did not compress the event, send any pending ones.
719 if( !compressed )
720 {
722 }
723 return compressed;
724 }
725
726 /// Passes along the resulting compressed event to the target object's callback function.
728 {
729 // Avoids infinite loop
731 {
732 return;
733 }
734
736 {
737 _sendingCompressed = true;
738 // Call the callback
740 // The event is no longer valid
741 _sendingCompressed = false;
742
744 }
745 }
746};
747
748} // namespace disti
749
750#endif // INCLUDED_DISTI_EVENTS_H
Definition: component_base.h:67
Definition: events.h:111
virtual ~DisplayEvent()
Definition: events.h:132
DisplayEvent(const DisplayEvent &source)
Definition: events.h:125
unsigned short eventSubtype
Definition: events.h:114
unsigned short eventType
Definition: events.h:113
DisplayEvent()
Definition: events.h:117
Definition: display.h:95
virtual DisplayObject * handle(DisplayEvent *ev)
virtual void ParentGroup(Group *group)
Definition: events.h:660
bool _lastEventWasCompressed
If true, the event we're passing along was compressed.
Definition: events.h:666
bool CompressEvent(const DisplayEvent &ev)
Definition: events.h:697
void SendAnyCompressedEvents()
Passes along the resulting compressed event to the target object's callback function.
Definition: events.h:727
bool _sendingCompressed
Flag set to avoid compressing an already compressed event (infinite loop).
Definition: events.h:669
EventCompressor(T *objectPtr, EventSenderCbType cb)
Definition: events.h:683
T * _objectPtr
The object containing the callback function.
Definition: events.h:668
EventSenderCbType _handleCb
The callback function that will process this event.
Definition: events.h:667
bool _active
If active, events will be compressed, i.e. multiple MOUSE_DRAG will be boiled down to one equivalent ...
Definition: events.h:670
MouseEvent _lastCompressedEvent
The result of event compression, i.e. what all the other events boiled down to.
Definition: events.h:665
DisplayObject *(T::* EventSenderCbType)(DisplayEvent *ev)
Typedef for a event callback function pointer.
Definition: events.h:662
void Active(bool val)
Definition: events.h:675
bool Active()
Definition: events.h:678
Definition: events.h:280
KeyboardEvent()
Default Constructor.
Definition: events.h:283
int modifiers
Definition: events.h:325
KeyboardEvent(const KeyboardEvent &source)
Definition: events.h:293
int event_text
Definition: events.h:324
int keysym
Definition: events.h:323
KeyboardEvent(const LocationEvent &source)
Definition: events.h:303
KeyboardEvent operator=(const KeyboardEvent &source)
Definition: events.h:314
Definition: events.h:139
float & y
Definition: events.h:159
float & oy
Definition: events.h:167
float & ox
Definition: events.h:166
Vector winLoc
Definition: events.h:148
float & ly
Definition: events.h:163
float & lz
Definition: events.h:164
float & z
Definition: events.h:160
Vector lCoords
Definition: events.h:151
float & oz
Definition: events.h:168
Vector oCoords
Definition: events.h:154
LocationEvent()
Definition: events.h:174
LocationEvent(const LocationEvent &source)
Definition: events.h:190
float & lx
Definition: events.h:162
float & x
Definition: events.h:158
LocationEvent operator=(const LocationEvent &source)
Definition: events.h:210
Definition: events.h:223
unsigned char buttonMask
Definition: events.h:272
int modifiers
Definition: events.h:274
MouseEvent(const LocationEvent &source)
Definition: events.h:249
unsigned int cursorID
Definition: events.h:275
unsigned char clicks
Definition: events.h:273
MouseEvent()
Definition: events.h:226
MouseEvent operator=(const MouseEvent &source)
Definition: events.h:262
MouseEvent(const MouseEvent &source)
Definition: events.h:238
Definition: events.h:332
ObjectEvent(DisplayObject *initiator, const char *eventName, const char *eventData=NULL)
Definition: events.h:352
const char * EventData() const
Definition: events.h:448
ObjectEvent(DisplayObject *initiator, unsigned short eventSubtypeArg)
Definition: events.h:383
void EventData(const char *newData)
Definition: events.h:464
bool EventDataIs(const char *eventData) const
Definition: events.h:495
DisplayObject * Initiator() const
Definition: events.h:404
const char * EventName() const
Definition: events.h:413
void EventName(const char *newName)
Definition: events.h:429
void Initiator(DisplayObject *initiator)
Definition: events.h:409
bool EventNameIs(const char *eventName) const
Definition: events.h:483
Definition: vertex.h:84
The disti::ComponentBase class.
The disti::DisplayObject class and global enumerations.
A file for all GL Studio files to include.
The disti::Group class. Implements groups of objects.
Definition: bmpimage.h:46
MouseButtonType_e
Definition: events.h:83
@ MOUSE_BUTTON_ANY
Definition: events.h:87
@ MOUSE_LBUTTON
Definition: events.h:84
@ MOUSE_RBUTTON
Definition: events.h:86
@ MOUSE_MBUTTON
Definition: events.h:85
void EmitObjectEvent(DisplayObject *self, ObjectEvent *event)
Definition: events.h:509
bool OnKeyEvent(KeyboardEvent *kev, bool alphaNumeric, int key, int modifierMask=0)
Definition: events.h:621
EventType_e
Definition: events.h:57
@ EVENT_MOUSE
Definition: events.h:58
@ EVENT_KEYBOARD_UP
Definition: events.h:62
@ EVENT_OBJECT
Definition: events.h:61
@ EVENT_TIMER
Definition: events.h:60
@ EVENT_KEYBOARD
Definition: events.h:59
SpecialKeyState_e
Definition: events.h:92
bool ObjectEventIs(DisplayEvent *event, const char *eventName, const char *eventData=NULL)
Definition: events.h:537
MouseEventType_e
Definition: events.h:67
@ MOUSE_DOWN
Definition: events.h:68
@ MOUSE_ENTER
Definition: events.h:73
@ MOUSE_UP
Definition: events.h:69
@ MOUSE_DRAG
Definition: events.h:71
@ MOUSE_CANCEL
Definition: events.h:77
@ MOUSE_MOVE
Definition: events.h:70
@ MOUSE_WHEEL_PLUS
Definition: events.h:75
@ MOUSE_RECEIVE_MULTITOUCH
Definition: events.h:76
@ MOUSE_LEAVE
Definition: events.h:72
@ MOUSE_WHEEL_MINUS
Definition: events.h:74
@ MOUSE_DOUBLE
Definition: events.h:78
The disti::Timer class. An OS portable timing class.