Commit a8be2438 authored by Vladimir Serbinenko's avatar Vladimir Serbinenko
Browse files

Allow using analog to control mouse

parent c6af4ea7
......@@ -501,6 +501,8 @@ void retro_init(void)
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Mouse X" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Mouse Y" },
{ 0, 0, 0, 0, NULL }
};
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, &inputDescriptors);
......
......@@ -189,6 +189,17 @@ void Core_Processkey(void)
memcpy(Core_old_Key_Sate,Core_Key_Sate , sizeof(Core_Key_Sate) );
}
static int transform_axis(int val)
{
int sign = val >= 0 ? +1 : -1;
int absval = val >= 0 ? val : -val;
int deadzone_val = 15 * 0x7fff / 100;
if (absval < deadzone_val)
return 0;
return sign * ((absval - deadzone_val) * 5 * 10)
/ (0x7fff - deadzone_val);
}
// Core input (not GUI)
int Core_PollEvent(void)
{
......@@ -325,6 +336,8 @@ int Core_PollEvent(void)
mouse_y += PAS;
if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
mouse_y -= PAS;
mouse_x += transform_axis(input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X));
mouse_y += transform_axis(input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y));
mouse_l=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
mouse_r=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment