From 345e7f0b9f024a49d3f57e566ebd538b4b0284d9 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 23 Jan 2021 12:57:51 -0330 Subject: [PATCH] Fix final issue with snapshots not loading in RomInfoWidget. --- src/common/FBBackendSDL2.cxx | 2 -- src/common/FBSurfaceSDL2.cxx | 5 ----- src/emucore/FrameBuffer.cxx | 1 - src/gui/Dialog.cxx | 22 +++++++++++----------- src/gui/Dialog.hxx | 16 +++++++++------- src/gui/DialogContainer.cxx | 2 +- src/gui/LauncherDialog.cxx | 9 +++++++++ src/gui/LauncherDialog.hxx | 1 + src/gui/RomInfoWidget.cxx | 13 ++++++++++++- src/gui/RomInfoWidget.hxx | 2 ++ 10 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/common/FBBackendSDL2.cxx b/src/common/FBBackendSDL2.cxx index c1204065e..b0b710ca4 100644 --- a/src/common/FBBackendSDL2.cxx +++ b/src/common/FBBackendSDL2.cxx @@ -71,8 +71,6 @@ FBBackendSDL2::~FBBackendSDL2() myWindow = nullptr; } SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER); - -cerr << "~FBBackendSDL2()" << endl; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index 15923a099..a2b8d0166 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -40,8 +40,6 @@ namespace { } } -static int REF_COUNT = 0; - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend, uInt32 width, uInt32 height, @@ -50,7 +48,6 @@ FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend, : myBackend{backend}, myInterpolationMode{inter} { -REF_COUNT++; createSurface(width, height, staticData); } @@ -61,8 +58,6 @@ FBSurfaceSDL2::~FBSurfaceSDL2() if(mySurface) { -REF_COUNT--; -cerr << " ~FBSurfaceSDL2(): " << this << " " << REF_COUNT << endl; SDL_FreeSurface(mySurface); mySurface = nullptr; } diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index f74f084b9..f34c72d42 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -67,7 +67,6 @@ FrameBuffer::FrameBuffer(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameBuffer::~FrameBuffer() { -cerr << "~FrameBuffer()" << endl << endl; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index c07830159..47ff33d08 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -50,7 +50,8 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font const string& title, int x, int y, int w, int h) : GuiObject(instance, parent, *this, x, y, w, h), _font{font}, - _title{title} + _title{title}, + _renderCallback{[]() { return; }} { _flags = Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG; setTitle(title); @@ -75,8 +76,6 @@ Dialog::~Dialog() _firstWidget = nullptr; _buttonGroup.clear(); - -cerr << "\n~Dialog(): " << this << endl; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -163,6 +162,12 @@ void Dialog::setDirtyChain() _dirtyChain = true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Dialog::resetSurfaces() +{ + _surface->reload(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::tick() { @@ -241,11 +246,7 @@ void Dialog::render() // Update dialog surface; also render any extra surfaces // Extra surfaces must be rendered afterwards, so they are drawn on top if(_surface->render()) - { - mySurfaceStack.applyAll([](unique_ptr& surface) { - surface->render(); - }); - } + _renderCallback(); // A dialog is still on top if a non-shading dialog (e.g. ContextMenu) // is opended above it. @@ -422,10 +423,9 @@ void Dialog::buildCurrentFocusList(int tabID) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::addSurface(const unique_ptr& surface) +void Dialog::addRenderCallback(const std::function& callback) { -// FIXME : add this to the stack somehow -// mySurfaceStack.push(surface); + _renderCallback = callback; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index 31421988e..a9f352591 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -28,7 +28,6 @@ class TabWidget; class CommandSender; class ToolTip; -#include "Stack.hxx" #include "Widget.hxx" #include "GuiObject.hxx" #include "StellaKeys.hxx" @@ -45,6 +44,8 @@ class Dialog : public GuiObject friend class DialogContainer; public: + using RenderCallback = std::function; + Dialog(OSystem& instance, DialogContainer& parent, int x = 0, int y = 0, int w = 0, int h = 0); Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, @@ -62,6 +63,8 @@ class Dialog : public GuiObject virtual void saveConfig() { } virtual void setDefaults() { } + virtual void resetSurfaces(); + void setDirty() override; void setDirtyChain() override; void redraw(bool force = false); @@ -85,12 +88,11 @@ class Dialog : public GuiObject FBSurface& surface() const { return *_surface; } /** - Adds a surface to this dialog, which is rendered on top of the - base surface whenever the base surface is re-rendered. Since - the surface render() call will always occur in such a case, the - surface should call setVisible() to enable/disable its output. + This method is called each time the main Dialog::render is called. + It is called *after* the dialog has been rendered, so it can be + used to render another surface on top of it, among other things. */ - void addSurface(const unique_ptr& surface); + void addRenderCallback(const RenderCallback& callback); void setTitle(const string& title); bool hasTitle() { return !_title.empty(); } @@ -253,7 +255,7 @@ class Dialog : public GuiObject uInt32 _max_w{0}; // maximum wanted width uInt32 _max_h{0}; // maximum wanted height - Common::FixedStack> mySurfaceStack; + RenderCallback _renderCallback; private: // Following constructors and assignment operators not supported diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index 4784acac5..3993dba04 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -203,7 +203,7 @@ void DialogContainer::reStack() void DialogContainer::resetSurfaces() { myDialogStack.applyAll([&](Dialog*& d) { - d->surface().reload(); + d->resetSurfaces(); }); } diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index e9acf0d57..588e17666 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -350,6 +350,15 @@ void LauncherDialog::reload() myPendingReload = false; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void LauncherDialog::resetSurfaces() +{ + if(myRomInfoWidget) + myRomInfoWidget->resetSurfaces(); + + Dialog::resetSurfaces(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::tick() { diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index b10e1d4df..162032065 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -108,6 +108,7 @@ class LauncherDialog : public Dialog void loadConfig() override; void saveConfig() override; + void resetSurfaces() override; void updateUI(); /** diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 8798681a7..fb62e913f 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -94,7 +94,11 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) myAvail.w, myAvail.h, ScalingInterpolation::blur); mySurface->applyAttributes(); - dialog().addSurface(mySurface); + dialog().addRenderCallback([this]() { + if(mySurfaceIsValid) + mySurface->render(); + } + ); } // Initialize to empty properties entry @@ -169,6 +173,13 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) setDirty(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void RomInfoWidget::resetSurfaces() +{ + if(mySurface) + mySurface->reload(); +} + #ifdef PNG_SUPPORT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool RomInfoWidget::loadPng(const string& filename) diff --git a/src/gui/RomInfoWidget.hxx b/src/gui/RomInfoWidget.hxx index a5c73ee28..f21f85e3b 100644 --- a/src/gui/RomInfoWidget.hxx +++ b/src/gui/RomInfoWidget.hxx @@ -39,6 +39,8 @@ class RomInfoWidget : public Widget void clearProperties(); void reloadProperties(const FilesystemNode& node); + void resetSurfaces(); + protected: void drawWidget(bool hilite) override;