mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-20 13:53:14 +01:00
SDL2: Added gamepad support.
This commit is contained in:
@@ -17,7 +17,6 @@ extern "C" int _main_(int _argc, char** _argv);
|
||||
|
||||
namespace entry
|
||||
{
|
||||
const uint16_t WindowHandle::invalidHandle = UINT16_MAX;
|
||||
static uint32_t s_debug = BGFX_DEBUG_NONE;
|
||||
static uint32_t s_reset = BGFX_RESET_NONE;
|
||||
static bool s_exit = false;
|
||||
@@ -112,16 +111,17 @@ namespace entry
|
||||
|
||||
static const InputBinding s_bindings[] =
|
||||
{
|
||||
{ entry::Key::KeyQ, entry::Modifier::LeftCtrl, 1, cmd, "exit" },
|
||||
{ entry::Key::F1, entry::Modifier::None, 1, cmd, "graphics stats" },
|
||||
{ entry::Key::F1, entry::Modifier::LeftShift, 1, cmd, "graphics stats 0\ngraphics text 0" },
|
||||
{ entry::Key::F3, entry::Modifier::None, 1, cmd, "graphics wireframe" },
|
||||
{ entry::Key::F4, entry::Modifier::None, 1, cmd, "graphics hmd" },
|
||||
{ entry::Key::F4, entry::Modifier::LeftShift, 1, cmd, "graphics hmdrecenter" },
|
||||
{ entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" },
|
||||
{ entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" },
|
||||
{ entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" },
|
||||
{ entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" },
|
||||
{ entry::Key::KeyQ, entry::Modifier::LeftCtrl, 1, cmd, "exit" },
|
||||
{ entry::Key::F1, entry::Modifier::None, 1, cmd, "graphics stats" },
|
||||
{ entry::Key::GamepadStart, entry::Modifier::None, 1, cmd, "graphics stats" },
|
||||
{ entry::Key::F1, entry::Modifier::LeftShift, 1, cmd, "graphics stats 0\ngraphics text 0" },
|
||||
{ entry::Key::F3, entry::Modifier::None, 1, cmd, "graphics wireframe" },
|
||||
{ entry::Key::F4, entry::Modifier::None, 1, cmd, "graphics hmd" },
|
||||
{ entry::Key::F4, entry::Modifier::LeftShift, 1, cmd, "graphics hmdrecenter" },
|
||||
{ entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" },
|
||||
{ entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" },
|
||||
{ entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" },
|
||||
{ entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" },
|
||||
|
||||
INPUT_BINDING_END
|
||||
};
|
||||
@@ -157,6 +157,16 @@ namespace entry
|
||||
return result;
|
||||
}
|
||||
|
||||
static const char* s_gamepadAxisName[GamepadAxis::Count] =
|
||||
{
|
||||
"LeftX",
|
||||
"LeftY",
|
||||
"LeftZ",
|
||||
"RightX",
|
||||
"RightY",
|
||||
"RightZ",
|
||||
};
|
||||
|
||||
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
|
||||
{
|
||||
s_debug = _debug;
|
||||
@@ -176,6 +186,20 @@ namespace entry
|
||||
{
|
||||
switch (ev->m_type)
|
||||
{
|
||||
case Event::Axis:
|
||||
{
|
||||
const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
|
||||
inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Char:
|
||||
{
|
||||
const CharEvent* chev = static_cast<const CharEvent*>(ev);
|
||||
inputChar(chev->m_len, chev->m_char);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Exit:
|
||||
return true;
|
||||
|
||||
@@ -219,13 +243,6 @@ namespace entry
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Char:
|
||||
{
|
||||
const CharEvent* chev = static_cast<const CharEvent*>(ev);
|
||||
inputChar(chev->m_len, chev->m_char);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Size:
|
||||
{
|
||||
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
|
||||
@@ -302,6 +319,21 @@ namespace entry
|
||||
|
||||
switch (ev->m_type)
|
||||
{
|
||||
case Event::Axis:
|
||||
{
|
||||
const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
|
||||
inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Char:
|
||||
{
|
||||
const CharEvent* chev = static_cast<const CharEvent*>(ev);
|
||||
win.m_handle = chev->m_handle;
|
||||
inputChar(chev->m_len, chev->m_char);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Exit:
|
||||
return true;
|
||||
|
||||
@@ -344,14 +376,6 @@ namespace entry
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Char:
|
||||
{
|
||||
const CharEvent* chev = static_cast<const CharEvent*>(ev);
|
||||
win.m_handle = chev->m_handle;
|
||||
inputChar(chev->m_len, chev->m_char);
|
||||
}
|
||||
break;
|
||||
|
||||
case Event::Size:
|
||||
{
|
||||
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
|
||||
|
||||
Reference in New Issue
Block a user