فهرست منبع

Removed usage of SDL_KeyboardEvent from UI code

Ivan Savenko 2 سال پیش
والد
کامیت
d4fba3787c

+ 1 - 1
client/CPlayerInterface.cpp

@@ -1589,7 +1589,7 @@ void CPlayerInterface::update()
 
 	if (!adventureInt || adventureInt->isActive())
 		GH.simpleRedraw();
-	else if((adventureInt->swipeEnabled && adventureInt->swipeMovementRequested) || adventureInt->scrollingDir)
+	else if((adventureInt->swipeEnabled && adventureInt->swipeMovementRequested) || (adventureInt->scrollingDir && GH.isKeyboardCtrlDown()))
 		GH.totalRedraw(); //player forces map scrolling though interface is disabled
 	else
 		GH.simpleRedraw();

+ 74 - 46
client/adventureMap/CAdvMapInt.cpp

@@ -43,7 +43,6 @@
 #include "../../lib/TerrainHandler.h"
 
 #include <SDL_surface.h>
-#include <SDL_events.h>
 
 #define ADVOPT (conf.go()->ac)
 
@@ -616,7 +615,7 @@ void CAdvMapInt::handleMapScrollingUpdate()
 	int scrollSpeed = static_cast<int>(settings["adventure"]["scrollSpeed"].Float());
 	//if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
 	if((animValHitCount % (4 / scrollSpeed)) == 0
-	   && ((GH.topInt().get() == this) || GH.isKeyboardCtrlDown()))
+	   && GH.isKeyboardCtrlDown())
 	{
 		if((scrollingDir & LEFT) && (position.x > -CGI->mh->frameW))
 			position.x--;
@@ -712,21 +711,46 @@ void CAdvMapInt::centerOn(const CGObjectInstance * obj, bool fade)
 	centerOn(obj->getSightCenter(), fade);
 }
 
-void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
+void CAdvMapInt::keyReleased(const SDL_Keycode &key)
 {
+	if (mode == EAdvMapMode::WORLD_VIEW)
+		return;
+
+	switch (key)
+	{
+		case SDLK_s:
+			if(isActive())
+				GH.pushIntT<CSavingScreen>();
+			return;
+		default:
+		{
+			auto direction = keyToMoveDirection(key);
+
+			if (!direction)
+				return;
+
+			ui8 Dir = (direction->x<0 ? LEFT  : 0) |
+				  (direction->x>0 ? RIGHT : 0) |
+				  (direction->y<0 ? UP    : 0) |
+				  (direction->y>0 ? DOWN  : 0) ;
+
+			scrollingDir &= ~Dir;
+		}
+	}
+}
 
+void CAdvMapInt::keyDown(const SDL_Keycode & key)
+{
 	if (mode == EAdvMapMode::WORLD_VIEW)
 		return;
 
-	ui8 Dir = 0;
-	SDL_Keycode k = key.keysym.sym;
 	const CGHeroInstance *h = curHero(); //selected hero
 	const CGTownInstance *t = curTown(); //selected town
 
-	switch(k)
+	switch(key)
 	{
 	case SDLK_g:
-		if(key.state != SDL_PRESSED || GH.topInt()->type & BLOCK_ADV_HOTKEYS)
+		if(GH.topInt()->type & BLOCK_ADV_HOTKEYS)
 			return;
 
 		{
@@ -750,13 +774,9 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		if(isActive())
 			LOCPLINT->proposeLoadingGame();
 		return;
-	case SDLK_s:
-		if(isActive() && key.type == SDL_KEYUP)
-			GH.pushIntT<CSavingScreen>();
-		return;
 	case SDLK_d:
 		{
-			if(h && isActive() && LOCPLINT->makingTurn && key.state == SDL_PRESSED)
+			if(h && isActive() && LOCPLINT->makingTurn)
 				LOCPLINT->tryDiggging(h);
 			return;
 		}
@@ -779,7 +799,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		{
 			if(!isActive())
 				return;
-			if(h && key.state == SDL_PRESSED)
+			if(h)
 			{
 				auto unlockPim = vstd::makeUnlockGuard(*CPlayerInterface::pim);
 				//TODO!!!!!!! possible freeze, when GS mutex is locked and network thread can't apply package
@@ -792,7 +812,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		return;
 	case SDLK_RETURN:
 		{
-			if(!isActive() || !selection || key.state != SDL_PRESSED)
+			if(!isActive() || !selection)
 				return;
 			if(h)
 				LOCPLINT->openHeroWindow(h);
@@ -802,7 +822,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		}
 	case SDLK_ESCAPE:
 		{
-			if(isActive() || GH.topInt().get() != this || !spellBeingCasted || key.state != SDL_PRESSED)
+			if(isActive() || GH.topInt().get() != this || !spellBeingCasted)
 				return;
 
 			leaveCastingMode();
@@ -811,7 +831,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 	case SDLK_t:
 		{
 			//act on key down if marketplace windows is not already opened
-			if(key.state != SDL_PRESSED || GH.topInt()->type & BLOCK_ADV_HOTKEYS)
+			if(GH.topInt()->type & BLOCK_ADV_HOTKEYS)
 				return;
 
 			if(GH.isKeyboardCtrlDown()) //CTRL + T => open marketplace
@@ -840,37 +860,29 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		}
 	default:
 		{
-			static const int3 directions[] = {  int3(-1, +1, 0), int3(0, +1, 0), int3(+1, +1, 0),
-												int3(-1, 0, 0),  int3(0, 0, 0),  int3(+1, 0, 0),
-												int3(-1, -1, 0), int3(0, -1, 0), int3(+1, -1, 0) };
+			auto direction = keyToMoveDirection(key);
 
-			//numpad arrow
-			if(CGuiHandler::isArrowKey(k))
-				k = CGuiHandler::arrowToNum(k);
+			if (!direction)
+				return;
 
-			k -= SDLK_KP_1;
+			ui8 Dir = (direction->x<0 ? LEFT  : 0) |
+				  (direction->x>0 ? RIGHT : 0) |
+				  (direction->y<0 ? UP    : 0) |
+				  (direction->y>0 ? DOWN  : 0) ;
 
-			if(k < 0 || k > 8)
-				return;
+			scrollingDir |= Dir;
 
-			if (!CGI->mh->canStartHeroMovement())
+			//ctrl makes arrow move screen, not hero
+			if(GH.isKeyboardCtrlDown())
 				return;
 
-			int3 dir = directions[k];
-
-			if(!isActive() || GH.isKeyboardCtrlDown())//ctrl makes arrow move screen, not hero
-			{
-				Dir = (dir.x<0 ? LEFT  : 0) |
-					  (dir.x>0 ? RIGHT : 0) |
-					  (dir.y<0 ? UP    : 0) |
-					  (dir.y>0 ? DOWN  : 0) ;
-				break;
-			}
+			if(!h || !isActive())
+				return;
 
-			if(!h || key.state != SDL_PRESSED)
-				break;
+			if (!CGI->mh->canStartHeroMovement())
+				return;
 
-			if(k == 4)
+			if(*direction == Point(0,0))
 			{
 				centerOn(h);
 				return;
@@ -878,7 +890,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 
 			CGPath &path = LOCPLINT->paths[h];
 			terrain.currentPath = &path;
-			int3 dst = h->visitablePos() + dir;
+			int3 dst = h->visitablePos() + int3(direction->x, direction->y, 0);
 			if(dst != verifyPos(dst) || !LOCPLINT->cb->getPathsInfo(h)->getPath(path, dst))
 			{
 				terrain.currentPath = nullptr;
@@ -894,13 +906,29 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 
 		return;
 	}
-	if(Dir && key.state == SDL_PRESSED //arrow is pressed
-		&& GH.isKeyboardCtrlDown()
-	)
-		scrollingDir |= Dir;
-	else
-		scrollingDir &= ~Dir;
 }
+
+boost::optional<Point> CAdvMapInt::keyToMoveDirection(const SDL_Keycode & key)
+{
+	switch (key) {
+		case SDLK_DOWN:  return Point( 0, +1);
+		case SDLK_LEFT:  return Point(-1,  0);
+		case SDLK_RIGHT: return Point(+1,  0);
+		case SDLK_UP:    return Point( 0, -1);
+
+		case SDLK_KP_1: return Point(-1, +1);
+		case SDLK_KP_2: return Point( 0, +1);
+		case SDLK_KP_3: return Point(+1, +1);
+		case SDLK_KP_4: return Point(-1,  0);
+		case SDLK_KP_5: return Point( 0,  0);
+		case SDLK_KP_6: return Point(+1,  0);
+		case SDLK_KP_7: return Point(-1, -1);
+		case SDLK_KP_8: return Point( 0, -1);
+		case SDLK_KP_9: return Point(+1, -1);
+	}
+	return boost::none;
+}
+
 void CAdvMapInt::handleRightClick(std::string text, tribool down)
 {
 	if(down)

+ 4 - 1
client/adventureMap/CAdvMapInt.h

@@ -56,6 +56,8 @@ class CAdvMapInt : public CIntObject
 	//Return object that must be active at this tile (=clickable)
 	const CGObjectInstance *getActiveObject(const int3 &tile);
 
+	boost::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
+
 public:
 	CAdvMapInt();
 
@@ -158,7 +160,8 @@ public:
 	void centerOn(const CGObjectInstance *obj, bool fade = false);
 	int3 verifyPos(int3 ver);
 	void handleRightClick(std::string text, tribool down);
-	void keyPressed(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
+	void keyReleased(const SDL_Keycode & key) override;
 	void mouseMoved (const Point & cursorPosition) override;
 	bool isActive();
 

+ 4 - 6
client/adventureMap/CInGameConsole.cpp

@@ -91,13 +91,11 @@ void CInGameConsole::print(const std::string &txt)
 	}
 }
 
-void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
+void CInGameConsole::keyDown (const SDL_Keycode & key)
 {
-	if(key.type != SDL_KEYDOWN) return;
+	if(!captureAllKeys && key != SDLK_TAB) return; //because user is not entering any text
 
-	if(!captureAllKeys && key.keysym.sym != SDLK_TAB) return; //because user is not entering any text
-
-	switch(key.keysym.sym)
+	switch(key)
 	{
 	case SDLK_TAB:
 	case SDLK_ESCAPE:
@@ -106,7 +104,7 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
 			{
 				endEnteringText(false);
 			}
-			else if(SDLK_TAB == key.keysym.sym)
+			else if(SDLK_TAB == key)
 			{
 				startEnteringText();
 			}

+ 1 - 1
client/adventureMap/CInGameConsole.h

@@ -26,7 +26,7 @@ public:
 	std::string enteredText;
 	void show(SDL_Surface * to) override;
 	void print(const std::string &txt);
-	void keyPressed (const SDL_KeyboardEvent & key) override; //call-in
+	void keyDown(const SDL_Keycode & key) override;
 
 	void textInputed(const SDL_TextInputEvent & event) override;
 	void textEdited(const SDL_TextEditingEvent & event) override;

+ 1 - 1
client/adventureMap/CTerrainRect.cpp

@@ -28,7 +28,7 @@
 #include "../../lib/mapping/CMap.h"
 #include "../../lib/CPathfinder.h"
 
-#include <SDL_events.h>
+#include <SDL_surface.h>
 
 #define ADVOPT (conf.go()->ac)
 

+ 0 - 1
client/battle/BattleInterfaceClasses.cpp

@@ -48,7 +48,6 @@
 #include "../../lib/mapObjects/CGTownInstance.h"
 
 #include <SDL_surface.h>
-#include <SDL_events.h>
 
 void BattleConsole::showAll(SDL_Surface * to)
 {

+ 4 - 5
client/battle/BattleWindow.cpp

@@ -37,7 +37,6 @@
 #include "../../lib/filesystem/ResourceID.h"
 
 #include <SDL_surface.h>
-#include <SDL_events.h>
 
 BattleWindow::BattleWindow(BattleInterface & owner):
 	owner(owner)
@@ -165,9 +164,9 @@ void BattleWindow::deactivate()
 	LOCPLINT->cingconsole->deactivate();
 }
 
-void BattleWindow::keyPressed(const SDL_KeyboardEvent & key)
+void BattleWindow::keyDown(const SDL_Keycode & key)
 {
-	if(key.keysym.sym == SDLK_q && key.state == SDL_PRESSED)
+	if(key == SDLK_q)
 	{
 		if(settings["battle"]["showQueue"].Bool()) //hide queue
 			hideQueue();
@@ -175,11 +174,11 @@ void BattleWindow::keyPressed(const SDL_KeyboardEvent & key)
 			showQueue();
 
 	}
-	else if(key.keysym.sym == SDLK_f && key.state == SDL_PRESSED)
+	else if(key == SDLK_f)
 	{
 		owner.actionsController->enterCreatureCastingMode();
 	}
-	else if(key.keysym.sym == SDLK_ESCAPE)
+	else if(key == SDLK_ESCAPE)
 	{
 		if(owner.getAnimationCondition(EAnimationEvents::OPENING) == true)
 			CCS->soundh->stopSound(owner.battleIntroSoundChannel);

+ 1 - 1
client/battle/BattleWindow.h

@@ -79,7 +79,7 @@ public:
 
 	void activate() override;
 	void deactivate() override;
-	void keyPressed(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
 	void clickRight(tribool down, bool previousState) override;
 	void show(SDL_Surface *to) override;
 	void showAll(SDL_Surface *to) override;

+ 8 - 3
client/gui/CGuiHandler.cpp

@@ -403,7 +403,7 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
 		bool keysCaptured = false;
 		for(auto i = keyinterested.begin(); i != keyinterested.end() && continueEventHandling; i++)
 		{
-			if((*i)->captureThisEvent(key))
+			if((*i)->captureThisKey(key.keysym.sym))
 			{
 				keysCaptured = true;
 				break;
@@ -412,8 +412,13 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
 
 		std::list<CIntObject*> miCopy = keyinterested;
 		for(auto i = miCopy.begin(); i != miCopy.end() && continueEventHandling; i++)
-			if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureThisEvent(key)))
-				(**i).keyPressed(key);
+			if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureThisKey(key.keysym.sym)))
+			{
+				if (key.state == SDL_PRESSED)
+					(**i).keyDown(key.keysym.sym);
+				if (key.state == SDL_RELEASED)
+					(**i).keyReleased(key.keysym.sym);
+			}
 	}
 	else if(current.type == SDL_MOUSEMOTION)
 	{

+ 18 - 7
client/gui/CIntObject.cpp

@@ -16,7 +16,6 @@
 
 #include <SDL_pixels.h>
 #include <SDL_surface.h>
-#include <SDL_events.h>
 
 IShowActivatable::IShowActivatable()
 {
@@ -325,7 +324,7 @@ const Rect & CIntObject::center(const Point & p, bool propagate)
 	return pos;
 }
 
-bool CIntObject::captureThisEvent(const SDL_KeyboardEvent & key)
+bool CIntObject::captureThisKey(const SDL_Keycode & key)
 {
 	return captureAllKeys;
 }
@@ -343,14 +342,26 @@ CKeyShortcut::CKeyShortcut(std::set<int> Keys)
 	:assignedKeys(Keys)
 {}
 
-void CKeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
+void CKeyShortcut::keyDown(const SDL_Keycode & key)
 {
-	if(vstd::contains(assignedKeys,key.keysym.sym)
-	 || vstd::contains(assignedKeys, CGuiHandler::numToDigit(key.keysym.sym)))
+	if(vstd::contains(assignedKeys,key)
+	 || vstd::contains(assignedKeys, CGuiHandler::numToDigit(key)))
 	{
 		bool prev = mouseState(MouseButton::LEFT);
-		updateMouseState(MouseButton::LEFT, key.state == SDL_PRESSED);
-		clickLeft(key.state == SDL_PRESSED, prev);
+		updateMouseState(MouseButton::LEFT, true);
+		clickLeft(true, prev);
+
+	}
+}
+
+void CKeyShortcut::keyReleased(const SDL_Keycode & key)
+{
+	if(vstd::contains(assignedKeys,key)
+	 || vstd::contains(assignedKeys, CGuiHandler::numToDigit(key)))
+	{
+		bool prev = mouseState(MouseButton::LEFT);
+		updateMouseState(MouseButton::LEFT, false);
+		clickLeft(false, prev);
 
 	}
 }

+ 7 - 4
client/gui/CIntObject.h

@@ -17,7 +17,7 @@ struct SDL_Surface;
 class CGuiHandler;
 class CPicture;
 
-struct SDL_KeyboardEvent;
+typedef int32_t SDL_Keycode;
 struct SDL_TextInputEvent;
 struct SDL_TextEditingEvent;
 
@@ -119,8 +119,9 @@ public:
 
 	//keyboard handling
 	bool captureAllKeys; //if true, only this object should get info about pressed keys
-	virtual void keyPressed(const SDL_KeyboardEvent & key){}
-	virtual bool captureThisEvent(const SDL_KeyboardEvent & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER)
+	virtual void keyDown(const SDL_Keycode & key){}
+	virtual void keyReleased(const SDL_Keycode & key){}
+	virtual bool captureThisKey(const SDL_Keycode & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER)
 
 	virtual void textInputed(const SDL_TextInputEvent & event){};
 	virtual void textEdited(const SDL_TextEditingEvent & event){};
@@ -202,7 +203,9 @@ public:
 	CKeyShortcut();
 	CKeyShortcut(int key);
 	CKeyShortcut(std::set<int> Keys);
-	virtual void keyPressed(const SDL_KeyboardEvent & key) override; //call-in
+	void keyDown(const SDL_Keycode & key) override;
+	void keyReleased(const SDL_Keycode & key) override;
+
 };
 
 class WindowBase : public CIntObject

+ 3 - 5
client/lobby/CSelectionBase.cpp

@@ -43,8 +43,6 @@
 #include "../../lib/mapping/CMapInfo.h"
 #include "../../lib/serializer/Connection.h"
 
-#include <SDL_events.h>
-
 ISelectionScreenInfo::ISelectionScreenInfo(ESelectionScreen ScreenType)
 	: screenType(ScreenType)
 {
@@ -320,15 +318,15 @@ CChatBox::CChatBox(const Rect & rect)
 	chatHistory->label->color = Colors::GREEN;
 }
 
-void CChatBox::keyPressed(const SDL_KeyboardEvent & key)
+void CChatBox::keyDown(const SDL_Keycode & key)
 {
-	if(key.keysym.sym == SDLK_RETURN && key.state == SDL_PRESSED && inputBox->getText().size())
+	if(key == SDLK_RETURN && inputBox->getText().size())
 	{
 		CSH->sendMessage(inputBox->getText());
 		inputBox->setText("");
 	}
 	else
-		inputBox->keyPressed(key);
+		inputBox->keyDown(key);
 }
 
 void CChatBox::addNewMessage(const std::string & text)

+ 1 - 2
client/lobby/CSelectionBase.h

@@ -120,8 +120,7 @@ public:
 
 	CChatBox(const Rect & rect);
 
-	void keyPressed(const SDL_KeyboardEvent & key) override;
-
+	void keyDown(const SDL_Keycode & key) override;
 	void addNewMessage(const std::string & text);
 };
 

+ 2 - 7
client/lobby/SelectionTab.cpp

@@ -35,8 +35,6 @@
 #include "../../lib/mapping/CMapInfo.h"
 #include "../../lib/serializer/Connection.h"
 
-#include <SDL_events.h>
-
 bool mapSorter::operator()(const std::shared_ptr<CMapInfo> aaa, const std::shared_ptr<CMapInfo> bbb)
 {
 	auto a = aaa->mapHeader.get();
@@ -280,13 +278,10 @@ void SelectionTab::clickLeft(tribool down, bool previousState)
 	}
 }
 
-void SelectionTab::keyPressed(const SDL_KeyboardEvent & key)
+void SelectionTab::keyDown(const SDL_Keycode & key)
 {
-	if(key.state != SDL_PRESSED)
-		return;
-
 	int moveBy = 0;
-	switch(key.keysym.sym)
+	switch(key)
 	{
 	case SDLK_UP:
 		moveBy = -1;

+ 2 - 1
client/lobby/SelectionTab.h

@@ -66,7 +66,8 @@ public:
 	void toggleMode();
 
 	void clickLeft(tribool down, bool previousState) override;
-	void keyPressed(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
+
 	void onDoubleClick() override;
 
 	void filter(int size, bool selectFirst = false); //0 - all

+ 2 - 6
client/widgets/Buttons.cpp

@@ -25,8 +25,6 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
 
-#include <SDL_events.h>
-
 void CButton::update()
 {
 	if (overlay)
@@ -780,12 +778,10 @@ void CSlider::wheelScrolled(bool down, bool in)
 	moveTo(value + 3 * (down ? +scrollStep : -scrollStep));
 }
 
-void CSlider::keyPressed(const SDL_KeyboardEvent & key)
+void CSlider::keyDown(const SDL_Keycode & key)
 {
-	if(key.state != SDL_PRESSED) return;
-
 	int moveDest = value;
-	switch(key.keysym.sym)
+	switch(key)
 	{
 	case SDLK_UP:
 		if (!horizontal)

+ 1 - 1
client/widgets/Buttons.h

@@ -270,7 +270,7 @@ public:
 
 	void addCallback(std::function<void(int)> callback);
 
-	void keyPressed(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
 	void wheelScrolled(bool down, bool in) override;
 	void clickLeft(tribool down, bool previousState) override;
 	void mouseMoved (const Point & cursorPosition) override;

+ 6 - 7
client/widgets/TextControls.cpp

@@ -549,13 +549,12 @@ void CTextInput::clickLeft(tribool down, bool previousState)
 		giveFocus();
 }
 
-void CTextInput::keyPressed(const SDL_KeyboardEvent & key)
+void CTextInput::keyDown(const SDL_Keycode & key)
 {
-
-	if(!focus || key.state != SDL_PRESSED)
+	if(!focus)
 		return;
 
-	if(key.keysym.sym == SDLK_TAB)
+	if(key == SDLK_TAB)
 	{
 		moveFocus();
 		GH.breakEventHandling();
@@ -564,7 +563,7 @@ void CTextInput::keyPressed(const SDL_KeyboardEvent & key)
 
 	bool redrawNeeded = false;
 
-	switch(key.keysym.sym)
+	switch(key)
 	{
 	case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section
 		return;
@@ -603,9 +602,9 @@ void CTextInput::setText(const std::string & nText, bool callCb)
 		cb(text);
 }
 
-bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
+bool CTextInput::captureThisKey(const SDL_Keycode & key)
 {
-	if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER || key.keysym.sym == SDLK_ESCAPE)
+	if(key == SDLK_RETURN || key == SDLK_KP_ENTER || key == SDLK_ESCAPE)
 		return false;
 
 	return true;

+ 3 - 2
client/widgets/TextControls.h

@@ -225,8 +225,9 @@ public:
 	CTextInput(const Rect & Pos, std::shared_ptr<IImage> srf);
 
 	void clickLeft(tribool down, bool previousState) override;
-	void keyPressed(const SDL_KeyboardEvent & key) override;
-	bool captureThisEvent(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
+
+	bool captureThisKey(const SDL_Keycode & key) override;
 
 	void textInputed(const SDL_TextInputEvent & event) override;
 	void textEdited(const SDL_TextEditingEvent & event) override;

+ 3 - 5
client/windows/CCastleInterface.cpp

@@ -43,7 +43,7 @@
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 
-#include <SDL_events.h>
+#include <SDL_surface.h>
 
 CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str)
 	: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME),
@@ -1255,11 +1255,9 @@ void CCastleInterface::recreateIcons()
 		creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 507), town, (int)i+4));
 }
 
-void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key)
+void CCastleInterface::keyDown(const SDL_Keycode & key)
 {
-	if(key.state != SDL_PRESSED) return;
-
-	switch(key.keysym.sym)
+	switch(key)
 	{
 	case SDLK_UP:
 		townlist->selectPrev();

+ 2 - 1
client/windows/CCastleInterface.h

@@ -245,7 +245,8 @@ public:
 
 	void castleTeleport(int where);
 	void townChange();
-	void keyPressed(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
+
 	void close();
 	void addBuilding(BuildingID bid);
 	void removeBuilding(BuildingID bid);

+ 6 - 9
client/windows/CSpellWindow.cpp

@@ -39,8 +39,6 @@
 
 #include "../../lib/mapObjects/CGHeroInstance.h"
 
-#include <SDL_events.h>
-
 CSpellWindow::InteractiveArea::InteractiveArea(const Rect & myRect, std::function<void()> funcL, int helpTextId, CSpellWindow * _owner)
 {
 	addUsedEvents(LCLICK | RCLICK | HOVER);
@@ -422,17 +420,16 @@ void CSpellWindow::turnPageRight()
 		CCS->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15);
 }
 
-void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
+void CSpellWindow::keyDown(const SDL_Keycode & key)
 {
-	if(key.keysym.sym == SDLK_ESCAPE ||  key.keysym.sym == SDLK_RETURN)
+	if(key == SDLK_ESCAPE ||  key == SDLK_RETURN)
 	{
 		fexitb();
 		return;
 	}
-
-	if(key.state == SDL_PRESSED)
+	else
 	{
-		switch(key.keysym.sym)
+		switch(key)
 		{
 		case SDLK_LEFT:
 			fLcornerb();
@@ -443,7 +440,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
 		case SDLK_UP:
 		case SDLK_DOWN:
 		{
-			bool down = key.keysym.sym == SDLK_DOWN;
+			bool down = key == SDLK_DOWN;
 			static const int schoolsOrder[] = { 0, 3, 1, 2, 4 };
 			int index = -1;
 			while(schoolsOrder[++index] != selectedTab);
@@ -466,7 +463,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
 		//alt + 1234567890-= casts spell from 1 - 12 slot
 		if(GH.isKeyboardAltDown())
 		{
-			SDL_Keycode hlpKey = key.keysym.sym;
+			SDL_Keycode hlpKey = key;
 			if(CGuiHandler::isNumKey(hlpKey, false))
 			{
 				if(hlpKey == SDLK_KP_PLUS)

+ 2 - 1
client/windows/CSpellWindow.h

@@ -112,6 +112,7 @@ public:
 	void selectSchool(int school); //schools: 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
 	int pagesWithinCurrentTab();
 
-	void keyPressed(const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
+
 	void show(SDL_Surface * to) override;
 };

+ 2 - 5
client/windows/GUIClasses.cpp

@@ -2170,14 +2170,11 @@ void CObjectListWindow::changeSelection(size_t which)
 	selected = which;
 }
 
-void CObjectListWindow::keyPressed (const SDL_KeyboardEvent & key)
+void CObjectListWindow::keyDown (const SDL_Keycode & key)
 {
-	if(key.state != SDL_PRESSED)
-		return;
-
 	int sel = static_cast<int>(selected);
 
-	switch(key.keysym.sym)
+	switch(key)
 	{
 	break; case SDLK_UP:
 		sel -=1;

+ 1 - 1
client/windows/GUIClasses.h

@@ -193,7 +193,7 @@ public:
 	std::shared_ptr<CIntObject> genItem(size_t index);
 	void elementSelected();//call callback and close this window
 	void changeSelection(size_t which);
-	void keyPressed (const SDL_KeyboardEvent & key) override;
+	void keyDown(const SDL_Keycode & key) override;
 };
 
 class CSystemOptionsWindow : public CWindowObject