added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / fxwt / fxwt.cpp
1 /*
2 This file is part of fxwt, the window system toolkit of 3dengfx.
3
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
5
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.
10
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.
15
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
19 */
20
21 /* main fxwt event handling and system abstraction.
22  *
23  * Author: John Tsiombikas 2004
24  * Modified:
25  *              John Tsiombikas 2005
26  */
27
28 #include <iostream>
29 #include <list>
30 #include <stdlib.h>
31 #include "3dengfx/3denginefx.hpp"
32 #include "common/err_msg.h"
33 #include "fxwt.hpp"
34 #include "text.hpp"
35 #include "gfx_library.h"
36
37 using std::list;
38
39 namespace fxwt {
40         list<void (*)()> disp_handlers;
41         list<void (*)()> idle_handlers;
42         list<void (*)(int)> keyb_handlers;
43         list<void (*)(int, int)> motion_handlers;
44         list<void (*)(int, int, int, int)> button_handlers;
45         
46         bool button_state[6];
47         int screenx, screeny;
48 }
49
50 using namespace fxwt;
51
52 void fxwt::init() {
53         fxwt::text_init();
54
55         const GraphicsInitParameters *gip = get_graphics_init_parameters();
56         screenx = gip->x;
57         screeny = gip->y;
58 }
59
60 void fxwt::set_display_handler(void (*handler)()) {
61         disp_handlers.push_back(handler);
62 }
63
64 void fxwt::set_idle_handler(void (*handler)()) {
65         idle_handlers.push_back(handler);
66 }
67
68 void fxwt::set_keyboard_handler(void (*handler)(int)) {
69         keyb_handlers.push_back(handler);
70 }
71
72 void fxwt::set_motion_handler(void (*handler)(int, int)) {
73         motion_handlers.push_back(handler);
74 }
75
76 void fxwt::set_button_handler(void (*handler)(int, int, int, int)) {
77         button_handlers.push_back(handler);
78 }
79
80 void fxwt::remove_display_handler(void (*handler)()) {
81         disp_handlers.remove(handler);
82 }
83
84 void fxwt::remove_idle_handler(void (*handler)()) {
85         idle_handlers.remove(handler);
86 }
87
88 void fxwt::remove_keyboard_handler(void (*handler)(int)) {
89         keyb_handlers.remove(handler);
90 }
91
92 void fxwt::remove_motion_handler(void (*handler)(int, int)) {
93         motion_handlers.remove(handler);
94 }
95
96 void fxwt::remove_button_handler(void (*handler)(int, int, int, int)) {
97         button_handlers.remove(handler);
98 }
99
100 bool fxwt::mouse_button_pressed(int bn) {
101         return button_state[bn];
102 }