Skip to content

Commit

Permalink
fix numpad behavior: movement keys are no longer triggered with numlo…
Browse files Browse the repository at this point in the history
…ck on
  • Loading branch information
mniip committed Feb 27, 2014
1 parent d59253c commit 43bff37
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/PowderToySDL.cpp
Expand Up @@ -414,6 +414,27 @@ std::map<std::string, std::string> readArguments(int argc, char * argv[])
return arguments;
}

SDLKey MapNumpad(SDLKey key)
{
switch(key)
{
case KEY_NUM_UP:
return KEY_UP;
case KEY_NUM_DOWN:
return KEY_DOWN;
case KEY_NUM_RIGHT:
return KEY_RIGHT;
case KEY_NUM_LEFT:
return KEY_LEFT;
case KEY_NUM_HOME:
return KEY_HOME;
case KEY_NUM_END:
return KEY_END;
default:
return key;
}
}

int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
unsigned int lastTick = 0;
float fps = 0, delta = 1.0f, inputScale = 1.0f;
Expand All @@ -422,6 +443,9 @@ float currentWidth, currentHeight;

void EventProcess(SDL_Event event)
{
if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
if(!(event.key.keysym.mod&KEY_MOD_NUM))
event.key.keysym.sym = MapNumpad(event.key.keysym.sym);
switch (event.type)
{
case SDL_QUIT:
Expand Down
4 changes: 2 additions & 2 deletions src/gui/console/ConsoleView.cpp
Expand Up @@ -41,10 +41,10 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b
commandField->SetText("");
commandField->SetDisplayText("");
break;
case KEY_DOWN: case KEY_NUM_DOWN:
case KEY_DOWN:
c->NextCommand();
break;
case KEY_UP: case KEY_NUM_UP:
case KEY_UP:
c->PreviousCommand();
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/gui/game/PropertyTool.cpp
Expand Up @@ -229,9 +229,9 @@ void PropertyWindow::OnDraw()

void PropertyWindow::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if (key == KEY_UP || key == KEY_NUM_UP)
if (key == KEY_UP)
property->SetOption(property->GetOption().second-1);
else if (key == KEY_DOWN || key == KEY_NUM_DOWN)
else if (key == KEY_DOWN)
property->SetOption(property->GetOption().second+1);
}

Expand Down
8 changes: 4 additions & 4 deletions src/gui/interface/Textbox.cpp
Expand Up @@ -342,20 +342,20 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{
switch(key)
{
case KEY_HOME: case KEY_NUM_HOME:
case KEY_HOME:
cursor = 0;
ClearSelection();
break;
case KEY_END: case KEY_NUM_END:
case KEY_END:
cursor = backingText.length();
ClearSelection();
break;
case KEY_LEFT: case KEY_NUM_LEFT:
case KEY_LEFT:
if(cursor > 0)
cursor--;
ClearSelection();
break;
case KEY_RIGHT: case KEY_NUM_RIGHT:
case KEY_RIGHT:
if(cursor < backingText.length())
cursor++;
ClearSelection();
Expand Down

0 comments on commit 43bff37

Please sign in to comment.