diff options
Diffstat (limited to 'tests/sdl_mouse.c')
-rw-r--r-- | tests/sdl_mouse.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tests/sdl_mouse.c b/tests/sdl_mouse.c index dae3f636..0c10198a 100644 --- a/tests/sdl_mouse.c +++ b/tests/sdl_mouse.c @@ -12,6 +12,7 @@ void one() { switch(event.type) { case SDL_MOUSEMOTION: { SDL_MouseMotionEvent *m = (SDL_MouseMotionEvent*)&event; + assert(m->state == 0); int x, y; SDL_GetMouseState(&x, &y); assert(x == m->x && y == m->y); @@ -33,12 +34,17 @@ void one() { SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event; printf("button up: %d,%d %d,%d\n", m->button, m->state, m->x, m->y); result += 5 * (m->button + m->state + m->x + m->y); + // Remove another click we want to ignore + assert(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN) == 1); + assert(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEBUTTONUP, SDL_MOUSEBUTTONUP) == 1); break; } } } } +void main_2(); + int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); @@ -46,13 +52,18 @@ int main() { SDL_Rect rect = { 0, 0, 600, 450 }; SDL_FillRect(screen, &rect, 0x2244ffff); - emscripten_run_script("simulateMouseEvent(10, 20, -1)"); // move from 0,0 to 10,20 - emscripten_run_script("simulateMouseEvent(10, 20, 0)"); // click - emscripten_run_script("simulateMouseEvent(30, 77, -1)"); // move some more - emscripten_run_script("simulateMouseEvent(30, 77, 1)"); // trigger the end - - emscripten_set_main_loop(one, 0); + emscripten_async_call(main_2, 3000); // avoid startup delays and intermittent errors return 0; } +void main_2() { + emscripten_run_script("window.simulateMouseEvent(10, 20, -1)"); // move from 0,0 to 10,20 + emscripten_run_script("window.simulateMouseEvent(10, 20, 0)"); // click + emscripten_run_script("window.simulateMouseEvent(10, 20, 0)"); // click some more, but this one should be ignored through PeepEvent + emscripten_run_script("window.simulateMouseEvent(30, 77, -1)"); // move some more + emscripten_run_script("window.simulateMouseEvent(30, 77, 1)"); // trigger the end + + emscripten_set_main_loop(one, 0); +} + |