From 2a15b8b280af4d4beddb142e468f511a65552e2d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 3 Jun 2016 19:18:01 +0600 Subject: GUI: Add clearOSD() method So one can erase everything from OSD and then blit something on it. --- backends/base-backend.cpp | 5 ++++ backends/base-backend.h | 1 + backends/graphics/graphics.h | 1 + backends/graphics/opengl/opengl-graphics.cpp | 17 ++++++++++++ backends/graphics/opengl/opengl-graphics.h | 1 + .../graphics/surfacesdl/surfacesdl-graphics.cpp | 32 ++++++++++++++++++++++ backends/graphics/surfacesdl/surfacesdl-graphics.h | 1 + backends/modular-backend.cpp | 4 +++ backends/modular-backend.h | 1 + 9 files changed, 63 insertions(+) (limited to 'backends') diff --git a/backends/base-backend.cpp b/backends/base-backend.cpp index cf6fdfc877..59d674461c 100644 --- a/backends/base-backend.cpp +++ b/backends/base-backend.cpp @@ -43,6 +43,11 @@ void BaseBackend::copyRectToOSD(const void *buf, int pitch, int x, int y, int w, warning("BaseBackend::copyRectToOSD not implemented"); //TODO } +void BaseBackend::clearOSD() { + warning("BaseBackend::clearOSD not implemented"); //TODO + //what should I do? Remove all TimedMessageDialogs? +} + void BaseBackend::initBackend() { // Init Event manager #ifndef DISABLE_DEFAULT_EVENT_MANAGER diff --git a/backends/base-backend.h b/backends/base-backend.h index 7000d3b14a..edee427ca7 100644 --- a/backends/base-backend.h +++ b/backends/base-backend.h @@ -34,6 +34,7 @@ public: virtual void displayMessageOnOSD(const char *msg); virtual void copyRectToOSD(const void *buf, int pitch, int x, int y, int w, int h); + virtual void clearOSD(); virtual void fillScreen(uint32 col); }; diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h index 8b0ac19d9e..1063a10a9c 100644 --- a/backends/graphics/graphics.h +++ b/backends/graphics/graphics.h @@ -85,6 +85,7 @@ public: virtual void displayMessageOnOSD(const char *msg) {} virtual void copyRectToOSD(const void *buf, int pitch, int x, int y, int w, int h) {} + virtual void clearOSD() {} // Graphics::PaletteManager interface //virtual void setPalette(const byte *colors, uint start, uint num) = 0; diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index e9f26bc7bc..97788be3ad 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -757,6 +757,23 @@ void OpenGLGraphicsManager::copyRectToOSD(const void *buf, int pitch, int x, int #endif } +void OpenGLGraphicsManager::clearOSD() { +#ifdef USE_OSD + // HACK: Actually no client code should use graphics functions from + // another thread. But the MT-32 emulator still does, thus we need to + // make sure this doesn't happen while a updateScreen call is done. + Common::StackLock lock(_osdMutex); + + Graphics::Surface *dst = _osd->getSurface(); + _osd->fill(0); + _osd->flagDirty(); + + // Init the OSD display parameters. + _osdAlpha = kOSDInitialAlpha; + _osdFadeStartTime = g_system->getMillis() + kOSDFadeOutDelay; +#endif +} + void OpenGLGraphicsManager::setPalette(const byte *colors, uint start, uint num) { assert(_gameScreen->hasPalette()); diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index e0d1664e76..f36d5d17f2 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -116,6 +116,7 @@ public: virtual void displayMessageOnOSD(const char *msg); virtual void copyRectToOSD(const void *buf, int pitch, int x, int y, int w, int h); + virtual void clearOSD(); // PaletteManager interface virtual void setPalette(const byte *colors, uint start, uint num); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 88fdc09f0a..4a33890f42 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -2245,6 +2245,38 @@ void SurfaceSdlGraphicsManager::copyRectToOSD(const void *buf, int pitch, int x, // Ensure a full redraw takes place next time the screen is updated _forceFull = true; } + +void SurfaceSdlGraphicsManager::clearOSD() { + assert(_transactionMode == kTransactionNone); + + Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends + + // Lock the OSD surface for drawing + if (SDL_LockSurface(_osdSurface)) + error("displayMessageOnOSD: SDL_LockSurface failed: %s", SDL_GetError()); + + Graphics::Surface dst; + dst.init(_osdSurface->w, _osdSurface->h, _osdSurface->pitch, _osdSurface->pixels, + Graphics::PixelFormat(_osdSurface->format->BytesPerPixel, + 8 - _osdSurface->format->Rloss, 8 - _osdSurface->format->Gloss, + 8 - _osdSurface->format->Bloss, 8 - _osdSurface->format->Aloss, + _osdSurface->format->Rshift, _osdSurface->format->Gshift, + _osdSurface->format->Bshift, _osdSurface->format->Ashift)); + + // Clear everything with the "transparent" color, i.e. the colorkey + SDL_FillRect(_osdSurface, 0, kOSDColorKey); + + // Finished drawing, so unlock the OSD surface again + SDL_UnlockSurface(_osdSurface); + + // Init the OSD display parameters, and the fade out + _osdAlpha = SDL_ALPHA_TRANSPARENT + kOSDInitialAlpha * (SDL_ALPHA_OPAQUE - SDL_ALPHA_TRANSPARENT) / 100; + _osdFadeStartTime = SDL_GetTicks() + kOSDFadeOutDelay; + SDL_SetAlpha(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _osdAlpha); + + // Ensure a full redraw takes place next time the screen is updated + _forceFull = true; +} #endif bool SurfaceSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) { diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index a8bafd0a84..01974cf6ab 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -146,6 +146,7 @@ public: #ifdef USE_OSD virtual void displayMessageOnOSD(const char *msg); virtual void copyRectToOSD(const void *buf, int pitch, int x, int y, int w, int h); + virtual void clearOSD(); #endif // Override from Common::EventObserver diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp index 08565dcbdd..6ad80ecbb3 100644 --- a/backends/modular-backend.cpp +++ b/backends/modular-backend.cpp @@ -245,6 +245,10 @@ void ModularBackend::copyRectToOSD(const void *buf, int pitch, int x, int y, int _graphicsManager->copyRectToOSD(buf, pitch, x, y, w, h); } +void ModularBackend::clearOSD() { + _graphicsManager->clearOSD(); +} + void ModularBackend::quit() { exit(0); } diff --git a/backends/modular-backend.h b/backends/modular-backend.h index cf3babfc47..06c69b55ad 100644 --- a/backends/modular-backend.h +++ b/backends/modular-backend.h @@ -128,6 +128,7 @@ public: virtual void quit(); virtual void displayMessageOnOSD(const char *msg); virtual void copyRectToOSD(const void *buf, int pitch, int x, int y, int w, int h); + virtual void clearOSD(); //@} -- cgit v1.2.3