Mercurial > sdl-ios-xcode
comparison src/video/aalib/SDL_aaevents.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 | bf8db2d92be1 |
children |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
34 #include "SDL_aaevents_c.h" | 34 #include "SDL_aaevents_c.h" |
35 | 35 |
36 /* The translation tables from a console scancode to a SDL keysym */ | 36 /* The translation tables from a console scancode to a SDL keysym */ |
37 static SDLKey keymap[401]; | 37 static SDLKey keymap[401]; |
38 | 38 |
39 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); | 39 static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym); |
40 | 40 |
41 | 41 |
42 void AA_PumpEvents(_THIS) | 42 void |
43 AA_PumpEvents(_THIS) | |
43 { | 44 { |
44 int posted = 0; | 45 int posted = 0; |
45 int mouse_button, mouse_x, mouse_y; | 46 int mouse_button, mouse_x, mouse_y; |
46 int evt; | 47 int evt; |
47 SDL_keysym keysym; | 48 SDL_keysym keysym; |
48 | 49 |
49 static int prev_button = -1, prev_x = -1, prev_y = -1; | 50 static int prev_button = -1, prev_x = -1, prev_y = -1; |
50 | 51 |
51 if( ! this->screen ) /* Wait till we got the screen initialized */ | 52 if (!this->screen) /* Wait till we got the screen initialized */ |
52 return; | 53 return; |
53 | 54 |
54 do { | 55 do { |
55 posted = 0; | 56 posted = 0; |
56 /* Gather events */ | 57 /* Gather events */ |
57 | 58 |
58 /* Get mouse status */ | 59 /* Get mouse status */ |
59 SDL_mutexP(AA_mutex); | 60 SDL_mutexP(AA_mutex); |
60 aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button); | 61 aa_getmouse(AA_context, &mouse_x, &mouse_y, &mouse_button); |
61 SDL_mutexV(AA_mutex); | 62 SDL_mutexV(AA_mutex); |
62 mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context); | 63 mouse_x = mouse_x * this->screen->w / aa_scrwidth(AA_context); |
63 mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context); | 64 mouse_y = mouse_y * this->screen->h / aa_scrheight(AA_context); |
64 | 65 |
65 /* Compare against previous state and generate events */ | 66 /* Compare against previous state and generate events */ |
66 if( prev_button != mouse_button ) { | 67 if (prev_button != mouse_button) { |
67 if( mouse_button & AA_BUTTON1 ) { | 68 if (mouse_button & AA_BUTTON1) { |
68 if ( ! (prev_button & AA_BUTTON1) ) { | 69 if (!(prev_button & AA_BUTTON1)) { |
69 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0); | 70 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0); |
70 } | 71 } |
71 } else { | 72 } else { |
72 if ( prev_button & AA_BUTTON1 ) { | 73 if (prev_button & AA_BUTTON1) { |
73 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0); | 74 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0); |
74 } | 75 } |
75 } | 76 } |
76 if( mouse_button & AA_BUTTON2 ) { | 77 if (mouse_button & AA_BUTTON2) { |
77 if ( ! (prev_button & AA_BUTTON2) ) { | 78 if (!(prev_button & AA_BUTTON2)) { |
78 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0); | 79 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0); |
79 } | 80 } |
80 } else { | 81 } else { |
81 if ( prev_button & AA_BUTTON2 ) { | 82 if (prev_button & AA_BUTTON2) { |
82 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0); | 83 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0); |
83 } | 84 } |
84 } | 85 } |
85 if( mouse_button & AA_BUTTON3 ) { | 86 if (mouse_button & AA_BUTTON3) { |
86 if ( ! (prev_button & AA_BUTTON3) ) { | 87 if (!(prev_button & AA_BUTTON3)) { |
87 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0); | 88 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0); |
88 } | 89 } |
89 } else { | 90 } else { |
90 if ( prev_button & AA_BUTTON3 ) { | 91 if (prev_button & AA_BUTTON3) { |
91 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0); | 92 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0); |
92 } | 93 } |
93 } | 94 } |
94 } | 95 } |
95 if ( prev_x != mouse_x || prev_y != mouse_y ) { | 96 if (prev_x != mouse_x || prev_y != mouse_y) { |
96 posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y); | 97 posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y); |
97 } | 98 } |
98 | 99 |
99 prev_button = mouse_button; | 100 prev_button = mouse_button; |
100 prev_x = mouse_x; prev_y = mouse_y; | 101 prev_x = mouse_x; |
101 | 102 prev_y = mouse_y; |
102 /* Get keyboard event */ | 103 |
103 SDL_mutexP(AA_mutex); | 104 /* Get keyboard event */ |
104 evt = aa_getevent(AA_context, 0); | 105 SDL_mutexP(AA_mutex); |
105 SDL_mutexV(AA_mutex); | 106 evt = aa_getevent(AA_context, 0); |
106 if ( (evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) && (evt != AA_RESIZE) ) { | 107 SDL_mutexV(AA_mutex); |
107 /* Key pressed */ | 108 if ((evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) |
109 && (evt != AA_RESIZE)) { | |
110 /* Key pressed */ | |
108 /* printf("Key pressed: %d (%c)\n", evt, evt); */ | 111 /* printf("Key pressed: %d (%c)\n", evt, evt); */ |
109 posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym)); | 112 posted += |
110 } else if ( evt >= AA_RELEASE ) { | 113 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym)); |
111 /* Key released */ | 114 } else if (evt >= AA_RELEASE) { |
112 evt &= ~AA_RELEASE; | 115 /* Key released */ |
116 evt &= ~AA_RELEASE; | |
113 /* printf("Key released: %d (%c)\n", evt, evt); */ | 117 /* printf("Key released: %d (%c)\n", evt, evt); */ |
114 posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym)); | 118 posted += |
115 } | 119 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym)); |
116 } while ( posted ); | 120 } |
121 } | |
122 while (posted); | |
117 } | 123 } |
118 | 124 |
119 void AA_InitOSKeymap(_THIS) | 125 void |
126 AA_InitOSKeymap(_THIS) | |
120 { | 127 { |
121 int i; | 128 int i; |
122 static const char *std_keys = " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9"; | 129 static const char *std_keys = |
123 const char *std; | 130 " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9"; |
124 | 131 const char *std; |
125 /* Initialize the AAlib key translation table */ | 132 |
126 for ( i=0; i<SDL_arraysize(keymap); ++i ) | 133 /* Initialize the AAlib key translation table */ |
127 keymap[i] = SDLK_UNKNOWN; | 134 for (i = 0; i < SDL_arraysize(keymap); ++i) |
128 | 135 keymap[i] = SDLK_UNKNOWN; |
129 /* Alphabet keys */ | 136 |
130 for ( i = 0; i<26; ++i ){ | 137 /* Alphabet keys */ |
131 keymap['a' + i] = SDLK_a+i; | 138 for (i = 0; i < 26; ++i) { |
132 keymap['A' + i] = SDLK_a+i; | 139 keymap['a' + i] = SDLK_a + i; |
133 } | 140 keymap['A' + i] = SDLK_a + i; |
134 /* Function keys */ | 141 } |
135 for ( i = 0; i<12; ++i ){ | 142 /* Function keys */ |
136 keymap[334 + i] = SDLK_F1+i; | 143 for (i = 0; i < 12; ++i) { |
137 } | 144 keymap[334 + i] = SDLK_F1 + i; |
138 /* Keys that have the same symbols and don't have to be translated */ | 145 } |
139 for( std = std_keys; *std; std ++ ) { | 146 /* Keys that have the same symbols and don't have to be translated */ |
140 keymap[*std] = *std; | 147 for (std = std_keys; *std; std++) { |
141 } | 148 keymap[*std] = *std; |
142 | 149 } |
143 keymap[13] = SDLK_RETURN; | 150 |
144 keymap[AA_BACKSPACE] = SDLK_BACKSPACE; | 151 keymap[13] = SDLK_RETURN; |
145 | 152 keymap[AA_BACKSPACE] = SDLK_BACKSPACE; |
146 keymap[369] = SDLK_LSHIFT; | 153 |
147 keymap[370] = SDLK_RSHIFT; | 154 keymap[369] = SDLK_LSHIFT; |
148 keymap[371] = SDLK_LCTRL; | 155 keymap[370] = SDLK_RSHIFT; |
149 keymap[372] = SDLK_RCTRL; | 156 keymap[371] = SDLK_LCTRL; |
150 keymap[377] = SDLK_LALT; | 157 keymap[372] = SDLK_RCTRL; |
151 keymap[270] = SDLK_RALT; | 158 keymap[377] = SDLK_LALT; |
152 keymap[271] = SDLK_NUMLOCK; | 159 keymap[270] = SDLK_RALT; |
153 keymap[373] = SDLK_CAPSLOCK; | 160 keymap[271] = SDLK_NUMLOCK; |
154 keymap[164] = SDLK_SCROLLOCK; | 161 keymap[373] = SDLK_CAPSLOCK; |
155 | 162 keymap[164] = SDLK_SCROLLOCK; |
156 keymap[243] = SDLK_INSERT; | 163 |
157 keymap[304] = SDLK_DELETE; | 164 keymap[243] = SDLK_INSERT; |
158 keymap[224] = SDLK_HOME; | 165 keymap[304] = SDLK_DELETE; |
159 keymap[231] = SDLK_END; | 166 keymap[224] = SDLK_HOME; |
160 keymap[229] = SDLK_PAGEUP; | 167 keymap[231] = SDLK_END; |
161 keymap[230] = SDLK_PAGEDOWN; | 168 keymap[229] = SDLK_PAGEUP; |
162 | 169 keymap[230] = SDLK_PAGEDOWN; |
163 keymap[241] = SDLK_PRINT; | 170 |
164 keymap[163] = SDLK_BREAK; | 171 keymap[241] = SDLK_PRINT; |
165 | 172 keymap[163] = SDLK_BREAK; |
166 keymap[302] = SDLK_KP0; | 173 |
167 keymap[300] = SDLK_KP1; | 174 keymap[302] = SDLK_KP0; |
168 keymap[297] = SDLK_KP2; | 175 keymap[300] = SDLK_KP1; |
169 keymap[299] = SDLK_KP3; | 176 keymap[297] = SDLK_KP2; |
170 keymap[294] = SDLK_KP4; | 177 keymap[299] = SDLK_KP3; |
171 keymap[301] = SDLK_KP5; | 178 keymap[294] = SDLK_KP4; |
172 keymap[296] = SDLK_KP6; | 179 keymap[301] = SDLK_KP5; |
173 keymap[293] = SDLK_KP7; | 180 keymap[296] = SDLK_KP6; |
174 keymap[295] = SDLK_KP8; | 181 keymap[293] = SDLK_KP7; |
175 keymap[298] = SDLK_KP9; | 182 keymap[295] = SDLK_KP8; |
176 | 183 keymap[298] = SDLK_KP9; |
177 keymap[AA_ESC] = SDLK_ESCAPE; | 184 |
178 keymap[AA_UP] = SDLK_UP; | 185 keymap[AA_ESC] = SDLK_ESCAPE; |
179 keymap[AA_DOWN] = SDLK_DOWN; | 186 keymap[AA_UP] = SDLK_UP; |
180 keymap[AA_LEFT] = SDLK_LEFT; | 187 keymap[AA_DOWN] = SDLK_DOWN; |
181 keymap[AA_RIGHT] = SDLK_RIGHT; | 188 keymap[AA_LEFT] = SDLK_LEFT; |
189 keymap[AA_RIGHT] = SDLK_RIGHT; | |
182 } | 190 } |
183 | 191 |
184 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | 192 static SDL_keysym * |
193 TranslateKey(int scancode, SDL_keysym * keysym) | |
185 { | 194 { |
186 /* Sanity check */ | 195 /* Sanity check */ |
187 if ( scancode >= SDL_arraysize(keymap) ) | 196 if (scancode >= SDL_arraysize(keymap)) |
188 scancode = AA_UNKNOWN; | 197 scancode = AA_UNKNOWN; |
189 | 198 |
190 /* Set the keysym information */ | 199 /* Set the keysym information */ |
191 keysym->scancode = scancode; | 200 keysym->scancode = scancode; |
192 keysym->sym = keymap[scancode]; | 201 keysym->sym = keymap[scancode]; |
193 keysym->mod = KMOD_NONE; | 202 keysym->mod = KMOD_NONE; |
194 | 203 |
195 /* If UNICODE is on, get the UNICODE value for the key */ | 204 /* If UNICODE is on, get the UNICODE value for the key */ |
196 keysym->unicode = 0; | 205 keysym->unicode = 0; |
197 if ( SDL_TranslateUNICODE ) { | 206 if (SDL_TranslateUNICODE) { |
198 /* Populate the unicode field with the ASCII value */ | 207 /* Populate the unicode field with the ASCII value */ |
199 keysym->unicode = scancode; | 208 keysym->unicode = scancode; |
200 } | 209 } |
201 return(keysym); | 210 return (keysym); |
202 } | 211 } |
212 | |
213 /* vi: set ts=4 sw=4 expandtab: */ |