diff options
| author | Max Horn | 2007-03-17 19:02:05 +0000 |
|---|---|---|
| committer | Max Horn | 2007-03-17 19:02:05 +0000 |
| commit | ed54ea9155961d8ca5d5fb3c7777fc57a29f2751 (patch) | |
| tree | 467b926af11cd4129ba003d04ba01de044c7a6df /common | |
| parent | f272d1957084098c5b53975ad3501074f6971af8 (diff) | |
| download | scummvm-rg350-ed54ea9155961d8ca5d5fb3c7777fc57a29f2751.tar.gz scummvm-rg350-ed54ea9155961d8ca5d5fb3c7777fc57a29f2751.tar.bz2 scummvm-rg350-ed54ea9155961d8ca5d5fb3c7777fc57a29f2751.zip | |
Moved Event/EventType/keyboard enum from common/system.h (part of class OSystem) to common/events.h (part of namespace Common). Porters may have to make minor changes to their backends to get them to compile again
svn-id: r26180
Diffstat (limited to 'common')
| -rw-r--r-- | common/events.h | 114 | ||||
| -rw-r--r-- | common/system.h | 116 |
2 files changed, 116 insertions, 114 deletions
diff --git a/common/events.h b/common/events.h index 201faa977c..1f05188d90 100644 --- a/common/events.h +++ b/common/events.h @@ -30,6 +30,118 @@ namespace Common { /** + * The types of events backends may generate. + * @see Event + * + * @todo Merge EVENT_LBUTTONDOWN, EVENT_RBUTTONDOWN and EVENT_WHEELDOWN; + * likewiese EVENT_LBUTTONUP, EVENT_RBUTTONUP, EVENT_WHEELUP. + * To do that, we just have to add a field to the Event which + * indicates which button was pressed. + */ +enum EventType { + /** A key was pressed, details in Event::kbd. */ + EVENT_KEYDOWN = 1, + /** A key was released, details in Event::kbd. */ + EVENT_KEYUP = 2, + /** The mouse moved, details in Event::mouse. */ + EVENT_MOUSEMOVE = 3, + EVENT_LBUTTONDOWN = 4, + EVENT_LBUTTONUP = 5, + EVENT_RBUTTONDOWN = 6, + EVENT_RBUTTONUP = 7, + EVENT_WHEELUP = 8, + EVENT_WHEELDOWN = 9, + + EVENT_QUIT = 10, + EVENT_SCREEN_CHANGED = 11 +}; + +/** + * Keyboard modifier flags, used for Event::kbd::flags. + */ +enum { + KBD_CTRL = 1 << 0, + KBD_ALT = 1 << 1, + KBD_SHIFT = 1 << 2 +}; + +/** + * Data structure for an event. A pointer to an instance of Event + * can be passed to pollEvent. + * @todo Rework/document this structure. It should be made 100% clear which + * field is valid for which event type. + * Implementation wise, we might want to use the classic + * union-of-structs trick. It goes roughly like this: + * struct BasicEvent { + * EventType type; + * }; + * struct MouseMovedEvent : BasicEvent { + * Common::Point pos; + * }; + * struct MouseButtonEvent : MouseMovedEvent { + * int button; + * }; + * struct KeyEvent : BasicEvent { + * ... + * }; + * ... + * union Event { + * EventType type; + * MouseMovedEvent mouse; + * MouseButtonEvent button; + * KeyEvent key; + * ... + * }; + */ +struct Event { + /** The type of the event. */ + EventType type; + /** Flag to indicate if the event is real or synthetic. E.g. keyboard + * repeat events are synthetic. + */ + bool synthetic; + /** + * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and + * EVENT_KEYUP). For all other event types, content is undefined. + */ + struct { + /** + * Abstract key code (will be the same for any given key regardless + * of modifiers being held at the same time. + * For example, this is the same for both 'A' and Shift-'A'. + * @todo Document which values are to be used for non-ASCII keys + * like F1-F10. For now, let's just say that our primary backend + * is the SDL one, and it uses the values SDL uses... so until + * we fix this, your best bet is to get a copy of SDL_keysym.h + * and look at that, if you want to find out a key code. + */ + int keycode; + /** + * ASCII-value of the pressed key (if any). + * This depends on modifiers, i.e. pressing the 'A' key results in + * different values here depending on the status of shift, alt and + * caps lock. + * For the function keys F1-F9, values of 315-323 are used. + */ + uint16 ascii; + /** + * Status of the modifier keys. Bits are set in this for each + * pressed modifier + * @see KBD_CTRL, KBD_ALT, KBD_SHIFT + */ + byte flags; + } kbd; + /** + * The mouse coordinates, in virtual screen coordinates. Only valid + * for mouse events. + * Virtual screen coordinates means: the coordinate system of the + * screen area as defined by the most recent call to initSize(). + */ + Common::Point mouse; +}; + + +/** * The EventManager provides user input events to the client code. * In addition, it keeps track of the state of various input devices, * like keys, mouse position and buttons. @@ -49,7 +161,7 @@ public: * @param event point to an Event struct, which will be filled with the event data. * @return true if an event was retrieved. */ - virtual bool pollEvent(OSystem::Event &event) = 0; + virtual bool pollEvent(Common::Event &event) = 0; /** Return the current key state */ diff --git a/common/system.h b/common/system.h index 9e7e19afa0..09249e7acd 100644 --- a/common/system.h +++ b/common/system.h @@ -38,6 +38,7 @@ namespace Graphics { } namespace Common { + struct Event; class EventManager; class SaveFileManager; class TimerManager; @@ -676,126 +677,15 @@ public: /** @name Events and Time */ //@{ - /** - * The types of events backends may generate. - * @see Event - * - * @todo Merge EVENT_LBUTTONDOWN, EVENT_RBUTTONDOWN and EVENT_WHEELDOWN; - * likewiese EVENT_LBUTTONUP, EVENT_RBUTTONUP, EVENT_WHEELUP. - * To do that, we just have to add a field to the Event which - * indicates which button was pressed. - */ - enum EventType { - /** A key was pressed, details in Event::kbd. */ - EVENT_KEYDOWN = 1, - /** A key was released, details in Event::kbd. */ - EVENT_KEYUP = 2, - /** The mouse moved, details in Event::mouse. */ - EVENT_MOUSEMOVE = 3, - EVENT_LBUTTONDOWN = 4, - EVENT_LBUTTONUP = 5, - EVENT_RBUTTONDOWN = 6, - EVENT_RBUTTONUP = 7, - EVENT_WHEELUP = 8, - EVENT_WHEELDOWN = 9, - - EVENT_QUIT = 10, - EVENT_SCREEN_CHANGED = 11 - }; - - /** - * Keyboard modifier flags, used for Event::kbd::flags. - */ - enum { - KBD_CTRL = 1 << 0, - KBD_ALT = 1 << 1, - KBD_SHIFT = 1 << 2 - }; - - /** - * Data structure for an event. A pointer to an instance of Event - * can be passed to pollEvent. - * @todo Rework/document this structure. It should be made 100% clear which - * field is valid for which event type. - * Implementation wise, we might want to use the classic - * union-of-structs trick. It goes roughly like this: - * struct BasicEvent { - * EventType type; - * }; - * struct MouseMovedEvent : BasicEvent { - * Common::Point pos; - * }; - * struct MouseButtonEvent : MouseMovedEvent { - * int button; - * }; - * struct KeyEvent : BasicEvent { - * ... - * }; - * ... - * union Event { - * EventType type; - * MouseMovedEvent mouse; - * MouseButtonEvent button; - * KeyEvent key; - * ... - * }; - */ - struct Event { - /** The type of the event. */ - EventType type; - /** Flag to indicate if the event is real or synthetic. E.g. keyboard - * repeat events are synthetic. - */ - bool synthetic; - /** - * Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and - * EVENT_KEYUP). For all other event types, content is undefined. - */ - struct { - /** - * Abstract key code (will be the same for any given key regardless - * of modifiers being held at the same time. - * For example, this is the same for both 'A' and Shift-'A'. - * @todo Document which values are to be used for non-ASCII keys - * like F1-F10. For now, let's just say that our primary backend - * is the SDL one, and it uses the values SDL uses... so until - * we fix this, your best bet is to get a copy of SDL_keysym.h - * and look at that, if you want to find out a key code. - */ - int keycode; - /** - * ASCII-value of the pressed key (if any). - * This depends on modifiers, i.e. pressing the 'A' key results in - * different values here depending on the status of shift, alt and - * caps lock. - * For the function keys F1-F9, values of 315-323 are used. - */ - uint16 ascii; - /** - * Status of the modifier keys. Bits are set in this for each - * pressed modifier - * @see KBD_CTRL, KBD_ALT, KBD_SHIFT - */ - byte flags; - } kbd; - /** - * The mouse coordinates, in virtual screen coordinates. Only valid - * for mouse events. - * Virtual screen coordinates means: the coordinate system of the - * screen area as defined by the most recent call to initSize(). - */ - Common::Point mouse; - }; - protected: friend class DefaultEventManager; /** * Get the next event in the event queue. - * @param event point to an Event struct, which will be filled with the event data. + * @param event point to an Common::Event struct, which will be filled with the event data. * @return true if an event was retrieved. */ - virtual bool pollEvent(Event &event) = 0; + virtual bool pollEvent(Common::Event &event) = 0; public: /** Get the number of milliseconds since the program was started. */ |
