comparison src/video/aalib/SDL_aaevents.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
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 42 void
43 AA_PumpEvents (_THIS) 43 AA_PumpEvents(_THIS)
44 { 44 {
45 int posted = 0; 45 int posted = 0;
46 int mouse_button, mouse_x, mouse_y; 46 int mouse_button, mouse_x, mouse_y;
47 int evt; 47 int evt;
48 SDL_keysym keysym; 48 SDL_keysym keysym;
55 do { 55 do {
56 posted = 0; 56 posted = 0;
57 /* Gather events */ 57 /* Gather events */
58 58
59 /* Get mouse status */ 59 /* Get mouse status */
60 SDL_mutexP (AA_mutex); 60 SDL_mutexP(AA_mutex);
61 aa_getmouse (AA_context, &mouse_x, &mouse_y, &mouse_button); 61 aa_getmouse(AA_context, &mouse_x, &mouse_y, &mouse_button);
62 SDL_mutexV (AA_mutex); 62 SDL_mutexV(AA_mutex);
63 mouse_x = mouse_x * this->screen->w / aa_scrwidth (AA_context); 63 mouse_x = mouse_x * this->screen->w / aa_scrwidth(AA_context);
64 mouse_y = mouse_y * this->screen->h / aa_scrheight (AA_context); 64 mouse_y = mouse_y * this->screen->h / aa_scrheight(AA_context);
65 65
66 /* Compare against previous state and generate events */ 66 /* Compare against previous state and generate events */
67 if (prev_button != mouse_button) { 67 if (prev_button != mouse_button) {
68 if (mouse_button & AA_BUTTON1) { 68 if (mouse_button & AA_BUTTON1) {
69 if (!(prev_button & AA_BUTTON1)) { 69 if (!(prev_button & AA_BUTTON1)) {
70 posted += SDL_PrivateMouseButton (SDL_PRESSED, 1, 0, 0); 70 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0);
71 } 71 }
72 } else { 72 } else {
73 if (prev_button & AA_BUTTON1) { 73 if (prev_button & AA_BUTTON1) {
74 posted += SDL_PrivateMouseButton (SDL_RELEASED, 1, 0, 0); 74 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0);
75 } 75 }
76 } 76 }
77 if (mouse_button & AA_BUTTON2) { 77 if (mouse_button & AA_BUTTON2) {
78 if (!(prev_button & AA_BUTTON2)) { 78 if (!(prev_button & AA_BUTTON2)) {
79 posted += SDL_PrivateMouseButton (SDL_PRESSED, 2, 0, 0); 79 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0);
80 } 80 }
81 } else { 81 } else {
82 if (prev_button & AA_BUTTON2) { 82 if (prev_button & AA_BUTTON2) {
83 posted += SDL_PrivateMouseButton (SDL_RELEASED, 2, 0, 0); 83 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0);
84 } 84 }
85 } 85 }
86 if (mouse_button & AA_BUTTON3) { 86 if (mouse_button & AA_BUTTON3) {
87 if (!(prev_button & AA_BUTTON3)) { 87 if (!(prev_button & AA_BUTTON3)) {
88 posted += SDL_PrivateMouseButton (SDL_PRESSED, 3, 0, 0); 88 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0);
89 } 89 }
90 } else { 90 } else {
91 if (prev_button & AA_BUTTON3) { 91 if (prev_button & AA_BUTTON3) {
92 posted += SDL_PrivateMouseButton (SDL_RELEASED, 3, 0, 0); 92 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0);
93 } 93 }
94 } 94 }
95 } 95 }
96 if (prev_x != mouse_x || prev_y != mouse_y) { 96 if (prev_x != mouse_x || prev_y != mouse_y) {
97 posted += SDL_PrivateMouseMotion (0, 0, mouse_x, mouse_y); 97 posted += SDL_PrivateMouseMotion(0, 0, mouse_x, mouse_y);
98 } 98 }
99 99
100 prev_button = mouse_button; 100 prev_button = mouse_button;
101 prev_x = mouse_x; 101 prev_x = mouse_x;
102 prev_y = mouse_y; 102 prev_y = mouse_y;
103 103
104 /* Get keyboard event */ 104 /* Get keyboard event */
105 SDL_mutexP (AA_mutex); 105 SDL_mutexP(AA_mutex);
106 evt = aa_getevent (AA_context, 0); 106 evt = aa_getevent(AA_context, 0);
107 SDL_mutexV (AA_mutex); 107 SDL_mutexV(AA_mutex);
108 if ((evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE) 108 if ((evt > AA_NONE) && (evt < AA_RELEASE) && (evt != AA_MOUSE)
109 && (evt != AA_RESIZE)) { 109 && (evt != AA_RESIZE)) {
110 /* Key pressed */ 110 /* Key pressed */
111 /* printf("Key pressed: %d (%c)\n", evt, evt); */ 111 /* printf("Key pressed: %d (%c)\n", evt, evt); */
112 posted += 112 posted +=
113 SDL_PrivateKeyboard (SDL_PRESSED, 113 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(evt, &keysym));
114 TranslateKey (evt, &keysym));
115 } else if (evt >= AA_RELEASE) { 114 } else if (evt >= AA_RELEASE) {
116 /* Key released */ 115 /* Key released */
117 evt &= ~AA_RELEASE; 116 evt &= ~AA_RELEASE;
118 /* printf("Key released: %d (%c)\n", evt, evt); */ 117 /* printf("Key released: %d (%c)\n", evt, evt); */
119 posted += 118 posted +=
120 SDL_PrivateKeyboard (SDL_RELEASED, 119 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(evt, &keysym));
121 TranslateKey (evt, &keysym));
122 } 120 }
123 } 121 }
124 while (posted); 122 while (posted);
125 } 123 }
126 124
127 void 125 void
128 AA_InitOSKeymap (_THIS) 126 AA_InitOSKeymap(_THIS)
129 { 127 {
130 int i; 128 int i;
131 static const char *std_keys = 129 static const char *std_keys =
132 " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9"; 130 " 01234567890&#'()_-|$*+-=/\\:;.,!?<>{}[]@~%^\x9";
133 const char *std; 131 const char *std;
134 132
135 /* Initialize the AAlib key translation table */ 133 /* Initialize the AAlib key translation table */
136 for (i = 0; i < SDL_arraysize (keymap); ++i) 134 for (i = 0; i < SDL_arraysize(keymap); ++i)
137 keymap[i] = SDLK_UNKNOWN; 135 keymap[i] = SDLK_UNKNOWN;
138 136
139 /* Alphabet keys */ 137 /* Alphabet keys */
140 for (i = 0; i < 26; ++i) { 138 for (i = 0; i < 26; ++i) {
141 keymap['a' + i] = SDLK_a + i; 139 keymap['a' + i] = SDLK_a + i;
190 keymap[AA_LEFT] = SDLK_LEFT; 188 keymap[AA_LEFT] = SDLK_LEFT;
191 keymap[AA_RIGHT] = SDLK_RIGHT; 189 keymap[AA_RIGHT] = SDLK_RIGHT;
192 } 190 }
193 191
194 static SDL_keysym * 192 static SDL_keysym *
195 TranslateKey (int scancode, SDL_keysym * keysym) 193 TranslateKey(int scancode, SDL_keysym * keysym)
196 { 194 {
197 /* Sanity check */ 195 /* Sanity check */
198 if (scancode >= SDL_arraysize (keymap)) 196 if (scancode >= SDL_arraysize(keymap))
199 scancode = AA_UNKNOWN; 197 scancode = AA_UNKNOWN;
200 198
201 /* Set the keysym information */ 199 /* Set the keysym information */
202 keysym->scancode = scancode; 200 keysym->scancode = scancode;
203 keysym->sym = keymap[scancode]; 201 keysym->sym = keymap[scancode];