mirror of
https://github.com/glfw/glfw.git
synced 2025-02-28 22:02:49 +00:00
Added some switches
This commit is contained in:
parent
6281f498c8
commit
6bcf518685
58
src/input.c
58
src/input.c
@ -202,14 +202,21 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
|
|||||||
c += 1;
|
c += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*c == 'a')
|
switch (*c)
|
||||||
|
{
|
||||||
|
case 'a':
|
||||||
e->type = _GLFW_JOYSTICK_AXIS;
|
e->type = _GLFW_JOYSTICK_AXIS;
|
||||||
else if (*c == 'b')
|
|
||||||
e->type = _GLFW_JOYSTICK_BUTTON;
|
|
||||||
else if (*c == 'h')
|
|
||||||
e->type = _GLFW_JOYSTICK_HATBIT;
|
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
|
case 'b':
|
||||||
|
e->type = _GLFW_JOYSTICK_BUTTON;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
e->type = _GLFW_JOYSTICK_HATBIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (e->type == _GLFW_JOYSTICK_HATBIT)
|
if (e->type == _GLFW_JOYSTICK_HATBIT)
|
||||||
{
|
{
|
||||||
@ -1067,8 +1074,7 @@ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)
|
|||||||
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS))
|
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_BUTTONS))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*count = js->hatCount;
|
return *count = js->hats;
|
||||||
return js->hats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI const char* glfwGetJoystickName(int jid)
|
GLFWAPI const char* glfwGetJoystickName(int jid)
|
||||||
@ -1324,7 +1330,9 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
|
|||||||
for (i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++)
|
for (i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++)
|
||||||
{
|
{
|
||||||
const _GLFWmapelement* e = js->mapping->buttons + i;
|
const _GLFWmapelement* e = js->mapping->buttons + i;
|
||||||
if (e->type == _GLFW_JOYSTICK_AXIS)
|
switch (e->type)
|
||||||
|
{
|
||||||
|
case _GLFW_JOYSTICK_AXIS:
|
||||||
{
|
{
|
||||||
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
|
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
|
||||||
// HACK: This should be baked into the value transform
|
// HACK: This should be baked into the value transform
|
||||||
@ -1340,26 +1348,33 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
|
|||||||
state->buttons[i] = GLFW_PRESS;
|
state->buttons[i] = GLFW_PRESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_HATBIT)
|
break;
|
||||||
|
case _GLFW_JOYSTICK_HATBIT:
|
||||||
{
|
{
|
||||||
const unsigned int hat = e->index >> 4;
|
const unsigned int hat = e->index >> 4;
|
||||||
const unsigned int bit = e->index & 0xf;
|
const unsigned int bit = e->index & 0xf;
|
||||||
if (js->hats[hat] & bit)
|
if (js->hats[hat] & bit)
|
||||||
state->buttons[i] = GLFW_PRESS;
|
state->buttons[i] = GLFW_PRESS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case _GLFW_JOYSTICK_BUTTON:
|
||||||
|
state->buttons[i] = js->buttons[e->index];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_BUTTON)
|
|
||||||
state->buttons[i] = js->buttons[e->index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++)
|
for (i = 0; i <= GLFW_GAMEPAD_AXIS_LAST; i++)
|
||||||
{
|
{
|
||||||
const _GLFWmapelement* e = js->mapping->axes + i;
|
const _GLFWmapelement* e = js->mapping->axes + i;
|
||||||
if (e->type == _GLFW_JOYSTICK_AXIS)
|
switch (e->type)
|
||||||
|
{
|
||||||
|
case _GLFW_JOYSTICK_AXIS:
|
||||||
{
|
{
|
||||||
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
|
const float value = js->axes[e->index] * e->axisScale + e->axisOffset;
|
||||||
state->axes[i] = _glfw_fminf(_glfw_fmaxf(value, -1.f), 1.f);
|
state->axes[i] = _glfw_fminf(_glfw_fmaxf(value, -1.f), 1.f);
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_HATBIT)
|
break;
|
||||||
|
case _GLFW_JOYSTICK_HATBIT:
|
||||||
{
|
{
|
||||||
const unsigned int hat = e->index >> 4;
|
const unsigned int hat = e->index >> 4;
|
||||||
const unsigned int bit = e->index & 0xf;
|
const unsigned int bit = e->index & 0xf;
|
||||||
@ -1368,8 +1383,11 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
|
|||||||
else
|
else
|
||||||
state->axes[i] = -1.f;
|
state->axes[i] = -1.f;
|
||||||
}
|
}
|
||||||
else if (e->type == _GLFW_JOYSTICK_BUTTON)
|
break;
|
||||||
|
case _GLFW_JOYSTICK_BUTTON:
|
||||||
state->axes[i] = js->buttons[e->index] * 2.f - 1.f;
|
state->axes[i] = js->buttons[e->index] * 2.f - 1.f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user