41 #ifndef INCLUDED_DISTI_EVENTS_H
42 #define INCLUDED_DISTI_EVENTS_H
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
126 eventType( source.eventType ),
127 eventSubtype( source.eventSubtype )
191 winLoc( source.winLoc ),
192 lCoords( source.lCoords ),
193 oCoords( source.oCoords ),
343 _initiator( initiator ),
347 int size = (int)strlen( eventName ) + 1;
348 _eventName =
new char[size];
349 #if defined( _WIN32 )
350 strcpy_s( _eventName, size, eventName );
352 strcpy( _eventName, eventName );
356 size = (int)strlen( eventData ) + 1;
357 _eventData =
new char[size];
358 #if defined( _WIN32 )
359 strcpy_s( _eventData, size, eventData );
361 strcpy( _eventData, eventData );
374 _initiator( initiator ),
425 int size = (int)strlen( newName ) + 1;
426 _eventName =
new char[size];
427 #if defined( _WIN32 )
428 strcpy_s( _eventName, size, newName );
430 strcpy( _eventName, newName );
460 int size = (int)strlen( newData ) + 1;
461 _eventData =
new char[size];
462 #if defined( _WIN32 )
463 strcpy_s( _eventData, size, newData );
465 strcpy( _eventData, newData );
475 if( !_eventName || !eventName )
480 return( 0 == strcmp( _eventName, eventName ) );
488 if( !_eventData || !eventData )
493 return( 0 == strcmp( _eventData, eventData ) );
500 if( self->ParentGroup() )
502 self->ParentGroup()->handle( event );
504 else if( dynamic_cast< ComponentBase* >(
self ) )
507 self->handle( event );
526 bool is = ( objEvent && objEvent->
EventNameIs( eventName ) );
527 if( is && eventData )
535 #define ON(event,subevent) if ((ev->eventType==(event)) && (ev->eventSubtype==(subevent)))
538 #define ON_MOUSE_UP(btnMask) if ((ev->eventType==EVENT_MOUSE) && \
539 (ev->eventSubtype==MOUSE_UP) && ((btnMask) & mev->buttonMask))
542 #define ON_MOUSE_DOWN(btnMask) if ((ev->eventType==EVENT_MOUSE) && \
543 (ev->eventSubtype==MOUSE_DOWN) && ((btnMask) & mev->buttonMask))
546 #define ON_MOUSE_DRAG(btnMask) if ((ev->eventType==EVENT_MOUSE) && \
547 (ev->eventSubtype==MOUSE_DRAG) && ((btnMask) & mev->buttonMask))
550 #define ON_KEY_DOWN(testKey) if ((ev->eventType==EVENT_KEYBOARD) && \
551 OnKeyEvent( kev, true, int(testKey) ))
554 #define ON_KEY_UP(testKey) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
555 OnKeyEvent( kev, true, int(testKey) ))
558 #define ON_KEY_DOWN_WITH_MODIFIER(testKey, modifierMask) if ((ev->eventType==EVENT_KEYBOARD) && \
559 OnKeyEvent( kev, true, int(testKey), modifierMask ))
562 #define ON_KEY_UP_WITH_MODIFIER(testKey, modifierMask) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
563 OnKeyEvent( kev, true, int(testKey), modifierMask ))
566 #define ON_SPECIAL_KEY_DOWN(keySym) if ((ev->eventType==EVENT_KEYBOARD) && \
567 OnKeyEvent( kev, false, int(keySym) ))
570 #define ON_SPECIAL_KEY_UP(keySym) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
571 OnKeyEvent( kev, false, int(keySym) ))
574 #define ON_SPECIAL_KEY_DOWN_WITH_MODIFIER(keySym, modifierMask) if ((ev->eventType==EVENT_KEYBOARD) && \
575 OnKeyEvent( kev, false, int(keySym), modifierMask ))
578 #define ON_SPECIAL_KEY_UP_WITH_MODIFIER(keySym, modifierMask) if ((ev->eventType==EVENT_KEYBOARD_UP) && \
579 OnKeyEvent( kev, false, int(keySym), modifierMask ))
582 #define ON_ANY_KEY_DOWN() if ((ev->eventType==EVENT_KEYBOARD))
585 #define ON_ANY_KEY_UP() if ((ev->eventType==EVENT_KEYBOARD_UP))
614 bool keySuccess =
false;
622 if(CTRL_STATE & modifierMask)
625 key = std::tolower( key );
626 keySuccess = ( key == kev->
keysym );
635 keySuccess = ( key == kev->
keysym );
643 bool modSuccess = ( 0 != ( modifierMask & kev->
modifiers ) || ( 0 == modifierMask && 0 == (
int( SHIFT_STATE | CTRL_STATE | ALT_STATE | META_STATE ) & kev->
modifiers ) ) );
645 return ( keySuccess && modSuccess );
650 class EventCompressor
653 typedef DisplayObject* (T::*EventSenderCbType)(DisplayEvent* ev);
656 MouseEvent _lastCompressedEvent;
657 bool _lastEventWasCompressed;
658 EventSenderCbType _handleCb;
660 bool _sendingCompressed;
664 void Active(
bool val ) { _active = val; }
665 bool Active() {
return _active; }
667 EventCompressor( T* objectPtr, EventSenderCbType cb ) :
668 _lastEventWasCompressed( false ),
670 _objectPtr( objectPtr ),
671 _sendingCompressed( false ),
683 if( !_active || _sendingCompressed )
688 bool compressed =
false;
695 if( !_lastEventWasCompressed ||
696 ( _lastEventWasCompressed &&
697 _lastCompressedEvent.eventType == ev.
eventType &&
699 _lastCompressedEvent.cursorID == mev->
cursorID ) )
702 _lastCompressedEvent = *mev;
703 _lastEventWasCompressed =
true;
711 SendAnyCompressedEvents();
716 void SendAnyCompressedEvents()
719 if( _sendingCompressed )
724 if( _lastEventWasCompressed )
726 _sendingCompressed =
true;
728 (_objectPtr->*(_handleCb))(&_lastCompressedEvent);
730 _sendingCompressed =
false;
732 _lastEventWasCompressed =
false;
739 #endif // INCLUDED_DISTI_EVENTS_H
int keysym
Definition: events.h:312
unsigned short eventSubtype
Definition: events.h:115
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
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
LocationEvent()
Definition: events.h:174
bool OnKeyEvent(KeyboardEvent *kev, bool alphaNumeric, int key, int modifierMask=0)
Definition: events.h:612
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
A file for all GL Studio files to include.
MouseEventType_e
Definition: events.h:69
const char * EventName() const
Definition: events.h:402
The disti::DisplayObject class and global enumerations.
DisplayObject * Initiator() const
Definition: events.h:393
int modifiers
Definition: events.h:267
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
EventType_e
Definition: events.h:59
void Initiator(DisplayObject *initiator)
Definition: events.h:398
Vector lCoords
Definition: events.h:151
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
DisplayEvent()
Definition: events.h:118
void EventData(const char *newData)
Definition: events.h:453
ObjectEvent(DisplayObject *initiator, const char *eventName, const char *eventData=NULL)
Definition: events.h:341
MouseEvent()
Definition: events.h:223
virtual ~DisplayEvent()
Definition: events.h:132
const char * EventData() const
Definition: events.h:437
KeyboardEvent(const LocationEvent &source)
Definition: events.h:294
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: bmpimage.h:46
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