0
|
1 /*
|
|
2 SDL - Simple DirectMedia Layer
|
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
|
|
4
|
|
5 This library is free software; you can redistribute it and/or
|
|
6 modify it under the terms of the GNU Library General Public
|
|
7 License as published by the Free Software Foundation; either
|
|
8 version 2 of the License, or (at your option) any later version.
|
|
9
|
|
10 This library 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 GNU
|
|
13 Library General Public License for more details.
|
|
14
|
|
15 You should have received a copy of the GNU Library General Public
|
|
16 License along with this library; if not, write to the Free
|
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18
|
|
19 Sam Lantinga
|
|
20 slouken@devolution.com
|
|
21 */
|
|
22
|
|
23 #ifdef SAVE_RCSID
|
|
24 static char rcsid =
|
|
25 "@(#) $Id$";
|
|
26 #endif
|
|
27
|
|
28 /* Handle the event stream, converting AA events into SDL events */
|
|
29
|
|
30 #include <stdio.h>
|
|
31
|
|
32 #include <aalib.h>
|
|
33
|
|
34 #include "SDL.h"
|
|
35 #include "SDL_sysevents.h"
|
|
36 #include "SDL_events_c.h"
|
|
37 #include "SDL_aavideo.h"
|
|
38 #include "SDL_aaevents_c.h"
|
|
39
|
|
40 /* The translation tables from a console scancode to a SDL keysym */
|
|
41 static SDLKey keymap[401];
|
|
42
|
|
43 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
|
|
44
|
|
45
|
|
46 void AA_PumpEvents(_THIS)
|
|
47 {
|
|
48 int posted = 0;
|
|
49 int mouse_button, mouse_x, mouse_y;
|
|
50 int evt;
|
|
51 SDL_keysym keysym;
|
|
52
|
|
53 static int prev_button = -1, prev_x = -1, prev_y = -1;
|
|
54
|
|
55 if( ! this->screen ) /* Wait till we got the screen initialized */
|
|
56 return;
|
|
57
|
|
58 do {
|
|
59 posted = 0;
|
|
60 /* Gather events */
|
|
61
|
|
62 /* Get mouse status */
|
|
63 SDL_mutexP(AA_mutex);
|
|
64 aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button);
|
|
65 SDL_mutexV(AA_mutex);
|
|
66 mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context);
|
|
67 mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context);
|
|
68
|
|
69 /* Compare against previous state and generate events */
|
|
70 if( prev_button != mouse_button ) {
|
|
71 if( mouse_button & AA_BUTTON1 ) {
|
|
72 if ( ! (prev_button & AA_BUTTON1) ) {
|
|
73 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0);
|
|
74 }
|
|
75 } else {
|
|
76 if ( prev_button & AA_BUTTON1 ) {
|
|
77 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0);
|
|
78 }
|
|
79 }
|
|
80 if( mouse_button & AA_BUTTON2 ) {
|
|
81 if ( ! (prev_button & AA_BUTTON2) ) {
|
|
82 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0);
|
|
83 }
|
|
84 } else {
|
|
85 if ( prev_button & AA_BUTTON2 ) {
|
|
86 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0);
|
|
87 }
|
|
88 }
|
|
89 if( mouse_button & AA_BUTTON3 ) {
|
|
90 if ( ! (prev_button & AA_BUTTON3) ) {
|
|
91 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0);
|
|
92 }
|
|
93 } else {
|
|
94 if ( prev_button & AA_BUTTON3 ) {
|
|
95 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0);
|
|
96 }
|
|
97 }
|
|
98 }
|
|
99 if ( prev_x != mouse_x || prev_y != mouse_y ) {
|
|
100 posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y);
|
|
101 }
|
|
102
|
|
103 prev_button = mouse_button;
|
|
104 prev_x = mouse_x; prev_y = mouse_y;
|
|
105
|
|
106 /* Get keyboard event */
|
|
107 SDL_mutexP(AA_mutex);
|
|
108 evt = aa_getevent(AA_context, 0);
|
|
109 SDL_mutexV(AA_mutex);
|
|
110 if ( (evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) && (evt != AA_RESIZE) ) {
|
|
111 /* Key pressed */
|
|
112 /* printf("Key pressed: %d (%c)\n", evt, evt); */
|
|
113 posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym));
|
|
114 } else if ( evt >= AA_RELEASE ) {
|
|
115 /* Key released */
|
|
116 evt &= ~AA_RELEASE;
|
|
117 /* printf("Key released: %d (%c)\n", evt, evt); */
|
|
118 posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym));
|
|
119 }
|
|
120 } while ( posted );
|
|
121 }
|
|
122
|
|
123 void AA_InitOSKeymap(_THIS)
|
|
124 {
|
|
125 int i;
|
|
126 static const char *std_keys = " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9";
|
|
127 const char *std;
|
|
128
|
|
129 /* Initialize the AAlib key translation table */
|
|
130 for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
|
|
131 keymap[i] = SDLK_UNKNOWN;
|
|
132
|
|
133 keymap[AA_ESC] = SDLK_ESCAPE;
|
|
134 keymap[AA_UP] = SDLK_UP;
|
|
135 keymap[AA_DOWN] = SDLK_DOWN;
|
|
136 keymap[AA_LEFT] = SDLK_LEFT;
|
|
137 keymap[AA_RIGHT] = SDLK_RIGHT;
|
|
138
|
|
139 /* Alphabet keys */
|
|
140 for ( i = 0; i<26; ++i ){
|
|
141 keymap['a' + i] = SDLK_a+i;
|
|
142 keymap['A' + i] = SDLK_a+i;
|
|
143 }
|
|
144 /* Function keys */
|
|
145 for ( i = 0; i<12; ++i ){
|
|
146 keymap[334 + i] = SDLK_F1+i;
|
|
147 }
|
|
148 /* Keys that have the same symbols and don't have to be translated */
|
|
149 for( std = std_keys; *std; std ++ ) {
|
|
150 keymap[*std] = *std;
|
|
151 }
|
|
152
|
|
153 keymap[13] = SDLK_RETURN;
|
|
154 keymap[AA_BACKSPACE] = SDLK_BACKSPACE;
|
|
155
|
|
156 keymap[369] = SDLK_LSHIFT;
|
|
157 keymap[370] = SDLK_RSHIFT;
|
|
158 keymap[371] = SDLK_LCTRL;
|
|
159 keymap[372] = SDLK_RCTRL;
|
|
160 keymap[377] = SDLK_LALT;
|
|
161 keymap[270] = SDLK_RALT;
|
|
162 keymap[271] = SDLK_NUMLOCK;
|
|
163 keymap[373] = SDLK_CAPSLOCK;
|
|
164 keymap[164] = SDLK_SCROLLOCK;
|
|
165
|
|
166 keymap[243] = SDLK_INSERT;
|
|
167 keymap[304] = SDLK_DELETE;
|
|
168 keymap[224] = SDLK_HOME;
|
|
169 keymap[231] = SDLK_END;
|
|
170 keymap[229] = SDLK_PAGEUP;
|
|
171 keymap[230] = SDLK_PAGEDOWN;
|
|
172
|
|
173 keymap[241] = SDLK_PRINT;
|
|
174 keymap[163] = SDLK_BREAK;
|
|
175
|
|
176 keymap[302] = SDLK_KP0;
|
|
177 keymap[300] = SDLK_KP1;
|
|
178 keymap[297] = SDLK_KP2;
|
|
179 keymap[299] = SDLK_KP3;
|
|
180 keymap[294] = SDLK_KP4;
|
|
181 keymap[301] = SDLK_KP5;
|
|
182 keymap[296] = SDLK_KP6;
|
|
183 keymap[293] = SDLK_KP7;
|
|
184 keymap[295] = SDLK_KP8;
|
|
185 keymap[298] = SDLK_KP9;
|
|
186 }
|
|
187
|
|
188 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
|
|
189 {
|
|
190 /* Set the keysym information */
|
|
191 keysym->scancode = scancode;
|
|
192 keysym->sym = keymap[scancode];
|
|
193 keysym->mod = KMOD_NONE;
|
|
194
|
|
195 /* If UNICODE is on, get the UNICODE value for the key */
|
|
196 keysym->unicode = 0;
|
|
197 if ( SDL_TranslateUNICODE ) {
|
|
198 /* Populate the unicode field with the ASCII value */
|
|
199 keysym->unicode = scancode;
|
|
200 }
|
|
201 return(keysym);
|
|
202 }
|