Skip to content

Commit ecb0895

Browse files
committed
Add SDL_keysym.h, Use official SDL constants
1 parent 95fde9d commit ecb0895

File tree

8 files changed

+102
-76
lines changed

8 files changed

+102
-76
lines changed

src/PowderToySDL.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -587,24 +587,24 @@ SDLKey MapNumpad(SDLKey key)
587587
{
588588
switch(key)
589589
{
590-
case KEY_NUM_UP:
591-
return KEY_UP;
592-
case KEY_NUM_DOWN:
593-
return KEY_DOWN;
594-
case KEY_NUM_RIGHT:
595-
return KEY_RIGHT;
596-
case KEY_NUM_LEFT:
597-
return KEY_LEFT;
598-
case KEY_NUM_HOME:
599-
return KEY_HOME;
600-
case KEY_NUM_END:
601-
return KEY_END;
602-
case KEY_NUM_PERIOD:
603-
return KEY_DELETE;
604-
case KEY_NUM_INS:
605-
case KEY_NUM_PGUP:
606-
case KEY_NUM_PGDOWN:
607-
return KEY_UNKNOWN;
590+
case SDLK_KP8:
591+
return SDLK_UP;
592+
case SDLK_KP2:
593+
return SDLK_DOWN;
594+
case SDLK_KP6:
595+
return SDLK_RIGHT;
596+
case SDLK_KP4:
597+
return SDLK_LEFT;
598+
case SDLK_KP7:
599+
return SDLK_HOME;
600+
case SDLK_KP1:
601+
return SDLK_END;
602+
case SDLK_KP_PERIOD:
603+
return SDLK_DELETE;
604+
case SDLK_KP0:
605+
case SDLK_KP9:
606+
case SDLK_KP3:
607+
return SDLK_UNKNOWN;
608608
default:
609609
return key;
610610
}
@@ -641,10 +641,10 @@ void EventProcess(SDL_Event event)
641641
engine->Exit();
642642
break;
643643
case SDL_KEYDOWN:
644-
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KEY_MOD_SHIFT, event.key.keysym.mod&KEY_MOD_CONTROL, event.key.keysym.mod&KEY_MOD_ALT);
644+
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
645645
break;
646646
case SDL_KEYUP:
647-
engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KEY_MOD_SHIFT, event.key.keysym.mod&KEY_MOD_CONTROL, event.key.keysym.mod&KEY_MOD_ALT);
647+
engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
648648
break;
649649
case SDL_MOUSEMOTION:
650650
engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale);

src/gui/colourpicker/ColourPickerActivity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
243243

244244
void ColourPickerActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
245245
{
246-
if (key == KEY_TAB)
246+
if (key == SDLK_TAB)
247247
{
248248
if (rValue->IsFocused())
249249
gValue->TabFocus();

src/gui/console/ConsoleView.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b
2828
{
2929
switch(key)
3030
{
31-
case KEY_ESCAPE:
31+
case SDLK_ESCAPE:
3232
case '`':
3333
if (character != '~')
3434
c->CloseConsole();
3535
else
3636
Window::DoKeyPress(key, character, shift, ctrl, alt);
3737
break;
38-
case KEY_RETURN:
39-
case KEY_ENTER:
38+
case SDLK_RETURN:
39+
case SDLK_KP_ENTER:
4040
c->EvaluateCommand(commandField->GetText());
4141
commandField->SetText("");
4242
commandField->SetDisplayText("");
4343
break;
44-
case KEY_DOWN:
44+
case SDLK_DOWN:
4545
c->NextCommand();
4646
break;
47-
case KEY_UP:
47+
case SDLK_UP:
4848
c->PreviousCommand();
4949
break;
5050
default:

src/gui/elementsearch/ElementSearchActivity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ void ElementSearchActivity::OnTick(float dt)
188188

189189
void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
190190
{
191-
if(key == KEY_ENTER || key == KEY_RETURN)
191+
if (key == SDLK_KP_ENTER || key == SDLK_RETURN)
192192
{
193193
if(firstResult)
194194
gameController->SetActiveTool(0, firstResult);
195195
exit = true;
196196
}
197-
if(key == KEY_ESCAPE)
197+
if (key == SDLK_ESCAPE)
198198
{
199199
exit = true;
200200
}

src/gui/game/GameController.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "gui/save/LocalSaveActivity.h"
2626
#include "gui/save/ServerSaveActivity.h"
2727
#include "gui/interface/Keys.h"
28+
#include "gui/interface/Mouse.h"
2829
#include "simulation/Snapshot.h"
2930
#include "debug/DebugInfo.h"
3031
#include "debug/DebugParts.h"
@@ -562,7 +563,7 @@ bool GameController::MouseDown(int x, int y, unsigned button)
562563
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
563564
x = point.X;
564565
y = point.Y;
565-
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
566+
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
566567
{
567568
foundSign = GetSignAt(x, y);
568569
if(foundSign && sign::splitsign(foundSign->text.c_str()))
@@ -582,7 +583,7 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
582583
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
583584
x = point.X;
584585
y = point.Y;
585-
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
586+
if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != SDL_BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
586587
{
587588
sign * foundSign = GetSignAt(x, y);
588589
if (foundSign)
@@ -644,36 +645,36 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl,
644645
if (ret)
645646
{
646647
Simulation * sim = gameModel->GetSimulation();
647-
if (key == KEY_RIGHT)
648+
if (key == SDLK_RIGHT)
648649
{
649650
sim->player.comm = (int)(sim->player.comm)|0x02; //Go right command
650651
}
651-
if (key == KEY_LEFT)
652+
if (key == SDLK_LEFT)
652653
{
653654
sim->player.comm = (int)(sim->player.comm)|0x01; //Go left command
654655
}
655-
if (key == KEY_DOWN && ((int)(sim->player.comm)&0x08)!=0x08)
656+
if (key == SDLK_DOWN && ((int)(sim->player.comm)&0x08)!=0x08)
656657
{
657658
sim->player.comm = (int)(sim->player.comm)|0x08; //Use element command
658659
}
659-
if (key == KEY_UP && ((int)(sim->player.comm)&0x04)!=0x04)
660+
if (key == SDLK_UP && ((int)(sim->player.comm)&0x04)!=0x04)
660661
{
661662
sim->player.comm = (int)(sim->player.comm)|0x04; //Jump command
662663
}
663664

664-
if (key == KEY_d)
665+
if (key == SDLK_d)
665666
{
666667
sim->player2.comm = (int)(sim->player2.comm)|0x02; //Go right command
667668
}
668-
if (key == KEY_a)
669+
if (key == SDLK_a)
669670
{
670671
sim->player2.comm = (int)(sim->player2.comm)|0x01; //Go left command
671672
}
672-
if (key == KEY_s && ((int)(sim->player2.comm)&0x08)!=0x08)
673+
if (key == SDLK_s && ((int)(sim->player2.comm)&0x08)!=0x08)
673674
{
674675
sim->player2.comm = (int)(sim->player2.comm)|0x08; //Use element command
675676
}
676-
if (key == KEY_w && ((int)(sim->player2.comm)&0x04)!=0x04)
677+
if (key == SDLK_w && ((int)(sim->player2.comm)&0x04)!=0x04)
677678
{
678679
sim->player2.comm = (int)(sim->player2.comm)|0x04; //Jump command
679680
}
@@ -710,30 +711,30 @@ bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl
710711
if (ret)
711712
{
712713
Simulation * sim = gameModel->GetSimulation();
713-
if (key == KEY_RIGHT || key == KEY_LEFT)
714+
if (key == SDLK_RIGHT || key == SDLK_LEFT)
714715
{
715716
sim->player.pcomm = sim->player.comm; //Saving last movement
716717
sim->player.comm = (int)(sim->player.comm)&12; //Stop command
717718
}
718-
if (key == KEY_UP)
719+
if (key == SDLK_UP)
719720
{
720721
sim->player.comm = (int)(sim->player.comm)&11;
721722
}
722-
if (key == KEY_DOWN)
723+
if (key == SDLK_DOWN)
723724
{
724725
sim->player.comm = (int)(sim->player.comm)&7;
725726
}
726727

727-
if (key == KEY_d || key == KEY_a)
728+
if (key == SDLK_d || key == SDLK_a)
728729
{
729730
sim->player2.pcomm = sim->player2.comm; //Saving last movement
730731
sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command
731732
}
732-
if (key == KEY_w)
733+
if (key == SDLK_w)
733734
{
734735
sim->player2.comm = (int)(sim->player2.comm)&11;
735736
}
736-
if (key == KEY_s)
737+
if (key == SDLK_s)
737738
{
738739
sim->player2.comm = (int)(sim->player2.comm)&7;
739740
}

src/gui/game/GameView.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "gui/interface/Button.h"
1111
#include "gui/interface/Colour.h"
1212
#include "gui/interface/Keys.h"
13+
#include "gui/interface/Mouse.h"
1314
#include "gui/interface/Slider.h"
1415
#include "gui/search/Thumbnail.h"
1516
#include "simulation/SaveRenderer.h"
@@ -1142,13 +1143,13 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
11421143
{
11431144
currentMouse = ui::Point(x, y);
11441145
if (altBehaviour && !shiftBehaviour && !ctrlBehaviour)
1145-
button = BUTTON_MIDDLE;
1146+
button = SDL_BUTTON_MIDDLE;
11461147
if (!(zoomEnabled && !zoomCursorFixed))
11471148
{
11481149
if (selectMode != SelectNone)
11491150
{
11501151
isMouseDown = true;
1151-
if (button == BUTTON_LEFT && selectPoint1.X == -1)
1152+
if (button == SDL_BUTTON_LEFT && selectPoint1.X == -1)
11521153
{
11531154
selectPoint1 = c->PointTranslate(currentMouse);
11541155
selectPoint2 = selectPoint1;
@@ -1158,11 +1159,11 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
11581159
if (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES)
11591160
{
11601161
// update tool index, set new "last" tool so GameView can detect certain tools properly
1161-
if (button == BUTTON_LEFT)
1162+
if (button == SDL_BUTTON_LEFT)
11621163
toolIndex = 0;
1163-
if (button == BUTTON_RIGHT)
1164+
if (button == SDL_BUTTON_RIGHT)
11641165
toolIndex = 1;
1165-
if (button == BUTTON_MIDDLE)
1166+
if (button == SDL_BUTTON_MIDDLE)
11661167
toolIndex = 2;
11671168
Tool *lastTool = c->GetActiveTool(toolIndex);
11681169
c->SetLastTool(lastTool);
@@ -1201,7 +1202,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
12011202
isMouseDown = false;
12021203
if (selectMode != SelectNone)
12031204
{
1204-
if (button == BUTTON_LEFT && selectPoint1.X != -1 && selectPoint1.Y != -1 && selectPoint2.X != -1 && selectPoint2.Y != -1)
1205+
if (button == SDL_BUTTON_LEFT && selectPoint1.X != -1 && selectPoint1.Y != -1 && selectPoint2.X != -1 && selectPoint2.Y != -1)
12051206
{
12061207
if (selectMode == PlaceSave)
12071208
{
@@ -1276,7 +1277,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
12761277
}
12771278
}
12781279
// this shouldn't happen, but do this just in case
1279-
else if (selectMode != SelectNone && button != BUTTON_LEFT)
1280+
else if (selectMode != SelectNone && button != SDL_BUTTON_LEFT)
12801281
selectMode = SelectNone;
12811282

12821283
// update the drawing mode for the next line
@@ -1369,16 +1370,16 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
13691370
{
13701371
switch (key)
13711372
{
1372-
case KEY_RIGHT:
1373+
case SDLK_RIGHT:
13731374
c->TranslateSave(ui::Point(1, 0));
13741375
return;
1375-
case KEY_LEFT:
1376+
case SDLK_LEFT:
13761377
c->TranslateSave(ui::Point(-1, 0));
13771378
return;
1378-
case KEY_UP:
1379+
case SDLK_UP:
13791380
c->TranslateSave(ui::Point(0, -1));
13801381
return;
1381-
case KEY_DOWN:
1382+
case SDLK_DOWN:
13821383
c->TranslateSave(ui::Point(0, 1));
13831384
return;
13841385
case 'r':
@@ -1403,16 +1404,16 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
14031404
}
14041405
switch(key)
14051406
{
1406-
case KEY_LALT:
1407-
case KEY_RALT:
1407+
case SDLK_LALT:
1408+
case SDLK_RALT:
14081409
enableAltBehaviour();
14091410
break;
1410-
case KEY_LCTRL:
1411-
case KEY_RCTRL:
1411+
case SDLK_LCTRL:
1412+
case SDLK_RCTRL:
14121413
enableCtrlBehaviour();
14131414
break;
1414-
case KEY_LSHIFT:
1415-
case KEY_RSHIFT:
1415+
case SDLK_LSHIFT:
1416+
case SDLK_RSHIFT:
14161417
enableShiftBehaviour();
14171418
break;
14181419
case ' ': //Space
@@ -1432,20 +1433,20 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
14321433
c->SetZoomEnabled(true);
14331434
}
14341435
break;
1435-
case KEY_TAB: //Tab
1436+
case SDLK_TAB: //Tab
14361437
c->ChangeBrush();
14371438
break;
14381439
case '`':
14391440
c->ShowConsole();
14401441
break;
14411442
case 'p':
1442-
case KEY_F2:
1443+
case SDLK_F2:
14431444
screenshot();
14441445
break;
1445-
case KEY_F3:
1446+
case SDLK_F3:
14461447
SetDebugHUD(!GetDebugHUD());
14471448
break;
1448-
case KEY_F5:
1449+
case SDLK_F5:
14491450
c->ReloadSim();
14501451
break;
14511452
case 'r':
@@ -1477,7 +1478,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
14771478
else
14781479
c->AdjustGridSize(1);
14791480
break;
1480-
case KEY_F1:
1481+
case SDLK_F1:
14811482
if(!introText)
14821483
introText = 8047;
14831484
else
@@ -1510,7 +1511,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
15101511
case 'y':
15111512
c->SwitchAir();
15121513
break;
1513-
case KEY_ESCAPE:
1514+
case SDLK_ESCAPE:
15141515
case 'q':
15151516
ExitPrompt();
15161517
break;
@@ -1597,10 +1598,10 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
15971598
break;
15981599
}
15991600
//fancy case switch without break
1600-
case KEY_INSERT:
1601+
case SDLK_INSERT:
16011602
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
16021603
break;
1603-
case KEY_DELETE:
1604+
case SDLK_DELETE:
16041605
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
16051606
break;
16061607
}
@@ -1617,16 +1618,16 @@ void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bo
16171618
{
16181619
switch(key)
16191620
{
1620-
case KEY_LALT:
1621-
case KEY_RALT:
1621+
case SDLK_LALT:
1622+
case SDLK_RALT:
16221623
disableAltBehaviour();
16231624
break;
1624-
case KEY_LCTRL:
1625-
case KEY_RCTRL:
1625+
case SDLK_LCTRL:
1626+
case SDLK_RCTRL:
16261627
disableCtrlBehaviour();
16271628
break;
1628-
case KEY_LSHIFT:
1629-
case KEY_RSHIFT:
1629+
case SDLK_LSHIFT:
1630+
case SDLK_RSHIFT:
16301631
disableShiftBehaviour();
16311632
break;
16321633
case 'z':

0 commit comments

Comments
 (0)