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