Mercurial > sdl-ios-xcode
annotate src/video/ggi/SDL_ggievents.c @ 1643:51038e80ae59
More general fix for bug #189
The clipping is done at a higher level, and the low level functions are
passed clipped rectangles. Drivers which don't support source clipping
have not been changed, so the image will be squished instead of clipped,
but at least they will no longer crash when the destination rect was out
of bounds.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 17 Apr 2006 06:47:23 +0000 |
parents | d910939febfa |
children | 782fd950bd46 2c4923336dd0 |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Handle the event stream, converting GGI events into SDL events */ | |
25 | |
26 #include <sys/types.h> | |
27 #include <sys/time.h> | |
28 #include <unistd.h> | |
29 #include <fcntl.h> | |
30 #include <termios.h> | |
31 | |
32 #include <ggi/keyboard.h> | |
33 | |
34 #include "SDL_ggikeys.h" | |
35 | |
36 #include "SDL.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
37 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
38 #include "../../events/SDL_sysevents.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
39 #include "../../events/SDL_events_c.h" |
0 | 40 #include "SDL_ggivideo.h" |
41 #include "SDL_ggievents_c.h" | |
42 | |
43 /* The translation tables from a GGI keycode to a SDL keysym */ | |
44 static SDLKey keymap[128]; | |
45 static SDL_keysym *GGI_TranslateKey(ggi_event *ev, SDL_keysym *keysym); | |
46 | |
47 static int posted = 0; | |
48 | |
49 void GGI_PumpEvents(_THIS) | |
50 { | |
51 struct timeval *tvp, tv = { 0, 0 }; | |
52 ggi_event ev; | |
53 | |
54 tvp = &tv; | |
55 | |
56 /* ggiFlush(VIS); */ | |
57 | |
58 while (ggiEventPoll(VIS, emAll, tvp)) | |
59 /* while (ggiEventPoll(VIS, (emKeyboard | emPointer | emCommand), tvp)) */ | |
60 { | |
61 int queueevent_mouse = 0, queueevent_kbd = 0; | |
62 static int buttons = 0; | |
63 static int mouse_x = 0, mouse_y = 0, mouse_z = 0; | |
64 int x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0; | |
65 uint32 sym; | |
66 int pressed_mouse, pressed_kbd; | |
67 SDL_keysym keysym; | |
68 | |
69 posted = 0; | |
70 | |
71 /* FIXME: We do not actually want all events, only | |
72 * mouse and keyboard events. Having to handle all | |
73 * events will slow things down. */ | |
74 | |
75 ggiEventRead(VIS, &ev, emAll); | |
76 /* ggiEventRead(VIS, &ev, (emKeyboard | emPointer | emCommand)); */ | |
77 | |
78 switch (ev.any.type) | |
79 { | |
80 case evPtrRelative: | |
81 x = ev.pmove.x; | |
82 y = ev.pmove.y; | |
83 z = ev.pmove.wheel; | |
84 posted += SDL_PrivateMouseMotion(0, 1, x, y); | |
85 break; | |
86 case evPtrAbsolute: | |
87 if (mouse_x != ev.pmove.x || mouse_y != ev.pmove.y || mouse_z != ev.pmove.wheel) | |
88 { | |
89 x = ev.pmove.x - mouse_x; | |
90 y = ev.pmove.y - mouse_y; | |
91 z = ev.pmove.wheel - mouse_z; | |
92 mouse_x = ev.pmove.x; | |
93 mouse_y = ev.pmove.y; | |
94 mouse_z = ev.pmove.wheel; | |
95 posted += SDL_PrivateMouseMotion(0, 1, x, y); | |
96 } | |
97 break; | |
98 case evPtrButtonPress: | |
99 posted += SDL_PrivateMouseButton(SDL_PRESSED, ev.pbutton.button, 0, 0); | |
100 break; | |
101 case evPtrButtonRelease: | |
102 posted += SDL_PrivateMouseButton(SDL_RELEASED, ev.pbutton.button, 0, 0); | |
103 break; | |
104 case evKeyPress: | |
105 case evKeyRepeat: | |
106 posted += SDL_PrivateKeyboard(SDL_PRESSED, GGI_TranslateKey(&ev, &keysym)); | |
107 break; | |
108 case evKeyRelease: | |
109 posted += SDL_PrivateKeyboard(SDL_RELEASED, GGI_TranslateKey(&ev, &keysym)); | |
110 break; | |
111 case evCommand: | |
112 fprintf(stderr, "Command event %x recieved\n", ev.cmd.code); | |
113 break; | |
114 default: | |
115 fprintf(stderr, "Unhandled event type %d\n", ev.any.type); | |
116 break; | |
117 } | |
118 } | |
119 | |
120 } | |
121 | |
122 void GGI_InitOSKeymap(_THIS) | |
123 { | |
124 int i; | |
125 | |
126 /* Initialize the GGI key translation table */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
127 for ( i=0; i<SDL_arraysize(keymap); ++i ) |
0 | 128 keymap[i] = SDLK_UNKNOWN; |
129 | |
130 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; | |
131 keymap[SCANCODE_1] = SDLK_1; | |
132 keymap[SCANCODE_2] = SDLK_2; | |
133 keymap[SCANCODE_3] = SDLK_3; | |
134 keymap[SCANCODE_4] = SDLK_4; | |
135 keymap[SCANCODE_5] = SDLK_5; | |
136 keymap[SCANCODE_6] = SDLK_6; | |
137 keymap[SCANCODE_7] = SDLK_7; | |
138 keymap[SCANCODE_8] = SDLK_8; | |
139 keymap[SCANCODE_9] = SDLK_9; | |
140 keymap[SCANCODE_0] = SDLK_0; | |
141 keymap[SCANCODE_MINUS] = SDLK_MINUS; | |
142 keymap[SCANCODE_EQUAL] = SDLK_EQUALS; | |
143 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; | |
144 keymap[SCANCODE_TAB] = SDLK_TAB; | |
145 keymap[SCANCODE_Q] = SDLK_q; | |
146 keymap[SCANCODE_W] = SDLK_w; | |
147 keymap[SCANCODE_E] = SDLK_e; | |
148 keymap[SCANCODE_R] = SDLK_r; | |
149 keymap[SCANCODE_T] = SDLK_t; | |
150 keymap[SCANCODE_Y] = SDLK_y; | |
151 keymap[SCANCODE_U] = SDLK_u; | |
152 keymap[SCANCODE_I] = SDLK_i; | |
153 keymap[SCANCODE_O] = SDLK_o; | |
154 keymap[SCANCODE_P] = SDLK_p; | |
155 keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET; | |
156 keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET; | |
157 keymap[SCANCODE_ENTER] = SDLK_RETURN; | |
158 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; | |
159 keymap[SCANCODE_A] = SDLK_a; | |
160 keymap[SCANCODE_S] = SDLK_s; | |
161 keymap[SCANCODE_D] = SDLK_d; | |
162 keymap[SCANCODE_F] = SDLK_f; | |
163 keymap[SCANCODE_G] = SDLK_g; | |
164 keymap[SCANCODE_H] = SDLK_h; | |
165 keymap[SCANCODE_J] = SDLK_j; | |
166 keymap[SCANCODE_K] = SDLK_k; | |
167 keymap[SCANCODE_L] = SDLK_l; | |
168 keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON; | |
169 keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE; | |
170 keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE; | |
171 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; | |
172 keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH; | |
173 keymap[SCANCODE_Z] = SDLK_z; | |
174 keymap[SCANCODE_X] = SDLK_x; | |
175 keymap[SCANCODE_C] = SDLK_c; | |
176 keymap[SCANCODE_V] = SDLK_v; | |
177 keymap[SCANCODE_B] = SDLK_b; | |
178 keymap[SCANCODE_N] = SDLK_n; | |
179 keymap[SCANCODE_M] = SDLK_m; | |
180 keymap[SCANCODE_COMMA] = SDLK_COMMA; | |
181 keymap[SCANCODE_PERIOD] = SDLK_PERIOD; | |
182 keymap[SCANCODE_SLASH] = SDLK_SLASH; | |
183 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; | |
184 keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY; | |
185 keymap[SCANCODE_LEFTALT] = SDLK_LALT; | |
186 keymap[SCANCODE_SPACE] = SDLK_SPACE; | |
187 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; | |
188 keymap[SCANCODE_F1] = SDLK_F1; | |
189 keymap[SCANCODE_F2] = SDLK_F2; | |
190 keymap[SCANCODE_F3] = SDLK_F3; | |
191 keymap[SCANCODE_F4] = SDLK_F4; | |
192 keymap[SCANCODE_F5] = SDLK_F5; | |
193 keymap[SCANCODE_F6] = SDLK_F6; | |
194 keymap[SCANCODE_F7] = SDLK_F7; | |
195 keymap[SCANCODE_F8] = SDLK_F8; | |
196 keymap[SCANCODE_F9] = SDLK_F9; | |
197 keymap[SCANCODE_F10] = SDLK_F10; | |
198 keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK; | |
199 keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK; | |
200 keymap[SCANCODE_KEYPAD7] = SDLK_KP7; | |
201 keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7; | |
202 keymap[SCANCODE_KEYPAD8] = SDLK_KP8; | |
203 keymap[SCANCODE_CURSORUP] = SDLK_KP8; | |
204 keymap[SCANCODE_KEYPAD9] = SDLK_KP9; | |
205 keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9; | |
206 keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS; | |
207 keymap[SCANCODE_KEYPAD4] = SDLK_KP4; | |
208 keymap[SCANCODE_CURSORLEFT] = SDLK_KP4; | |
209 keymap[SCANCODE_KEYPAD5] = SDLK_KP5; | |
210 keymap[SCANCODE_KEYPAD6] = SDLK_KP6; | |
211 keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6; | |
212 keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS; | |
213 keymap[SCANCODE_KEYPAD1] = SDLK_KP1; | |
214 keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1; | |
215 keymap[SCANCODE_KEYPAD2] = SDLK_KP2; | |
216 keymap[SCANCODE_CURSORDOWN] = SDLK_KP2; | |
217 keymap[SCANCODE_KEYPAD3] = SDLK_KP3; | |
218 keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3; | |
219 keymap[SCANCODE_KEYPAD0] = SDLK_KP0; | |
220 keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD; | |
221 keymap[SCANCODE_LESS] = SDLK_LESS; | |
222 keymap[SCANCODE_F11] = SDLK_F11; | |
223 keymap[SCANCODE_F12] = SDLK_F12; | |
224 keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER; | |
225 keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL; | |
226 keymap[SCANCODE_CONTROL] = SDLK_RCTRL; | |
227 keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE; | |
228 keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT; | |
229 keymap[SCANCODE_RIGHTALT] = SDLK_RALT; | |
230 keymap[SCANCODE_BREAK] = SDLK_BREAK; | |
231 keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN; | |
232 keymap[SCANCODE_HOME] = SDLK_HOME; | |
233 keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP; | |
234 keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP; | |
235 keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT; | |
236 keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT; | |
237 keymap[SCANCODE_END] = SDLK_END; | |
238 keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN; | |
239 keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN; | |
240 keymap[SCANCODE_INSERT] = SDLK_INSERT; | |
241 keymap[SCANCODE_REMOVE] = SDLK_DELETE; | |
242 keymap[119] = SDLK_PAUSE; | |
243 keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER; | |
244 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER; | |
245 keymap[127] = SDLK_MENU; | |
246 } | |
247 | |
248 | |
249 | |
250 static SDL_keysym *GGI_TranslateKey(gii_event *ev, SDL_keysym *keysym) | |
251 { | |
252 /* Set the keysym information */ | |
253 keysym->scancode = ev->key.button; | |
254 keysym->sym = keymap[ev->key.button]; | |
255 keysym->mod = KMOD_NONE; | |
256 | |
257 /* If UNICODE is on, get the UNICODE value for the key */ | |
258 keysym->unicode = 0; | |
259 if (SDL_TranslateUNICODE) | |
260 { | |
261 keysym->unicode = GII_UNICODE(ev->key.sym); | |
262 } | |
263 | |
264 return keysym; | |
265 } |