Skip to content

Commit

Permalink
Merge branch 'sdl-focus-rect' of https://github.com/lordhoto/scummvm
Browse files Browse the repository at this point in the history
Conflicts:
	backends/graphics/sdl/sdl-graphics.cpp
  • Loading branch information
Johannes Schickel committed Mar 17, 2011
2 parents 0389bd0 + 7f139f8 commit cb6f02f
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 3 deletions.
119 changes: 118 additions & 1 deletion backends/graphics/sdl/sdl-graphics.cpp
Expand Up @@ -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());
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 ---
Expand Down
14 changes: 12 additions & 2 deletions backends/graphics/sdl/sdl-graphics.h
Expand Up @@ -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.
Expand Down Expand Up @@ -114,8 +118,8 @@ class SdlGraphicsManager : public GraphicsManager, public Common::EventObserver
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();
Expand Down Expand Up @@ -301,6 +305,12 @@ class SdlGraphicsManager : public GraphicsManager, public Common::EventObserver
*/
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();
Expand Down

0 comments on commit cb6f02f

Please sign in to comment.