Some crude mouse support, but it does not seem to work. :(
This commit is contained in:
parent
a7e35571cd
commit
dad1ead3e0
61
input/sdl.c
61
input/sdl.c
|
@ -167,12 +167,9 @@ static bool sdl_bind_button_pressed(void *data, int key)
|
||||||
return false;
|
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];
|
const struct snes_keybind *snes_keybinds = binds[port == SNES_PORT_1 ? 0 : 1];
|
||||||
|
|
||||||
// Checks if button is pressed.
|
// 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;
|
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)
|
static void sdl_input_free(void *data)
|
||||||
{
|
{
|
||||||
if (data)
|
if (data)
|
||||||
|
|
|
@ -32,6 +32,7 @@ typedef struct sdl_input
|
||||||
bool *should_resize;
|
bool *should_resize;
|
||||||
unsigned *new_width;
|
unsigned *new_width;
|
||||||
unsigned *new_height;
|
unsigned *new_height;
|
||||||
|
int16_t mouse_x, mouse_y;
|
||||||
} sdl_input_t;
|
} sdl_input_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
3
ssnes.c
3
ssnes.c
|
@ -468,6 +468,9 @@ int main(int argc, char *argv[])
|
||||||
// Main loop
|
// Main loop
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
// Poll input.
|
||||||
|
driver.input->poll(driver.input_data);
|
||||||
|
|
||||||
// Time to drop?
|
// Time to drop?
|
||||||
if (driver.input->key_pressed(driver.input_data, SSNES_QUIT_KEY) ||
|
if (driver.input->key_pressed(driver.input_data, SSNES_QUIT_KEY) ||
|
||||||
!driver.video->alive(driver.video_data))
|
!driver.video->alive(driver.video_data))
|
||||||
|
|
Loading…
Reference in New Issue