1 /*
2  * Tux Racer
3  * Copyright (C) 1999-2001 Jasmin F. Patry
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 #ifndef WINSYS_H
20 #define WINSYS_H 1
21 
22 #include "tuxracer.h"
23 #include "tux_types.h"
24 
25 #if defined( HAVE_SDL )
26 #   include "SDL.h"
27 #elif defined( HAVE_GLUT )
28 #   include "GL/glut.h"
29 #else
30 #   error "Neither SDL nor GLUT are present."
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 /* Keysyms */
39 
40 #if defined( HAVE_SDL )
41 /*---------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------*/
43 /* SDL version */
44 /*---------------------------------------------------------------------------*/
45 /*---------------------------------------------------------------------------*/
46 
47 typedef enum {
48     WSK_NOT_AVAIL = SDLK_UNKNOWN,
49 
50     /* Numeric keypad */
51     WSK_KP0 = SDLK_KP0,
52     WSK_KP1 = SDLK_KP1,
53     WSK_KP2 = SDLK_KP2,
54     WSK_KP3 = SDLK_KP3,
55     WSK_KP4 = SDLK_KP4,
56     WSK_KP5 = SDLK_KP5,
57     WSK_KP6 = SDLK_KP6,
58     WSK_KP7 = SDLK_KP7,
59     WSK_KP8 = SDLK_KP8,
60     WSK_KP9 = SDLK_KP9,
61     WSK_KP_PERIOD = SDLK_KP_PERIOD,
62     WSK_KP_DIVIDE = SDLK_KP_DIVIDE,
63     WSK_KP_MULTIPLY = SDLK_KP_MULTIPLY,
64     WSK_KP_MINUS = SDLK_KP_MINUS,
65     WSK_KP_PLUS = SDLK_KP_PLUS,
66     WSK_KP_ENTER = SDLK_KP_ENTER,
67     WSK_KP_EQUALS = SDLK_KP_EQUALS,
68 
69     /* Arrows + Home/End pad */
70     WSK_UP = SDLK_UP,
71     WSK_DOWN = SDLK_DOWN,
72     WSK_RIGHT = SDLK_RIGHT,
73     WSK_LEFT = SDLK_LEFT,
74     WSK_INSERT = SDLK_INSERT,
75     WSK_HOME = SDLK_HOME,
76     WSK_END = SDLK_END,
77     WSK_PAGEUP = SDLK_PAGEUP,
78     WSK_PAGEDOWN = SDLK_PAGEDOWN,
79 
80     /* Function keys */
81     WSK_F1 = SDLK_F1,
82     WSK_F2 = SDLK_F2,
83     WSK_F3 = SDLK_F3,
84     WSK_F4 = SDLK_F4,
85     WSK_F5 = SDLK_F5,
86     WSK_F6 = SDLK_F6,
87     WSK_F7 = SDLK_F7,
88     WSK_F8 = SDLK_F8,
89     WSK_F9 = SDLK_F9,
90     WSK_F10 = SDLK_F10,
91     WSK_F11 = SDLK_F11,
92     WSK_F12 = SDLK_F12,
93     WSK_F13 = SDLK_F13,
94     WSK_F14 = SDLK_F14,
95     WSK_F15 = SDLK_F15,
96 
97     /* Key state modifier keys */
98     WSK_NUMLOCK = SDLK_NUMLOCK,
99     WSK_CAPSLOCK = SDLK_CAPSLOCK,
100     WSK_SCROLLOCK = SDLK_SCROLLOCK,
101     WSK_RSHIFT = SDLK_RSHIFT,
102     WSK_LSHIFT = SDLK_LSHIFT,
103     WSK_RCTRL = SDLK_RCTRL,
104     WSK_LCTRL = SDLK_LCTRL,
105     WSK_RALT = SDLK_RALT,
106     WSK_LALT = SDLK_LALT,
107     WSK_RMETA = SDLK_RMETA,
108     WSK_LMETA = SDLK_LMETA,
109 
110     WSK_LAST
111 
112 } winsys_keysym_t;
113 
114 typedef enum {
115     WS_LEFT_BUTTON = SDL_BUTTON_LEFT,
116     WS_MIDDLE_BUTTON = SDL_BUTTON_MIDDLE,
117     WS_RIGHT_BUTTON = SDL_BUTTON_RIGHT
118 } winsys_mouse_button_t;
119 
120 typedef enum {
121     WS_MOUSE_DOWN = SDL_PRESSED,
122     WS_MOUSE_UP = SDL_RELEASED
123 } winsys_button_state_t;
124 
125 #else
126 /*---------------------------------------------------------------------------*/
127 /*---------------------------------------------------------------------------*/
128 /* GLUT version */
129 /*---------------------------------------------------------------------------*/
130 /*---------------------------------------------------------------------------*/
131 
132 /* GLUT doesn't define as many keysyms as SDL; we map those to
133    WSK_NOT_AVAIL (0) */
134 
135 typedef enum {
136     WSK_NOT_AVAIL = 0,
137 
138     /* Numeric keypad */
139     WSK_KP0 = 0,
140     WSK_KP1 = 0,
141     WSK_KP2 = 0,
142     WSK_KP3 = 0,
143     WSK_KP4 = 0,
144     WSK_KP5 = 0,
145     WSK_KP6 = 0,
146     WSK_KP7 = 0,
147     WSK_KP8 = 0,
148     WSK_KP9 = 0,
149     WSK_KP_PERIOD = 0,
150     WSK_KP_DIVIDE = 0,
151     WSK_KP_MULTIPLY = 0,
152     WSK_KP_MINUS = 0,
153     WSK_KP_PLUS = 0,
154     WSK_KP_ENTER = 0,
155     WSK_KP_EQUALS = 0,
156 
157     /* Arrows + Home/End pad */
158     WSK_UP = GLUT_KEY_UP,
159     WSK_DOWN = GLUT_KEY_DOWN,
160     WSK_RIGHT = GLUT_KEY_RIGHT,
161     WSK_LEFT = GLUT_KEY_LEFT,
162     WSK_INSERT = GLUT_KEY_INSERT,
163     WSK_HOME = GLUT_KEY_HOME,
164     WSK_END = GLUT_KEY_END,
165     WSK_PAGEUP = GLUT_KEY_PAGE_UP,
166     WSK_PAGEDOWN = GLUT_KEY_PAGE_DOWN,
167 
168     /* Function keys */
169     WSK_F1 = GLUT_KEY_F1,
170     WSK_F2 = GLUT_KEY_F2,
171     WSK_F3 = GLUT_KEY_F3,
172     WSK_F4 = GLUT_KEY_F4,
173     WSK_F5 = GLUT_KEY_F5,
174     WSK_F6 = GLUT_KEY_F6,
175     WSK_F7 = GLUT_KEY_F7,
176     WSK_F8 = GLUT_KEY_F8,
177     WSK_F9 = GLUT_KEY_F9,
178     WSK_F10 = GLUT_KEY_F10,
179     WSK_F11 = GLUT_KEY_F11,
180     WSK_F12 = GLUT_KEY_F12,
181     WSK_F13 = 0,
182     WSK_F14 = 0,
183     WSK_F15 = 0,
184 
185     /* Key state modifier keys */
186     WSK_NUMLOCK = 0,
187     WSK_CAPSLOCK = 0,
188     WSK_SCROLLOCK = 0,
189     WSK_RSHIFT = 0,
190     WSK_LSHIFT = 0,
191     WSK_RCTRL = 0,
192     WSK_LCTRL = 0,
193     WSK_RALT = 0,
194     WSK_LALT = 0,
195     WSK_RMETA = 0,
196     WSK_LMETA = 0,
197 
198     WSK_LAST = UCHAR_MAX /* GLUT doesn't define a max key, but this is more
199 			    than enough as of version 3.7 */
200 } winsys_keysym_t;
201 
202 typedef enum {
203     WS_LEFT_BUTTON = GLUT_LEFT_BUTTON,
204     WS_MIDDLE_BUTTON = GLUT_MIDDLE_BUTTON,
205     WS_RIGHT_BUTTON = GLUT_RIGHT_BUTTON
206 } winsys_mouse_button_t;
207 
208 typedef enum {
209     WS_MOUSE_DOWN = GLUT_DOWN,
210     WS_MOUSE_UP = GLUT_UP
211 } winsys_button_state_t;
212 
213 #endif /* defined( HAVE_SDL ) */
214 
215 
216 typedef void (*winsys_display_func_t)();
217 typedef void (*winsys_idle_func_t)();
218 typedef void (*winsys_reshape_func_t)( int w, int h );
219 typedef void (*winsys_keyboard_func_t)( unsigned int key, bool_t special,
220 					bool_t release, int x, int y );
221 typedef void (*winsys_mouse_func_t)( int button, int state, int x, int y );
222 typedef void (*winsys_motion_func_t)( int x, int y );
223 
224 typedef void (*winsys_atexit_func_t)( void );
225 
226 void winsys_post_redisplay();
227 void winsys_set_display_func( winsys_display_func_t func );
228 void winsys_set_idle_func( winsys_idle_func_t func );
229 void winsys_set_reshape_func( winsys_reshape_func_t func );
230 void winsys_set_keyboard_func( winsys_keyboard_func_t func );
231 void winsys_set_mouse_func( winsys_mouse_func_t func );
232 void winsys_set_motion_func( winsys_motion_func_t func );
233 void winsys_set_passive_motion_func( winsys_motion_func_t func );
234 
235 void winsys_swap_buffers();
236 void winsys_enable_key_repeat( bool_t enabled );
237 void winsys_warp_pointer( int x, int y );
238 void winsys_show_cursor( bool_t visible );
239 
240 void winsys_init( int *argc, char **argv, char *window_title,
241 		  char *icon_title );
242 void winsys_shutdown();
243 
244 void winsys_process_events(); /* Never returns */
245 
246 void winsys_atexit( winsys_atexit_func_t func );
247 
248 void winsys_exit( int code );
249 
250 #ifdef __cplusplus
251 } /* extern "C" */
252 #endif
253 
254 #endif /* WINSYS_H */
255 
256 /* Emacs Customizations
257 ;;; Local Variables: ***
258 ;;; c-basic-offset:0 ***
259 ;;; End: ***
260 */
261 
262 /* EOF */
263