2 This file is part of fxwt, the window system toolkit of 3dengfx.
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
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 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* main fxwt event handling and system abstraction.
23 * Author: John Tsiombikas 2004
24 * modified: Mihalis Georgoulopoulos 2006
27 #include "3dengfx_config.h"
29 #if GFX_LIBRARY == NATIVE && NATIVE_LIB == NATIVE_WIN32
31 #include "gfx_library.h"
33 #include "3dengfx/3denginefx.hpp"
34 #include "common/err_msg.h"
39 long CALLBACK fxwt_win32_handle_event(HWND__ *win, unsigned int msg, unsigned int wparam, long lparam);
40 static void button_event(int bn, bool state, int x, int y);
41 static int vkey_to_keysym(unsigned int vkey);
43 extern HWND__ *fxwt_win32_win;
44 extern HDC__ *fxwt_win32_dc;
46 Vector2 fxwt::get_mouse_pos_normalized() {
50 void fxwt::set_window_title(const char *title) {
51 SetWindowText(fxwt_win32_win, title);
54 void fxwt::swap_buffers() {
55 SwapBuffers(fxwt_win32_dc);
59 int fxwt::main_loop() {
63 if(!idle_handlers.empty()) {
65 while(PeekMessage(&event, 0, 0, 0, PM_REMOVE)) {
66 TranslateMessage(&event);
67 DispatchMessage(&event);
70 list<void (*)()>::iterator iter = idle_handlers.begin();
71 while(iter != idle_handlers.end()) {
76 if(!GetMessage(&event, 0, 0, 0)) break;
77 TranslateMessage(&event);
78 DispatchMessage(&event);
85 long CALLBACK fxwt_win32_handle_event(HWND__ *win, unsigned int msg, unsigned int wparam, long lparam) {
86 static int window_mapped;
99 list<void (*)()>::iterator iter = disp_handlers.begin();
100 while(iter != disp_handlers.end()) {
111 list<void (*)(int)>::iterator iter = keyb_handlers.begin();
112 while(iter != keyb_handlers.end()) {
113 (*iter++)(vkey_to_keysym(wparam));
120 list<void (*)(int)>::iterator iter = keyb_handlers.begin();
121 while(iter != keyb_handlers.end()) {
129 list<void (*)(int, int)>::iterator iter = motion_handlers.begin();
130 while(iter != motion_handlers.end()) {
131 (*iter++)(LOWORD(lparam), HIWORD(lparam));
138 int bn = HIWORD(wparam) > 0 ? BN_WHEELUP : BN_WHEELDOWN;
139 button_event(bn, true, LOWORD(lparam), HIWORD(lparam));
144 button_event(BN_LEFT, true, LOWORD(lparam), HIWORD(lparam));
148 button_event(BN_MIDDLE, true, LOWORD(lparam), HIWORD(lparam));
152 button_event(BN_RIGHT, true, LOWORD(lparam), HIWORD(lparam));
156 button_event(BN_LEFT, false, LOWORD(lparam), HIWORD(lparam));
160 button_event(BN_MIDDLE, false, LOWORD(lparam), HIWORD(lparam));
164 button_event(BN_RIGHT, false, LOWORD(lparam), HIWORD(lparam));
170 // DefWindowProc(win, msg, wparam, lparam);
173 return DefWindowProc(win, msg, wparam, lparam);
176 static void button_event(int bn, bool state, int x, int y) {
177 button_state[bn] = state;
178 list<void (*)(int, int, int, int)>::iterator iter = button_handlers.begin();
179 while(iter != button_handlers.end()) {
180 (*iter++)(bn, state, x, y);
185 static int win32_keysyms[] =
187 // 0 1 2 3 4 5 6 7 8 9
188 0, 0, 0, 0, 0, 0, 0, 0, 8, 9, // 000
189 0, 0, 12, 13, 0, 0, 304, 306, 0, 19, // 010
190 301, 0, 0, 0, 0, 0, 0, 27, 0, 0, // 020
191 0, 0, 0, 280, 281, 279, 278, 276, 273, 275, // 030
192 274, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 040
193 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 050
194 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 060
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 070
196 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 080
197 0, 311, 312, 0, 0, 0, 256, 257, 258, 259, // 090
198 260, 261, 262, 263, 264, 265, 268, 270, 0, 269, // 100
199 0, 267, 282, 283, 284, 285, 286, 287, 288, 289, // 110
200 290, 291, 292, 293, 294, 295, 296, 0, 127, 0, // 120
201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 130
202 0, 0, 0, 0, 300, 302, // 140
205 static int vkey_to_keysym(unsigned int vkey) {
206 if (vkey < 146) return win32_keysyms[vkey];
210 #endif // GFX_LIBRARY == NATIVE && NATIVE_LIB == NATIVE_WIN32