From: John Tsiombikas Date: Sat, 1 Sep 2018 09:43:02 +0000 (+0300) Subject: fixed mouse handling X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosrtxon;a=commitdiff_plain;h=2a30b097337f5adaf8342d2e597acb71569d7e0a;ds=sidebyside fixed mouse handling --- diff --git a/src/demo.c b/src/demo.c index 072b6ce..2ff25a7 100644 --- a/src/demo.c +++ b/src/demo.c @@ -211,7 +211,7 @@ void mouse_orbit_update(float *theta, float *phi, float *dist) int dy = mouse_y - prev_my; if(dx || dy) { - if(mouse_bmask & 1) { + if(mouse_bmask & MOUSE_LEFT) { float p = *phi; *theta += dx * 1.0; p += dy * 1.0; @@ -220,7 +220,7 @@ void mouse_orbit_update(float *theta, float *phi, float *dist) if(p > 90) p = 90; *phi = p; } - if(mouse_bmask & 4) { + if(mouse_bmask & MOUSE_RIGHT) { *dist += dy * 0.5; if(*dist < 0) *dist = 0; diff --git a/src/demo.h b/src/demo.h index fdb238b..63489c7 100644 --- a/src/demo.h +++ b/src/demo.h @@ -13,6 +13,12 @@ extern unsigned long time_msec; extern int mouse_x, mouse_y; extern unsigned int mouse_bmask; +enum { + MOUSE_LEFT = 1, + MOUSE_RIGHT = 2, + MOUSE_MIDDLE = 4 +}; + extern float sball_matrix[16]; int demo_init(int argc, char **argv); diff --git a/src/sdl/main.c b/src/sdl/main.c index 2bb2d47..358d774 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -119,6 +119,21 @@ void swap_buffers(void *pixels) } } +static int bnmask(int sdlbn) +{ + switch(sdlbn) { + case SDL_BUTTON_LEFT: + return MOUSE_LEFT; + case SDL_BUTTON_RIGHT: + return MOUSE_RIGHT; + case SDL_BUTTON_MIDDLE: + return MOUSE_MIDDLE; + default: + break; + } + return 0; +} + static void handle_event(SDL_Event *ev) { switch(ev->type) { @@ -142,10 +157,10 @@ static void handle_event(SDL_Event *ev) break; case SDL_MOUSEBUTTONDOWN: - mouse_bmask |= 1 << (ev->button.button - SDL_BUTTON_LEFT); + mouse_bmask |= bnmask(ev->button.button); if(0) { case SDL_MOUSEBUTTONUP: - mouse_bmask &= ~(1 << (ev->button.button - SDL_BUTTON_LEFT)); + mouse_bmask &= ~bnmask(ev->button.button); } mouse_x = ev->button.x / fbscale; mouse_y = ev->button.y / fbscale;