Implement "show_cursor" attribute in Graphics module

If false (the default), the system cursor is hidden
inside the game window.
This commit is contained in:
Jonas Kulla 2013-09-24 22:52:42 +02:00
parent a9454fdf9c
commit fe557bca1d
7 changed files with 105 additions and 41 deletions

View file

@ -53,11 +53,13 @@ enum
REQUEST_TERMINATION,
REQUEST_SETFULLSCREEN,
REQUEST_WINRESIZE,
REQUEST_MESSAGEBOX
REQUEST_MESSAGEBOX,
REQUEST_SETCURSORVISIBLE
};
EventThread::EventThread()
: fullscreen(false)
: fullscreen(false),
showCursor(false)
{}
void EventThread::process(RGSSThreadData &rtData)
@ -68,6 +70,8 @@ void EventThread::process(RGSSThreadData &rtData)
fullscreen = rtData.config.fullscreen;
bool cursorInWindow = false;
bool terminate = false;
SDL_Joystick *js = 0;
@ -92,11 +96,28 @@ void EventThread::process(RGSSThreadData &rtData)
event.window.data2);
break;
case SDL_WINDOWEVENT_ENTER :
cursorInWindow = true;
updateCursorState(cursorInWindow);
break;
case SDL_WINDOWEVENT_LEAVE :
cursorInWindow = false;
updateCursorState(cursorInWindow);
break;
case SDL_WINDOWEVENT_CLOSE :
terminate = true;
break;
case SDL_WINDOWEVENT_FOCUS_GAINED :
cursorInWindow = true;
updateCursorState(cursorInWindow);
break;
case SDL_WINDOWEVENT_FOCUS_LOST :
cursorInWindow = false;
updateCursorState(cursorInWindow);
resetInputStates();
break;
}
@ -135,6 +156,11 @@ void EventThread::process(RGSSThreadData &rtData)
msgBoxDone = true;
break;
case REQUEST_SETCURSORVISIBLE :
showCursor = event.user.code;
updateCursorState(cursorInWindow);
break;
case SDL_KEYUP :
keyStates[event.key.keysym.scancode] = false;
break;
@ -214,6 +240,14 @@ void EventThread::setFullscreen(SDL_Window *win, bool mode)
fullscreen = mode;
}
void EventThread::updateCursorState(bool inWindow)
{
if (inWindow)
SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE);
else
SDL_ShowCursor(SDL_TRUE);
}
void EventThread::requestTerminate()
{
SDL_Event event;
@ -241,6 +275,14 @@ void EventThread::requestWindowResize(int width, int height)
SDL_PushEvent(&event);
}
void EventThread::requestShowCursor(bool mode)
{
SDL_Event event;
event.type = REQUEST_SETCURSORVISIBLE;
event.user.code = mode;
SDL_PushEvent(&event);
}
void EventThread::showMessageBox(const char *body, int flags)
{
msgBoxDone = false;
@ -257,7 +299,12 @@ void EventThread::showMessageBox(const char *body, int flags)
resetInputStates();
}
bool EventThread::getFullscreen()
bool EventThread::getFullscreen() const
{
return fullscreen;
}
bool EventThread::getShowCursor() const
{
return showCursor;
}

View file

@ -69,17 +69,21 @@ public:
/* Called from rgss thread */
void requestFullscreenMode(bool mode);
void requestWindowResize(int width, int height);
void requestShowCursor(bool mode);
void requestTerminate();
bool getFullscreen();
bool getFullscreen() const;
bool getShowCursor() const;
void showMessageBox(const char *body, int flags = 0);
private:
void resetInputStates();
void setFullscreen(SDL_Window *, bool mode);
void updateCursorState(bool inWindow);
bool fullscreen;
bool showCursor;
volatile bool msgBoxDone;
};

View file

@ -869,6 +869,16 @@ void Graphics::setFullscreen(bool value)
p->threadData->ethread->requestFullscreenMode(value);
}
bool Graphics::getShowCursor() const
{
return p->threadData->ethread->getShowCursor();
}
void Graphics::setShowCursor(bool value)
{
p->threadData->ethread->requestShowCursor(value);
}
Scene *Graphics::getScreen() const
{
return &p->screen;

View file

@ -59,6 +59,7 @@ public:
/* Non-standard extension */
DECL_ATTR( Fullscreen, bool )
DECL_ATTR( ShowCursor, bool )
/* <internal> */
Scene *getScreen() const;