diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-03-24 15:04:41 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-03-24 15:04:41 -0700 |
commit | 6ad919104f7c00ae3774be7d275d9a259869dbc9 (patch) | |
tree | f6025334ba38604c3bd82fe359c46c930dd1fd6d /tests/sdl_mouse.c | |
parent | 63af5eac0a10434cc62244d80675f13473d38b02 (diff) |
SDL mouse support and emscripten_set_main_loop
Diffstat (limited to 'tests/sdl_mouse.c')
-rw-r--r-- | tests/sdl_mouse.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/sdl_mouse.c b/tests/sdl_mouse.c new file mode 100644 index 00000000..87619ef2 --- /dev/null +++ b/tests/sdl_mouse.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> +#include <assert.h> +#include <emscripten.h> + +int result = 1; + +void one() { + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_MOUSEMOTION: { + SDL_MouseMotionEvent *m = (SDL_MouseMotionEvent*)&event; + int x, y; + SDL_GetMouseState(&x, &y); + assert(x == m->x && y == m->y); + printf("motion: %d,%d %d,%d\n", m->x, m->y, m->xrel, m->yrel); + result += 2 * (m->x + m->y + m->xrel + m->yrel); + break; + } + case SDL_MOUSEBUTTONDOWN: { + SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event; + if (m->button == 2) { + REPORT_RESULT(); + emscripten_run_script("throw 'done'"); + } + printf("button down: %d,%d %d,%d\n", m->button, m->state, m->x, m->y); + result += 3 * (m->button + m->state + m->x + m->y); + break; + } + case SDL_MOUSEBUTTONUP: { + 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); + break; + } + } + } +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + emscripten_run_script("simulateMouseEvent(10, 20, 0)"); // move from 0,0 to 10,20 + emscripten_run_script("simulateMouseEvent(10, 20, 1)"); // click + emscripten_run_script("simulateMouseEvent(30, 77, 0)"); // move some more + emscripten_run_script("simulateMouseEvent(30, 77, 2)"); // trigger the end + + emscripten_set_main_loop(one, 0); + + return 0; +} + |