EventThread: Make system cursor visible over black aspect ratio bars

Should be less confusing for the player.
This commit is contained in:
Jonas Kulla 2017-04-08 16:16:36 +02:00
parent 60e967e3b7
commit 3ea24bd757
3 changed files with 47 additions and 10 deletions

View File

@ -83,6 +83,7 @@ enum
REQUEST_SETCURSORVISIBLE, REQUEST_SETCURSORVISIBLE,
UPDATE_FPS, UPDATE_FPS,
UPDATE_SCREEN_RECT,
EVENT_COUNT EVENT_COUNT
}; };
@ -131,6 +132,8 @@ void EventThread::process(RGSSThreadData &rtData)
bool displayingFPS = false; bool displayingFPS = false;
bool cursorInWindow = false; bool cursorInWindow = false;
/* Will be updated eventually */
SDL_Rect gameScreen = { 0, 0, 0, 0 };
/* SDL doesn't send an initial FOCUS_GAINED event */ /* SDL doesn't send an initial FOCUS_GAINED event */
bool windowFocused = true; bool windowFocused = true;
@ -170,7 +173,7 @@ void EventThread::process(RGSSThreadData &rtData)
delete sMenu; delete sMenu;
sMenu = 0; sMenu = 0;
updateCursorState(cursorInWindow && windowFocused); updateCursorState(cursorInWindow && windowFocused, gameScreen);
} }
continue; continue;
@ -211,14 +214,14 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_WINDOWEVENT_ENTER : case SDL_WINDOWEVENT_ENTER :
cursorInWindow = true; cursorInWindow = true;
mouseState.inWindow = true; mouseState.inWindow = true;
updateCursorState(cursorInWindow && windowFocused && !sMenu); updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
break; break;
case SDL_WINDOWEVENT_LEAVE : case SDL_WINDOWEVENT_LEAVE :
cursorInWindow = false; cursorInWindow = false;
mouseState.inWindow = false; mouseState.inWindow = false;
updateCursorState(cursorInWindow && windowFocused && !sMenu); updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
break; break;
@ -229,13 +232,13 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_WINDOWEVENT_FOCUS_GAINED : case SDL_WINDOWEVENT_FOCUS_GAINED :
windowFocused = true; windowFocused = true;
updateCursorState(cursorInWindow && windowFocused && !sMenu); updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST : case SDL_WINDOWEVENT_FOCUS_LOST :
windowFocused = false; windowFocused = false;
updateCursorState(cursorInWindow && windowFocused && !sMenu); updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
resetInputStates(); resetInputStates();
break; break;
@ -268,7 +271,7 @@ void EventThread::process(RGSSThreadData &rtData)
if (!sMenu) if (!sMenu)
{ {
sMenu = new SettingsMenu(rtData); sMenu = new SettingsMenu(rtData);
updateCursorState(false); updateCursorState(false, gameScreen);
} }
sMenu->raise(); sMenu->raise();
@ -374,6 +377,7 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_MOUSEMOTION : case SDL_MOUSEMOTION :
mouseState.x = event.motion.x; mouseState.x = event.motion.x;
mouseState.y = event.motion.y; mouseState.y = event.motion.y;
updateCursorState(cursorInWindow, gameScreen);
break; break;
case SDL_FINGERDOWN : case SDL_FINGERDOWN :
@ -413,7 +417,7 @@ void EventThread::process(RGSSThreadData &rtData)
case REQUEST_SETCURSORVISIBLE : case REQUEST_SETCURSORVISIBLE :
showCursor = event.user.code; showCursor = event.user.code;
updateCursorState(cursorInWindow); updateCursorState(cursorInWindow, gameScreen);
break; break;
case UPDATE_FPS : case UPDATE_FPS :
@ -438,6 +442,15 @@ void EventThread::process(RGSSThreadData &rtData)
SDL_SetWindowTitle(win, buffer); SDL_SetWindowTitle(win, buffer);
break; break;
case UPDATE_SCREEN_RECT :
gameScreen.x = event.user.windowID;
gameScreen.y = event.user.code;
gameScreen.w = reinterpret_cast<intptr_t>(event.user.data1);
gameScreen.h = reinterpret_cast<intptr_t>(event.user.data2);
updateCursorState(cursorInWindow, gameScreen);
break;
} }
} }
@ -532,9 +545,13 @@ void EventThread::setFullscreen(SDL_Window *win, bool mode)
fullscreen = mode; fullscreen = mode;
} }
void EventThread::updateCursorState(bool inWindow) void EventThread::updateCursorState(bool inWindow,
const SDL_Rect &screen)
{ {
if (inWindow) SDL_Point pos = { mouseState.x, mouseState.y };
bool inScreen = inWindow && SDL_PointInRect(&pos, &screen);
if (inScreen)
SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE); SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE);
else else
SDL_ShowCursor(SDL_TRUE); SDL_ShowCursor(SDL_TRUE);
@ -640,6 +657,19 @@ void EventThread::notifyFrame()
SDL_PushEvent(&event); SDL_PushEvent(&event);
} }
void EventThread::notifyGameScreenChange(const SDL_Rect &screen)
{
/* We have to get a bit hacky here to fit the rectangle
* data into the user event struct */
SDL_Event event;
event.type = usrIdStart + UPDATE_SCREEN_RECT;
event.user.windowID = screen.x;
event.user.code = screen.y;
event.user.data1 = reinterpret_cast<void*>(screen.w);
event.user.data2 = reinterpret_cast<void*>(screen.h);
SDL_PushEvent(&event);
}
void SyncPoint::haltThreads() void SyncPoint::haltThreads()
{ {
if (mainSync.locked) if (mainSync.locked)

View File

@ -98,12 +98,16 @@ public:
/* RGSS thread calls this once per frame */ /* RGSS thread calls this once per frame */
void notifyFrame(); void notifyFrame();
/* Called on game screen (size / offset) changes */
void notifyGameScreenChange(const SDL_Rect &screen);
private: private:
static int eventFilter(void *, SDL_Event*); static int eventFilter(void *, SDL_Event*);
void resetInputStates(); void resetInputStates();
void setFullscreen(SDL_Window *, bool mode); void setFullscreen(SDL_Window *, bool mode);
void updateCursorState(bool inWindow); void updateCursorState(bool inWindow,
const SDL_Rect &screen);
bool fullscreen; bool fullscreen;
bool showCursor; bool showCursor;

View File

@ -566,6 +566,9 @@ struct GraphicsPrivate
glState.viewport.refresh(); glState.viewport.refresh();
recalculateScreenSize(threadData); recalculateScreenSize(threadData);
updateScreenResoRatio(threadData); updateScreenResoRatio(threadData);
SDL_Rect screen = { scOffset.x, scOffset.y, scSize.x, scSize.y };
threadData->ethread->notifyGameScreenChange(screen);
} }
} }