From f4ef58b9bfa3fe69b89bf16d12714e580190b3e3 Mon Sep 17 00:00:00 2001 From: "Martin Felis (schakeline)" Date: Mon, 31 Jan 2011 08:39:42 +0100 Subject: [PATCH] key repetitions are now allowed for text input --- asteroids/View.cc | 1 - engine/ControllerBase.cc | 35 ++++++++++++++-------------------- engine/ControllerBase.h | 3 --- engine/IMGUIControls.cc | 3 --- engine/SimpleConsoleOverlay.cc | 10 ---------- 5 files changed, 14 insertions(+), 38 deletions(-) diff --git a/asteroids/View.cc b/asteroids/View.cc index 80fa878..079c867 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -407,7 +407,6 @@ void View::DrawUi () { SelectFont("console.ttf"); SetFontJustification (Engine::FontJustificationLeft); - GetController()->EnableTextinput(true); ViewState current_view_state = GetViewState(); diff --git a/engine/ControllerBase.cc b/engine/ControllerBase.cc index ccb992d..4a12165 100644 --- a/engine/ControllerBase.cc +++ b/engine/ControllerBase.cc @@ -47,6 +47,14 @@ MouseButton convert_sdl_button (Uint8 button) { int ControllerBase::OnInit (int argc, char* argv[]) { LogDebug ("Controller Init"); + // we want to use key repeat so that we can keep e.g. backspace pressed in a + // LineEdit + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + // we also enable unicode processing all the time as it is only little + // overhead and simplifies text input a lot + SDL_EnableUNICODE(1); + // clear all bindings int i; for (i = 0; i < BINDING_KEYS_LAST; i++) { @@ -142,17 +150,6 @@ void ControllerBase::ProcessEvents () { } } -/** \brief Activates or deactivates unicode processing and key delays of the keyboard inputs */ -void ControllerBase::EnableTextinput (bool textinput_state) { - if (textinput_state) { - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(500, 50); - } else { - SDL_EnableUNICODE(-1); - SDL_EnableKeyRepeat(0, 100); - } -} - void ControllerBase::IMGUIFinish () { if (GetButtonState(MouseButtonLeft) == false) { uistate.activeitem = 0; @@ -169,7 +166,6 @@ void ControllerBase::IMGUIFinish () { /** \brief Keyboard processing */ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) { - mButtonStates.set(keysym.sym, true); uistate.last_keysym = keysym.sym; uistate.last_key = keysym.sym; @@ -179,25 +175,22 @@ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) { // LogMessage ("Received key down of %s and unicode %d", convert_keycode(keysym.sym), keysym.unicode); } - if (mView->mOverlayManager.SendKeyDown (keysym)) - return true; - - if (mBindings[keysym.sym].size () != 0) { + if (mBindings[keysym.sym].size () != 0 + && GetButtonState(keysym.sym) == false) { QueueCommand (mBindings[keysym.sym]); - return true; } + SetButtonState (keysym.sym, true); + return false; } /** \brief Keyboard processing */ bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) { - mButtonStates.set(keysym.sym, false); + SetButtonState (keysym.sym, false); + uistate.keypressed_set.insert (keysym.sym); - if (mView->mOverlayManager.SendKeyUp (keysym)) - return true; - if (mBindings[keysym.sym].size () != 0) { if (mBindings[keysym.sym][0] == '+') { std::string upcommand = mBindings[keysym.sym]; diff --git a/engine/ControllerBase.h b/engine/ControllerBase.h index 98ea173..ea8e2ce 100644 --- a/engine/ControllerBase.h +++ b/engine/ControllerBase.h @@ -76,9 +76,6 @@ class ControllerBase : public Module { } bool BindKey (int key, const char *command); - /** \brief Activates or deactivates unicode processing and key delays of the keyboard inputs */ - void EnableTextinput (bool textinput_state); - void IMGUIPrepare () { uistate.hotitem = 0; } diff --git a/engine/IMGUIControls.cc b/engine/IMGUIControls.cc index cbbba7f..9461495 100644 --- a/engine/IMGUIControls.cc +++ b/engine/IMGUIControls.cc @@ -322,9 +322,6 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng DrawBlock (x, y, w, h); } - SDL_EnableKeyRepeat(500, 50); - - // Rendering of the current value float width, height; view = EngineGetView (); diff --git a/engine/SimpleConsoleOverlay.cc b/engine/SimpleConsoleOverlay.cc index 65482b9..a1b4a18 100644 --- a/engine/SimpleConsoleOverlay.cc +++ b/engine/SimpleConsoleOverlay.cc @@ -14,15 +14,6 @@ static Variable Var_ConsoleTransparency ("consoletransparency", "0.2"); bool SimpleConsoleOverlay::OnKeyDown (const SDL_keysym &keysym) { if (keysym.sym == SDLK_F8) { - if (mActive) { - // We have to call SetActive() to actually - // activate the unicode processing of SDL - EngineGetController()->EnableTextinput(false); - } - else { - EngineGetController()->EnableTextinput(true); - } - return true; } @@ -32,7 +23,6 @@ bool SimpleConsoleOverlay::OnKeyDown (const SDL_keysym &keysym) { // check for input that requires actions switch (keysym.sym) { case SDLK_ESCAPE: - EngineGetController()->EnableTextinput(false); return true; break; case SDLK_BACKSPACE: