comparison test/threadwin.c @ 4429:faa9fc8e7f67

General improvements for user custom event registration * Switched event type to enum (int32) * Switched polling by mask to polling by type range * Added SDL_RegisterEvents() to allow dynamic user event registration * Spread events out to allow inserting new related events without breaking binary compatibility * Added padding to event structures so they're the same size regardless of 32-bit compiler structure packing settings * Split SDL_HasEvent() to SDL_HasEvent() for a single event and SDL_HasEvents() for a range of events * Added SDL_GetEventState() as a shortcut for SDL_EventState(X, SDL_QUERY) * Added SDL_FlushEvent() and SDL_FlushEvents() to clear events from the event queue
author Sam Lantinga <slouken@libsdl.org>
date Thu, 25 Mar 2010 01:08:26 -0700
parents 40888832d785
children dc0dfdd58f27
comparison
equal deleted inserted replaced
4428:68dfd6df47da 4429:faa9fc8e7f67
131 int SDLCALL 131 int SDLCALL
132 HandleMouse(void *unused) 132 HandleMouse(void *unused)
133 { 133 {
134 SDL_Event events[10]; 134 SDL_Event events[10];
135 int i, found; 135 int i, found;
136 Uint32 mask;
137 136
138 /* Handle mouse events here */ 137 /* Handle mouse events here */
139 mask =
140 (SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK |
141 SDL_MOUSEBUTTONUPMASK);
142 while (!done) { 138 while (!done) {
143 found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask); 139 found = SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
144 for (i = 0; i < found; ++i) { 140 for (i = 0; i < found; ++i) {
145 switch (events[i].type) { 141 switch (events[i].type) {
146 /* We want to toggle visibility on buttonpress */ 142 /* We want to toggle visibility on buttonpress */
147 case SDL_MOUSEBUTTONDOWN: 143 case SDL_MOUSEBUTTONDOWN:
148 case SDL_MOUSEBUTTONUP: 144 case SDL_MOUSEBUTTONUP:
171 int SDLCALL 167 int SDLCALL
172 HandleKeyboard(void *unused) 168 HandleKeyboard(void *unused)
173 { 169 {
174 SDL_Event events[10]; 170 SDL_Event events[10];
175 int i, found; 171 int i, found;
176 Uint32 mask;
177 172
178 /* Handle mouse events here */ 173 /* Handle mouse events here */
179 mask = (SDL_KEYDOWNMASK | SDL_KEYUPMASK);
180 while (!done) { 174 while (!done) {
181 found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask); 175 found = SDL_PeepEvents(events, 10, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP);
182 for (i = 0; i < found; ++i) { 176 for (i = 0; i < found; ++i) {
183 switch (events[i].type) { 177 switch (events[i].type) {
184 /* We want to toggle visibility on buttonpress */ 178 /* We want to toggle visibility on buttonpress */
185 case SDL_KEYDOWN: 179 case SDL_KEYDOWN:
186 case SDL_KEYUP: 180 case SDL_KEYUP:
327 /* Loop, waiting for QUIT */ 321 /* Loop, waiting for QUIT */
328 while (!done) { 322 while (!done) {
329 if (!(init_flags & SDL_INIT_EVENTTHREAD)) { 323 if (!(init_flags & SDL_INIT_EVENTTHREAD)) {
330 SDL_PumpEvents(); /* Needed when event thread is off */ 324 SDL_PumpEvents(); /* Needed when event thread is off */
331 } 325 }
332 if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUITMASK)) { 326 if (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUIT, SDL_QUIT)) {
333 done = 1; 327 done = 1;
334 } 328 }
335 /* Give up some CPU so the events can accumulate */ 329 /* Give up some CPU so the events can accumulate */
336 SDL_Delay(20); 330 SDL_Delay(20);
337 } 331 }