OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Window.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 /* A wrapper class to OS dependent event and window interfaces */
18 
19 #ifndef INC_STDWINDOW
20 #define INC_STDWINDOW
21 
23 #include "lib/StdBuf.h"
24 
25 #if defined(USE_SDL_MAINLOOP)
26 #include <SDL.h>
27 #define MK_SHIFT (KMOD_LSHIFT | KMOD_RSHIFT)
28 #define MK_CONTROL (KMOD_LCTRL | KMOD_RCTRL)
29 #define MK_ALT (KMOD_LALT | KMOD_RALT)
30 #elif defined(USE_CONSOLE)
31 #ifndef _WIN32
32 #define MK_SHIFT 0
33 #define MK_CONTROL 0
34 #endif
35 #define MK_ALT 0
36 #elif defined(USE_COCOA)
37 // declare as extern variables and initialize them in StdMacWindow.mm so as to not include objc headers
38 extern int MK_SHIFT;
39 extern int MK_CONTROL;
40 extern int MK_ALT;
41 #elif defined(USE_WIN32_WINDOWS)
43 #ifndef MK_ALT
44 #define MK_ALT 0x20 // as defined in oleidl.h
45 #endif
46 #endif
47 
48 #ifdef USE_SDL_MAINLOOP
49 #include <SDL.h>
50 #endif
51 
52 #if defined(USE_WIN32_WINDOWS) || defined(USE_CONSOLE) || defined(USE_SDL_MAINLOOP)
53 #define K_ESCAPE 1
54 #define K_1 2
55 #define K_2 3
56 #define K_3 4
57 #define K_4 5
58 #define K_5 6
59 #define K_6 7
60 #define K_7 8
61 #define K_8 9
62 #define K_9 10
63 #define K_0 11
64 #define K_MINUS 12
65 #define K_EQUAL 13
66 #define K_BACK 14
67 #define K_TAB 15
68 #define K_Q 16
69 #define K_W 17
70 #define K_E 18
71 #define K_R 19
72 #define K_T 20
73 #define K_Y 21
74 #define K_U 22
75 #define K_I 23
76 #define K_O 24
77 #define K_P 25
78 #define K_LEFT_BRACKET 26
79 #define K_RIGHT_BRACKET 27
80 #define K_RETURN 28
81 #define K_CONTROL_L 29
82 #define K_A 30
83 #define K_S 31
84 #define K_D 32
85 #define K_F 33
86 #define K_G 34
87 #define K_H 35
88 #define K_J 36
89 #define K_K 37
90 #define K_L 38
91 #define K_SEMICOLON 39
92 #define K_APOSTROPHE 40
93 #define K_GRAVE_ACCENT 41
94 #define K_SHIFT_L 42
95 #define K_BACKSLASH 43
96 #define K_Z 44
97 #define K_X 45
98 #define K_C 46
99 #define K_V 47
100 #define K_B 48
101 #define K_N 49
102 #define K_M 50
103 #define K_COMMA 51
104 #define K_PERIOD 52
105 #define K_SLASH 53
106 #define K_SHIFT_R 54
107 #define K_MULTIPLY 55
108 #define K_ALT_L 56
109 #define K_SPACE 57
110 #define K_CAPS 58
111 #define K_F1 59
112 #define K_F2 60
113 #define K_F3 61
114 #define K_F4 62
115 #define K_F5 63
116 #define K_F6 64
117 #define K_F7 65
118 #define K_F8 66
119 #define K_F9 67
120 #define K_F10 68
121 #define K_NUM 69
122 #define K_SCROLL 70
123 #define K_SUBTRACT 74
124 #define K_ADD 78
125 #define K_86 86
126 #define K_F11 87
127 #define K_F12 88
128 
129 /*
130 // starting from here, scancodes between windows and linux differ
131 // this is not used because the windows scancodes are converted to
132 // unix scancodes in C4WindowWin32.cpp ConvertToUnixScancode
133 #if defined(USE_WIN32_WINDOWS)
134 #define K_HOME 71
135 #define K_UP 72
136 #define K_PAGEUP 73
137 #define K_LEFT 75
138 #define K_CENTER 76
139 #define K_RIGHT 77
140 #define K_END 79
141 #define K_DOWN 80
142 #define K_PAGEDOWN 81
143 #define K_INSERT 82
144 #define K_DELETE 83
145 #define K_WIN_L 91
146 #define K_WIN_R 92
147 #define K_MENU 93
148 #define K_PAUSE 69 // same as numlock?!
149 #define K_PRINT 55 // same as multiply?!
150 #define K_ALT_R K_ALT_L // 29 56
151 #define K_CONTROL_R K_CONTROL_L // 29 29
152 #define K_NUM_RETURN K_RETURN // 28 57
153 #define K_NUM7 K_HOME
154 #define K_NUM8 K_UP
155 #define K_NUM9 K_PAGEUP
156 #define K_NUM4 K_LEFT
157 #define K_NUM5 K_CENTER
158 #define K_NUM6 K_RIGHT
159 #define K_NUM1 K_END
160 #define K_NUM2 K_DOWN
161 #define K_NUM3 K_PAGEDOWN
162 #define K_NUM0 K_INSERT
163 #define K_DECIMAL K_DELETE
164 #define K_DIVIDE K_SLASH
165 #elif defined(USE_X11) || defined(USE_CONSOLE)
166 */
167 #define K_NUM7 71
168 #define K_NUM8 72
169 #define K_NUM9 73
170 #define K_NUM4 75
171 #define K_NUM5 76
172 #define K_NUM6 77
173 #define K_NUM1 79
174 #define K_NUM2 80
175 #define K_NUM3 81
176 #define K_NUM0 82
177 #define K_DECIMAL 83
178 #define K_DIVIDE 98
179 
180 #define K_ALT_R 100
181 #define K_CONTROL_R 97
182 #define K_NUM_RETURN 96
183 
184 #define K_HOME 102
185 #define K_UP 103
186 #define K_PAGEUP 104
187 #define K_LEFT 105
188 #define K_RIGHT 106
189 #define K_END 107
190 #define K_DOWN 108
191 #define K_PAGEDOWN 109
192 #define K_INSERT 110
193 #define K_DELETE 111
194 #define K_WIN_L 125
195 #define K_WIN_R 126
196 #define K_MENU 127
197 #define K_PAUSE 119
198 #define K_PRINT 99
199 #define K_CENTER 76
200 
201 #elif defined(USE_COCOA)
203 // FIXME
204 // declare as extern variables and initialize them in StdMacWindow.mm so as to not include objc headers
205 const int CocoaKeycodeOffset = 300;
206 extern C4KeyCode K_SHIFT_L;
207 extern C4KeyCode K_SHIFT_R;
208 extern C4KeyCode K_CONTROL_L;
209 extern C4KeyCode K_CONTROL_R;
210 extern C4KeyCode K_ALT_L;
211 extern C4KeyCode K_ALT_R;
212 extern C4KeyCode K_COMMAND_L;
213 extern C4KeyCode K_COMMAND_R;
214 extern C4KeyCode K_F1;
215 extern C4KeyCode K_F2;
216 extern C4KeyCode K_F3;
217 extern C4KeyCode K_F4;
218 extern C4KeyCode K_F5;
219 extern C4KeyCode K_F6;
220 extern C4KeyCode K_F7;
221 extern C4KeyCode K_F8;
222 extern C4KeyCode K_F9;
223 extern C4KeyCode K_F10;
224 extern C4KeyCode K_F11;
225 extern C4KeyCode K_F12;
226 extern C4KeyCode K_ADD;
227 extern C4KeyCode K_SUBTRACT;
228 extern C4KeyCode K_MULTIPLY;
229 extern C4KeyCode K_ESCAPE;
230 extern C4KeyCode K_PAUSE;
231 extern C4KeyCode K_TAB;
232 extern C4KeyCode K_RETURN;
233 extern C4KeyCode K_DELETE;
234 extern C4KeyCode K_INSERT;
235 extern C4KeyCode K_BACK;
236 extern C4KeyCode K_SPACE;
237 extern C4KeyCode K_UP;
238 extern C4KeyCode K_DOWN;
239 extern C4KeyCode K_LEFT;
240 extern C4KeyCode K_RIGHT;
241 extern C4KeyCode K_HOME;
242 extern C4KeyCode K_END;
243 extern C4KeyCode K_SCROLL;
244 extern C4KeyCode K_MENU;
245 extern C4KeyCode K_PAGEUP;
246 extern C4KeyCode K_PAGEDOWN;
247 extern C4KeyCode K_M;
248 extern C4KeyCode K_T;
249 extern C4KeyCode K_W;
250 extern C4KeyCode K_I;
251 extern C4KeyCode K_C;
252 extern C4KeyCode K_V;
253 extern C4KeyCode K_X;
254 extern C4KeyCode K_A;
255 extern C4KeyCode K_NUM;
256 extern C4KeyCode K_PRINT;
257 extern C4KeyCode K_CENTER;
258 #endif
259 
260 
261 class C4Window
262 #ifdef USE_COCOA
263  : public ObjectiveCAssociated
264 #endif
265 {
266 public:
268  {
273  W_Control // wrapper to a render target control inside a window
274  };
275 public:
276  C4Window ();
277  virtual ~C4Window ();
278  bool Active;
281  virtual void Clear();
282  // Only when the wm requests a close
283  // For example, when the user clicks the little x in the corner or uses Alt-F4
284  virtual void Close() = 0;
285  // Keypress(es) translated to a char
286  virtual void CharIn(const char *) { }
287 
288  // Reinitialize the window with updated configuration settings.
289  // Keep window kind, title and size as they are. Currently the only point
290  // at which it makes sense for this function to be called is when the
291  // multisampling configuration option changes, since, for the change to
292  // take effect, we need to choose another visual or pixel format, respectively.
293  virtual bool ReInit(C4AbstractApp* pApp);
294 
295  // Creates a list of available samples for multisampling
296  virtual void EnumerateMultiSamples(std::vector<int>& samples) const;
297 
298  bool StorePosition(const char *szWindowName, const char *szSubKey, bool fStoreSize = true);
299  bool RestorePosition(const char *szWindowName, const char *szSubKey, bool fHidden = false);
300  bool GetSize(C4Rect * pRect);
301  void SetSize(unsigned int cx, unsigned int cy); // resize
302  void SetTitle(const char * Title);
303  void FlashWindow();
304  void GrabMouse(bool grab);
305  // request that this window be redrawn in the near future (including immediately)
306  virtual void RequestUpdate();
307  // Invokes actual drawing code - should not be called directly
308  virtual void PerformUpdate();
309 
310 public:
311 #if defined(USE_WIN32_WINDOWS)
312  HWND hWindow;
313  virtual bool Win32DialogMessageHandling(MSG * msg) { return false; };
314 #elif defined(USE_SDL_MAINLOOP)
315  SDL_Window * window;
316  void HandleSDLEvent(SDL_WindowEvent &e);
317 #endif
318 #ifdef USE_WGL
319  HWND renderwnd;
320 #endif
321 #ifdef WITH_QT_EDITOR
322  class QOpenGLWidget *glwidget;
323 #endif
324 protected:
325  virtual C4Window * Init(WindowKind windowKind, C4AbstractApp * pApp, const char * Title, const C4Rect * size);
326  friend class C4Draw;
327  friend class CStdGL;
328  friend class CStdGLCtx;
329  friend class C4AbstractApp;
330 };
331 
332 #endif // INC_STDWINDOW
bool StorePosition(const char *szWindowName, const char *szSubKey, bool fStoreSize=true)
void GrabMouse(bool grab)
Definition: C4AppT.cpp:105
bool GetSize(C4Rect *pRect)
Definition: C4AppT.cpp:106
void FlashWindow()
Definition: C4AppMac.mm:75
C4Surface * pSurface
Definition: C4Window.h:279
void SetTitle(const char *Title)
Definition: C4AppT.cpp:112
Definition: C4Rect.h:29
virtual void EnumerateMultiSamples(std::vector< int > &samples) const
Definition: C4AppT.cpp:103
virtual void PerformUpdate()
Definition: C4App.cpp:85
virtual bool ReInit(C4AbstractApp *pApp)
Definition: C4AppT.cpp:108
void SetSize(unsigned int cx, unsigned int cy)
Definition: C4AppT.cpp:111
virtual ~C4Window()
Definition: C4AppT.cpp:102
virtual void CharIn(const char *)
Definition: C4Window.h:286
WindowKind eKind
Definition: C4Window.h:280
bool RestorePosition(const char *szWindowName, const char *szSubKey, bool fHidden=false)
Definition: C4AppT.cpp:109
virtual void RequestUpdate()
Definition: C4AppT.cpp:110
bool Active
Definition: C4Window.h:278
virtual C4Window * Init(WindowKind windowKind, C4AbstractApp *pApp, const char *Title, const C4Rect *size)
Definition: C4AppT.cpp:107
virtual void Close()=0
virtual void Clear()
Definition: C4AppT.cpp:100
Definition: C4Draw.h:84
unsigned long C4KeyCode
C4Window()
Definition: C4AppT.cpp:101