diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/event.h | 118 | ||||
-rw-r--r-- | src/common/event_ids.h | 6 |
2 files changed, 61 insertions, 63 deletions
diff --git a/src/common/event.h b/src/common/event.h index 378960c..dc50ee6 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -31,42 +31,33 @@ class CInstanceManager; /** - * \enum PressState - * \brief State of key/mouse button - */ -enum PressState -{ - STATE_PRESSED, - STATE_RELEASED -}; - - -/** * \struct KeyEventData * \brief Additional data for keyboard event */ struct KeyEventData { - //! STATE_PRESSED or STATE_RELEASED */ - PressState state; - //! If true, the key is a virtual code generated by key modifier press or joystick button press + //! If true, the key is a virtual code generated by certain key modifiers or joystick buttons bool virt; //! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h) unsigned int key; - //! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h) - unsigned int mod; //! Unicode character + //! NOTE: applicable only to EVENT_KEY_DOWN events! unsigned int unicode; }; -/** \struct MouseMotionEventData - \brief Additional data for mouse move event */ -struct MouseMoveEventData +/** + * \enum MouseButton + * \brief Mouse button + * + * Values are a bitmask to have a state bitmask + */ +enum MouseButton { - //! Current button state - PressState state; - //! Position of mouse in normalized coordinates (0..1) - Math::Point pos; + MOUSE_BUTTON_LEFT = (1<<1), + MOUSE_BUTTON_MIDDLE = (1<<2), + MOUSE_BUTTON_RIGHT = (1<<3), + //! There may be additional mouse buttons >= this value + MOUSE_BUTTON_OTHER = (1<<4) }; /** @@ -75,12 +66,8 @@ struct MouseMoveEventData */ struct MouseButtonEventData { - //! The mouse button index - unsigned char button; - //! STATE_PRESSED or STATE_RELEASED - PressState state; - //! Position of mouse in normalized coordinates (0..1) - Math::Point pos; + //! The mouse button + MouseButton button; }; /** @@ -101,8 +88,6 @@ struct MouseWheelEventData { //! Wheel direction WheelDirection dir; - //! Position of mouse in normalized coordinates (0..1) - Math::Point pos; }; /** @@ -125,8 +110,6 @@ struct JoyButtonEventData { //! The joystick button index unsigned char button; - //! STATE_PRESSED or STATE_RELEASED - PressState state; }; /** @@ -170,20 +153,48 @@ struct ActiveEventData **/ struct Event { - //! Type of event (EVENT_*) + //! Type of event EventType type; - //! If true, the event was produced by system (SDL); else, it has come from user interface + //! If true, the event was produced by system in CApplication; else, it has come from game engine bool systemEvent; + //! Relative time since last EVENT_FRAME + //! Scope: only EVENT_FRAME events + // TODO: gradually replace the usage of this with new CApplication's time functions + float rTime; + + //! Motion vector set by keyboard or joystick (managed by CRobotMain) + //! Scope: all system events + Math::Vector motionInput; + + //! Current state of keyboard modifier keys: bitmask made of KEY_MOD(...) macro values (from common/key.h) + //! Scope: all system events + unsigned int kmodState; + + //! Current state of tracked keys: bitmask of TrackedKey enum values + //! Scope: all system events + unsigned int trackedKeysState; + + //! Current position of mouse cursor in interface coords + //! Scope: all system events + Math::Point mousePos; + + //! Current state of mouse buttons: bitmask of MouseButton enum values + //! Scope: all system events + unsigned int mouseButtonsState; + + //! Custom parameter that may be set for some events + //! Scope: some interface events + long customParam; + + //! Union with additional data, applicable only to some events union { //! Additional data for EVENT_KEY_DOWN and EVENT_KEY_UP KeyEventData key; //! Additional data for EVENT_MOUSE_BUTTON_DOWN and EVENT_MOUSE_BUTTON_UP MouseButtonEventData mouseButton; - //! Additional data for EVENT_MOUSE_MOVE - MouseMoveEventData mouseMove; //! Additional data for EVENT_MOUSE_WHEEL MouseWheelEventData mouseWheel; //! Additional data for EVENT_JOY @@ -194,35 +205,15 @@ struct Event ActiveEventData active; }; - //! State of tracked keys (mask of TrackedKey enum values) - unsigned int trackedKeys; - - //! Mouse position is provided also for other types of events besides mouse events - Math::Point mousePos; - - //! Motion vector set by keyboard or joystick - Math::Vector motionInput; - - // TODO: remove and replace references with trackedKeys - short keyState; - - // TODO: remove and replace references with mousePos - Math::Point pos; - - // TODO: remove - long param; // parameter - - // TODO: remove in longer term (use CApplication's new time functions instead) - float rTime; // relative time - - Event(EventType aType = EVENT_NULL) + Event(EventType type = EVENT_NULL) { - type = aType; - systemEvent = false; - trackedKeys = 0; + this->type = type; - param = 0; + systemEvent = false; rTime = 0.0f; + mouseButtonsState = 0; + trackedKeysState = 0; + customParam = 0; } }; @@ -254,6 +245,7 @@ public: void Flush(); //! Adds an event to the queue bool AddEvent(const Event &event); + //! Removes and returns an event from queue front bool GetEvent(Event &event); protected: diff --git a/src/common/event_ids.h b/src/common/event_ids.h index 9cbbf94..b6c646c 100644 --- a/src/common/event_ids.h +++ b/src/common/event_ids.h @@ -60,10 +60,16 @@ enum EventType //! Event sent after releasing a joystick button EVENT_JOY_BUTTON_UP = 14, + + /* Events sent/received in game and user interface */ + EVENT_UPDINTERFACE = 20, EVENT_WIN = 30, EVENT_LOST = 31, + //! CEdit focus + EVENT_FOCUS = 35, + EVENT_BUTTON_OK = 40, EVENT_BUTTON_CANCEL = 41, EVENT_BUTTON_NEXT = 42, |