From 4b53b4f1aa1578a9fe5da34d86968856b5b4eef8 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Wed, 8 Feb 2023 21:38:04 +0100 Subject: [PATCH] GUI: Darken thumbnails of invalid entries Applies a dark transparent overlay to the games that are non-startable --- gui/widgets/grid.cpp | 30 +++++++++++++++++++++++++++++- gui/widgets/grid.h | 3 ++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gui/widgets/grid.cpp b/gui/widgets/grid.cpp index 77efe1d89b9..91031f12be7 100644 --- a/gui/widgets/grid.cpp +++ b/gui/widgets/grid.cpp @@ -145,6 +145,17 @@ void GridItemWidget::drawWidget() { g_gui.theme()->drawSurface(p, *demoGfx, true); } + bool validEntry = _activeEntry->validEntry; + + // Darken thumbnail if path is unreachable + if (!validEntry) { + const Graphics::ManagedSurface *darkenGfx = _grid->disabledThumbnail(); + if (darkenGfx) { + Common::Point p(_x, _y); + g_gui.theme()->drawSurface(p, *darkenGfx, true); + } + } + // Draw Title if (_grid->_isTitlesVisible) { // TODO: Currently title is fixed to two lines at all times, we may want @@ -156,7 +167,7 @@ void GridItemWidget::drawWidget() { } // Display text in alternate color if the path is unreachable // Should be ok using kStateDisabled, but the list widget uses FontColorAlternate so let's stick to that - GUI::ThemeEngine::FontColor color = _activeEntry->validEntry ? GUI::ThemeEngine::kFontColorNormal : GUI::ThemeEngine::kFontColorAlternate; + GUI::ThemeEngine::FontColor color = validEntry ? GUI::ThemeEngine::kFontColorNormal : GUI::ThemeEngine::kFontColorAlternate; Common::Rect r(_x, _y + thumbHeight, _x + thumbWidth, _y + thumbHeight + kLineHeight); for (uint k = 0; k < MIN(2U, titleLines.size()); ++k) { g_gui.theme()->drawText(r, titleLines[k], GUI::ThemeEngine::kStateEnabled, Graphics::kTextAlignCenter, GUI::ThemeEngine::kTextInversionNone, @@ -354,6 +365,8 @@ GridWidget::GridWidget(GuiObject *boss, const Common::String &name) _platformIconWidth = 0; _extraIconHeight = 0; _extraIconWidth = 0; + _disabledIconOverlay = nullptr; + _minGridXSpacing = 0; _minGridYSpacing = 0; _isTitlesVisible = 0; @@ -392,6 +405,7 @@ GridWidget::~GridWidget() { unloadSurfaces(_languageIcons); unloadSurfaces(_extraIcons); unloadSurfaces(_loadedSurfaces); + delete _disabledIconOverlay; _gridItems.clear(); _dataEntryList.clear(); _headerEntryList.clear(); @@ -431,6 +445,10 @@ const Graphics::ManagedSurface *GridWidget::demoToSurface(const Common::String e return _extraIcons[0]; } +const Graphics::ManagedSurface *GridWidget::disabledThumbnail() { + return _disabledIconOverlay; +} + void GridWidget::setEntryList(Common::Array *list) { _dataEntryList.clear(); _headerEntryList.clear(); @@ -952,10 +970,20 @@ void GridWidget::reflowLayout() { unloadSurfaces(_platformIcons); unloadSurfaces(_languageIcons); unloadSurfaces(_loadedSurfaces); + if (_disabledIconOverlay) + _disabledIconOverlay->free(); reloadThumbnails(); loadFlagIcons(); loadPlatformIcons(); loadExtraIcons(); + + Graphics::ManagedSurface *gfx = new Graphics::ManagedSurface(_thumbnailWidth, _thumbnailHeight, g_system->getOverlayFormat()); + uint32 disabledThumbnailColor = gfx->format.ARGBToColor(153, 0, 0, 0); // 60% opacity black + gfx->fillRect(Common::Rect(0, 0, _thumbnailWidth, _thumbnailHeight), disabledThumbnailColor); + if (gfx) + _disabledIconOverlay = gfx; + else + _disabledIconOverlay = nullptr; } _trayHeight = kLineHeight * 3; diff --git a/gui/widgets/grid.h b/gui/widgets/grid.h index 087e32d482c..98d47339a8a 100644 --- a/gui/widgets/grid.h +++ b/gui/widgets/grid.h @@ -101,7 +101,7 @@ protected: Common::HashMap _platformIcons; Common::HashMap _languageIcons; Common::HashMap _extraIcons; - + Graphics::ManagedSurface *_disabledIconOverlay; // Images are mapped by filename -> surface. Common::HashMap _loadedSurfaces; @@ -174,6 +174,7 @@ public: const Graphics::ManagedSurface *languageToSurface(Common::Language languageCode); const Graphics::ManagedSurface *platformToSurface(Common::Platform platformCode); const Graphics::ManagedSurface *demoToSurface(const Common::String extraString); + const Graphics::ManagedSurface *disabledThumbnail(); /// Update _visibleEntries from _allEntries and returns true if reload is required. bool calcVisibleEntries();