Browse Source

sdl input tweak

sdl integration now supports OS character input as per existing in sdl.
Use SetTextInputActive to turn it off/on
legacy
touky 8 years ago
parent
commit
d8efedf4d7
4 changed files with 32 additions and 12 deletions
  1. +10
    -0
      src/input/input.cpp
  2. +3
    -0
      src/input/input.h
  3. +2
    -0
      src/lolimgui.cpp
  4. +17
    -12
      src/platform/sdl/sdlinput.cpp

+ 10
- 0
src/input/input.cpp View File

@@ -36,6 +36,16 @@ String InputDevice::GetText()
return ret;
}

bool InputDevice::IsTextInputActive()
{
return m_input_active;
}

void InputDevice::SetTextInputActive(bool status)
{
m_input_active = status;
}

void InputDeviceInternal::AddKey(int index, const char* name)
{
if (index == -1)


+ 3
- 0
src/input/input.h View File

@@ -98,6 +98,8 @@ public:

/** Gets the latest contents of text input. */
String GetText();
bool IsTextInputActive();
void SetTextInputActive(bool status);

/** Gets the current value of the given axis. Devices should try to
* clamp this value between -1 and 1, though it is not guaranteed. */
@@ -199,6 +201,7 @@ protected:

/** Text input state */
String m_text;
bool m_input_active;

/** Axis states (value and sensitivity) */
array<float, float> m_axis;


+ 2
- 0
src/lolimgui.cpp View File

@@ -227,6 +227,8 @@ void LolImGui::TickGame(float seconds)
}
}

m_keyboard->SetTextInputActive(io.WantTextInput);

//Update text input
String text = m_keyboard->GetText();
//text.case_change(io.KeyShift);


+ 17
- 12
src/platform/sdl/sdlinput.cpp View File

@@ -251,6 +251,13 @@ void SdlInputData::Tick(float seconds)

m_mouse->SetAxis(4, 0);

# if !LOL_USE_OLD_SDL
if (m_keyboard->IsTextInputActive())
SDL_StartTextInput();
else
SDL_StopTextInput();
# endif

/* Handle keyboard and WM events */
SDL_Event event;
while (SDL_PollEvent(&event))
@@ -306,19 +313,9 @@ void SdlInputData::Tick(float seconds)
# else
if (ScanCodeIsValid(sc))
{
//Set key updates the corresponding key
m_keyboard->SetKey(sc, event.type == SDL_KEYDOWN);
if (event.type == SDL_KEYDOWN
&& !m_keyboard->GetKey(SDLOL_RCtrl)
&& !m_keyboard->GetKey(SDLOL_LCtrl)
&& !m_keyboard->GetKey(SDLOL_RAlt)
&& !m_keyboard->GetKey(SDLOL_LAlt))
{
String str = ScanCodeToText(sc);
str.case_change(m_keyboard->GetKey(SDLOL_CapsLockStatus)
^ (m_keyboard->GetKey(SDLOL_RShift)
|| m_keyboard->GetKey(SDLOL_LShift)));
m_keyboard->AddText(str);
}

/* DEBUG STUFF
msg::info("Repeat: 0x%02x : %s/%s/%s/%i\n",
(int)m_keyboard, ScanCodeToText(sc).C(), ScanCodeToName(sc).C(),
@@ -334,6 +331,14 @@ void SdlInputData::Tick(float seconds)
}
break;

# if !LOL_USE_OLD_SDL
//case SDL_TEXTEDITING: //TODO: handle that ?
case SDL_TEXTINPUT:
m_keyboard->AddText(event.text.text);
break;

# endif

# if LOL_USE_OLD_SDL
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:


Loading…
Cancel
Save