Skip to content
Permalink
Browse files

use scancode instead of keycode for most keyboard shortcuts

keys like 0-9, tab, enter, ctrl/shift/alt, ins, and del are still looking for keys instead of scan codes, just in case (but I expect them to be always equivalent anyway)
  • Loading branch information...
jacob1 committed Feb 20, 2019
1 parent 0c6ce20 commit 08cd32abbe63a358cae619b5036b62654f2b2517
Showing with 95 additions and 84 deletions.
  1. +16 −16 src/gui/game/GameController.cpp
  2. +73 −62 src/gui/game/GameView.cpp
  3. +2 −2 src/gui/interface/Label.cpp
  4. +4 −4 src/gui/interface/Textbox.cpp
@@ -737,54 +737,54 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c
sim->player.comm = (int)(sim->player.comm)|0x02;
}
// Go left command
if (key == SDLK_LEFT)
else if (key == SDLK_LEFT)
{
sim->player.comm = (int)(sim->player.comm)|0x01;
}
// Use element command
if (key == SDLK_DOWN && ((int)(sim->player.comm)&0x08)!=0x08)
else if (key == SDLK_DOWN && ((int)(sim->player.comm)&0x08)!=0x08)
{
sim->player.comm = (int)(sim->player.comm)|0x08;
}
// Jump command
if (key == SDLK_UP && ((int)(sim->player.comm)&0x04)!=0x04)
else if (key == SDLK_UP && ((int)(sim->player.comm)&0x04)!=0x04)
{
sim->player.comm = (int)(sim->player.comm)|0x04;
}
}

// Go right command
if (key == SDLK_d)
if (scan == SDL_SCANCODE_D)
{
sim->player2.comm = (int)(sim->player2.comm)|0x02;
}
// Go left command
if (key == SDLK_a)
else if (scan == SDL_SCANCODE_A)
{
sim->player2.comm = (int)(sim->player2.comm)|0x01;
}
// Use element command
if (key == SDLK_s && ((int)(sim->player2.comm)&0x08)!=0x08)
else if (scan == SDL_SCANCODE_S && ((int)(sim->player2.comm)&0x08)!=0x08)
{
sim->player2.comm = (int)(sim->player2.comm)|0x08;
}
// Jump command
if (key == SDLK_w && ((int)(sim->player2.comm)&0x04)!=0x04)
else if (scan == SDL_SCANCODE_W && ((int)(sim->player2.comm)&0x04)!=0x04)
{
sim->player2.comm = (int)(sim->player2.comm)|0x04;
}

if (!sim->elementCount[PT_STKM2] || ctrl)
{
switch(key)
switch(scan)
{
case 'w':
case SDL_SCANCODE_W:
SwitchGravity();
break;
case 'd':
case SDL_SCANCODE_D:
gameView->SetDebugHUD(!gameView->GetDebugHUD());
break;
case 's':
case SDL_SCANCODE_S:
gameView->BeginStampSelection();
break;
}
@@ -814,25 +814,25 @@ bool GameController::KeyRelease(int key, int scan, bool repeat, bool shift, bool
sim->player.pcomm = sim->player.comm; //Saving last movement
sim->player.comm = (int)(sim->player.comm)&12; //Stop command
}
if (key == SDLK_UP)
else if (key == SDLK_UP)
{
sim->player.comm = (int)(sim->player.comm)&11;
}
if (key == SDLK_DOWN)
else if (key == SDLK_DOWN)
{
sim->player.comm = (int)(sim->player.comm)&7;
}

if (key == SDLK_d || key == SDLK_a)
if (scan == SDL_SCANCODE_D || scan == SDL_SCANCODE_A)
{
sim->player2.pcomm = sim->player2.comm; //Saving last movement
sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command
}
if (key == SDLK_w)
else if (scan == SDL_SCANCODE_W)
{
sim->player2.comm = (int)(sim->player2.comm)&11;
}
if (key == SDLK_s)
else if (scan == SDL_SCANCODE_S)
{
sim->player2.comm = (int)(sim->player2.comm)&7;
}
@@ -1405,9 +1405,9 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
case SDLK_DOWN:
c->TranslateSave(ui::Point(0, 1));
return;
case 'r':
if (repeat)
return;
}
if (scan == SDL_SCANCODE_R && !repeat)
{
if (ctrl && shift)
{
//Vertical flip
@@ -1430,29 +1430,16 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,

if (repeat)
return;
if (scan == SDL_SCANCODE_GRAVE)
bool didKeyShortcut = true;
switch(scan)
{
case SDL_SCANCODE_GRAVE:
c->ShowConsole();
return;
}
switch(key)
{
case SDLK_LALT:
case SDLK_RALT:
enableAltBehaviour();
break;
case SDLK_LCTRL:
case SDLK_RCTRL:
enableCtrlBehaviour();
break;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
enableShiftBehaviour();
break;
case ' ': //Space
case SDL_SCANCODE_SPACE: //Space
c->SetPaused();
break;
case 'z':
case SDL_SCANCODE_Z:
if (selectMode != SelectNone && isMouseDown)
break;
if (ctrl && !isMouseDown)
@@ -1469,11 +1456,8 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
c->SetZoomEnabled(true);
}
break;
case SDLK_TAB: //Tab
c->ChangeBrush();
break;
case 'p':
case SDLK_F2:
case SDL_SCANCODE_P:
case SDL_SCANCODE_F2:
if (ctrl)
{
if (shift)
@@ -1484,10 +1468,10 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
else
screenshot();
break;
case SDLK_F3:
case SDL_SCANCODE_F3:
SetDebugHUD(!GetDebugHUD());
break;
case SDLK_F5:
case SDL_SCANCODE_F5:
c->ReloadSim();
break;
case 'a':
@@ -1498,14 +1482,14 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
new InformationMessage("Save authorship info", authorString.FromUtf8(), true);
}
break;
case 'r':
case SDL_SCANCODE_R:
if (ctrl)
c->ReloadSim();
break;
case 'e':
case SDL_SCANCODE_E:
c->OpenElementSearch();
break;
case 'f':
case SDL_SCANCODE_F:
if (ctrl)
{
Tool *active = c->GetActiveTool(0);
@@ -1517,21 +1501,21 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
else
c->FrameStep();
break;
case 'g':
case SDL_SCANCODE_G:
if (ctrl)
c->ShowGravityGrid();
else if(shift)
c->AdjustGridSize(-1);
else
c->AdjustGridSize(1);
break;
case SDLK_F1:
case SDL_SCANCODE_F1:
if(!introText)
introText = 8047;
else
introText = 0;
break;
case 'h':
case SDL_SCANCODE_H:
if(ctrl)
{
if(!introText)
@@ -1542,7 +1526,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
else
showHud = !showHud;
break;
case 'b':
case SDL_SCANCODE_B:
if(ctrl)
c->SetDecoration();
else
@@ -1555,7 +1539,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
c->SetActiveMenu(SC_DECO);
}
break;
case 'y':
case SDL_SCANCODE_Y:
if (ctrl)
{
c->HistoryForward();
@@ -1565,23 +1549,23 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
c->SwitchAir();
}
break;
case SDLK_ESCAPE:
case 'q':
case SDL_SCANCODE_ESCAPE:
case SDL_SCANCODE_Q:
ui::Engine::Ref().ConfirmExit();
break;
case 'u':
case SDL_SCANCODE_U:
c->ToggleAHeat();
break;
case 'n':
case SDL_SCANCODE_N:
c->ToggleNewtonianGravity();
break;
case '=':
case SDL_SCANCODE_EQUALS:
if(ctrl)
c->ResetSpark();
else
c->ResetAir();
break;
case 'c':
case SDL_SCANCODE_C:
if(ctrl)
{
selectMode = SelectCopy;
@@ -1591,7 +1575,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
buttonTipShow = 120;
}
break;
case 'x':
case SDL_SCANCODE_X:
if(ctrl)
{
selectMode = SelectCut;
@@ -1601,7 +1585,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
buttonTipShow = 120;
}
break;
case 'v':
case SDL_SCANCODE_V:
if (ctrl)
{
if (c->LoadClipboard())
@@ -1611,7 +1595,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
}
}
break;
case 'l':
case SDL_SCANCODE_L:
{
std::vector<ByteString> stampList = Client::Ref().GetStamps(0, 1);
if (stampList.size())
@@ -1624,47 +1608,72 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
break;
}
}
case 'k':
case SDL_SCANCODE_K:
selectMode = SelectNone;
selectPoint1 = selectPoint2 = ui::Point(-1, -1);
c->OpenStamps();
break;
case ']':
case SDL_SCANCODE_RIGHTBRACKET:
if(zoomEnabled && !zoomCursorFixed)
c->AdjustZoomSize(1, !alt);
else
c->AdjustBrushSize(1, !alt, shiftBehaviour, ctrlBehaviour);
break;
case '[':
case SDL_SCANCODE_LEFTBRACKET:
if(zoomEnabled && !zoomCursorFixed)
c->AdjustZoomSize(-1, !alt);
else
c->AdjustBrushSize(-1, !alt, shiftBehaviour, ctrlBehaviour);
break;
case 'i':
case SDL_SCANCODE_I:
if(ctrl)
c->Install();
else
c->InvertAirSim();
break;
case ';':
case SDL_SCANCODE_SEMICOLON:
if (ctrl)
{
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
}
//fancy case switch without break
case SDLK_INSERT:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break;
case SDLK_DELETE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
default:
didKeyShortcut = false;
}
if (!didKeyShortcut)
{
switch (key)
{
case SDLK_LALT:
case SDLK_RALT:
enableAltBehaviour();
break;
case SDLK_LCTRL:
case SDLK_RCTRL:
enableCtrlBehaviour();
break;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
enableShiftBehaviour();
break;
case SDLK_TAB: //Tab
c->ChangeBrush();
break;
case SDLK_INSERT:
if (ctrl)
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
else
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break;
case SDLK_DELETE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break;
}
}

if (shift && showDebug && key == '1')
c->LoadRenderPreset(10);
else if(key >= '0' && key <= '9')
else if (key >= '0' && key <= '9')
{
c->LoadRenderPreset(key-'0');
}
@@ -1674,6 +1683,12 @@ void GameView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctr
{
if (repeat)
return;
if (scan == SDL_SCANCODE_Z)
{
if (!zoomCursorFixed && !alt)
c->SetZoomEnabled(false);
return;
}
switch(key)
{
case SDLK_LALT:
@@ -1688,10 +1703,6 @@ void GameView::OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctr
case SDLK_RSHIFT:
disableShiftBehaviour();
break;
case 'z':
if(!zoomCursorFixed && !alt)
c->SetZoomEnabled(false);
break;
}
}

Oops, something went wrong.

0 comments on commit 08cd32a

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.