xoreos  0.0.5
types.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef EVENTS_TYPES_H
26 #define EVENTS_TYPES_H
27 
28 #include <stdexcept>
29 
30 #include "src/common/error.h"
31 
32 #include <boost/function.hpp>
33 #include <boost/shared_ptr.hpp>
34 
35 #include "src/common/fallthrough.h"
37 #include <SDL_events.h>
39 
40 namespace Events {
41 
42 typedef SDL_Event Event;
43 
45 enum EventType {
46  kEventKeyDown = SDL_KEYDOWN ,
47  kEventKeyUp = SDL_KEYUP ,
48  kEventMouseMove = SDL_MOUSEMOTION ,
49  kEventMouseDown = SDL_MOUSEBUTTONDOWN,
50  kEventMouseUp = SDL_MOUSEBUTTONUP ,
51  kEventMouseWheel= SDL_MOUSEWHEEL ,
52  kEventTextInput = SDL_TEXTINPUT ,
53  kEventQuit = SDL_QUIT ,
54  kEventWindow = SDL_WINDOWEVENT ,
55  kEventUserMIN = SDL_USEREVENT - 1 ,
56  kEventITC = SDL_USEREVENT ,
57  kEventUserMAX = SDL_LASTEVENT
58 };
59 
62  kEventWindowResized = SDL_WINDOWEVENT_RESIZED ,
63  kEventWindowSizeChanged = SDL_WINDOWEVENT_SIZE_CHANGED,
64  kEventWindowMinimized = SDL_WINDOWEVENT_MINIMIZED ,
65  kEventWindowMaximized = SDL_WINDOWEVENT_MAXIMIZED ,
66  kEventWindowRestored = SDL_WINDOWEVENT_RESTORED
67 };
68 
70 enum ITCEvent {
76 };
77 
78 enum Key {
79  kKeyUnknown = SDLK_UNKNOWN,
80 
81  kKeyReturn = SDLK_RETURN,
82  kKeyEscape = SDLK_ESCAPE,
83  kKeyBackspace = SDLK_BACKSPACE,
84  kKeyTab = SDLK_TAB,
85  kKeySpace = SDLK_SPACE,
86  kKeyExclaim = SDLK_EXCLAIM,
87  kKeyQuoteDbl = SDLK_QUOTEDBL,
88  kKeyHash = SDLK_HASH,
89  kKeyPercent = SDLK_PERCENT,
90  kKeyDollar = SDLK_DOLLAR,
91  kKeyAmpersand = SDLK_AMPERSAND,
92  kKeyQuote = SDLK_QUOTE,
93  kKeyLeftParen = SDLK_LEFTPAREN,
94  kKeyRightParen = SDLK_RIGHTPAREN,
95  kKeyAsterisk = SDLK_ASTERISK,
96  kKeyPlus = SDLK_PLUS,
97  kKeyComma = SDLK_COMMA,
98  kKeyMinus = SDLK_MINUS,
99  kKeyPeriod = SDLK_PERIOD,
100  kKeySlash = SDLK_SLASH,
101  kKey0 = SDLK_0,
102  kKey1 = SDLK_1,
103  kKey2 = SDLK_2,
104  kKey3 = SDLK_3,
105  kKey4 = SDLK_4,
106  kKey5 = SDLK_5,
107  kKey6 = SDLK_6,
108  kKey7 = SDLK_7,
109  kKey8 = SDLK_8,
110  kKey9 = SDLK_9,
111  kKeyColon = SDLK_COLON,
112  kKeySemicolon = SDLK_SEMICOLON,
113  kKeyLess = SDLK_LESS,
114  kKeyEquals = SDLK_EQUALS,
115  kKeyGreater = SDLK_GREATER,
116  kKeyQuestion = SDLK_QUESTION,
117  kKeyAt = SDLK_AT,
118 
119  kKeyCapsLock = SDLK_CAPSLOCK,
120 
121  kKeyF1 = SDLK_F1,
122  kKeyF2 = SDLK_F2,
123  kKeyF3 = SDLK_F3,
124  kKeyF4 = SDLK_F4,
125  kKeyF5 = SDLK_F5,
126  kKeyF6 = SDLK_F6,
127  kKeyF7 = SDLK_F7,
128  kKeyF8 = SDLK_F8,
129  kKeyF9 = SDLK_F9,
130  kKeyF10 = SDLK_F10,
131  kKeyF11 = SDLK_F11,
132  kKeyF12 = SDLK_F12,
133 
134  kKeyPrintScreen = SDLK_PRINTSCREEN,
135  kKeyScrollLock = SDLK_SCROLLLOCK,
136  kKeyPause = SDLK_PAUSE,
137  kKeyInsert = SDLK_INSERT,
138  kKeyHome = SDLK_HOME,
139  kKeyPageUp = SDLK_PAGEUP,
140  kKeyDelete = SDLK_DELETE,
141  kKeyEnd = SDLK_END,
142  kKeyPageDown = SDLK_PAGEDOWN,
143  kKeyRight = SDLK_RIGHT,
144  kKeyLeft = SDLK_LEFT,
145  kKeyDown = SDLK_DOWN,
146  kKeyUp = SDLK_UP,
147 
148  kKeyNumLockClear = SDLK_NUMLOCKCLEAR,
149  kKeyKPDivide = SDLK_KP_DIVIDE,
150  kKeyKPMultiply = SDLK_KP_MULTIPLY,
151  kKeyKPMinus = SDLK_KP_MINUS,
152  kKeyKPPlus = SDLK_KP_PLUS,
153  kKeyKPEnter = SDLK_KP_ENTER,
154  kKeyKP1 = SDLK_KP_1,
155  kKeyKP2 = SDLK_KP_2,
156  kKeyKP3 = SDLK_KP_3,
157  kKeyKP4 = SDLK_KP_4,
158  kKeyKP5 = SDLK_KP_5,
159  kKeyKP6 = SDLK_KP_6,
160  kKeyKP7 = SDLK_KP_7,
161  kKeyKP8 = SDLK_KP_8,
162  kKeyKP9 = SDLK_KP_9,
163  kKeyKP0 = SDLK_KP_0,
164  kKeyKPPeriod = SDLK_KP_PERIOD,
165 
166  kKeyApplication = SDLK_APPLICATION,
167  kKeyPower = SDLK_POWER,
168  kKeyKPEquals = SDLK_KP_EQUALS,
169  kKeyF13 = SDLK_F13,
170  kKeyF14 = SDLK_F14,
171  kKeyF15 = SDLK_F15,
172  kKeyF16 = SDLK_F16,
173  kKeyF17 = SDLK_F17,
174  kKeyF18 = SDLK_F18,
175  kKeyF19 = SDLK_F19,
176  kKeyF20 = SDLK_F20,
177  kKeyF21 = SDLK_F21,
178  kKeyF22 = SDLK_F22,
179  kKeyF23 = SDLK_F23,
180  kKeyF24 = SDLK_F24,
181  kKeyExecute = SDLK_EXECUTE,
182  kKeyHelp = SDLK_HELP,
183  kKeyMenu = SDLK_MENU,
184  kKeySelect = SDLK_SELECT,
185  kKeyStop = SDLK_STOP,
186  kKeyAgain = SDLK_AGAIN,
187  kKeyUndo = SDLK_UNDO,
188  kKeyCut = SDLK_CUT,
189  kKeyCopy = SDLK_COPY,
190  kKeyPaste = SDLK_PASTE,
191  kKeyFind = SDLK_FIND,
192  kKeyMute = SDLK_MUTE,
193  kKeyVolumeUp = SDLK_VOLUMEUP,
194  kKeyVolumeDown = SDLK_VOLUMEDOWN,
195  kKeyKPComma = SDLK_KP_COMMA,
196  kKeyKPEqualsAs400 = SDLK_KP_EQUALSAS400,
197 
198  kKeyAltErase = SDLK_ALTERASE,
199  kKeySysReq = SDLK_SYSREQ,
200  kKeyCancel = SDLK_CANCEL,
201  kKeyClear = SDLK_CLEAR,
202  kKeyPrior = SDLK_PRIOR,
203  kKeyReturn2 = SDLK_RETURN2,
204  kKeySeparator = SDLK_SEPARATOR,
205  kKeyOut = SDLK_OUT,
206  kKeyOper = SDLK_OPER,
207  kKeyClearAgain = SDLK_CLEARAGAIN,
208  kKeyCRSel = SDLK_CRSEL,
209  kKeyExSel = SDLK_EXSEL,
210 
211  kKeyKP00 = SDLK_KP_00,
212  kKeyKP000 = SDLK_KP_000,
213  kKeyThousandsSeperator = SDLK_THOUSANDSSEPARATOR,
214  kKeyDecimalSeperator = SDLK_DECIMALSEPARATOR,
215  kKeyCurrencyUnit = SDLK_CURRENCYUNIT,
216  kKeyCurrencySubUnit = SDLK_CURRENCYSUBUNIT,
217  kKeyKPLeftParen = SDLK_KP_LEFTPAREN,
218  kKeyKPRightParen = SDLK_KP_RIGHTPAREN,
219  kKeyKPLeftBrace = SDLK_KP_LEFTBRACE,
220  kKeyKPRightBrace = SDLK_KP_RIGHTBRACE,
221  kKeyKPTab = SDLK_KP_TAB,
222  kKeyKPBackspace = SDLK_KP_BACKSPACE,
223  kKeyKPA = SDLK_KP_A,
224  kKeyKPB = SDLK_KP_B,
225  kKeyKPC = SDLK_KP_C,
226  kKeyKPD = SDLK_KP_D,
227  kKeyKPE = SDLK_KP_E,
228  kKeyKPF = SDLK_KP_F,
229  kKeyKPXor = SDLK_KP_XOR,
230  kKeyKPPower = SDLK_KP_POWER,
231  kKeyKPPercent = SDLK_KP_PERCENT,
232  kKeyKPLess = SDLK_KP_LESS,
233  kKeyKPGreater = SDLK_KP_GREATER,
234  kKeyKPAmpersand = SDLK_KP_AMPERSAND,
235  kKeyKPDblAmpersand = SDLK_KP_DBLAMPERSAND,
236  kKeyKPVerticalBar = SDLK_KP_VERTICALBAR,
237  kKeyKPDblVerticalBar = SDLK_KP_DBLVERTICALBAR,
238  kKeyKPColon = SDLK_KP_COLON,
239  kKeyKPHash = SDLK_KP_HASH,
240  kKeyKPSpace = SDLK_KP_SPACE,
241  kKeyKPAt = SDLK_KP_AT,
242  kKeyKPExclam = SDLK_KP_EXCLAM,
243  kKeyKPMemStore = SDLK_KP_MEMSTORE,
244  kKeyKPMemRecall = SDLK_KP_MEMRECALL,
245  kKeyKPMemClear = SDLK_KP_MEMCLEAR,
246  kKeyKPMemAdd = SDLK_KP_MEMADD,
247  kKeyKPMemSubtract = SDLK_KP_MEMSUBTRACT,
248  kKeyKPMemMultiply = SDLK_KP_MEMMULTIPLY,
249  kKeyKPMemDivide = SDLK_KP_MEMDIVIDE,
250  kKeyKPPlusMinus = SDLK_KP_PLUSMINUS,
251  kKeyKPClear = SDLK_KP_CLEAR,
252  kKeyKPClearEntry = SDLK_KP_CLEARENTRY,
253  kKeyKPBinary = SDLK_KP_BINARY,
254  kKeyKPOctal = SDLK_KP_OCTAL,
255  kKeyKPDecimal = SDLK_KP_DECIMAL,
256  kKeyKPHexadecimal = SDLK_KP_HEXADECIMAL,
257 
258  kKeyLeftCtrl = SDLK_LCTRL,
259  kKeyLeftShift = SDLK_LSHIFT,
260  kKeyLeftAlt = SDLK_LALT,
261  kKeyLeftGui = SDLK_LGUI,
262  kKeyRightCtrl = SDLK_RCTRL,
263  kKeyRightShift = SDLK_RSHIFT,
264  kKeyRightAlt = SDLK_RALT,
265  kKeyRightGui = SDLK_RGUI,
266 
267  kKeyMode = SDLK_MODE,
268 
269  kKeyAudioNext = SDLK_AUDIONEXT,
270  kKeyAudioPrev = SDLK_AUDIOPREV,
271  kKeyAudioStop = SDLK_AUDIOSTOP,
272  kKeyAudioPlay = SDLK_AUDIOPLAY,
273  kKeyAudioMute = SDLK_AUDIOMUTE,
274  kKeyMediaSelect = SDLK_MEDIASELECT,
275  kKeyWWW = SDLK_WWW,
276  kKeyMail = SDLK_MAIL,
277  kKeyCalculator = SDLK_CALCULATOR,
278  kKeyComputer = SDLK_COMPUTER,
279  kKeyACSearch = SDLK_AC_SEARCH,
280  kKeyACHome = SDLK_AC_HOME,
281  kKeyACBack = SDLK_AC_BACK,
282  kKeyACForward = SDLK_AC_FORWARD,
283  kKeyACStop = SDLK_AC_STOP,
284  kKeyACRefresh = SDLK_AC_REFRESH,
285  kKeyACBookmarks = SDLK_AC_BOOKMARKS,
286 
287  kKeyBrightnessDown = SDLK_BRIGHTNESSDOWN,
288  kKeyBrightnessUp = SDLK_BRIGHTNESSUP,
289  kKeyDisplaySwitch = SDLK_DISPLAYSWITCH,
290  kKeyKbdIllUmToggle = SDLK_KBDILLUMTOGGLE,
291  kKeyKbdIllUmDown = SDLK_KBDILLUMDOWN,
292  kKeyKbdIllUmUp = SDLK_KBDILLUMUP,
293  kKeyEject = SDLK_EJECT,
294  kKeySleep = SDLK_SLEEP
295 };
296 
298 template<typename T> struct MainThreadFunctor {
299 private:
300  boost::function<T ()> func;
301  boost::shared_ptr<T> retVal;
302  boost::shared_ptr<Common::Exception> error;
303 
304 public:
305  MainThreadFunctor(const boost::function<T ()> &f) : func(f), retVal(new T), error(new Common::Exception) { }
306  void operator()() const {
307  try {
308  *retVal = func();
309  } catch (Common::Exception &e) {
310  *error = e;
311  } catch (std::exception &e) {
312  *error = Common::Exception(e);
313  } catch (...) {
314  *error = Common::Exception("Unknown exception thrown in MainThreadFunctor");
315  }
316  }
317 
318  T getReturnValue() const { return *retVal; }
319  const Common::Exception &getError() const { return *error; }
320 };
321 
323 template<> struct MainThreadFunctor<void> {
324 private:
325  boost::function<void ()> func;
326  boost::shared_ptr<Common::Exception> error;
327 
328 public:
329  MainThreadFunctor(const boost::function<void ()> &f) : func(f), error(new Common::Exception) { }
330  void operator()() const {
331  try {
332  func();
333  } catch (Common::Exception &e) {
334  *error = e;
335  } catch (std::exception &e) {
336  *error = Common::Exception(e);
337  } catch (...) {
338  *error = Common::Exception("Unknown exception thrown in MainThreadFunctor");
339  }
340  }
341 
342  void getReturnValue() const { (void) 0; }
343  const Common::Exception &getError() const { return *error; }
344 };
345 
346 typedef boost::function<void ()> MainThreadCallerFunctor;
347 
348 } // End of namespace Events
349 
350 #endif // EVENTS_TYPES_H
Request the rebuilding of a GL container.
Definition: types.h:73
For range checks.
Definition: types.h:55
Definition: 2dafile.h:39
#define START_IGNORE_IMPLICIT_FALLTHROUGH
Definition: fallthrough.h:79
const Common::Exception & getError() const
Definition: types.h:319
Inter-thread communication.
Definition: types.h:56
Text was written.
Definition: types.h:52
MainThreadFunctor(const boost::function< T()> &f)
Definition: types.h:305
MainThreadFunctor(const boost::function< void()> &f)
Definition: types.h:329
Mouse was moved.
Definition: types.h:48
Exception that provides a stack of explanations.
Definition: error.h:36
SDL_Event Event
Definition: types.h:42
Mouse button was pressed.
Definition: types.h:49
Keyboard key was pressed.
Definition: types.h:46
Mouse button was released.
Definition: types.h:50
boost::function< void()> func
Definition: types.h:325
Basic exceptions to throw.
Window&#39;s size was otherwise changed.
Definition: types.h:63
void operator()() const
Definition: types.h:306
boost::shared_ptr< T > retVal
Definition: types.h:301
boost::shared_ptr< Common::Exception > error
Definition: types.h:326
ITCEvent
Specific type of the inter-thread communication.
Definition: types.h:70
boost::function< T()> func
Definition: types.h:300
Window was minimized.
Definition: types.h:64
For range checks.
Definition: types.h:75
StackException Exception
Definition: error.h:59
boost::shared_ptr< Common::Exception > error
Definition: types.h:302
Request the destruction of a GL container.
Definition: types.h:74
Application quit was requested.
Definition: types.h:53
Window has been resized.
Definition: types.h:62
For range checks.
Definition: types.h:57
boost::function< void()> MainThreadCallerFunctor
Definition: types.h:346
#define STOP_IGNORE_IMPLICIT_FALLTHROUGH
Definition: fallthrough.h:80
Window was maximized.
Definition: types.h:65
EventType
Custom event types.
Definition: types.h:45
Key
Definition: types.h:78
Compiler-specific defines to mark an implicit switch-case fallthrough.
const Common::Exception & getError() const
Definition: types.h:343
EventWindowType
Sub events for kEventWindow.
Definition: types.h:61
T getReturnValue() const
Definition: types.h:318
Request to call a function in the main thread.
Definition: types.h:72
Window was restored.
Definition: types.h:66
Keyboard key was released.
Definition: types.h:47
A functor for a function that needs to be called in the main thread.
Definition: types.h:298
Resize the window.
Definition: types.h:54
Mouse wheel was used.
Definition: types.h:51
Request a sync, letting all prior requests finish.
Definition: types.h:71