Add SDL_keysym.h, Use official SDL constants

This commit is contained in:
jacob1 2016-07-19 22:42:10 -04:00
parent 95fde9d699
commit ecb08952e5
8 changed files with 102 additions and 76 deletions

View File

@ -587,24 +587,24 @@ SDLKey MapNumpad(SDLKey key)
{ {
switch(key) switch(key)
{ {
case KEY_NUM_UP: case SDLK_KP8:
return KEY_UP; return SDLK_UP;
case KEY_NUM_DOWN: case SDLK_KP2:
return KEY_DOWN; return SDLK_DOWN;
case KEY_NUM_RIGHT: case SDLK_KP6:
return KEY_RIGHT; return SDLK_RIGHT;
case KEY_NUM_LEFT: case SDLK_KP4:
return KEY_LEFT; return SDLK_LEFT;
case KEY_NUM_HOME: case SDLK_KP7:
return KEY_HOME; return SDLK_HOME;
case KEY_NUM_END: case SDLK_KP1:
return KEY_END; return SDLK_END;
case KEY_NUM_PERIOD: case SDLK_KP_PERIOD:
return KEY_DELETE; return SDLK_DELETE;
case KEY_NUM_INS: case SDLK_KP0:
case KEY_NUM_PGUP: case SDLK_KP9:
case KEY_NUM_PGDOWN: case SDLK_KP3:
return KEY_UNKNOWN; return SDLK_UNKNOWN;
default: default:
return key; return key;
} }
@ -641,10 +641,10 @@ void EventProcess(SDL_Event event)
engine->Exit(); engine->Exit();
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
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); 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);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
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); 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);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale); engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale);

View File

@ -243,7 +243,7 @@ void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
void ColourPickerActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) void ColourPickerActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{ {
if (key == KEY_TAB) if (key == SDLK_TAB)
{ {
if (rValue->IsFocused()) if (rValue->IsFocused())
gValue->TabFocus(); gValue->TabFocus();

View File

@ -28,23 +28,23 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b
{ {
switch(key) switch(key)
{ {
case KEY_ESCAPE: case SDLK_ESCAPE:
case '`': case '`':
if (character != '~') if (character != '~')
c->CloseConsole(); c->CloseConsole();
else else
Window::DoKeyPress(key, character, shift, ctrl, alt); Window::DoKeyPress(key, character, shift, ctrl, alt);
break; break;
case KEY_RETURN: case SDLK_RETURN:
case KEY_ENTER: case SDLK_KP_ENTER:
c->EvaluateCommand(commandField->GetText()); c->EvaluateCommand(commandField->GetText());
commandField->SetText(""); commandField->SetText("");
commandField->SetDisplayText(""); commandField->SetDisplayText("");
break; break;
case KEY_DOWN: case SDLK_DOWN:
c->NextCommand(); c->NextCommand();
break; break;
case KEY_UP: case SDLK_UP:
c->PreviousCommand(); c->PreviousCommand();
break; break;
default: default:

View File

@ -188,13 +188,13 @@ void ElementSearchActivity::OnTick(float dt)
void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) void ElementSearchActivity::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{ {
if(key == KEY_ENTER || key == KEY_RETURN) if (key == SDLK_KP_ENTER || key == SDLK_RETURN)
{ {
if(firstResult) if(firstResult)
gameController->SetActiveTool(0, firstResult); gameController->SetActiveTool(0, firstResult);
exit = true; exit = true;
} }
if(key == KEY_ESCAPE) if (key == SDLK_ESCAPE)
{ {
exit = true; exit = true;
} }

View File

@ -25,6 +25,7 @@
#include "gui/save/LocalSaveActivity.h" #include "gui/save/LocalSaveActivity.h"
#include "gui/save/ServerSaveActivity.h" #include "gui/save/ServerSaveActivity.h"
#include "gui/interface/Keys.h" #include "gui/interface/Keys.h"
#include "gui/interface/Mouse.h"
#include "simulation/Snapshot.h" #include "simulation/Snapshot.h"
#include "debug/DebugInfo.h" #include "debug/DebugInfo.h"
#include "debug/DebugParts.h" #include "debug/DebugParts.h"
@ -562,7 +563,7 @@ bool GameController::MouseDown(int x, int y, unsigned button)
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y)); ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
x = point.X; x = point.X;
y = point.Y; y = point.Y;
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 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
{ {
foundSign = GetSignAt(x, y); foundSign = GetSignAt(x, y);
if(foundSign && sign::splitsign(foundSign->text.c_str())) if(foundSign && sign::splitsign(foundSign->text.c_str()))
@ -582,7 +583,7 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y)); ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
x = point.X; x = point.X;
y = point.Y; y = point.Y;
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 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
{ {
sign * foundSign = GetSignAt(x, y); sign * foundSign = GetSignAt(x, y);
if (foundSign) if (foundSign)
@ -644,36 +645,36 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl,
if (ret) if (ret)
{ {
Simulation * sim = gameModel->GetSimulation(); Simulation * sim = gameModel->GetSimulation();
if (key == KEY_RIGHT) if (key == SDLK_RIGHT)
{ {
sim->player.comm = (int)(sim->player.comm)|0x02; //Go right command sim->player.comm = (int)(sim->player.comm)|0x02; //Go right command
} }
if (key == KEY_LEFT) if (key == SDLK_LEFT)
{ {
sim->player.comm = (int)(sim->player.comm)|0x01; //Go left command sim->player.comm = (int)(sim->player.comm)|0x01; //Go left command
} }
if (key == KEY_DOWN && ((int)(sim->player.comm)&0x08)!=0x08) if (key == SDLK_DOWN && ((int)(sim->player.comm)&0x08)!=0x08)
{ {
sim->player.comm = (int)(sim->player.comm)|0x08; //Use element command sim->player.comm = (int)(sim->player.comm)|0x08; //Use element command
} }
if (key == KEY_UP && ((int)(sim->player.comm)&0x04)!=0x04) if (key == SDLK_UP && ((int)(sim->player.comm)&0x04)!=0x04)
{ {
sim->player.comm = (int)(sim->player.comm)|0x04; //Jump command sim->player.comm = (int)(sim->player.comm)|0x04; //Jump command
} }
if (key == KEY_d) if (key == SDLK_d)
{ {
sim->player2.comm = (int)(sim->player2.comm)|0x02; //Go right command sim->player2.comm = (int)(sim->player2.comm)|0x02; //Go right command
} }
if (key == KEY_a) if (key == SDLK_a)
{ {
sim->player2.comm = (int)(sim->player2.comm)|0x01; //Go left command sim->player2.comm = (int)(sim->player2.comm)|0x01; //Go left command
} }
if (key == KEY_s && ((int)(sim->player2.comm)&0x08)!=0x08) if (key == SDLK_s && ((int)(sim->player2.comm)&0x08)!=0x08)
{ {
sim->player2.comm = (int)(sim->player2.comm)|0x08; //Use element command sim->player2.comm = (int)(sim->player2.comm)|0x08; //Use element command
} }
if (key == KEY_w && ((int)(sim->player2.comm)&0x04)!=0x04) if (key == SDLK_w && ((int)(sim->player2.comm)&0x04)!=0x04)
{ {
sim->player2.comm = (int)(sim->player2.comm)|0x04; //Jump command sim->player2.comm = (int)(sim->player2.comm)|0x04; //Jump command
} }
@ -710,30 +711,30 @@ bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl
if (ret) if (ret)
{ {
Simulation * sim = gameModel->GetSimulation(); Simulation * sim = gameModel->GetSimulation();
if (key == KEY_RIGHT || key == KEY_LEFT) if (key == SDLK_RIGHT || key == SDLK_LEFT)
{ {
sim->player.pcomm = sim->player.comm; //Saving last movement sim->player.pcomm = sim->player.comm; //Saving last movement
sim->player.comm = (int)(sim->player.comm)&12; //Stop command sim->player.comm = (int)(sim->player.comm)&12; //Stop command
} }
if (key == KEY_UP) if (key == SDLK_UP)
{ {
sim->player.comm = (int)(sim->player.comm)&11; sim->player.comm = (int)(sim->player.comm)&11;
} }
if (key == KEY_DOWN) if (key == SDLK_DOWN)
{ {
sim->player.comm = (int)(sim->player.comm)&7; sim->player.comm = (int)(sim->player.comm)&7;
} }
if (key == KEY_d || key == KEY_a) if (key == SDLK_d || key == SDLK_a)
{ {
sim->player2.pcomm = sim->player2.comm; //Saving last movement sim->player2.pcomm = sim->player2.comm; //Saving last movement
sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command
} }
if (key == KEY_w) if (key == SDLK_w)
{ {
sim->player2.comm = (int)(sim->player2.comm)&11; sim->player2.comm = (int)(sim->player2.comm)&11;
} }
if (key == KEY_s) if (key == SDLK_s)
{ {
sim->player2.comm = (int)(sim->player2.comm)&7; sim->player2.comm = (int)(sim->player2.comm)&7;
} }

View File

@ -10,6 +10,7 @@
#include "gui/interface/Button.h" #include "gui/interface/Button.h"
#include "gui/interface/Colour.h" #include "gui/interface/Colour.h"
#include "gui/interface/Keys.h" #include "gui/interface/Keys.h"
#include "gui/interface/Mouse.h"
#include "gui/interface/Slider.h" #include "gui/interface/Slider.h"
#include "gui/search/Thumbnail.h" #include "gui/search/Thumbnail.h"
#include "simulation/SaveRenderer.h" #include "simulation/SaveRenderer.h"
@ -1142,13 +1143,13 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
{ {
currentMouse = ui::Point(x, y); currentMouse = ui::Point(x, y);
if (altBehaviour && !shiftBehaviour && !ctrlBehaviour) if (altBehaviour && !shiftBehaviour && !ctrlBehaviour)
button = BUTTON_MIDDLE; button = SDL_BUTTON_MIDDLE;
if (!(zoomEnabled && !zoomCursorFixed)) if (!(zoomEnabled && !zoomCursorFixed))
{ {
if (selectMode != SelectNone) if (selectMode != SelectNone)
{ {
isMouseDown = true; isMouseDown = true;
if (button == BUTTON_LEFT && selectPoint1.X == -1) if (button == SDL_BUTTON_LEFT && selectPoint1.X == -1)
{ {
selectPoint1 = c->PointTranslate(currentMouse); selectPoint1 = c->PointTranslate(currentMouse);
selectPoint2 = selectPoint1; selectPoint2 = selectPoint1;
@ -1158,11 +1159,11 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
if (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES) if (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES)
{ {
// update tool index, set new "last" tool so GameView can detect certain tools properly // update tool index, set new "last" tool so GameView can detect certain tools properly
if (button == BUTTON_LEFT) if (button == SDL_BUTTON_LEFT)
toolIndex = 0; toolIndex = 0;
if (button == BUTTON_RIGHT) if (button == SDL_BUTTON_RIGHT)
toolIndex = 1; toolIndex = 1;
if (button == BUTTON_MIDDLE) if (button == SDL_BUTTON_MIDDLE)
toolIndex = 2; toolIndex = 2;
Tool *lastTool = c->GetActiveTool(toolIndex); Tool *lastTool = c->GetActiveTool(toolIndex);
c->SetLastTool(lastTool); c->SetLastTool(lastTool);
@ -1201,7 +1202,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
isMouseDown = false; isMouseDown = false;
if (selectMode != SelectNone) if (selectMode != SelectNone)
{ {
if (button == BUTTON_LEFT && selectPoint1.X != -1 && selectPoint1.Y != -1 && selectPoint2.X != -1 && selectPoint2.Y != -1) if (button == SDL_BUTTON_LEFT && selectPoint1.X != -1 && selectPoint1.Y != -1 && selectPoint2.X != -1 && selectPoint2.Y != -1)
{ {
if (selectMode == PlaceSave) if (selectMode == PlaceSave)
{ {
@ -1276,7 +1277,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
} }
} }
// this shouldn't happen, but do this just in case // this shouldn't happen, but do this just in case
else if (selectMode != SelectNone && button != BUTTON_LEFT) else if (selectMode != SelectNone && button != SDL_BUTTON_LEFT)
selectMode = SelectNone; selectMode = SelectNone;
// update the drawing mode for the next line // update the drawing mode for the next line
@ -1369,16 +1370,16 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{ {
switch (key) switch (key)
{ {
case KEY_RIGHT: case SDLK_RIGHT:
c->TranslateSave(ui::Point(1, 0)); c->TranslateSave(ui::Point(1, 0));
return; return;
case KEY_LEFT: case SDLK_LEFT:
c->TranslateSave(ui::Point(-1, 0)); c->TranslateSave(ui::Point(-1, 0));
return; return;
case KEY_UP: case SDLK_UP:
c->TranslateSave(ui::Point(0, -1)); c->TranslateSave(ui::Point(0, -1));
return; return;
case KEY_DOWN: case SDLK_DOWN:
c->TranslateSave(ui::Point(0, 1)); c->TranslateSave(ui::Point(0, 1));
return; return;
case 'r': case 'r':
@ -1403,16 +1404,16 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
} }
switch(key) switch(key)
{ {
case KEY_LALT: case SDLK_LALT:
case KEY_RALT: case SDLK_RALT:
enableAltBehaviour(); enableAltBehaviour();
break; break;
case KEY_LCTRL: case SDLK_LCTRL:
case KEY_RCTRL: case SDLK_RCTRL:
enableCtrlBehaviour(); enableCtrlBehaviour();
break; break;
case KEY_LSHIFT: case SDLK_LSHIFT:
case KEY_RSHIFT: case SDLK_RSHIFT:
enableShiftBehaviour(); enableShiftBehaviour();
break; break;
case ' ': //Space case ' ': //Space
@ -1432,20 +1433,20 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
c->SetZoomEnabled(true); c->SetZoomEnabled(true);
} }
break; break;
case KEY_TAB: //Tab case SDLK_TAB: //Tab
c->ChangeBrush(); c->ChangeBrush();
break; break;
case '`': case '`':
c->ShowConsole(); c->ShowConsole();
break; break;
case 'p': case 'p':
case KEY_F2: case SDLK_F2:
screenshot(); screenshot();
break; break;
case KEY_F3: case SDLK_F3:
SetDebugHUD(!GetDebugHUD()); SetDebugHUD(!GetDebugHUD());
break; break;
case KEY_F5: case SDLK_F5:
c->ReloadSim(); c->ReloadSim();
break; break;
case 'r': case 'r':
@ -1477,7 +1478,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
else else
c->AdjustGridSize(1); c->AdjustGridSize(1);
break; break;
case KEY_F1: case SDLK_F1:
if(!introText) if(!introText)
introText = 8047; introText = 8047;
else else
@ -1510,7 +1511,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
case 'y': case 'y':
c->SwitchAir(); c->SwitchAir();
break; break;
case KEY_ESCAPE: case SDLK_ESCAPE:
case 'q': case 'q':
ExitPrompt(); ExitPrompt();
break; break;
@ -1597,10 +1598,10 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
break; break;
} }
//fancy case switch without break //fancy case switch without break
case KEY_INSERT: case SDLK_INSERT:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE); c->SetReplaceModeFlags(c->GetReplaceModeFlags()^REPLACE_MODE);
break; break;
case KEY_DELETE: case SDLK_DELETE:
c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE); c->SetReplaceModeFlags(c->GetReplaceModeFlags()^SPECIFIC_DELETE);
break; break;
} }
@ -1617,16 +1618,16 @@ void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bo
{ {
switch(key) switch(key)
{ {
case KEY_LALT: case SDLK_LALT:
case KEY_RALT: case SDLK_RALT:
disableAltBehaviour(); disableAltBehaviour();
break; break;
case KEY_LCTRL: case SDLK_LCTRL:
case KEY_RCTRL: case SDLK_RCTRL:
disableCtrlBehaviour(); disableCtrlBehaviour();
break; break;
case KEY_LSHIFT: case SDLK_LSHIFT:
case KEY_RSHIFT: case SDLK_RSHIFT:
disableShiftBehaviour(); disableShiftBehaviour();
break; break;
case 'z': case 'z':

24
src/gui/interface/Mouse.h Normal file
View File

@ -0,0 +1,24 @@
#ifdef USE_SDL
#ifdef SDL_INC
#include "SDL/SDL_mouse.h"
#else
#include "SDL_mouse.h"
#endif
#else // USE_SDL
/* These are used for the renderer, which doesn't include the rest of SDL and only this file
* It still needs fake SDL_BUTTON_* constants to compile
*/
#define SDL_BUTTON(X) (1 << ((X)-1))
#define SDL_BUTTON_LEFT 1
#define SDL_BUTTON_MIDDLE 2
#define SDL_BUTTON_RIGHT 3
#define SDL_BUTTON_WHEELUP 4
#define SDL_BUTTON_WHEELDOWN 5
#endif // USE_SDL

View File

@ -457,7 +457,7 @@ int luacon_keyevent(int key, Uint16 character, int modifier, int event)
for (int i = 1; i <= len && kycontinue; i++) for (int i = 1; i <= len && kycontinue; i++)
{ {
lua_rawgeti(l, -1, i); lua_rawgeti(l, -1, i);
if ((modifier & KEY_MOD_CONTROL) && (character < ' ' || character > '~') && key < 256) if ((modifier & KMOD_CTRL) && (character < ' ' || character > '~') && key < 256)
lua_pushlstring(l, (const char*)&key, 1); lua_pushlstring(l, (const char*)&key, 1);
else else
lua_pushlstring(l, (const char*)&character, 1); lua_pushlstring(l, (const char*)&character, 1);