Mercurial > sdl-ios-xcode
annotate src/video/aalib/SDL_aaevents.c @ 1869:65800e7f7146
Date: Fri, 9 Jun 2006 11:35:23 +0300
From: "Janne Junnila"
Subject: [SDL] SDL_SetGamma bug
You can't set the the gamma 'brighter' than 1.0. There's a patch attached.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 20 Jun 2006 06:50:42 +0000 |
parents | bf8db2d92be1 |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
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 */ |
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 AA events into SDL events */ | |
25 | |
26 #include <stdio.h> | |
27 | |
28 #include <aalib.h> | |
29 | |
30 #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
|
31 #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
|
32 #include "../../events/SDL_events_c.h" |
0 | 33 #include "SDL_aavideo.h" |
34 #include "SDL_aaevents_c.h" | |
35 | |
36 /* The translation tables from a console scancode to a SDL keysym */ | |
37 static SDLKey keymap[401]; | |
38 | |
39 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); | |
40 | |
41 | |
42 void AA_PumpEvents(_THIS) | |
43 { | |
44 int posted = 0; | |
45 int mouse_button, mouse_x, mouse_y; | |
46 int evt; | |
47 SDL_keysym keysym; | |
48 | |
49 static int prev_button = -1, prev_x = -1, prev_y = -1; | |
50 | |
51 if( ! this->screen ) /* Wait till we got the screen initialized */ | |
52 return; | |
53 | |
54 do { | |
55 posted = 0; | |
56 /* Gather events */ | |
57 | |
58 /* Get mouse status */ | |
59 SDL_mutexP(AA_mutex); | |
60 aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button); | |
61 SDL_mutexV(AA_mutex); | |
62 mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context); | |
63 mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context); | |
64 | |
65 /* Compare against previous state and generate events */ | |
66 if( prev_button != mouse_button ) { | |
67 if( mouse_button & AA_BUTTON1 ) { | |
68 if ( ! (prev_button & AA_BUTTON1) ) { | |
69 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0); | |
70 } | |
71 } else { | |
72 if ( prev_button & AA_BUTTON1 ) { | |
73 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0); | |
74 } | |
75 } | |
76 if( mouse_button & AA_BUTTON2 ) { | |
77 if ( ! (prev_button & AA_BUTTON2) ) { | |
78 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0); | |
79 } | |
80 } else { | |
81 if ( prev_button & AA_BUTTON2 ) { | |
82 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0); | |
83 } | |
84 } | |
85 if( mouse_button & AA_BUTTON3 ) { | |
86 if ( ! (prev_button & AA_BUTTON3) ) { | |
87 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0); | |
88 } | |
89 } else { | |
90 if ( prev_button & AA_BUTTON3 ) { | |
91 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0); | |
92 } | |
93 } | |
94 } | |
95 if ( prev_x != mouse_x || prev_y != mouse_y ) { | |
96 posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y); | |
97 } | |
98 | |
99 prev_button = mouse_button; | |
100 prev_x = mouse_x; prev_y = mouse_y; | |
101 | |
102 /* Get keyboard event */ | |
103 SDL_mutexP(AA_mutex); | |
104 evt = aa_getevent(AA_context, 0); | |
105 SDL_mutexV(AA_mutex); | |
106 if ( (evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) && (evt != AA_RESIZE) ) { | |
107 /* Key pressed */ | |
108 /* printf("Key pressed: %d (%c)\n", evt, evt); */ | |
109 posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym)); | |
110 } else if ( evt >= AA_RELEASE ) { | |
111 /* Key released */ | |
112 evt &= ~AA_RELEASE; | |
113 /* printf("Key released: %d (%c)\n", evt, evt); */ | |
114 posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym)); | |
115 } | |
116 } while ( posted ); | |
117 } | |
118 | |
119 void AA_InitOSKeymap(_THIS) | |
120 { | |
121 int i; | |
122 static const char *std_keys = " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9"; | |
123 const char *std; | |
124 | |
125 /* Initialize the AAlib key translation table */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
126 for ( i=0; i<SDL_arraysize(keymap); ++i ) |
0 | 127 keymap[i] = SDLK_UNKNOWN; |
128 | |
129 /* Alphabet keys */ | |
130 for ( i = 0; i<26; ++i ){ | |
131 keymap['a' + i] = SDLK_a+i; | |
132 keymap['A' + i] = SDLK_a+i; | |
133 } | |
134 /* Function keys */ | |
135 for ( i = 0; i<12; ++i ){ | |
136 keymap[334 + i] = SDLK_F1+i; | |
137 } | |
138 /* Keys that have the same symbols and don't have to be translated */ | |
139 for( std = std_keys; *std; std ++ ) { | |
140 keymap[*std] = *std; | |
141 } | |
142 | |
143 keymap[13] = SDLK_RETURN; | |
144 keymap[AA_BACKSPACE] = SDLK_BACKSPACE; | |
145 | |
146 keymap[369] = SDLK_LSHIFT; | |
147 keymap[370] = SDLK_RSHIFT; | |
148 keymap[371] = SDLK_LCTRL; | |
149 keymap[372] = SDLK_RCTRL; | |
150 keymap[377] = SDLK_LALT; | |
151 keymap[270] = SDLK_RALT; | |
152 keymap[271] = SDLK_NUMLOCK; | |
153 keymap[373] = SDLK_CAPSLOCK; | |
154 keymap[164] = SDLK_SCROLLOCK; | |
155 | |
156 keymap[243] = SDLK_INSERT; | |
157 keymap[304] = SDLK_DELETE; | |
158 keymap[224] = SDLK_HOME; | |
159 keymap[231] = SDLK_END; | |
160 keymap[229] = SDLK_PAGEUP; | |
161 keymap[230] = SDLK_PAGEDOWN; | |
162 | |
163 keymap[241] = SDLK_PRINT; | |
164 keymap[163] = SDLK_BREAK; | |
165 | |
166 keymap[302] = SDLK_KP0; | |
167 keymap[300] = SDLK_KP1; | |
168 keymap[297] = SDLK_KP2; | |
169 keymap[299] = SDLK_KP3; | |
170 keymap[294] = SDLK_KP4; | |
171 keymap[301] = SDLK_KP5; | |
172 keymap[296] = SDLK_KP6; | |
173 keymap[293] = SDLK_KP7; | |
174 keymap[295] = SDLK_KP8; | |
175 keymap[298] = SDLK_KP9; | |
1458
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
176 |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
177 keymap[AA_ESC] = SDLK_ESCAPE; |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
178 keymap[AA_UP] = SDLK_UP; |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
179 keymap[AA_DOWN] = SDLK_DOWN; |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
180 keymap[AA_LEFT] = SDLK_LEFT; |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
181 keymap[AA_RIGHT] = SDLK_RIGHT; |
0 | 182 } |
183 | |
184 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
185 { | |
1458
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
186 /* Sanity check */ |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
187 if ( scancode >= SDL_arraysize(keymap) ) |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
188 scancode = AA_UNKNOWN; |
bf8db2d92be1
Date: Wed, 1 Mar 2006 23:52:09 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
189 |
0 | 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 } |