From dad1ead3e01e9e8456ba628cf70f9074bf1f33c1 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 10 Jan 2011 08:40:44 +0100 Subject: [PATCH] Some crude mouse support, but it does not seem to work. :( --- input/sdl.c | 61 +++++++++++++++++++++++++++++++++++++---- input/ssnes_sdl_input.h | 1 + ssnes.c | 3 ++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/input/sdl.c b/input/sdl.c index 9c8827573f..4eb7188553 100644 --- a/input/sdl.c +++ b/input/sdl.c @@ -167,12 +167,9 @@ static bool sdl_bind_button_pressed(void *data, int key) return false; } -static int16_t sdl_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id) +static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct snes_keybind **binds, + bool port, unsigned device, unsigned index, unsigned id) { - sdl_input_t *sdl = data; - if (device != SNES_DEVICE_JOYPAD) - return 0; - const struct snes_keybind *snes_keybinds = binds[port == SNES_PORT_1 ? 0 : 1]; // Checks if button is pressed. @@ -186,6 +183,60 @@ static int16_t sdl_input_state(void *data, const struct snes_keybind **binds, bo return false; } +static int16_t sdl_mouse_device_state(sdl_input_t *sdl, const struct snes_keybind **binds, + bool port, unsigned device, unsigned index, unsigned id) +{ + int _x, _y; + Uint8 btn = SDL_GetRelativeMouseState(&_x, &_y); + sdl->mouse_x += _x; + sdl->mouse_y += _y; + SSNES_LOG("Mouse rel: %d %d, total %d %d\n", _x, _y, (int)sdl->mouse_x, (int)sdl->mouse_y); + + int16_t retval; + switch (id) + { + case SNES_DEVICE_ID_MOUSE_LEFT: + retval = SDL_BUTTON(1) & btn ? 1 : 0; + break; + case SNES_DEVICE_ID_MOUSE_RIGHT: + retval = SDL_BUTTON(3) & btn ? 1 : 0; + break; + case SNES_DEVICE_ID_MOUSE_X: + retval = sdl->mouse_x; + break; + case SNES_DEVICE_ID_MOUSE_Y: + retval = sdl->mouse_y; + break; + default: + retval = 0; + } + SSNES_LOG("Retval: %d\n", (int)retval); + return retval; +} + +// TODO: :D +static int16_t sdl_scope_device_state(sdl_input_t *sdl, const struct snes_keybind **binds, + bool port, unsigned device, unsigned index, unsigned id) +{ + return 0; +} + +static int16_t sdl_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id) +{ + switch (device) + { + case SNES_DEVICE_JOYPAD: + return sdl_joypad_device_state(data, binds, port, device, index, id); + case SNES_DEVICE_MOUSE: + return sdl_mouse_device_state(data, binds, port, device, index, id); + case SNES_DEVICE_SUPER_SCOPE: + return sdl_scope_device_state(data, binds, port, device, index, id); + + default: + return 0; + } +} + static void sdl_input_free(void *data) { if (data) diff --git a/input/ssnes_sdl_input.h b/input/ssnes_sdl_input.h index 519477d64a..d278b18169 100644 --- a/input/ssnes_sdl_input.h +++ b/input/ssnes_sdl_input.h @@ -32,6 +32,7 @@ typedef struct sdl_input bool *should_resize; unsigned *new_width; unsigned *new_height; + int16_t mouse_x, mouse_y; } sdl_input_t; #endif diff --git a/ssnes.c b/ssnes.c index c2971ca811..848a8d8e9e 100644 --- a/ssnes.c +++ b/ssnes.c @@ -468,6 +468,9 @@ int main(int argc, char *argv[]) // Main loop for(;;) { + // Poll input. + driver.input->poll(driver.input_data); + // Time to drop? if (driver.input->key_pressed(driver.input_data, SSNES_QUIT_KEY) || !driver.video->alive(driver.video_data))