1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

fix keyboard state access

* is somewhat playable already!
This commit is contained in:
AlexVinS 2014-05-21 23:14:05 +04:00 committed by AlexVinS
parent cd81e85a61
commit 6890c2650b
3 changed files with 34 additions and 9 deletions

View File

@ -732,9 +732,8 @@ void CAdvMapInt::show(SDL_Surface * to)
if((animValHitCount % (4/scrollSpeed)) == 0
&& (
(GH.topInt() == this)
|| SDL_GetKeyState(nullptr)[SDLK_LCTRL]
|| SDL_GetKeyState(nullptr)[SDLK_RCTRL]
)
|| isCtrlKeyDown()
)
)
{
if( (scrollingDir & LEFT) && (position.x>-CGI->mh->frameW) )
@ -1054,7 +1053,7 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/)
void CAdvMapInt::mouseMoved( const SDL_MouseMotionEvent & sEvent )
{
//adventure map scrolling with mouse
if(!SDL_GetKeyState(nullptr)[SDLK_LCTRL] && isActive())
if(!isCtrlKeyDown() && isActive())
{
if(sEvent.x<15)
{

View File

@ -1378,12 +1378,12 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
bool CPlayerInterface::shiftPressed() const
{
return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT];
return isShiftKeyDown();
}
bool CPlayerInterface::altPressed() const
{
return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT];
return isAltKeyDown();
}
void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID)
@ -1595,7 +1595,7 @@ void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
bool CPlayerInterface::ctrlPressed() const
{
return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL];
return isCtrlKeyDown();
}
void CPlayerInterface::update()

View File

@ -73,10 +73,36 @@ inline void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h)
SDL_RenderPresent(mainRenderer);
}
#endif // 0
inline bool isCtrlKeyDown()
{
#if 0
return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL];
#else
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
#endif // 0
}
inline bool isAltKeyDown()
{
#if 0
return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT];
#else
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
#endif // 0
}
inline bool isShiftKeyDown()
{
#if 0
return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT];
#else
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT];
#endif // 0
}
struct Rect;
extern SDL_Surface * screen, *screen2, *screenBuf;