From b8390fa161c0c324af0e52a4f3a740cca9e9a479 Mon Sep 17 00:00:00 2001 From: sluicebox Date: Fri, 15 Nov 2019 01:38:21 -0800 Subject: GRAPHICS: Add interface for horizontal shake --- backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 19 ++++++++++--------- backends/graphics/surfacesdl/surfacesdl-graphics.h | 3 ++- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'backends/graphics/surfacesdl') diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 92540d93f7..95c7ddc918 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -158,7 +158,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou _scalerProc(0), _screenChangeCount(0), _mouseData(nullptr), _mouseSurface(nullptr), _mouseOrigSurface(nullptr), _cursorDontScale(false), _cursorPaletteDisabled(true), - _currentShakePos(0), + _currentShakeXOffset(0), _currentShakeYOffset(0), _paletteDirtyStart(0), _paletteDirtyEnd(0), _screenIsLocked(false), _graphicsMutex(0), @@ -822,7 +822,8 @@ int SurfaceSdlGraphicsManager::getStretchMode() const { void SurfaceSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); - _gameScreenShakeOffset = 0; + _gameScreenShakeXOffset = 0; + _gameScreenShakeYOffset = 0; #ifdef USE_RGB_COLOR //avoid redundant format changes @@ -1206,16 +1207,16 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() { // If the shake position changed, fill the dirty area with blackness // When building with SDL2, the shake offset is added to the active rect instead, // so this isn't needed there. - if (_currentShakePos != _gameScreenShakeOffset || - (_cursorNeedsRedraw && _mouseBackup.y <= _currentShakePos)) { - SDL_Rect blackrect = {0, 0, (Uint16)(_videoMode.screenWidth * _videoMode.scaleFactor), (Uint16)(_gameScreenShakeOffset * _videoMode.scaleFactor)}; + if (_currentShakeYOffset != _gameScreenShakeYOffset || + (_cursorNeedsRedraw && _mouseBackup.y <= _currentShakeYOffset)) { + SDL_Rect blackrect = {0, 0, (Uint16)(_videoMode.screenWidth * _videoMode.scaleFactor), (Uint16)(_gameScreenShakeYOffset * _videoMode.scaleFactor)}; if (_videoMode.aspectRatioCorrection && !_overlayVisible) blackrect.h = real2Aspect(blackrect.h - 1) + 1; SDL_FillRect(_hwScreen, &blackrect, 0); - _currentShakePos = _gameScreenShakeOffset; + _currentShakeYOffset = _gameScreenShakeYOffset; _forceRedraw = true; } @@ -1293,7 +1294,7 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() { dstPitch = _hwScreen->pitch; for (r = _dirtyRectList; r != lastRect; ++r) { - int dst_y = r->y + _currentShakePos; + int dst_y = r->y + _currentShakeYOffset; int dst_h = 0; #ifdef USE_SCALERS int orig_dst_y = 0; @@ -1349,7 +1350,7 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() { // 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 y = _focusRect.top + _currentShakeYOffset; int h = 0; int x = _focusRect.left * scale1; int w = _focusRect.width() * scale1; @@ -2276,7 +2277,7 @@ void SurfaceSdlGraphicsManager::drawMouse() { // We draw the pre-scaled cursor image, so now we need to adjust for // scaling, shake position and aspect ratio correction manually. - dst.y += _currentShakePos; + dst.y += _currentShakeYOffset; if (_videoMode.aspectRatioCorrection && !_overlayVisible) dst.y = real2Aspect(dst.y); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index a51aa22e9b..6b8ae36b87 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -387,7 +387,8 @@ protected: // Shake mode // This is always set to 0 when building with SDL2. - int _currentShakePos; + int _currentShakeXOffset; + int _currentShakeYOffset; // Palette data SDL_Color *_currentPalette; -- cgit v1.2.3