1 
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <sys/time.h>
5 #include "doomdef.h"
6 
7 #include <SDL.h>
8 
9 #include "gl_struct.h"
10 
11 extern long do_grabMouse;
12 
13 static int      lastmousex = 0;
14 static int      lastmousey = 0;
15 
16 /* Public Data */
17 
18 
19 /*
20  *--------------------------------------------------------------------------
21  *
22  * PROC I_SetPalette
23  *
24  * Palette source must use 8 bit RGB elements.
25  *
26  *--------------------------------------------------------------------------
27  */
28 
I_SetPalette(byte * palette)29 void I_SetPalette(byte *palette)
30 {
31   /* dummy in OGL Mode */
32 }
33 
34 /*
35 ============================================================================
36 
37 							GRAPHICS MODE
38 
39 ============================================================================
40 */
41 
42 byte *destview;
43 
44 /*
45 ==============
46 =
47 = I_Update
48 =
49 ==============
50 */
51 
52 int UpdateState;
53 extern int screenblocks;
54 
I_FinishUpdate(void)55 void I_FinishUpdate (void)
56 {
57   GL_Finish();
58 }
59 
InitGraphLib(void)60 void InitGraphLib(void) {
61   /* is not needed */
62 }
63 
64 /*
65  *--------------------------------------------------------------------------
66  *
67  * PROC I_InitGraphics
68  *
69  *--------------------------------------------------------------------------
70  */
71 
I_InitGraphics(void)72 void I_InitGraphics(void) {
73   /* check if the user wants to grab the mouse (quite unnice) */
74   if ( !do_grabMouse && M_CheckParm("-grabmouse"))
75   	do_grabMouse = 1;
76 
77   I_GL_InitGraphics();
78 }
79 
80 /*
81  *--------------------------------------------------------------------------
82  *
83  * PROC I_ShutdownGraphics
84  *
85  *--------------------------------------------------------------------------
86  */
87 
I_ShutdownGraphics(void)88 void I_ShutdownGraphics(void)
89 {
90   /* Destroy our GL context, etc. */
91   SDL_Quit();
92 }
93 
I_CheckRes()94 void I_CheckRes()
95 {
96   /* nothing to do... */
97 }
98 
99 /*
100  *  Translates the key
101  */
102 
xlatekey(SDL_keysym * key)103 int xlatekey(SDL_keysym *key)
104 {
105   int rc;
106 
107   switch(key->sym)
108     {
109     case SDLK_LEFT:	rc = KEY_LEFTARROW;	break;
110     case SDLK_RIGHT:	rc = KEY_RIGHTARROW;	break;
111     case SDLK_DOWN:	rc = KEY_DOWNARROW;	break;
112     case SDLK_UP:	rc = KEY_UPARROW;	break;
113     case SDLK_ESCAPE:	rc = KEY_ESCAPE;	break;
114     case SDLK_RETURN:	rc = KEY_ENTER;		break;
115     case SDLK_F1:	rc = KEY_F1;		break;
116     case SDLK_F2:	rc = KEY_F2;		break;
117     case SDLK_F3:	rc = KEY_F3;		break;
118     case SDLK_F4:	rc = KEY_F4;		break;
119     case SDLK_F5:	rc = KEY_F5;		break;
120     case SDLK_F6:	rc = KEY_F6;		break;
121     case SDLK_F7:	rc = KEY_F7;		break;
122     case SDLK_F8:	rc = KEY_F8;		break;
123     case SDLK_F9:	rc = KEY_F9;		break;
124     case SDLK_F10:	rc = KEY_F10;		break;
125     case SDLK_F11:	rc = KEY_F11;		break;
126     case SDLK_F12:	rc = KEY_F12;		break;
127 
128     case SDLK_INSERT: rc = KEY_INSERT;           break;
129     case SDLK_DELETE: rc = KEY_DELETE;           break;
130     case SDLK_PAGEUP: rc = KEY_PAGEUP;          break;
131     case SDLK_PAGEDOWN: rc = KEY_PAGEDOWN;        break;
132     case SDLK_HOME:   rc = KEY_HOME;          break;
133     case SDLK_END:    rc = KEY_END;           break;
134 
135     case SDLK_BACKSPACE: rc = KEY_BACKSPACE;	break;
136 
137     case SDLK_PAUSE:	rc = KEY_PAUSE;		break;
138 
139     case SDLK_EQUALS:	rc = KEY_EQUALS;	break;
140 
141     case SDLK_KP_MINUS:
142     case SDLK_MINUS:	rc = KEY_MINUS;		break;
143 
144     case SDLK_KP_PLUS:
145     case SDLK_PLUS:         rc = KEY_EQUALS;        break;
146 
147     case SDLK_LSHIFT:
148     case SDLK_RSHIFT:
149       rc = KEY_RSHIFT;
150       break;
151 
152     case SDLK_LCTRL:
153     case SDLK_RCTRL:
154       rc = KEY_RCTRL;
155       break;
156 
157     case SDLK_LALT:
158     case SDLK_LMETA:
159     case SDLK_RALT:
160     case SDLK_RMETA:
161       rc = KEY_RALT;
162       break;
163 
164     default:
165       rc = key->sym;
166       break;
167     }
168   return rc;
169 }
170 
171 
172 /* This processes SDL events */
I_GetEvent(SDL_Event * Event)173 void I_GetEvent(SDL_Event *Event)
174 {
175   Uint8 buttonstate;
176   event_t event;
177 
178   switch (Event->type)
179     {
180     case SDL_KEYDOWN:
181       event.type = ev_keydown;
182       event.data1 = xlatekey(&Event->key.keysym);
183       D_PostEvent(&event);
184       break;
185 
186     case SDL_KEYUP:
187       event.type = ev_keyup;
188       event.data1 = xlatekey(&Event->key.keysym);
189       D_PostEvent(&event);
190       break;
191 
192     case SDL_MOUSEBUTTONDOWN:
193     case SDL_MOUSEBUTTONUP:
194       buttonstate = SDL_GetMouseState(NULL, NULL);
195       event.type = ev_mouse;
196       event.data1 = 0
197 	| (buttonstate & SDL_BUTTON(1) ? 1 : 0)
198 	| (buttonstate & SDL_BUTTON(2) ? 2 : 0)
199 	| (buttonstate & SDL_BUTTON(3) ? 4 : 0);
200       event.data2 = event.data3 = 0;
201       D_PostEvent(&event);
202       break;
203 
204     case SDL_MOUSEMOTION:
205       event.type = ev_mouse;
206       event.data1 = 0
207 	| (Event->motion.state & SDL_BUTTON(1) ? 1 : 0)
208 	| (Event->motion.state & SDL_BUTTON(2) ? 2 : 0)
209 	| (Event->motion.state & SDL_BUTTON(3) ? 4 : 0);
210       event.data2 = (Event->motion.x - lastmousex) << 2;
211       event.data3 = (lastmousey - Event->motion.y) << 2;
212 
213       if (event.data2 || event.data3) {
214 	lastmousex = Event->motion.x;
215 	lastmousey = Event->motion.y;
216 	if (Event->motion.x != screenwidth/2 &&
217 	    Event->motion.y != screenheight/2) {
218 	  D_PostEvent(&event);
219 	}
220       }
221 
222       if ( (Event->motion.x != screenwidth/2) ||
223 	   (Event->motion.y != screenheight/2) ) {
224 	/* Warp the mouse back to the center */
225 	if (do_grabMouse) {
226 	  SDL_WarpMouse(screenwidth/2, screenheight/2);
227 	}
228       }
229       break;
230 
231     case SDL_QUIT:
232       I_Quit();
233     }
234 }
235 
236 /*
237  * I_StartTic
238  */
I_StartTic(void)239 void I_StartTic (void)
240 {
241     SDL_Event Event;
242 
243     while ( SDL_PollEvent(&Event) )
244         I_GetEvent(&Event);
245 }
246 
247 /*
248 ===============
249 =
250 = I_StartFrame
251 =
252 ===============
253 */
254 
I_StartFrame(void)255 void I_StartFrame (void)
256 {
257     /* ? */
258 }
259