key repetitions are now allowed for text input

main
Martin Felis (schakeline) 2011-01-31 08:39:42 +01:00
parent a27ece921a
commit f4ef58b9bf
5 changed files with 14 additions and 38 deletions

View File

@ -407,7 +407,6 @@ void View::DrawUi () {
SelectFont("console.ttf");
SetFontJustification (Engine::FontJustificationLeft);
GetController()->EnableTextinput(true);
ViewState current_view_state = GetViewState();

View File

@ -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];

View File

@ -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;
}

View File

@ -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 ();

View File

@ -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: