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 window system abstraction through SDL.
23 * Author: John Tsiombikas 2004
26 #include "3dengfx_config.h"
28 #if GFX_LIBRARY == SDL
30 #include "gfx_library.h"
32 #include "3dengfx/3denginefx.hpp"
33 #include "common/err_msg.h"
37 #ifdef _POSIX_PRIORITY_SCHEDULING
39 #endif // _POSIX_PRIORITY_SCHEDULING
49 static void handle_event(const SDL_Event &event);
51 Vector2 fxwt::get_mouse_pos_normalized() {
53 SDL_GetMouseState(&x, &y);
55 return Vector2((scalar_t)x / (scalar_t)screenx, (scalar_t)y / (scalar_t)screeny);
58 void fxwt::set_window_title(const char *title) {
59 SDL_WM_SetCaption(title, 0);
62 void fxwt::swap_buffers() {
64 #if defined(_POSIX_PRIORITY_SCHEDULING)
71 int fxwt::main_loop() {
74 SDL_EnableKeyRepeat(300, 20);
79 if(!idle_handlers.empty()) {
80 while(SDL_PollEvent(&event)) {
84 list<void (*)()>::iterator iter = idle_handlers.begin();
85 while(iter != idle_handlers.end()) {
89 SDL_WaitEvent(&event);
97 static void handle_event(const SDL_Event &event) {
101 list<void (*)(int)>::iterator iter = keyb_handlers.begin();
102 while(iter != keyb_handlers.end()) {
103 (*iter++)(event.key.keysym.sym);
108 case SDL_VIDEOEXPOSE:
110 list<void (*)()>::iterator iter = disp_handlers.begin();
111 while(iter != disp_handlers.end()) {
117 case SDL_MOUSEMOTION:
119 list<void (*)(int, int)>::iterator iter = motion_handlers.begin();
120 while(iter != motion_handlers.end()) {
121 (*iter++)(event.motion.x, event.motion.y);
126 case SDL_MOUSEBUTTONDOWN:
127 case SDL_MOUSEBUTTONUP:
129 button_state[event.button.button] = event.button.state;
130 list<void (*)(int, int, int, int)>::iterator iter = button_handlers.begin();
131 while(iter != button_handlers.end()) {
132 (*iter++)(event.button.button, event.button.state == SDL_PRESSED, event.button.x, event.button.y);
146 #endif // GFX_LIBRARY == SDL