diff options
author | Johannes Schickel | 2011-03-17 16:48:55 +0100 |
---|---|---|
committer | Johannes Schickel | 2011-03-17 16:48:55 +0100 |
commit | cb6f02f7ef6c5c81892cd8f8bd2f5e323e388fa4 (patch) | |
tree | b3105906fc7f7b1435c5bf34c1f7f3e185bc8228 /backends | |
parent | 0389bd0c4b10e8286b6c2e52c726bfc370487ae5 (diff) | |
parent | 7f139f8dcfab740d6dacc2ea5e3a916618e7ce8f (diff) | |
download | scummvm-rg350-cb6f02f7ef6c5c81892cd8f8bd2f5e323e388fa4.tar.gz scummvm-rg350-cb6f02f7ef6c5c81892cd8f8bd2f5e323e388fa4.tar.bz2 scummvm-rg350-cb6f02f7ef6c5c81892cd8f8bd2f5e323e388fa4.zip |
Merge branch 'sdl-focus-rect' of https://github.com/lordhoto/scummvm
Conflicts:
backends/graphics/sdl/sdl-graphics.cpp
Diffstat (limited to 'backends')
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp | 119 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 14 |
2 files changed, 130 insertions, 3 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index 7d36786b7d..c0d93b3bf2 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -141,7 +141,11 @@ SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *sdlEventSource) _currentShakePos(0), _newShakePos(0), _paletteDirtyStart(0), _paletteDirtyEnd(0), _screenIsLocked(false), - _graphicsMutex(0), _transactionMode(kTransactionNone) { + _graphicsMutex(0), +#ifdef USE_SDL_DEBUG_FOCUSRECT + _enableFocusRectDebugCode(false), _enableFocusRect(false), _focusRect(), +#endif + _transactionMode(kTransactionNone) { if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { error("Could not initialize SDL: %s", SDL_GetError()); @@ -161,6 +165,11 @@ SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *sdlEventSource) _graphicsMutex = g_system->createMutex(); +#ifdef USE_SDL_DEBUG_FOCUSRECT + if (ConfMan.hasKey("use_sdl_debug_focusrect")) + _enableFocusRectDebugCode = ConfMan.getBool("use_sdl_debug_focusrect"); +#endif + SDL_ShowCursor(SDL_DISABLE); memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); @@ -1096,6 +1105,79 @@ void SdlGraphicsManager::internUpdateScreen() { SDL_BlitSurface(_osdSurface, 0, _hwscreen, 0); } #endif + +#ifdef USE_SDL_DEBUG_FOCUSRECT + // We draw the focus rectangle on top of everything, to assure it's easily visible. + // Of course when the overlay is visible we do not show it, since it is only for game + // specific focus. + if (_enableFocusRect && !_overlayVisible) { + int y = _focusRect.top + _currentShakePos; + int h = 0; + int x = _focusRect.left * scale1; + int w = _focusRect.width() * scale1; + + if (y < height) { + h = _focusRect.height(); + if (h > height - y) + h = height - y; + + y *= scale1; + + if (_videoMode.aspectRatioCorrection && !_overlayVisible) + y = real2Aspect(y); + + if (h > 0 && w > 0) { + SDL_LockSurface(_hwscreen); + + // Use white as color for now. + Uint32 rectColor = SDL_MapRGB(_hwscreen->format, 0xFF, 0xFF, 0xFF); + + // First draw the top and bottom lines + // then draw the left and right lines + if (_hwscreen->format->BytesPerPixel == 2) { + uint16 *top = (uint16 *)((byte *)_hwscreen->pixels + y * _hwscreen->pitch + x * 2); + uint16 *bottom = (uint16 *)((byte *)_hwscreen->pixels + (y + h) * _hwscreen->pitch + x * 2); + byte *left = ((byte *)_hwscreen->pixels + y * _hwscreen->pitch + x * 2); + byte *right = ((byte *)_hwscreen->pixels + y * _hwscreen->pitch + (x + w - 1) * 2); + + while (w--) { + *top++ = rectColor; + *bottom++ = rectColor; + } + + while (h--) { + *(uint16 *)left = rectColor; + *(uint16 *)right = rectColor; + + left += _hwscreen->pitch; + right += _hwscreen->pitch; + } + } else if (_hwscreen->format->BytesPerPixel == 4) { + uint32 *top = (uint32 *)((byte *)_hwscreen->pixels + y * _hwscreen->pitch + x * 4); + uint32 *bottom = (uint32 *)((byte *)_hwscreen->pixels + (y + h) * _hwscreen->pitch + x * 4); + byte *left = ((byte *)_hwscreen->pixels + y * _hwscreen->pitch + x * 4); + byte *right = ((byte *)_hwscreen->pixels + y * _hwscreen->pitch + (x + w - 1) * 4); + + while (w--) { + *top++ = rectColor; + *bottom++ = rectColor; + } + + while (h--) { + *(uint32 *)left = rectColor; + *(uint32 *)right = rectColor; + + left += _hwscreen->pitch; + right += _hwscreen->pitch; + } + } + + SDL_UnlockSurface(_hwscreen); + } + } + } +#endif + // Finally, blit all our changes to the screen SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList); } @@ -1389,6 +1471,41 @@ void SdlGraphicsManager::setShakePos(int shake_pos) { _newShakePos = shake_pos; } +void SdlGraphicsManager::setFocusRectangle(const Common::Rect &rect) { +#ifdef USE_SDL_DEBUG_FOCUSRECT + // Only enable focus rectangle debug code, when the user wants it + if (!_enableFocusRectDebugCode) + return; + + _enableFocusRect = true; + _focusRect = rect; + + if (rect.left < 0 || rect.top < 0 || rect.right > _videoMode.screenWidth || rect.bottom > _videoMode.screenHeight) + warning("SdlGraphicsManager::setFocusRectangle: Got a rect which does not fit inside the screen bounds: %d,%d,%d,%d", rect.left, rect.top, rect.right, rect.bottom); + + // It's gross but we actually sometimes get rects, which are not inside the screen bounds, + // thus we need to clip the rect here... + _focusRect.clip(_videoMode.screenWidth, _videoMode.screenHeight); + + // We just fake this as a dirty rect for now, to easily force an screen update whenever + // the rect changes. + addDirtyRect(_focusRect.left, _focusRect.top, _focusRect.width(), _focusRect.height()); +#endif +} + +void SdlGraphicsManager::clearFocusRectangle() { +#ifdef USE_SDL_DEBUG_FOCUSRECT + // Only enable focus rectangle debug code, when the user wants it + if (!_enableFocusRectDebugCode) + return; + + _enableFocusRect = false; + + // We just fake this as a dirty rect for now, to easily force an screen update whenever + // the rect changes. + addDirtyRect(_focusRect.left, _focusRect.top, _focusRect.width(), _focusRect.height()); +#endif +} #pragma mark - #pragma mark --- Overlays --- diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 0daaab104c..f467c38d5f 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -35,6 +35,10 @@ #include "backends/platform/sdl/sdl-sys.h" +#ifndef RELEASE_BUILD +// Define this to allow for focus rectangle debugging +#define USE_SDL_DEBUG_FOCUSRECT +#endif #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) // Uncomment this to enable the 'on screen display' code. @@ -114,8 +118,8 @@ public: virtual void fillScreen(uint32 col); virtual void updateScreen(); virtual void setShakePos(int shakeOffset); - virtual void setFocusRectangle(const Common::Rect& rect) {} - virtual void clearFocusRectangle() {} + virtual void setFocusRectangle(const Common::Rect& rect); + virtual void clearFocusRectangle(); virtual void showOverlay(); virtual void hideOverlay(); @@ -301,6 +305,12 @@ protected: */ OSystem::MutexRef _graphicsMutex; +#ifdef USE_SDL_DEBUG_FOCUSRECT + bool _enableFocusRectDebugCode; + bool _enableFocusRect; + Common::Rect _focusRect; +#endif + virtual void addDirtyRect(int x, int y, int w, int h, bool realCoordinates = false); virtual void drawMouse(); |