Mercurial > sdl-ios-xcode
comparison src/video/riscos/SDL_riscosevents.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | d910939febfa |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
68 /* Size of array for all keys */ | 68 /* Size of array for all keys */ |
69 #define ROKEYBD_ARRAYSIZE 125 | 69 #define ROKEYBD_ARRAYSIZE 125 |
70 | 70 |
71 static char RO_pressed[ROKEYBD_ARRAYSIZE]; | 71 static char RO_pressed[ROKEYBD_ARRAYSIZE]; |
72 | 72 |
73 static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed); | 73 static SDL_keysym *TranslateKey(int intkey, SDL_keysym * keysym, int pressed); |
74 | 74 |
75 void RISCOS_PollMouse(_THIS); | 75 void RISCOS_PollMouse(_THIS); |
76 void RISCOS_PollKeyboard(); | 76 void RISCOS_PollKeyboard(); |
77 | 77 |
78 void RISCOS_PollMouseHelper(_THIS, int fullscreen); | 78 void RISCOS_PollMouseHelper(_THIS, int fullscreen); |
83 /* Timer running function */ | 83 /* Timer running function */ |
84 extern void RISCOS_CheckTimer(); | 84 extern void RISCOS_CheckTimer(); |
85 | 85 |
86 #endif | 86 #endif |
87 | 87 |
88 void FULLSCREEN_PumpEvents(_THIS) | 88 void |
89 FULLSCREEN_PumpEvents(_THIS) | |
89 { | 90 { |
90 /* Current implementation requires keyboard and mouse polling */ | 91 /* Current implementation requires keyboard and mouse polling */ |
91 RISCOS_PollKeyboard(); | 92 RISCOS_PollKeyboard(); |
92 RISCOS_PollMouse(this); | 93 RISCOS_PollMouse(this); |
93 #if SDL_THREADS_DISABLED | 94 #if SDL_THREADS_DISABLED |
94 // DRenderer_FillBuffers(); | 95 // DRenderer_FillBuffers(); |
95 if (SDL_timer_running) RISCOS_CheckTimer(); | 96 if (SDL_timer_running) |
97 RISCOS_CheckTimer(); | |
96 #endif | 98 #endif |
97 } | 99 } |
98 | 100 |
99 | 101 |
100 void RISCOS_InitOSKeymap(_THIS) | 102 void |
101 { | 103 RISCOS_InitOSKeymap(_THIS) |
102 int i; | 104 { |
103 | 105 int i; |
104 /* Map the VK keysyms */ | 106 |
105 for ( i=0; i<SDL_arraysize(RO_keymap); ++i ) | 107 /* Map the VK keysyms */ |
106 RO_keymap[i] = SDLK_UNKNOWN; | 108 for (i = 0; i < SDL_arraysize(RO_keymap); ++i) |
107 | 109 RO_keymap[i] = SDLK_UNKNOWN; |
108 RO_keymap[3] = SDLK_LSHIFT; | 110 |
109 RO_keymap[4] = SDLK_LCTRL; | 111 RO_keymap[3] = SDLK_LSHIFT; |
110 RO_keymap[5] = SDLK_LALT; | 112 RO_keymap[4] = SDLK_LCTRL; |
111 RO_keymap[6] = SDLK_RSHIFT; | 113 RO_keymap[5] = SDLK_LALT; |
112 RO_keymap[7] = SDLK_RCTRL; | 114 RO_keymap[6] = SDLK_RSHIFT; |
113 RO_keymap[8] = SDLK_RALT; | 115 RO_keymap[7] = SDLK_RCTRL; |
114 RO_keymap[16] = SDLK_q; | 116 RO_keymap[8] = SDLK_RALT; |
115 RO_keymap[17] = SDLK_3; | 117 RO_keymap[16] = SDLK_q; |
116 RO_keymap[18] = SDLK_4; | 118 RO_keymap[17] = SDLK_3; |
117 RO_keymap[19] = SDLK_5; | 119 RO_keymap[18] = SDLK_4; |
118 RO_keymap[20] = SDLK_F4; | 120 RO_keymap[19] = SDLK_5; |
119 RO_keymap[21] = SDLK_8; | 121 RO_keymap[20] = SDLK_F4; |
120 RO_keymap[22] = SDLK_F7; | 122 RO_keymap[21] = SDLK_8; |
121 RO_keymap[23] = SDLK_MINUS, | 123 RO_keymap[22] = SDLK_F7; |
122 RO_keymap[25] = SDLK_LEFT; | 124 RO_keymap[23] = SDLK_MINUS, RO_keymap[25] = SDLK_LEFT; |
123 RO_keymap[26] = SDLK_KP6; | 125 RO_keymap[26] = SDLK_KP6; |
124 RO_keymap[27] = SDLK_KP7; | 126 RO_keymap[27] = SDLK_KP7; |
125 RO_keymap[28] = SDLK_F11; | 127 RO_keymap[28] = SDLK_F11; |
126 RO_keymap[29] = SDLK_F12; | 128 RO_keymap[29] = SDLK_F12; |
127 RO_keymap[30] = SDLK_F10; | 129 RO_keymap[30] = SDLK_F10; |
128 RO_keymap[31] = SDLK_SCROLLOCK; | 130 RO_keymap[31] = SDLK_SCROLLOCK; |
129 RO_keymap[32] = SDLK_PRINT; | 131 RO_keymap[32] = SDLK_PRINT; |
130 RO_keymap[33] = SDLK_w; | 132 RO_keymap[33] = SDLK_w; |
131 RO_keymap[34] = SDLK_e; | 133 RO_keymap[34] = SDLK_e; |
132 RO_keymap[35] = SDLK_t; | 134 RO_keymap[35] = SDLK_t; |
133 RO_keymap[36] = SDLK_7; | 135 RO_keymap[36] = SDLK_7; |
134 RO_keymap[37] = SDLK_i; | 136 RO_keymap[37] = SDLK_i; |
135 RO_keymap[38] = SDLK_9; | 137 RO_keymap[38] = SDLK_9; |
136 RO_keymap[39] = SDLK_0; | 138 RO_keymap[39] = SDLK_0; |
137 RO_keymap[41] = SDLK_DOWN; | 139 RO_keymap[41] = SDLK_DOWN; |
138 RO_keymap[42] = SDLK_KP8; | 140 RO_keymap[42] = SDLK_KP8; |
139 RO_keymap[43] = SDLK_KP9; | 141 RO_keymap[43] = SDLK_KP9; |
140 RO_keymap[44] = SDLK_BREAK; | 142 RO_keymap[44] = SDLK_BREAK; |
141 RO_keymap[45] = SDLK_BACKQUOTE; | 143 RO_keymap[45] = SDLK_BACKQUOTE; |
142 /* RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */ | 144 /* RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */ |
143 RO_keymap[47] = SDLK_BACKSPACE; | 145 RO_keymap[47] = SDLK_BACKSPACE; |
144 RO_keymap[48] = SDLK_1; | 146 RO_keymap[48] = SDLK_1; |
145 RO_keymap[49] = SDLK_2; | 147 RO_keymap[49] = SDLK_2; |
146 RO_keymap[50] = SDLK_d; | 148 RO_keymap[50] = SDLK_d; |
147 RO_keymap[51] = SDLK_r; | 149 RO_keymap[51] = SDLK_r; |
148 RO_keymap[52] = SDLK_6; | 150 RO_keymap[52] = SDLK_6; |
149 RO_keymap[53] = SDLK_u; | 151 RO_keymap[53] = SDLK_u; |
150 RO_keymap[54] = SDLK_o; | 152 RO_keymap[54] = SDLK_o; |
151 RO_keymap[55] = SDLK_p; | 153 RO_keymap[55] = SDLK_p; |
152 RO_keymap[56] = SDLK_LEFTBRACKET; | 154 RO_keymap[56] = SDLK_LEFTBRACKET; |
153 RO_keymap[57] = SDLK_UP; | 155 RO_keymap[57] = SDLK_UP; |
154 RO_keymap[58] = SDLK_KP_PLUS; | 156 RO_keymap[58] = SDLK_KP_PLUS; |
155 RO_keymap[59] = SDLK_KP_MINUS; | 157 RO_keymap[59] = SDLK_KP_MINUS; |
156 RO_keymap[60] = SDLK_KP_ENTER; | 158 RO_keymap[60] = SDLK_KP_ENTER; |
157 RO_keymap[61] = SDLK_INSERT; | 159 RO_keymap[61] = SDLK_INSERT; |
158 RO_keymap[62] = SDLK_HOME; | 160 RO_keymap[62] = SDLK_HOME; |
159 RO_keymap[63] = SDLK_PAGEUP; | 161 RO_keymap[63] = SDLK_PAGEUP; |
160 RO_keymap[64] = SDLK_CAPSLOCK; | 162 RO_keymap[64] = SDLK_CAPSLOCK; |
161 RO_keymap[65] = SDLK_a; | 163 RO_keymap[65] = SDLK_a; |
162 RO_keymap[66] = SDLK_x; | 164 RO_keymap[66] = SDLK_x; |
163 RO_keymap[67] = SDLK_f; | 165 RO_keymap[67] = SDLK_f; |
164 RO_keymap[68] = SDLK_y; | 166 RO_keymap[68] = SDLK_y; |
165 RO_keymap[69] = SDLK_j; | 167 RO_keymap[69] = SDLK_j; |
166 RO_keymap[70] = SDLK_k; | 168 RO_keymap[70] = SDLK_k; |
167 RO_keymap[72] = SDLK_SEMICOLON; | 169 RO_keymap[72] = SDLK_SEMICOLON; |
168 RO_keymap[73] = SDLK_RETURN; | 170 RO_keymap[73] = SDLK_RETURN; |
169 RO_keymap[74] = SDLK_KP_DIVIDE; | 171 RO_keymap[74] = SDLK_KP_DIVIDE; |
170 RO_keymap[76] = SDLK_KP_PERIOD; | 172 RO_keymap[76] = SDLK_KP_PERIOD; |
171 RO_keymap[77] = SDLK_NUMLOCK; | 173 RO_keymap[77] = SDLK_NUMLOCK; |
172 RO_keymap[78] = SDLK_PAGEDOWN; | 174 RO_keymap[78] = SDLK_PAGEDOWN; |
173 RO_keymap[79] = SDLK_QUOTE; | 175 RO_keymap[79] = SDLK_QUOTE; |
174 RO_keymap[81] = SDLK_s; | 176 RO_keymap[81] = SDLK_s; |
175 RO_keymap[82] = SDLK_c; | 177 RO_keymap[82] = SDLK_c; |
176 RO_keymap[83] = SDLK_g; | 178 RO_keymap[83] = SDLK_g; |
177 RO_keymap[84] = SDLK_h; | 179 RO_keymap[84] = SDLK_h; |
178 RO_keymap[85] = SDLK_n; | 180 RO_keymap[85] = SDLK_n; |
179 RO_keymap[86] = SDLK_l; | 181 RO_keymap[86] = SDLK_l; |
180 RO_keymap[87] = SDLK_SEMICOLON; | 182 RO_keymap[87] = SDLK_SEMICOLON; |
181 RO_keymap[88] = SDLK_RIGHTBRACKET; | 183 RO_keymap[88] = SDLK_RIGHTBRACKET; |
182 RO_keymap[89] = SDLK_DELETE; | 184 RO_keymap[89] = SDLK_DELETE; |
183 RO_keymap[90] = SDLK_KP_MINUS; | 185 RO_keymap[90] = SDLK_KP_MINUS; |
184 RO_keymap[91] = SDLK_KP_MULTIPLY; | 186 RO_keymap[91] = SDLK_KP_MULTIPLY; |
185 RO_keymap[93] = SDLK_EQUALS; | 187 RO_keymap[93] = SDLK_EQUALS; |
186 RO_keymap[94] = SDLK_BACKSLASH; | 188 RO_keymap[94] = SDLK_BACKSLASH; |
187 RO_keymap[96] = SDLK_TAB; | 189 RO_keymap[96] = SDLK_TAB; |
188 RO_keymap[97] = SDLK_z; | 190 RO_keymap[97] = SDLK_z; |
189 RO_keymap[98] = SDLK_SPACE; | 191 RO_keymap[98] = SDLK_SPACE; |
190 RO_keymap[99] = SDLK_v; | 192 RO_keymap[99] = SDLK_v; |
191 RO_keymap[100] = SDLK_b; | 193 RO_keymap[100] = SDLK_b; |
192 RO_keymap[101] = SDLK_m; | 194 RO_keymap[101] = SDLK_m; |
193 RO_keymap[102] = SDLK_COMMA; | 195 RO_keymap[102] = SDLK_COMMA; |
194 RO_keymap[103] = SDLK_PERIOD; | 196 RO_keymap[103] = SDLK_PERIOD; |
195 RO_keymap[104] = SDLK_SLASH; | 197 RO_keymap[104] = SDLK_SLASH; |
196 RO_keymap[105] = SDLK_END; | 198 RO_keymap[105] = SDLK_END; |
197 RO_keymap[106] = SDLK_KP0; | 199 RO_keymap[106] = SDLK_KP0; |
198 RO_keymap[107] = SDLK_KP1; | 200 RO_keymap[107] = SDLK_KP1; |
199 RO_keymap[108] = SDLK_KP3; | 201 RO_keymap[108] = SDLK_KP3; |
200 RO_keymap[112] = SDLK_ESCAPE; | 202 RO_keymap[112] = SDLK_ESCAPE; |
201 RO_keymap[113] = SDLK_F1; | 203 RO_keymap[113] = SDLK_F1; |
202 RO_keymap[114] = SDLK_F2; | 204 RO_keymap[114] = SDLK_F2; |
203 RO_keymap[115] = SDLK_F3; | 205 RO_keymap[115] = SDLK_F3; |
204 RO_keymap[116] = SDLK_F5; | 206 RO_keymap[116] = SDLK_F5; |
205 RO_keymap[117] = SDLK_F6; | 207 RO_keymap[117] = SDLK_F6; |
206 RO_keymap[118] = SDLK_F8; | 208 RO_keymap[118] = SDLK_F8; |
207 RO_keymap[119] = SDLK_F9; | 209 RO_keymap[119] = SDLK_F9; |
208 RO_keymap[120] = SDLK_HASH; | 210 RO_keymap[120] = SDLK_HASH; |
209 RO_keymap[121] = SDLK_RIGHT; | 211 RO_keymap[121] = SDLK_RIGHT; |
210 RO_keymap[122] = SDLK_KP4; | 212 RO_keymap[122] = SDLK_KP4; |
211 RO_keymap[123] = SDLK_KP5; | 213 RO_keymap[123] = SDLK_KP5; |
212 RO_keymap[124] = SDLK_KP2; | 214 RO_keymap[124] = SDLK_KP2; |
213 | 215 |
214 SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE); | 216 SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE); |
215 } | 217 } |
216 | 218 |
217 | 219 |
218 /* Variable for mouse relative processing */ | 220 /* Variable for mouse relative processing */ |
219 int mouse_relative = 0; | 221 int mouse_relative = 0; |
220 | 222 |
221 /* Check to see if we need to enter or leave mouse relative mode */ | 223 /* Check to see if we need to enter or leave mouse relative mode */ |
222 | 224 |
223 void RISCOS_CheckMouseMode(_THIS) | 225 void |
226 RISCOS_CheckMouseMode(_THIS) | |
224 { | 227 { |
225 /* If the mouse is hidden and input is grabbed, we use relative mode */ | 228 /* If the mouse is hidden and input is grabbed, we use relative mode */ |
226 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && | 229 if (!(SDL_cursorstate & CURSOR_VISIBLE) && |
227 (this->input_grab != SDL_GRAB_OFF) ) { | 230 (this->input_grab != SDL_GRAB_OFF)) { |
228 mouse_relative = 1; | 231 mouse_relative = 1; |
229 } else { | 232 } else { |
230 mouse_relative = 0; | 233 mouse_relative = 0; |
231 } | 234 } |
232 } | 235 } |
233 | 236 |
234 | 237 |
235 void RISCOS_PollMouse(_THIS) | 238 void |
236 { | 239 RISCOS_PollMouse(_THIS) |
237 RISCOS_PollMouseHelper(this, 1); | 240 { |
241 RISCOS_PollMouseHelper(this, 1); | |
238 } | 242 } |
239 | 243 |
240 extern int mouseInWindow; | 244 extern int mouseInWindow; |
241 | 245 |
242 void WIMP_PollMouse(_THIS) | 246 void |
243 { | 247 WIMP_PollMouse(_THIS) |
244 /* Only poll when mouse is over the window */ | 248 { |
245 if (!mouseInWindow) return; | 249 /* Only poll when mouse is over the window */ |
246 | 250 if (!mouseInWindow) |
247 RISCOS_PollMouseHelper(this, 0); | 251 return; |
252 | |
253 RISCOS_PollMouseHelper(this, 0); | |
248 } | 254 } |
249 | 255 |
250 /* Static variables so only changes are reported */ | 256 /* Static variables so only changes are reported */ |
251 static Sint16 last_x = -1, last_y = -1; | 257 static Sint16 last_x = -1, last_y = -1; |
252 static int last_buttons = 0; | 258 static int last_buttons = 0; |
253 | 259 |
254 /* Share routine between WIMP and FULLSCREEN for polling mouse and | 260 /* Share routine between WIMP and FULLSCREEN for polling mouse and |
255 passing on events */ | 261 passing on events */ |
256 void RISCOS_PollMouseHelper(_THIS, int fullscreen) | 262 void |
263 RISCOS_PollMouseHelper(_THIS, int fullscreen) | |
257 { | 264 { |
258 _kernel_swi_regs regs; | 265 _kernel_swi_regs regs; |
259 static int starting = 1; | 266 static int starting = 1; |
260 | 267 |
261 if (_kernel_swi(OS_Mouse, ®s, ®s) == NULL) | 268 if (_kernel_swi(OS_Mouse, ®s, ®s) == NULL) { |
262 { | 269 Sint16 new_x = regs.r[0]; /* Initialy get as OS units */ |
263 Sint16 new_x = regs.r[0]; /* Initialy get as OS units */ | 270 Sint16 new_y = regs.r[1]; |
264 Sint16 new_y = regs.r[1]; | 271 |
265 | 272 /* Discard mouse events until they let go of the mouse after starting */ |
266 /* Discard mouse events until they let go of the mouse after starting */ | 273 if (starting && regs.r[2] != 0) |
267 if (starting && regs.r[2] != 0) | 274 return; |
268 return; | 275 else |
269 else | 276 starting = 0; |
270 starting = 0; | 277 |
271 | 278 if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2]) { |
272 if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2]) | 279 /* Something changed so generate appropriate events */ |
273 { | 280 int topLeftX, topLeftY; /* Top left OS units */ |
274 /* Something changed so generate appropriate events */ | 281 int x, y; /* Mouse position in SDL pixels */ |
275 int topLeftX, topLeftY; /* Top left OS units */ | 282 |
276 int x, y; /* Mouse position in SDL pixels */ | 283 if (fullscreen) { |
277 | 284 topLeftX = 0; |
278 if (fullscreen) | 285 topLeftY = (this->hidden->height << this->hidden->yeig) - 1; |
279 { | 286 } else { |
280 topLeftX = 0; | 287 int window_state[9]; |
281 topLeftY = (this->hidden->height << this->hidden->yeig) - 1; | 288 |
282 } else | 289 /* Get current window state */ |
283 { | 290 window_state[0] = this->hidden->window_handle; |
284 int window_state[9]; | 291 regs.r[1] = (unsigned int) window_state; |
285 | 292 _kernel_swi(Wimp_GetWindowState, ®s, ®s); |
286 /* Get current window state */ | 293 |
287 window_state[0] = this->hidden->window_handle; | 294 topLeftX = window_state[1]; |
288 regs.r[1] = (unsigned int)window_state; | 295 topLeftY = window_state[4]; |
289 _kernel_swi(Wimp_GetWindowState, ®s, ®s); | 296 } |
290 | 297 |
291 topLeftX = window_state[1]; | 298 /* Convert co-ordinates to workspace */ |
292 topLeftY = window_state[4]; | 299 x = new_x - topLeftX; |
293 } | 300 y = topLeftY - new_y; /* Y goes from top of window/screen */ |
294 | 301 |
295 /* Convert co-ordinates to workspace */ | 302 /* Convert OS units to pixels */ |
296 x = new_x - topLeftX; | 303 x >>= this->hidden->xeig; |
297 y = topLeftY - new_y; /* Y goes from top of window/screen */ | 304 y >>= this->hidden->yeig; |
298 | 305 |
299 /* Convert OS units to pixels */ | 306 if (last_x != new_x || last_y != new_y) { |
300 x >>= this->hidden->xeig; | 307 if (mouse_relative) { |
301 y >>= this->hidden->yeig; | 308 int centre_x = SDL_VideoSurface->w / 2; |
302 | 309 int centre_y = SDL_VideoSurface->h / 2; |
303 if (last_x != new_x || last_y != new_y) | 310 |
304 { | 311 if (centre_x != x || centre_y != y) { |
305 if (mouse_relative) | 312 if (SDL_VideoSurface) |
306 { | 313 SDL_PrivateMouseMotion(0, 1, |
307 int centre_x = SDL_VideoSurface->w/2; | 314 x - centre_x, |
308 int centre_y = SDL_VideoSurface->h/2; | 315 y - centre_y); |
309 | 316 last_x = topLeftX + (centre_x << this->hidden->xeig); |
310 if (centre_x != x || centre_y != y) | 317 last_y = topLeftY - (centre_y << this->hidden->yeig); |
311 { | 318 |
312 if (SDL_VideoSurface) SDL_PrivateMouseMotion(0,1,x - centre_x, y - centre_y); | 319 /* Re-centre the mouse pointer, so we still get relative |
313 last_x = topLeftX + (centre_x << this->hidden->xeig); | 320 movement when the mouse is at the edge of the window |
314 last_y = topLeftY - (centre_y << this->hidden->yeig); | 321 or screen. |
315 | 322 */ |
316 /* Re-centre the mouse pointer, so we still get relative | 323 { |
317 movement when the mouse is at the edge of the window | 324 unsigned char block[5]; |
318 or screen. | 325 |
319 */ | 326 block[0] = 3; /* OSWORD move pointer sub-reason code */ |
320 { | 327 block[1] = last_x & 0xFF; |
321 unsigned char block[5]; | 328 block[2] = (last_x >> 8) & 0xFF; |
322 | 329 block[3] = last_y & 0xFF; |
323 block[0] = 3; /* OSWORD move pointer sub-reason code */ | 330 block[4] = (last_y >> 8) & 0xFF; |
324 block[1] = last_x & 0xFF; | 331 |
325 block[2] = (last_x >> 8) & 0xFF; | 332 regs.r[0] = 21; /* OSWORD pointer stuff code */ |
326 block[3] = last_y & 0xFF; | 333 regs.r[1] = (int) block; |
327 block[4] = (last_y >> 8) & 0xFF; | 334 _kernel_swi(OS_Word, ®s, ®s); |
328 | 335 } |
329 regs.r[0] = 21; /* OSWORD pointer stuff code */ | 336 } |
330 regs.r[1] = (int)block; | 337 } else { |
331 _kernel_swi(OS_Word, ®s, ®s); | 338 last_x = new_x; |
332 } | 339 last_y = new_y; |
340 SDL_PrivateMouseMotion(0, 0, x, y); | |
333 } | 341 } |
334 } else | 342 } |
335 { | 343 |
336 last_x = new_x; | 344 if (last_buttons != regs.r[2]) { |
337 last_y = new_y; | 345 int changed = last_buttons ^ regs.r[2]; |
338 SDL_PrivateMouseMotion(0,0,x,y); | 346 last_buttons = regs.r[2]; |
339 } | 347 if (changed & 4) |
340 } | 348 SDL_PrivateMouseButton((last_buttons & 4) ? |
341 | 349 SDL_PRESSED : SDL_RELEASED, |
342 if (last_buttons != regs.r[2]) | 350 SDL_BUTTON_LEFT, 0, 0); |
343 { | 351 if (changed & 2) |
344 int changed = last_buttons ^ regs.r[2]; | 352 SDL_PrivateMouseButton((last_buttons & 2) ? |
345 last_buttons = regs.r[2]; | 353 SDL_PRESSED : SDL_RELEASED, |
346 if (changed & 4) SDL_PrivateMouseButton((last_buttons & 4) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); | 354 SDL_BUTTON_MIDDLE, 0, 0); |
347 if (changed & 2) SDL_PrivateMouseButton((last_buttons & 2) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); | 355 if (changed & 1) |
348 if (changed & 1) SDL_PrivateMouseButton((last_buttons & 1) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); | 356 SDL_PrivateMouseButton((last_buttons & 1) ? |
349 } | 357 SDL_PRESSED : SDL_RELEASED, |
350 } | 358 SDL_BUTTON_RIGHT, 0, 0); |
359 } | |
360 } | |
351 } | 361 } |
352 } | 362 } |
353 | 363 |
354 void RISCOS_PollKeyboard() | 364 void |
355 { | 365 RISCOS_PollKeyboard() |
356 int which_key = ROKEY_LEFT_SHIFT; | 366 { |
357 int j; | 367 int which_key = ROKEY_LEFT_SHIFT; |
358 int min_key, max_key; | 368 int j; |
359 SDL_keysym key; | 369 int min_key, max_key; |
360 | 370 SDL_keysym key; |
361 /* Scan the keyboard to see what is pressed */ | 371 |
362 while (which_key <= ROKEY_LAST_KEY) | 372 /* Scan the keyboard to see what is pressed */ |
363 { | 373 while (which_key <= ROKEY_LAST_KEY) { |
364 which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF); | 374 which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF); |
365 if (which_key != ROKEY_NONE) | 375 if (which_key != ROKEY_NONE) { |
366 { | 376 switch (which_key) { |
367 switch(which_key) | 377 /* Skip over mouse keys */ |
368 { | 378 case ROKEY_LEFT_MOUSE: |
369 /* Skip over mouse keys */ | 379 case ROKEY_CENTRE_MOUSE: |
370 case ROKEY_LEFT_MOUSE: | 380 case ROKEY_RIGHT_MOUSE: |
371 case ROKEY_CENTRE_MOUSE: | 381 which_key = ROKEY_RIGHT_MOUSE; |
372 case ROKEY_RIGHT_MOUSE: | 382 break; |
373 which_key = ROKEY_RIGHT_MOUSE; | 383 |
374 break; | 384 /* Ignore keys that cause 2 internal number to be generated */ |
375 | 385 case 71: |
376 /* Ignore keys that cause 2 internal number to be generated */ | 386 case 24: |
377 case 71: case 24: case 87: case 40: | 387 case 87: |
378 break; | 388 case 40: |
379 | 389 break; |
380 /* Ignore break as it can be latched on */ | 390 |
391 /* Ignore break as it can be latched on */ | |
381 case 44: | 392 case 44: |
382 break; | 393 break; |
383 | 394 |
384 default: | 395 default: |
385 RO_pressed[which_key] += 2; | 396 RO_pressed[which_key] += 2; |
386 break; | 397 break; |
387 } | 398 } |
388 which_key++; | 399 which_key++; |
389 } | 400 } |
390 } | 401 } |
391 | 402 |
392 /* Generate key released messages */ | 403 /* Generate key released messages */ |
393 min_key = ROKEY_LAST_KEY+1; | 404 min_key = ROKEY_LAST_KEY + 1; |
394 max_key = ROKEY_LEFT_SHIFT; | 405 max_key = ROKEY_LEFT_SHIFT; |
395 | 406 |
396 for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) | 407 for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) { |
397 { | 408 if (RO_pressed[j]) { |
398 if (RO_pressed[j]) | 409 if (RO_pressed[j] == 1) { |
399 { | 410 RO_pressed[j] = 0; |
400 if (RO_pressed[j] == 1) | 411 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j, &key, 0)); |
401 { | 412 } else { |
402 RO_pressed[j] = 0; | 413 if (j < min_key) |
403 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j,&key,0)); | 414 min_key = j; |
404 } else | 415 if (j > max_key) |
405 { | 416 max_key = j; |
406 if (j < min_key) min_key = j; | 417 } |
407 if (j > max_key) max_key = j; | 418 } |
408 } | 419 } |
409 } | 420 |
410 } | 421 /* Generate key pressed messages */ |
411 | 422 for (j = min_key; j <= max_key; j++) { |
412 /* Generate key pressed messages */ | 423 if (RO_pressed[j]) { |
413 for (j = min_key; j <= max_key; j++) | 424 if (RO_pressed[j] == 2) { |
414 { | 425 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(j, &key, 1)); |
415 if (RO_pressed[j]) | 426 } |
416 { | 427 RO_pressed[j] = 1; |
417 if (RO_pressed[j] == 2) | 428 } |
418 { | 429 } |
419 SDL_PrivateKeyboard(SDL_PRESSED,TranslateKey(j,&key,1)); | 430 } |
420 } | 431 |
421 RO_pressed[j] = 1; | 432 static SDL_keysym * |
422 } | 433 TranslateKey(int intkey, SDL_keysym * keysym, int pressed) |
423 } | 434 { |
424 } | 435 /* Set the keysym information */ |
425 | 436 keysym->scancode = (unsigned char) intkey; |
426 static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed) | 437 keysym->sym = RO_keymap[intkey]; |
427 { | 438 keysym->mod = KMOD_NONE; |
428 /* Set the keysym information */ | 439 keysym->unicode = 0; |
429 keysym->scancode = (unsigned char) intkey; | 440 if (pressed && SDL_TranslateUNICODE) { |
430 keysym->sym = RO_keymap[intkey]; | 441 int state; |
431 keysym->mod = KMOD_NONE; | 442 int ch; |
432 keysym->unicode = 0; | 443 |
433 if ( pressed && SDL_TranslateUNICODE ) | 444 state = (_kernel_osbyte(202, 0, 255) & 0xFF); |
434 { | 445 |
435 int state; | 446 /*TODO: Take into account other keyboard layouts */ |
436 int ch; | 447 |
437 | 448 ch = keysym->sym; /* This should handle most unshifted keys */ |
438 state = (_kernel_osbyte(202, 0, 255) & 0xFF); | 449 |
439 | 450 if (intkey < 9 || ch == SDLK_UNKNOWN) { |
440 /*TODO: Take into account other keyboard layouts */ | 451 ch = 0; |
441 | 452 |
442 ch = keysym->sym; /* This should handle most unshifted keys */ | 453 } else if (state & 64) { /* Control on */ |
443 | 454 ch = ch & 31; |
444 if (intkey < 9 || ch == SDLK_UNKNOWN) | 455 |
445 { | 456 } else { |
446 ch = 0; | 457 int topOfKey = 0; |
447 | 458 if (state & 8) { /* Shift on */ |
448 } else if (state & 64) /* Control on */ | 459 topOfKey = 1; |
449 { | 460 } |
450 ch = ch & 31; | 461 |
451 | 462 if ((state & 16) == 0) { /* Caps lock is on */ |
452 } else | 463 if (ch >= SDLK_a && ch <= SDLK_z) { |
453 { | 464 if ((state & 128) == 0) { /* Shift Enable off */ |
454 int topOfKey = 0; | 465 /* All letter become upper case */ |
455 if (state & 8) /* Shift on */ | 466 topOfKey = 1; |
456 { | 467 } else { |
457 topOfKey = 1; | 468 /* Shift+Letters gives lower case */ |
458 } | 469 topOfKey = 1 - topOfKey; |
459 | 470 } |
460 if ((state & 16) == 0) /* Caps lock is on */ | 471 } |
461 { | 472 } |
462 if (ch >= SDLK_a && ch <= SDLK_z) | 473 |
463 { | 474 if (topOfKey) { |
464 if ((state & 128) == 0) /* Shift Enable off */ | 475 /* Key produced with shift held down */ |
465 { | 476 |
466 /* All letter become upper case */ | 477 /* Letters just give upper case version */ |
467 topOfKey = 1; | 478 if (ch >= SDLK_a && ch <= SDLK_z) |
468 } else | 479 ch = toupper(ch); |
469 { | 480 else { |
470 /* Shift+Letters gives lower case */ | 481 switch (ch) { |
471 topOfKey = 1 - topOfKey; | 482 case SDLK_HASH: |
472 } | 483 ch = '~'; |
473 } | 484 break; |
474 } | 485 case SDLK_QUOTE: |
475 | 486 ch = '@'; |
476 if (topOfKey) | 487 break; |
477 { | 488 case SDLK_COMMA: |
478 /* Key produced with shift held down */ | 489 ch = '<'; |
479 | 490 break; |
480 /* Letters just give upper case version */ | 491 case SDLK_MINUS: |
481 if (ch >= SDLK_a && ch <= SDLK_z) ch = toupper(ch); | 492 ch = '_'; |
482 else | 493 break; |
483 { | 494 case SDLK_PERIOD: |
484 switch(ch) | 495 ch = '>'; |
485 { | 496 break; |
486 case SDLK_HASH: ch = '~'; break; | 497 case SDLK_SLASH: |
487 case SDLK_QUOTE: ch = '@'; break; | 498 ch = '?'; |
488 case SDLK_COMMA: ch = '<'; break; | 499 break; |
489 case SDLK_MINUS: ch = '_'; break; | 500 |
490 case SDLK_PERIOD: ch = '>'; break; | 501 case SDLK_0: |
491 case SDLK_SLASH: ch = '?'; break; | 502 ch = ')'; |
492 | 503 break; |
493 case SDLK_0: ch = ')'; break; | 504 case SDLK_1: |
494 case SDLK_1: ch = '!'; break; | 505 ch = '!'; |
495 case SDLK_2: ch = '"'; break; | 506 break; |
496 case SDLK_3: ch = '£'; break; | 507 case SDLK_2: |
497 case SDLK_4: ch = '$'; break; | 508 ch = '"'; |
498 case SDLK_5: ch = '%'; break; | 509 break; |
499 case SDLK_6: ch = '^'; break; | 510 case SDLK_3: |
500 case SDLK_7: ch = '&'; break; | 511 ch = '£'; |
501 case SDLK_8: ch = '*'; break; | 512 break; |
502 case SDLK_9: ch = '('; break; | 513 case SDLK_4: |
503 | 514 ch = '$'; |
504 case SDLK_SEMICOLON: ch = ':'; break; | 515 break; |
505 case SDLK_EQUALS: ch = '+'; break; | 516 case SDLK_5: |
506 case SDLK_LEFTBRACKET: ch = '{'; break; | 517 ch = '%'; |
507 case SDLK_BACKSLASH: ch = '|'; break; | 518 break; |
508 case SDLK_RIGHTBRACKET: ch = '}'; break; | 519 case SDLK_6: |
509 case SDLK_BACKQUOTE: ch = '¬'; break; | 520 ch = '^'; |
510 | 521 break; |
511 default: | 522 case SDLK_7: |
512 ch = 0; /* Map to zero character if we don't understand it */ | 523 ch = '&'; |
513 break; | 524 break; |
514 } | 525 case SDLK_8: |
515 } | 526 ch = '*'; |
516 | 527 break; |
517 } else if (ch > 126) | 528 case SDLK_9: |
518 { | 529 ch = '('; |
519 /* SDL key code < 126 map directly onto their Unicode equivalents */ | 530 break; |
520 /* Keypad 0 to 9 maps to numeric equivalent */ | 531 |
521 if (ch >= SDLK_KP0 && ch <= SDLK_KP9) ch = ch - SDLK_KP0 + '0'; | 532 case SDLK_SEMICOLON: |
522 else | 533 ch = ':'; |
523 { | 534 break; |
524 /* Following switch maps other keys that produce an Ascii value */ | 535 case SDLK_EQUALS: |
525 switch(ch) | 536 ch = '+'; |
526 { | 537 break; |
527 case SDLK_KP_PERIOD: ch = '.'; break; | 538 case SDLK_LEFTBRACKET: |
528 case SDLK_KP_DIVIDE: ch = '/'; break; | 539 ch = '{'; |
529 case SDLK_KP_MULTIPLY: ch = '*'; break; | 540 break; |
530 case SDLK_KP_MINUS: ch = '-'; break; | 541 case SDLK_BACKSLASH: |
531 case SDLK_KP_PLUS: ch = '+'; break; | 542 ch = '|'; |
532 case SDLK_KP_EQUALS: ch = '='; break; | 543 break; |
533 | 544 case SDLK_RIGHTBRACKET: |
534 default: | 545 ch = '}'; |
535 /* If we don't know what it is set the Unicode to 0 */ | 546 break; |
536 ch = 0; | 547 case SDLK_BACKQUOTE: |
537 break; | 548 ch = '¬'; |
538 } | 549 break; |
539 } | 550 |
540 } | 551 default: |
541 } | 552 ch = 0; /* Map to zero character if we don't understand it */ |
542 | 553 break; |
543 keysym->unicode = ch; | 554 } |
544 } | 555 } |
545 return(keysym); | 556 |
557 } else if (ch > 126) { | |
558 /* SDL key code < 126 map directly onto their Unicode equivalents */ | |
559 /* Keypad 0 to 9 maps to numeric equivalent */ | |
560 if (ch >= SDLK_KP0 && ch <= SDLK_KP9) | |
561 ch = ch - SDLK_KP0 + '0'; | |
562 else { | |
563 /* Following switch maps other keys that produce an Ascii value */ | |
564 switch (ch) { | |
565 case SDLK_KP_PERIOD: | |
566 ch = '.'; | |
567 break; | |
568 case SDLK_KP_DIVIDE: | |
569 ch = '/'; | |
570 break; | |
571 case SDLK_KP_MULTIPLY: | |
572 ch = '*'; | |
573 break; | |
574 case SDLK_KP_MINUS: | |
575 ch = '-'; | |
576 break; | |
577 case SDLK_KP_PLUS: | |
578 ch = '+'; | |
579 break; | |
580 case SDLK_KP_EQUALS: | |
581 ch = '='; | |
582 break; | |
583 | |
584 default: | |
585 /* If we don't know what it is set the Unicode to 0 */ | |
586 ch = 0; | |
587 break; | |
588 } | |
589 } | |
590 } | |
591 } | |
592 | |
593 keysym->unicode = ch; | |
594 } | |
595 return (keysym); | |
546 } | 596 } |
547 | 597 |
548 /* end of SDL_riscosevents.c ... */ | 598 /* end of SDL_riscosevents.c ... */ |
549 | 599 /* vi: set ts=4 sw=4 expandtab: */ |