BACKENDS: Also hide mouse cursor outside game area when an engine has hidden the cursor

The only reason we show the system cursor outside the game area is
to show users where their mouse is when the window is resized and
the mouse is outside the game area. If the game cannot be
interacted with, then the mouse also does not need to be shown in
the black areas.
This commit is contained in:
Colin Snover
2017-10-15 13:24:20 -05:00
parent de2bbe3b97
commit da0a8db704
7 changed files with 46 additions and 40 deletions
+1 -13
View File
@@ -58,7 +58,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager()
_cursor(nullptr),
_cursorHotspotX(0), _cursorHotspotY(0),
_cursorHotspotXScaled(0), _cursorHotspotYScaled(0), _cursorWidthScaled(0), _cursorHeightScaled(0),
_cursorKeyColor(0), _cursorVisible(false), _cursorDontScale(false), _cursorPaletteEnabled(false)
_cursorKeyColor(0), _cursorDontScale(false), _cursorPaletteEnabled(false)
#ifdef USE_OSD
, _osdMessageChangeRequest(false), _osdMessageAlpha(0), _osdMessageFadeStartTime(0), _osdMessageSurface(nullptr),
_osdIconSurface(nullptr)
@@ -547,18 +547,6 @@ void OpenGLGraphicsManager::grabOverlay(void *buf, int pitch) const {
}
}
bool OpenGLGraphicsManager::showMouse(bool visible) {
// In case the mouse cursor visibility changed we need to redraw the whole
// screen even when nothing else changed.
if (_cursorVisible != visible) {
_cursorNeedsRedraw = true;
}
bool last = _cursorVisible;
_cursorVisible = visible;
return last;
}
namespace {
template<typename DstPixel, typename SrcPixel>
void applyColorKey(DstPixel *dst, const SrcPixel *src, uint w, uint h, uint dstPitch, uint srcPitch, SrcPixel keyColor, DstPixel alphaMask) {
@@ -107,7 +107,6 @@ public:
virtual void clearOverlay() override;
virtual void grabOverlay(void *buf, int pitch) const override;
virtual bool showMouse(bool visible) override;
virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) override;
virtual void setCursorPalette(const byte *colors, uint start, uint num) override;
@@ -395,11 +394,6 @@ protected:
*/
uint32 _cursorKeyColor;
/**
* Whether the cursor is actually visible.
*/
bool _cursorVisible;
/**
* Whether no cursor scaling should be applied.
*/
+24 -6
View File
@@ -148,18 +148,36 @@ void SdlGraphicsManager::initSizeHint(const Graphics::ModeList &modes) {
#endif
}
bool SdlGraphicsManager::showMouse(const bool visible) {
if (visible == _cursorVisible) {
return visible;
}
int showCursor = SDL_DISABLE;
if (visible) {
// _cursorX and _cursorY are currently always clipped to the active
// area, so we need to ask SDL where the system's mouse cursor is
// instead
int x, y;
SDL_GetMouseState(&x, &y);
if (!_activeArea.drawRect.contains(Common::Point(x, y))) {
showCursor = SDL_ENABLE;
}
}
SDL_ShowCursor(showCursor);
return WindowedGraphicsManager::showMouse(visible);
}
void SdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
int showCursor;
if (_activeArea.drawRect.contains(mouse)) {
showCursor = SDL_DISABLE;
} else {
int showCursor = SDL_DISABLE;
if (!_activeArea.drawRect.contains(mouse)) {
mouse.x = CLIP<int>(mouse.x, _activeArea.drawRect.left, _activeArea.drawRect.right - 1);
mouse.y = CLIP<int>(mouse.y, _activeArea.drawRect.top, _activeArea.drawRect.bottom - 1);
if (_window->mouseIsGrabbed()) {
setSystemMousePosition(mouse.x, mouse.y);
showCursor = SDL_DISABLE;
} else {
} else if (_cursorVisible) {
showCursor = SDL_ENABLE;
}
}
+2
View File
@@ -87,6 +87,8 @@ public:
*/
virtual void notifyMousePosition(Common::Point &mouse);
virtual bool showMouse(const bool visible) override;
/**
* A (subset) of the graphic manager's state. This is used when switching
* between different SDL graphic managers at runtime.
@@ -145,7 +145,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
#endif
_overlayscreen(0), _tmpscreen2(0),
_scalerProc(0), _screenChangeCount(0),
_mouseVisible(false), _mouseData(0), _mouseSurface(0),
_mouseData(0), _mouseSurface(0),
_mouseOrigSurface(0), _cursorDontScale(false), _cursorPaletteDisabled(true),
_currentShakePos(0), _newShakePos(0),
_paletteDirtyStart(0), _paletteDirtyEnd(0),
@@ -1863,17 +1863,6 @@ void SurfaceSdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, in
#pragma mark --- Mouse ---
#pragma mark -
bool SurfaceSdlGraphicsManager::showMouse(bool visible) {
if (_mouseVisible == visible)
return visible;
bool last = _mouseVisible;
_mouseVisible = visible;
_cursorNeedsRedraw = true;
return last;
}
void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
#ifdef USE_RGB_COLOR
if (!format)
@@ -2123,7 +2112,7 @@ void SurfaceSdlGraphicsManager::undrawMouse() {
}
void SurfaceSdlGraphicsManager::drawMouse() {
if (!_mouseVisible || !_mouseSurface) {
if (!_cursorVisible || !_mouseSurface) {
_mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0;
return;
}
@@ -129,7 +129,6 @@ public:
virtual int16 getOverlayHeight() const override { return _videoMode.overlayHeight; }
virtual int16 getOverlayWidth() const override { return _videoMode.overlayWidth; }
virtual bool showMouse(bool visible) override;
virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override;
virtual void setCursorPalette(const byte *colors, uint start, uint num) override;
@@ -318,7 +317,6 @@ protected:
{ }
};
bool _mouseVisible;
byte *_mouseData;
SDL_Rect _mouseBackup;
MousePos _mouseCurState;
+17
View File
@@ -36,6 +36,7 @@ public:
_windowHeight(0),
_overlayVisible(false),
_forceRedraw(false),
_cursorVisible(false),
_cursorX(0),
_cursorY(0),
_cursorNeedsRedraw(false) {}
@@ -182,6 +183,17 @@ protected:
*/
virtual void setSystemMousePosition(const int x, const int y) = 0;
virtual bool showMouse(const bool visible) override {
if (_cursorVisible == visible) {
return visible;
}
const bool last = _cursorVisible;
_cursorVisible = visible;
_cursorNeedsRedraw = true;
return last;
}
/**
* Move ("warp") the mouse cursor to the specified position.
*
@@ -281,6 +293,11 @@ protected:
*/
bool _forceRedraw;
/**
* Whether the cursor is actually visible.
*/
bool _cursorVisible;
/**
* Whether the mouse cursor needs to be redrawn on the next frame.
*/