diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 89b885ed2..be36dcfca 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Fixed inputting numbers with the numpad, except directx (bug #934) - Alex - Better location description in savegame summaries (bug #844) - Alex - Fixed crash when saving a game into the last slot while having too many devices on board - Alex diff --git a/sc2/src/sc2code/getchar.c b/sc2/src/sc2code/getchar.c index 9ad64d542..421b09651 100644 --- a/sc2/src/sc2code/getchar.c +++ b/sc2/src/sc2code/getchar.c @@ -170,8 +170,10 @@ DoTextEntry (TEXTENTRY_STATE *pTES) } pTES->CacheStr = HMalloc (pTES->MaxSize * sizeof (*pTES->CacheStr)); - + + EnterCharacterMode (); DoInput (pTES, TRUE); + ExitCharacterMode (); if (pTES->CacheStr) HFree (pTES->CacheStr); diff --git a/sc2/src/sc2code/libs/inplib.h b/sc2/src/sc2code/libs/inplib.h index d97c7e38b..84fd0e115 100644 --- a/sc2/src/sc2code/libs/inplib.h +++ b/sc2/src/sc2code/libs/inplib.h @@ -43,8 +43,8 @@ extern volatile int QuitPosted; /* Functions for dealing with Character Mode */ -void EnableCharacterMode (void); -void DisableCharacterMode (void); +void EnterCharacterMode (void); +void ExitCharacterMode (void); wchar_t GetNextCharacter (void); wchar_t GetLastCharacter (void); diff --git a/sc2/src/sc2code/libs/input/sdl/input.c b/sc2/src/sc2code/libs/input/sdl/input.c index ca3b0100d..86fd83cbb 100644 --- a/sc2/src/sc2code/libs/input/sdl/input.c +++ b/sc2/src/sc2code/libs/input/sdl/input.c @@ -42,7 +42,7 @@ static int *kbdstate = NULL; static BOOLEAN InputInitialized = FALSE; -static BOOLEAN _in_character_mode = FALSE; +static BOOLEAN in_character_mode = FALSE; static const char *menu_res_names[] = { "pause", @@ -217,7 +217,7 @@ TFB_InitInput (int driver, int flags) } #endif /* HAVE_JOYSTICK */ - _in_character_mode = FALSE; + in_character_mode = FALSE; resetKeyboardState (); /* Prepare the Virtual Controller system. */ @@ -239,22 +239,20 @@ TFB_UninitInput (void) HFree (kbdstate); } -// XXX: not currently used -- character mode is always on void -EnableCharacterMode (void) +EnterCharacterMode (void) { kbdhead = kbdtail = 0; lastchar = 0; - _in_character_mode = TRUE; + in_character_mode = TRUE; VControl_ResetInput (); } -// XXX: not currently used -- character mode is always on void -DisableCharacterMode (void) +ExitCharacterMode (void) { VControl_ResetInput (); - _in_character_mode = FALSE; + in_character_mode = FALSE; kbdhead = kbdtail = 0; lastchar = 0; } @@ -294,6 +292,16 @@ ProcessMouseEvent (const SDL_Event *e) } } +static inline int +is_numpad_char_event (const SDL_Event *Event) +{ + return in_character_mode && + (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP) && + (Event->key.keysym.mod & KMOD_NUM) && /* NumLock is ON */ + Event->key.keysym.unicode > 0 && /* Printable char */ + Event->key.keysym.sym >= SDLK_KP0 && /* Keypad key */ + Event->key.keysym.sym <= SDLK_KP_PLUS; +} void ProcessInputEvent (const SDL_Event *Event) @@ -302,7 +310,11 @@ ProcessInputEvent (const SDL_Event *Event) return; ProcessMouseEvent (Event); - VControl_HandleEvent (Event); + + // In character mode with NumLock on, numpad chars bypass VControl + // so that menu arrow events are not produced + if (!is_numpad_char_event (Event)) + VControl_HandleEvent (Event); if (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP) { // process character input event, if any