1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
21 #define _WM_EXPOSE_ALL
28 int w32_key_to_sym(sym_t
*s
, uint32_t key
)
37 s
->type
= SYM_TYPE_MOD
;
38 s
->sym
= SYM_MOD_SHIFT
;
42 s
->type
= SYM_TYPE_MOD
;
43 s
->sym
= SYM_MOD_CTRL
;
45 case VK_MENU
: /* alt */
46 s
->type
= SYM_TYPE_MOD
;
51 s
->type
= SYM_TYPE_MOD
;
52 s
->sym
= SYM_MOD_SUPER
;
55 s
->type
= SYM_TYPE_SKEY
;
56 s
->sym
= SYM_KEY_SPACE
;
59 s
->type
= SYM_TYPE_SKEY
;
60 s
->sym
= SYM_KEY_ESCAPE
;
63 s
->type
= SYM_TYPE_SKEY
;
67 s
->type
= SYM_TYPE_SKEY
;
71 s
->type
= SYM_TYPE_SKEY
;
75 s
->type
= SYM_TYPE_SKEY
;
79 s
->type
= SYM_TYPE_SKEY
;
83 s
->type
= SYM_TYPE_SKEY
;
87 s
->type
= SYM_TYPE_SKEY
;
91 s
->type
= SYM_TYPE_SKEY
;
95 s
->type
= SYM_TYPE_SKEY
;
99 s
->type
= SYM_TYPE_SKEY
;
100 s
->sym
= SYM_KEY_KP8
;
103 s
->type
= SYM_TYPE_SKEY
;
104 s
->sym
= SYM_KEY_KP9
;
107 s
->type
= SYM_TYPE_SKEY
;
108 s
->sym
= SYM_KEY_LEFT
;
111 s
->type
= SYM_TYPE_SKEY
;
115 s
->type
= SYM_TYPE_SKEY
;
116 s
->sym
= SYM_KEY_RIGHT
;
119 s
->type
= SYM_TYPE_SKEY
;
120 s
->sym
= SYM_KEY_DOWN
;
123 s
->type
= SYM_TYPE_SKEY
;
127 s
->type
= SYM_TYPE_SKEY
;
131 s
->type
= SYM_TYPE_SKEY
;
135 s
->type
= SYM_TYPE_SKEY
;
139 s
->type
= SYM_TYPE_SKEY
;
143 s
->type
= SYM_TYPE_SKEY
;
147 s
->type
= SYM_TYPE_SKEY
;
151 s
->type
= SYM_TYPE_SKEY
;
155 s
->type
= SYM_TYPE_SKEY
;
159 s
->type
= SYM_TYPE_SKEY
;
160 s
->sym
= SYM_KEY_F10
;
163 s
->type
= SYM_TYPE_SKEY
;
164 s
->sym
= SYM_KEY_F11
;
167 s
->type
= SYM_TYPE_SKEY
;
168 s
->sym
= SYM_KEY_F12
;
171 s
->type
= SYM_TYPE_SKEY
;
172 s
->sym
= SYM_KEY_BCKSPC
;
175 s
->type
= SYM_TYPE_SKEY
;
176 s
->sym
= SYM_KEY_RETURN
;
179 s
->type
= SYM_TYPE_SKEY
;
180 s
->sym
= SYM_KEY_DELETE
;
183 s
->type
= SYM_TYPE_SKEY
;
184 s
->sym
= SYM_KEY_KPMUL
;
187 s
->type
= SYM_TYPE_SKEY
;
188 s
->sym
= SYM_KEY_KPADD
;
191 s
->type
= SYM_TYPE_SKEY
;
192 s
->sym
= SYM_KEY_KPSUB
;
195 s
->type
= SYM_TYPE_SKEY
;
196 s
->sym
= SYM_KEY_KPDOT
;
199 s
->type
= SYM_TYPE_SKEY
;
200 s
->sym
= SYM_KEY_KPDIV
;
219 wc
= MapVirtualKey(key
,2);
223 s
->sym
= utf16_toutf32(str
);
224 if (!iswgraph(s
->sym
))
233 /* oh god w32, wtf */
234 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
240 e
.sym
.type
= SYM_TYPE_NONE
;
251 case SC_MONITORPOWER
:
261 /* this should put the character created by the key into e.sym.ch,
262 * and either the unmodified (ignore shift, etc) character, or special value into e.sym.sym */
263 e
.type
= EVENT_KEY_DOWN
;
264 GetKeyboardState(ks
);
265 if (ToUnicode(wParam
, MapVirtualKey(wParam
,0), ks
, (LPWSTR
)buff
, 5, 0) > 0)
266 e
.ch
= utf16_toutf32(buff
);
267 w32_key_to_sym(&e
.sym
,wParam
);
274 /* this should put the unmodified (ignore shift, etc) character, or special value into e.sym.sym */
275 e
.type
= EVENT_KEY_UP
;
276 w32_key_to_sym(&e
.sym
,wParam
);
283 wm_data
.size
.width
= LOWORD(lParam
);
284 wm_data
.size
.height
= HIWORD(lParam
);
289 e
.type
= EVENT_BUTTON_DOWN
;
290 e
.sym
.type
= SYM_TYPE_MOUSE
;
291 e
.sym
.sym
= MOUSE_BUTTON_LEFT
;
297 e
.type
= EVENT_BUTTON_UP
;
298 e
.sym
.type
= SYM_TYPE_MOUSE
;
299 e
.sym
.sym
= MOUSE_BUTTON_LEFT
;
305 e
.type
= EVENT_BUTTON_DOWN
;
306 e
.sym
.type
= SYM_TYPE_MOUSE
;
307 e
.sym
.sym
= MOUSE_BUTTON_CENTRE
;
313 e
.type
= EVENT_BUTTON_UP
;
314 e
.sym
.type
= SYM_TYPE_MOUSE
;
315 e
.sym
.sym
= MOUSE_BUTTON_CENTRE
;
321 e
.type
= EVENT_BUTTON_DOWN
;
322 e
.sym
.type
= SYM_TYPE_MOUSE
;
323 e
.sym
.sym
= MOUSE_BUTTON_RIGHT
;
329 e
.type
= EVENT_BUTTON_UP
;
330 e
.sym
.type
= SYM_TYPE_MOUSE
;
331 e
.sym
.sym
= MOUSE_BUTTON_RIGHT
;
337 e
.type
= EVENT_MOUSE_MOTION
;
338 e
.x
= LOWORD(lParam
);
339 e
.y
= HIWORD(lParam
);
345 e
.type
= EVENT_BUTTON_DOWN
;
346 e
.sym
.type
= SYM_TYPE_MOUSE
;
347 if (wParam
== VK_XBUTTON1
) {
348 e
.sym
.sym
= MOUSE_BUTTON_UP
;
350 }else if (wParam
== VK_XBUTTON2
) {
351 e
.sym
.sym
= MOUSE_BUTTON_DOWN
;
358 /* pass unhandled messages to DefWindowProc */
359 return DefWindowProc(hWnd
,uMsg
,wParam
,lParam
);
363 /* read and act on events */
367 while (PeekMessage(&msg
,NULL
,0,0,PM_REMOVE
)) {
368 if (msg
.message
== WM_QUIT
) {
369 client_state(VLSTATE_EXIT
);
371 TranslateMessage(&msg
);
372 DispatchMessage(&msg
);
375 events_trigger_active();