1 /*
2 * IceBreaker
3 * Copyright (c) 2000-2002 Matthew Miller <mattdm@mattdm.org> and
4 *   Enrico Tassi <gareuselesinge@infinito.it>
5 *
6 * <http://www.mattdm.org/icebreaker/>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23 
24 
25 #include <SDL.h>
26 #include "icebreaker.h"
27 #include "globals.h"
28 #include "event.h"
29 #include "options.h"
30 #include "laundry.h"
31 #include "text.h"
32 #include "fullscreen.h"
33 
34 static void alignmouse(SDL_Event* e);
35 
pollevent(SDL_Event * e)36 int pollevent(SDL_Event* e)
37 {
38 	int result = SDL_PollEvent(e);
39 	if ( gameflags.isfullscreen && e != NULL )
40 		alignmouse(e);
41 	return result;
42 }
43 
getmousestate(int * mx,int * my)44 Uint8 getmousestate(int* mx, int* my)
45 {
46 	Uint8 rc;
47 	rc=SDL_GetMouseState(mx, my);
48 
49 	if (gameflags.isfullscreen)
50 	{
51 		*mx -= (FULLWIDTH - WIDTH) / 2;
52 		*my -= FULLTOPMARGIN;
53 	}
54 
55 	return rc;
56 }
57 
jumpmouse(int mx,int my)58 void jumpmouse(int mx, int my)
59 {
60 	if (gameflags.isfullscreen)
61 		SDL_WarpMouse(mx+(FULLWIDTH - WIDTH) / 2,my+FULLTOPMARGIN);
62 	else
63 		SDL_WarpMouse(mx,my);
64 }
65 
translatekeyevent(SDL_Event * e)66 KeyboardActionType translatekeyevent(SDL_Event* e)
67 {
68 	if ((e->type != SDL_KEYUP) && (e->type != SDL_KEYDOWN))
69 		return KEYNONE;
70 
71 	switch (e->key.keysym.sym)
72 	{
73 		case SDLK_ESCAPE:
74 			return KEYCANCEL;
75 		break;
76 
77 		case SDLK_m:
78 			return KEYMENU;
79 		break;
80 
81 		case SDLK_p:
82 		case SDLK_PAUSE:
83 			return KEYPAUSE;
84 		break;
85 
86 		case SDLK_F1:
87 			return KEYHELP;
88 		break;
89 
90 		case SDLK_RETURN:
91 		case SDLK_KP_ENTER:
92 		case SDLK_z:
93 		case SDLK_COMMA:
94 		case SDLK_KP0:
95 			return KEYSTARTLINE;
96 		break;
97 
98 		case SDLK_SPACE:
99 		case SDLK_x:
100 		case SDLK_PERIOD:
101 		case SDLK_KP5:
102 			return KEYSWITCHLINE;
103 		break;
104 
105 		case SDLK_LEFT:
106 		case SDLK_h:
107 		case SDLK_KP4:
108 			return KEYMOVELEFT;
109 		break;
110 
111 		case SDLK_RIGHT:
112 		case SDLK_l:
113 		case SDLK_KP6:
114 			return KEYMOVERIGHT;
115 		break;
116 
117 		case SDLK_UP:
118 		case SDLK_k:
119 		case SDLK_KP8:
120 			return KEYMOVEUP;
121 		break;
122 
123 		case SDLK_DOWN:
124 		case SDLK_j:
125 		case SDLK_KP2:
126 			return KEYMOVEDOWN;
127 		break;
128 
129 		case SDLK_KP7:
130 		case SDLK_HOME:
131 			return KEYMOVELEFTUP;
132 		break;
133 
134 		case SDLK_KP9:
135 		case SDLK_PAGEUP:
136 			return KEYMOVERIGHTUP;
137 		break;
138 
139 		case SDLK_KP1:
140 		case SDLK_END:
141 			return KEYMOVELEFTDOWN;
142 		break;
143 
144 		case SDLK_KP3:
145 		case SDLK_PAGEDOWN:
146 			return KEYMOVERIGHTDOWN;
147 		break;
148 
149 		default:
150 			return KEYNONE;
151 		break;
152 	}
153 
154 	return KEYNONE;
155 }
156 
alignmouse(SDL_Event * e)157 void alignmouse(SDL_Event* e)
158 {
159 
160 	switch(e->type)
161 	{
162 		case SDL_MOUSEMOTION:
163 			e->motion.x -= (FULLWIDTH - WIDTH) / 2;
164 			e->motion.y -= FULLTOPMARGIN;
165 			e->motion.xrel -= (FULLWIDTH - WIDTH) / 2;
166 			e->motion.yrel -= FULLTOPMARGIN;
167 		break;
168 
169 		case SDL_MOUSEBUTTONDOWN: // falls through
170 		case SDL_MOUSEBUTTONUP:
171 			e->button.x -= (FULLWIDTH - WIDTH) / 2;
172 			e->button.y -= FULLTOPMARGIN;
173 		break;
174 
175 		default:
176 			return;
177 	}
178 }
179 
180