ソースを参照

sdl: improve input support stability and handle return/tab/backspace in text input mode.

legacy
Sam Hocevar 5年前
コミット
a822785879
3個のファイルの変更40行の追加42行の削除
  1. +25
    -33
      src/input/controller.cpp
  2. +4
    -7
      src/input/controller.h
  3. +11
    -2
      src/platform/sdl/sdlinput.cpp

+ 25
- 33
src/input/controller.cpp ファイルの表示

@@ -276,13 +276,6 @@ void Controller::ClearProfile()
UnbindProfile();
}

//Init mode 2: By hand, key/axis by key/axis ----------------------------------
void Controller::SetInputCount(int nb_keys, int nb_axis)
{
m_keys.resize(nb_keys);
m_axis.resize(nb_axis);
}

//Layer mask stuff ------------------------------------------------------------
void Controller::SetLayerMask(uint32_t layer_mask)
{
@@ -302,46 +295,48 @@ KeyBinding& Controller::GetKey(int index)
{
return m_keys[index];
}
KeyBinding const& Controller::GetKey(int index) const
{
return m_keys[index];
}

AxisBinding& Controller::GetAxis(int index)
{
return m_axis[index];
}
AxisBinding const& Controller::GetAxis(int index) const
{
return m_axis[index];
}

//Key methods: should not go directly to binding ------------------------------
// Key methods: should not go directly to binding
bool Controller::IsKeyPressed(int index) const
{
//#error do something better IsLayerActive()
return GetKey(index).IsPressed();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.IsPressed();
}

bool Controller::IsKeyReleased(int index) const
{
return GetKey(index).IsReleased();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.IsReleased();
}

bool Controller::WasKeyPressedThisFrame(int index) const
{
return GetKey(index).WasPressedThisFrame();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.WasPressedThisFrame();
}

bool Controller::WasKeyReleasedThisFrame(int index) const
{
return GetKey(index).WasReleasedThisFrame();
auto key = m_keys.find(index);
return key != m_keys.end() && key->second.WasReleasedThisFrame();
}

//Axis methods: should not go directly to binding -----------------------------
float Controller::GetAxisValue(int index) const
{
return GetAxis(index).GetValue();
auto axis = m_axis.find(index);
return axis != m_axis.end() ? axis->second.GetValue() : 0.f;
}

float Controller::GetAxisDelta(int index) const
{
return GetAxis(index).GetDelta();
auto axis = m_axis.find(index);
return axis != m_axis.end() ? axis->second.GetDelta() : 0.f;
}

//-----------------------------------------------------------------------------
@@ -403,10 +398,7 @@ void Controller::BindProfile(InputProfile const& setup)
m_mutex.lock();
m_profile = setup;

m_keys.resize(m_profile.GetKeyCount());
m_axis.resize(m_profile.GetAxisCount());

//Keyboard
// Keyboard
m_keyboard = InputDevice::GetKeyboard();
if (m_keyboard)
{
@@ -414,7 +406,7 @@ void Controller::BindProfile(InputProfile const& setup)
GetKey(key.m_idx).BindKeyboard(key.m_name);
}

//Mouse
// Mouse
m_mouse = InputDevice::GetMouse();
if (m_mouse)
{
@@ -424,7 +416,7 @@ void Controller::BindProfile(InputProfile const& setup)
GetAxis(axis.m_idx).BindMouse(axis.m_name);
}

//Joystick
// Joystick
for (uint64_t joy_idx : m_profile.m_joystick)
{
class InputDevice* joystick = InputDevice::GetJoystick(joy_idx);
@@ -455,11 +447,11 @@ void Controller::tick_game(float seconds)

if (m_active)
{
for (int i = 0; i < m_keys.count(); ++i)
m_keys[i].Update();
for (auto &kv : m_keys)
kv.second.Update();

for (int i = 0; i < m_axis.count(); ++i)
m_axis[i].Update();
for (auto &kv : m_axis)
kv.second.Update();
}

if (m_activate_nextframe)


+ 4
- 7
src/input/controller.h ファイルの表示

@@ -386,9 +386,6 @@ public:
void Init(InputProfile const& profile);
void ClearProfile();

/** Init mode 2: By hand, key/axis by key/axis */
void SetInputCount(int nb_keys, int nb_axis);

/** layer mask stuff */
void SetLayerMask(uint32_t layer_mask);
uint32_t GetLayerMask();
@@ -427,11 +424,11 @@ protected:
void BindProfile(InputProfile const& setup);

private:
uint32_t m_layer_mask = 1; //plugged on the first by default
array<KeyBinding> m_keys;
array<AxisBinding> m_axis;
uint32_t m_layer_mask = 1; // plugged on the first by default
std::map<int, KeyBinding> m_keys;
std::map<int, AxisBinding> m_axis;

static uint32_t m_active_layer; //All active by default
static uint32_t m_active_layer; // All active by default
static array<Controller*> controllers;
std::string m_name;
bool m_activate_nextframe;


+ 11
- 2
src/platform/sdl/sdlinput.cpp ファイルの表示

@@ -165,9 +165,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)
* - HDAPS, it's not a real joystick.
* - X360 controllers, Xinput handles them better since
* it won't think there is only one trigger axis. */
# if LOL_USE_SDL
char const *name = SDL_JoystickName(sdlstick);
# endif
if (strstr(name, "HDAPS")
# if LOL_USE_XINPUT
|| strstr(name, "XBOX 360 For Windows")
@@ -302,6 +300,17 @@ void SdlInputData::Tick(float seconds)
(int)m_keyboard, ScanCodeToText(sc).C(), ScanCodeToName(sc).C(),
event.type == SDL_KEYDOWN ? "up" : "down", event.key.repeat);
*/

// These are arguably text input characters, too.
if (event.type == SDL_KEYDOWN && m_keyboard->IsTextInputActive())
{
switch (sc)
{
case SDLOL_Return: m_keyboard->AddText("\n"); break;
case SDLOL_Tab: m_keyboard->AddText("\t"); break;
case SDLOL_Backspace: m_keyboard->AddText("\x08"); break;
}
}
}
/* DEBUG STUFF
else


読み込み中…
キャンセル
保存