mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Merge pull request #60 from WaywardHeart/autohide-cursor
Autohide mouse cursor after half a second
This commit is contained in:
commit
0f67af1712
3 changed files with 19 additions and 3 deletions
|
@ -125,7 +125,7 @@ bool EventThread::allocUserEvents()
|
|||
EventThread::EventThread()
|
||||
: ctrl(0),
|
||||
fullscreen(false),
|
||||
showCursor(true)
|
||||
showCursor(false)
|
||||
{
|
||||
textInputLock = SDL_CreateMutex();
|
||||
}
|
||||
|
@ -135,6 +135,20 @@ EventThread::~EventThread()
|
|||
SDL_DestroyMutex(textInputLock);
|
||||
}
|
||||
|
||||
SDL_TimerID hideCursorTimerID = 0;
|
||||
Uint32 cursorTimerCallback(Uint32 interval, void* param)
|
||||
{
|
||||
EventThread *ethread = static_cast<EventThread*>(param);
|
||||
hideCursorTimerID = 0;
|
||||
ethread->requestShowCursor(ethread->getShowCursor());
|
||||
return 0;
|
||||
}
|
||||
void EventThread::cursorTimer()
|
||||
{
|
||||
SDL_RemoveTimer(hideCursorTimerID);
|
||||
hideCursorTimerID = SDL_AddTimer(500, cursorTimerCallback, this);
|
||||
}
|
||||
|
||||
void EventThread::process(RGSSThreadData &rtData)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
@ -445,6 +459,7 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
case SDL_MOUSEMOTION :
|
||||
mouseState.x = event.motion.x;
|
||||
mouseState.y = event.motion.y;
|
||||
cursorTimer();
|
||||
updateCursorState(cursorInWindow, gameScreen);
|
||||
break;
|
||||
|
||||
|
@ -687,7 +702,7 @@ void EventThread::updateCursorState(bool inWindow,
|
|||
bool inScreen = inWindow && SDL_PointInRect(&pos, &screen);
|
||||
|
||||
if (inScreen)
|
||||
SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE);
|
||||
SDL_ShowCursor(showCursor || hideCursorTimerID ? SDL_TRUE : SDL_FALSE);
|
||||
else
|
||||
SDL_ShowCursor(SDL_TRUE);
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ private:
|
|||
void setFullscreen(SDL_Window *, bool mode);
|
||||
void updateCursorState(bool inWindow,
|
||||
const SDL_Rect &screen);
|
||||
void cursorTimer();
|
||||
|
||||
bool fullscreen;
|
||||
bool showCursor;
|
||||
|
|
|
@ -210,7 +210,7 @@ int main(int argc, char *argv[]) {
|
|||
#endif
|
||||
|
||||
/* initialize SDL first */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER) < 0) {
|
||||
showInitError(std::string("Error initializing SDL: ") + SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue