2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2011-01-06 17:34:11 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-01-06 17:34:11 +00:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-01-06 17:34:11 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-01-06 17:34:11 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-12-24 23:59:46 +00:00
|
|
|
#include "../driver.h"
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2012-09-28 20:38:42 +00:00
|
|
|
#include "SDL.h"
|
2012-05-26 02:47:24 +00:00
|
|
|
#include "../gfx/gfx_context.h"
|
2014-10-21 03:05:52 +00:00
|
|
|
#include <boolean.h>
|
2011-12-24 23:59:46 +00:00
|
|
|
#include "../general.h"
|
2011-01-06 17:34:11 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2012-04-07 09:55:37 +00:00
|
|
|
#include "../libretro.h"
|
2012-09-22 07:57:04 +00:00
|
|
|
#include "input_common.h"
|
2014-09-03 00:35:28 +00:00
|
|
|
#include "keyboard_line.h"
|
2011-01-06 17:34:11 +00:00
|
|
|
|
2012-09-28 20:38:42 +00:00
|
|
|
typedef struct sdl_input
|
|
|
|
{
|
|
|
|
const rarch_joypad_driver_t *joypad;
|
|
|
|
|
2012-10-28 10:04:07 +00:00
|
|
|
int mouse_x, mouse_y;
|
|
|
|
int mouse_abs_x, mouse_abs_y;
|
2014-08-11 17:00:30 +00:00
|
|
|
int mouse_l, mouse_r, mouse_m, mouse_wu, mouse_wd, mouse_wl, mouse_wr;
|
2012-09-28 20:38:42 +00:00
|
|
|
} sdl_input_t;
|
|
|
|
|
2011-11-02 18:31:36 +00:00
|
|
|
static void *sdl_input_init(void)
|
2011-01-06 17:34:11 +00:00
|
|
|
{
|
2012-12-08 12:25:42 +00:00
|
|
|
input_init_keyboard_lut(rarch_key_map_sdl);
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
|
2011-01-06 17:34:11 +00:00
|
|
|
if (!sdl)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-04 08:22:31 +00:00
|
|
|
sdl->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
|
2014-08-11 17:00:30 +00:00
|
|
|
|
|
|
|
RARCH_LOG("[SDL]: Input driver initialized.\n");
|
2011-01-06 17:34:11 +00:00
|
|
|
return sdl;
|
|
|
|
}
|
|
|
|
|
2011-01-08 21:15:02 +00:00
|
|
|
static bool sdl_key_pressed(int key)
|
2011-01-06 17:34:11 +00:00
|
|
|
{
|
2012-09-15 13:17:34 +00:00
|
|
|
if (key >= RETROK_LAST)
|
|
|
|
return false;
|
|
|
|
|
2014-09-03 00:34:34 +00:00
|
|
|
unsigned sym = input_translate_rk_to_keysym((enum retro_key)key);
|
2012-12-08 12:25:42 +00:00
|
|
|
|
2012-09-15 13:17:34 +00:00
|
|
|
int num_keys;
|
2014-08-11 17:00:30 +00:00
|
|
|
const uint8_t *keymap;
|
|
|
|
#if HAVE_SDL2
|
2014-09-03 00:34:34 +00:00
|
|
|
sym = SDL_GetScancodeFromKey(sym);
|
2014-08-11 17:00:30 +00:00
|
|
|
keymap = SDL_GetKeyboardState(&num_keys);
|
|
|
|
#else
|
|
|
|
keymap = SDL_GetKeyState(&num_keys);
|
|
|
|
#endif
|
2012-12-08 12:25:42 +00:00
|
|
|
if (sym < 0 || sym >= num_keys)
|
2012-09-15 13:17:34 +00:00
|
|
|
return false;
|
|
|
|
|
2012-12-08 12:25:42 +00:00
|
|
|
return keymap[sym];
|
2011-01-06 17:34:11 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 12:36:36 +00:00
|
|
|
static bool sdl_is_pressed(sdl_input_t *sdl, unsigned port_num, const struct retro_keybind *binds, unsigned key)
|
2011-01-08 21:15:02 +00:00
|
|
|
{
|
2013-04-26 12:36:36 +00:00
|
|
|
if (sdl_key_pressed(binds[key].key))
|
2011-01-08 21:15:02 +00:00
|
|
|
return true;
|
2011-06-10 15:34:04 +00:00
|
|
|
|
2013-04-26 12:36:36 +00:00
|
|
|
return input_joypad_pressed(sdl->joypad, port_num, binds, key);
|
2011-01-08 21:15:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 00:01:18 +00:00
|
|
|
static int16_t sdl_analog_pressed(sdl_input_t *sdl, const struct retro_keybind *binds,
|
2014-10-20 18:31:00 +00:00
|
|
|
unsigned idx, unsigned id)
|
2013-11-09 00:01:18 +00:00
|
|
|
{
|
|
|
|
unsigned id_minus = 0;
|
|
|
|
unsigned id_plus = 0;
|
2014-10-20 18:31:00 +00:00
|
|
|
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
|
2013-11-09 00:01:18 +00:00
|
|
|
|
|
|
|
int16_t pressed_minus = sdl_key_pressed(binds[id_minus].key) ? -0x7fff : 0;
|
|
|
|
int16_t pressed_plus = sdl_key_pressed(binds[id_plus].key) ? 0x7fff : 0;
|
|
|
|
return pressed_plus + pressed_minus;
|
|
|
|
}
|
|
|
|
|
2011-01-08 17:37:45 +00:00
|
|
|
static bool sdl_bind_button_pressed(void *data, int key)
|
|
|
|
{
|
2012-07-07 15:19:32 +00:00
|
|
|
const struct retro_keybind *binds = g_settings.input.binds[0];
|
2012-04-21 21:25:32 +00:00
|
|
|
if (key >= 0 && key < RARCH_BIND_LIST_END)
|
2013-04-26 12:36:36 +00:00
|
|
|
return sdl_is_pressed((sdl_input_t*)data, 0, binds, key);
|
2014-08-28 16:09:55 +00:00
|
|
|
return false;
|
2011-01-08 17:37:45 +00:00
|
|
|
}
|
|
|
|
|
2012-07-07 15:19:32 +00:00
|
|
|
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keybind **binds_,
|
2012-01-30 00:45:18 +00:00
|
|
|
unsigned port_num, unsigned id)
|
2011-01-06 17:34:11 +00:00
|
|
|
{
|
2012-07-07 15:19:32 +00:00
|
|
|
const struct retro_keybind *binds = binds_[port_num];
|
2012-04-21 21:25:32 +00:00
|
|
|
if (id < RARCH_BIND_LIST_END)
|
2013-04-26 12:36:36 +00:00
|
|
|
return binds[id].valid && sdl_is_pressed(sdl, port_num, binds, id);
|
2014-08-28 16:09:55 +00:00
|
|
|
return 0;
|
2011-01-06 17:34:11 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 20:38:42 +00:00
|
|
|
static int16_t sdl_analog_device_state(sdl_input_t *sdl, const struct retro_keybind **binds,
|
2014-10-20 18:31:00 +00:00
|
|
|
unsigned port_num, unsigned idx, unsigned id)
|
2012-06-28 15:57:50 +00:00
|
|
|
{
|
2014-10-20 18:31:00 +00:00
|
|
|
int16_t ret = sdl_analog_pressed(sdl, binds[port_num], idx, id);
|
2013-11-09 00:01:18 +00:00
|
|
|
if (!ret)
|
2014-10-20 18:31:00 +00:00
|
|
|
ret = input_joypad_analog(sdl->joypad, port_num, idx, id, binds[port_num]);
|
2013-11-09 00:01:18 +00:00
|
|
|
return ret;
|
2012-06-28 15:57:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-28 01:21:37 +00:00
|
|
|
static int16_t sdl_keyboard_device_state(sdl_input_t *sdl, unsigned id)
|
|
|
|
{
|
2012-09-28 20:38:42 +00:00
|
|
|
return sdl_key_pressed(id);
|
2012-07-28 01:21:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-10 15:34:04 +00:00
|
|
|
static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id)
|
2011-01-10 07:40:44 +00:00
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
2011-01-10 13:29:00 +00:00
|
|
|
return sdl->mouse_l;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
2011-01-10 13:29:00 +00:00
|
|
|
return sdl->mouse_r;
|
2014-04-25 19:35:13 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
|
|
|
return sdl->mouse_wu;
|
|
|
|
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
|
|
|
return sdl->mouse_wd;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_X:
|
2011-01-10 13:29:00 +00:00
|
|
|
return sdl->mouse_x;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_Y:
|
2011-01-10 13:29:00 +00:00
|
|
|
return sdl->mouse_y;
|
2014-04-25 21:44:53 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
|
|
|
return sdl->mouse_m;
|
2011-01-10 07:40:44 +00:00
|
|
|
default:
|
2011-01-10 13:29:00 +00:00
|
|
|
return 0;
|
2011-01-10 07:40:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 18:31:00 +00:00
|
|
|
static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
|
|
|
|
unsigned idx, unsigned id, bool screen)
|
2012-10-28 10:04:07 +00:00
|
|
|
{
|
2014-10-20 18:31:00 +00:00
|
|
|
if (idx != 0)
|
2012-12-27 11:26:13 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-01-11 15:23:04 +00:00
|
|
|
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
|
|
|
|
bool valid = input_translate_coord_viewport(sdl->mouse_abs_x, sdl->mouse_abs_y,
|
|
|
|
&res_x, &res_y, &res_screen_x, &res_screen_y);
|
2012-10-28 10:04:07 +00:00
|
|
|
|
|
|
|
if (!valid)
|
|
|
|
return 0;
|
|
|
|
|
2013-01-11 15:23:04 +00:00
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
res_x = res_screen_x;
|
|
|
|
res_y = res_screen_y;
|
|
|
|
}
|
|
|
|
|
2013-04-20 07:01:38 +00:00
|
|
|
bool inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
|
2012-10-28 10:04:07 +00:00
|
|
|
|
|
|
|
if (!inside)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_ID_POINTER_X:
|
|
|
|
return res_x;
|
|
|
|
case RETRO_DEVICE_ID_POINTER_Y:
|
|
|
|
return res_y;
|
|
|
|
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
|
|
|
return sdl->mouse_l;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-07 09:55:37 +00:00
|
|
|
static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id)
|
2011-01-10 07:40:44 +00:00
|
|
|
{
|
2011-01-10 14:01:34 +00:00
|
|
|
switch (id)
|
|
|
|
{
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
2011-01-10 14:01:34 +00:00
|
|
|
return sdl->mouse_x;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
2011-01-10 14:01:34 +00:00
|
|
|
return sdl->mouse_y;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
2011-01-10 14:01:34 +00:00
|
|
|
return sdl->mouse_l;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
2011-01-10 14:01:34 +00:00
|
|
|
return sdl->mouse_m;
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
2011-01-10 14:01:34 +00:00
|
|
|
return sdl->mouse_r;
|
2012-04-15 15:08:43 +00:00
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
|
|
|
return sdl->mouse_m && sdl->mouse_r;
|
|
|
|
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
|
|
|
return sdl->mouse_m && sdl->mouse_l;
|
2011-01-10 14:01:34 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-10 07:40:44 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 18:31:00 +00:00
|
|
|
static int16_t sdl_input_state(void *data_, const struct retro_keybind **binds,
|
|
|
|
unsigned port, unsigned device, unsigned idx, unsigned id)
|
2011-01-10 07:40:44 +00:00
|
|
|
{
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_input_t *data = (sdl_input_t*)data_;
|
2011-01-10 07:40:44 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_JOYPAD:
|
|
|
|
return sdl_joypad_device_state(data, binds, port, id);
|
2012-06-28 15:57:50 +00:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2014-10-20 18:31:00 +00:00
|
|
|
return sdl_analog_device_state(data, binds, port, idx, id);
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_MOUSE:
|
2011-06-10 15:34:04 +00:00
|
|
|
return sdl_mouse_device_state(data, id);
|
2012-10-28 10:04:07 +00:00
|
|
|
case RETRO_DEVICE_POINTER:
|
2013-01-11 15:23:04 +00:00
|
|
|
case RARCH_DEVICE_POINTER_SCREEN:
|
2014-10-20 18:31:00 +00:00
|
|
|
return sdl_pointer_device_state(data, idx, id, device == RARCH_DEVICE_POINTER_SCREEN);
|
2012-07-28 01:21:37 +00:00
|
|
|
case RETRO_DEVICE_KEYBOARD:
|
|
|
|
return sdl_keyboard_device_state(data, id);
|
2012-04-07 09:55:37 +00:00
|
|
|
case RETRO_DEVICE_LIGHTGUN:
|
|
|
|
return sdl_lightgun_device_state(data, id);
|
2011-01-10 07:40:44 +00:00
|
|
|
}
|
2014-10-20 18:31:00 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-01-10 07:40:44 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 17:34:11 +00:00
|
|
|
static void sdl_input_free(void *data)
|
|
|
|
{
|
2012-09-28 20:38:42 +00:00
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Flush out all pending events.
|
2014-08-11 17:00:30 +00:00
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
|
|
|
|
#else
|
2012-09-28 20:38:42 +00:00
|
|
|
SDL_Event event;
|
|
|
|
while (SDL_PollEvent(&event));
|
2014-08-11 17:00:30 +00:00
|
|
|
#endif
|
2012-09-28 20:38:42 +00:00
|
|
|
|
|
|
|
sdl_input_t *sdl = (sdl_input_t*)data;
|
|
|
|
|
|
|
|
if (sdl->joypad)
|
|
|
|
sdl->joypad->destroy();
|
|
|
|
|
|
|
|
free(data);
|
2011-01-06 17:34:11 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 17:00:30 +00:00
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
static void sdl_grab_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
sdl_input_t *sdl = (sdl_input_t*)data;
|
|
|
|
|
|
|
|
if (driver.video == &video_sdl2)
|
|
|
|
{
|
|
|
|
/* first member of sdl2_video_t is the window */
|
|
|
|
struct temp{
|
|
|
|
SDL_Window *w;
|
|
|
|
};
|
|
|
|
SDL_SetWindowGrab(((struct temp*)driver.video_data)->w,
|
|
|
|
state ? SDL_TRUE : SDL_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-20 18:31:00 +00:00
|
|
|
static bool sdl_set_rumble(void *data, unsigned port,
|
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
2013-09-25 20:59:05 +00:00
|
|
|
{
|
|
|
|
sdl_input_t *sdl = (sdl_input_t*)data;
|
2013-09-26 10:55:05 +00:00
|
|
|
return input_joypad_set_rumble(sdl->joypad, port, effect, strength);
|
2013-09-25 20:59:05 +00:00
|
|
|
}
|
|
|
|
|
2013-09-29 18:52:51 +00:00
|
|
|
static const rarch_joypad_driver_t *sdl_get_joypad_driver(void *data)
|
|
|
|
{
|
|
|
|
sdl_input_t *sdl = (sdl_input_t*)data;
|
|
|
|
return sdl->joypad;
|
|
|
|
}
|
|
|
|
|
2011-01-10 13:29:00 +00:00
|
|
|
static void sdl_poll_mouse(sdl_input_t *sdl)
|
|
|
|
{
|
2012-10-28 10:04:07 +00:00
|
|
|
Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y);
|
|
|
|
SDL_GetMouseState(&sdl->mouse_abs_x, &sdl->mouse_abs_y);
|
2014-04-25 19:35:13 +00:00
|
|
|
sdl->mouse_l = SDL_BUTTON(SDL_BUTTON_LEFT) & btn ? 1 : 0;
|
|
|
|
sdl->mouse_r = SDL_BUTTON(SDL_BUTTON_RIGHT) & btn ? 1 : 0;
|
|
|
|
sdl->mouse_m = SDL_BUTTON(SDL_BUTTON_MIDDLE) & btn ? 1 : 0;
|
2014-08-11 17:00:30 +00:00
|
|
|
#ifndef HAVE_SDL2
|
2014-04-25 19:35:13 +00:00
|
|
|
sdl->mouse_wu = SDL_BUTTON(SDL_BUTTON_WHEELUP) & btn ? 1 : 0;
|
|
|
|
sdl->mouse_wd = SDL_BUTTON(SDL_BUTTON_WHEELDOWN) & btn ? 1 : 0;
|
2014-08-11 17:00:30 +00:00
|
|
|
#endif
|
2011-01-10 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 17:34:11 +00:00
|
|
|
static void sdl_input_poll(void *data)
|
|
|
|
{
|
|
|
|
SDL_PumpEvents();
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_input_t *sdl = (sdl_input_t*)data;
|
2011-06-10 16:01:44 +00:00
|
|
|
|
2014-08-02 22:44:07 +00:00
|
|
|
if (sdl->joypad)
|
|
|
|
sdl->joypad->poll();
|
2011-06-11 10:54:14 +00:00
|
|
|
sdl_poll_mouse(sdl);
|
2014-08-11 17:00:30 +00:00
|
|
|
|
|
|
|
SDL_Event event;
|
2014-09-03 00:35:28 +00:00
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_MOUSEWHEEL) > 0)
|
|
|
|
#else
|
|
|
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYEVENTMASK) > 0)
|
|
|
|
#endif
|
2014-08-11 17:00:30 +00:00
|
|
|
{
|
2014-09-03 00:35:28 +00:00
|
|
|
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
|
|
|
|
{
|
|
|
|
uint16_t mod = 0;
|
|
|
|
unsigned code = input_translate_keysym_to_rk(event.key.keysym.sym);
|
|
|
|
|
|
|
|
if (event.key.keysym.mod & KMOD_SHIFT)
|
|
|
|
mod |= RETROKMOD_SHIFT;
|
|
|
|
|
|
|
|
if (event.key.keysym.mod & KMOD_CTRL)
|
|
|
|
mod |= RETROKMOD_CTRL;
|
|
|
|
|
|
|
|
if (event.key.keysym.mod & KMOD_ALT)
|
|
|
|
mod |= RETROKMOD_ALT;
|
|
|
|
|
|
|
|
if (event.key.keysym.mod & KMOD_NUM)
|
|
|
|
mod |= RETROKMOD_NUMLOCK;
|
|
|
|
|
|
|
|
if (event.key.keysym.mod & KMOD_CAPS)
|
|
|
|
mod |= RETROKMOD_CAPSLOCK;
|
|
|
|
|
|
|
|
input_keyboard_event(event.type == SDL_KEYDOWN, code, code, mod);
|
|
|
|
}
|
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
else if (event.type == SDL_MOUSEWHEEL)
|
2014-08-11 17:00:30 +00:00
|
|
|
{
|
|
|
|
sdl->mouse_wu = event.wheel.y < 0;
|
|
|
|
sdl->mouse_wd = event.wheel.y > 0;
|
|
|
|
sdl->mouse_wl = event.wheel.x < 0;
|
|
|
|
sdl->mouse_wr = event.wheel.x > 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-03 00:35:28 +00:00
|
|
|
}
|
2011-01-06 17:34:11 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 20:16:57 +00:00
|
|
|
static uint64_t sdl_get_capabilities(void *data)
|
|
|
|
{
|
|
|
|
uint64_t caps = 0;
|
|
|
|
|
|
|
|
caps |= (1 << RETRO_DEVICE_JOYPAD);
|
|
|
|
caps |= (1 << RETRO_DEVICE_MOUSE);
|
|
|
|
caps |= (1 << RETRO_DEVICE_KEYBOARD);
|
|
|
|
caps |= (1 << RETRO_DEVICE_LIGHTGUN);
|
|
|
|
caps |= (1 << RETRO_DEVICE_POINTER);
|
|
|
|
caps |= (1 << RETRO_DEVICE_ANALOG);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
input_driver_t input_sdl = {
|
2011-12-24 12:46:12 +00:00
|
|
|
sdl_input_init,
|
|
|
|
sdl_input_poll,
|
|
|
|
sdl_input_state,
|
|
|
|
sdl_bind_button_pressed,
|
|
|
|
sdl_input_free,
|
2013-03-13 15:33:39 +00:00
|
|
|
NULL,
|
2013-11-02 23:27:58 +00:00
|
|
|
NULL,
|
2013-11-02 20:16:57 +00:00
|
|
|
sdl_get_capabilities,
|
2014-08-11 17:00:30 +00:00
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
"sdl2",
|
|
|
|
sdl_grab_mouse,
|
|
|
|
#else
|
2012-09-28 20:38:42 +00:00
|
|
|
"sdl",
|
2013-09-25 20:59:05 +00:00
|
|
|
NULL,
|
2014-08-11 17:00:30 +00:00
|
|
|
#endif
|
2013-09-25 20:59:05 +00:00
|
|
|
sdl_set_rumble,
|
2013-09-29 18:52:51 +00:00
|
|
|
sdl_get_joypad_driver,
|
2011-01-06 17:34:11 +00:00
|
|
|
};
|