Fix final issue with snapshots not loading in RomInfoWidget.

This commit is contained in:
Stephen Anthony 2021-01-23 12:57:51 -03:30
parent 3a54adeca2
commit 95c8203f8d
10 changed files with 45 additions and 28 deletions

View File

@ -71,8 +71,6 @@ FBBackendSDL2::~FBBackendSDL2()
myWindow = nullptr; myWindow = nullptr;
} }
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER); SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER);
cerr << "~FBBackendSDL2()" << endl;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -40,8 +40,6 @@ namespace {
} }
} }
static int REF_COUNT = 0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend, FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend,
uInt32 width, uInt32 height, uInt32 width, uInt32 height,
@ -50,7 +48,6 @@ FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend,
: myBackend{backend}, : myBackend{backend},
myInterpolationMode{inter} myInterpolationMode{inter}
{ {
REF_COUNT++;
createSurface(width, height, staticData); createSurface(width, height, staticData);
} }
@ -61,8 +58,6 @@ FBSurfaceSDL2::~FBSurfaceSDL2()
if(mySurface) if(mySurface)
{ {
REF_COUNT--;
cerr << " ~FBSurfaceSDL2(): " << this << " " << REF_COUNT << endl;
SDL_FreeSurface(mySurface); SDL_FreeSurface(mySurface);
mySurface = nullptr; mySurface = nullptr;
} }

View File

@ -67,7 +67,6 @@ FrameBuffer::FrameBuffer(OSystem& osystem)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBuffer::~FrameBuffer() FrameBuffer::~FrameBuffer()
{ {
cerr << "~FrameBuffer()" << endl << endl;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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) const string& title, int x, int y, int w, int h)
: GuiObject(instance, parent, *this, x, y, w, h), : GuiObject(instance, parent, *this, x, y, w, h),
_font{font}, _font{font},
_title{title} _title{title},
_renderCallback{[]() { return; }}
{ {
_flags = Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG; _flags = Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG;
setTitle(title); setTitle(title);
@ -75,8 +76,6 @@ Dialog::~Dialog()
_firstWidget = nullptr; _firstWidget = nullptr;
_buttonGroup.clear(); _buttonGroup.clear();
cerr << "\n~Dialog(): " << this << endl;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -163,6 +162,12 @@ void Dialog::setDirtyChain()
_dirtyChain = true; _dirtyChain = true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::resetSurfaces()
{
_surface->reload();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::tick() void Dialog::tick()
{ {
@ -241,11 +246,7 @@ void Dialog::render()
// Update dialog surface; also render any extra surfaces // Update dialog surface; also render any extra surfaces
// Extra surfaces must be rendered afterwards, so they are drawn on top // Extra surfaces must be rendered afterwards, so they are drawn on top
if(_surface->render()) if(_surface->render())
{ _renderCallback();
mySurfaceStack.applyAll([](unique_ptr<FBSurface>& surface) {
surface->render();
});
}
// A dialog is still on top if a non-shading dialog (e.g. ContextMenu) // A dialog is still on top if a non-shading dialog (e.g. ContextMenu)
// is opended above it. // is opended above it.
@ -422,10 +423,9 @@ void Dialog::buildCurrentFocusList(int tabID)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::addSurface(const unique_ptr<FBSurface>& surface) void Dialog::addRenderCallback(const std::function<void()>& callback)
{ {
// FIXME : add this to the stack somehow _renderCallback = callback;
// mySurfaceStack.push(surface);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -28,7 +28,6 @@ class TabWidget;
class CommandSender; class CommandSender;
class ToolTip; class ToolTip;
#include "Stack.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#include "GuiObject.hxx" #include "GuiObject.hxx"
#include "StellaKeys.hxx" #include "StellaKeys.hxx"
@ -45,6 +44,8 @@ class Dialog : public GuiObject
friend class DialogContainer; friend class DialogContainer;
public: public:
using RenderCallback = std::function<void()>;
Dialog(OSystem& instance, DialogContainer& parent, Dialog(OSystem& instance, DialogContainer& parent,
int x = 0, int y = 0, int w = 0, int h = 0); int x = 0, int y = 0, int w = 0, int h = 0);
Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font,
@ -62,6 +63,8 @@ class Dialog : public GuiObject
virtual void saveConfig() { } virtual void saveConfig() { }
virtual void setDefaults() { } virtual void setDefaults() { }
virtual void resetSurfaces();
void setDirty() override; void setDirty() override;
void setDirtyChain() override; void setDirtyChain() override;
void redraw(bool force = false); void redraw(bool force = false);
@ -85,12 +88,11 @@ class Dialog : public GuiObject
FBSurface& surface() const { return *_surface; } FBSurface& surface() const { return *_surface; }
/** /**
Adds a surface to this dialog, which is rendered on top of the This method is called each time the main Dialog::render is called.
base surface whenever the base surface is re-rendered. Since It is called *after* the dialog has been rendered, so it can be
the surface render() call will always occur in such a case, the used to render another surface on top of it, among other things.
surface should call setVisible() to enable/disable its output.
*/ */
void addSurface(const unique_ptr<FBSurface>& surface); void addRenderCallback(const RenderCallback& callback);
void setTitle(const string& title); void setTitle(const string& title);
bool hasTitle() { return !_title.empty(); } bool hasTitle() { return !_title.empty(); }
@ -253,7 +255,7 @@ class Dialog : public GuiObject
uInt32 _max_w{0}; // maximum wanted width uInt32 _max_w{0}; // maximum wanted width
uInt32 _max_h{0}; // maximum wanted height uInt32 _max_h{0}; // maximum wanted height
Common::FixedStack<unique_ptr<FBSurface>> mySurfaceStack; RenderCallback _renderCallback;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported

View File

@ -203,7 +203,7 @@ void DialogContainer::reStack()
void DialogContainer::resetSurfaces() void DialogContainer::resetSurfaces()
{ {
myDialogStack.applyAll([&](Dialog*& d) { myDialogStack.applyAll([&](Dialog*& d) {
d->surface().reload(); d->resetSurfaces();
}); });
} }

View File

@ -350,6 +350,15 @@ void LauncherDialog::reload()
myPendingReload = false; myPendingReload = false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::resetSurfaces()
{
if(myRomInfoWidget)
myRomInfoWidget->resetSurfaces();
Dialog::resetSurfaces();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::tick() void LauncherDialog::tick()
{ {

View File

@ -108,6 +108,7 @@ class LauncherDialog : public Dialog
void loadConfig() override; void loadConfig() override;
void saveConfig() override; void saveConfig() override;
void resetSurfaces() override;
void updateUI(); void updateUI();
/** /**

View File

@ -94,7 +94,11 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node)
myAvail.w, myAvail.h, ScalingInterpolation::blur); myAvail.w, myAvail.h, ScalingInterpolation::blur);
mySurface->applyAttributes(); mySurface->applyAttributes();
dialog().addSurface(mySurface); dialog().addRenderCallback([this]() {
if(mySurfaceIsValid)
mySurface->render();
}
);
} }
// Initialize to empty properties entry // Initialize to empty properties entry
@ -169,6 +173,13 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node)
setDirty(); setDirty();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomInfoWidget::resetSurfaces()
{
if(mySurface)
mySurface->reload();
}
#ifdef PNG_SUPPORT #ifdef PNG_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool RomInfoWidget::loadPng(const string& filename) bool RomInfoWidget::loadPng(const string& filename)

View File

@ -39,6 +39,8 @@ class RomInfoWidget : public Widget
void clearProperties(); void clearProperties();
void reloadProperties(const FilesystemNode& node); void reloadProperties(const FilesystemNode& node);
void resetSurfaces();
protected: protected:
void drawWidget(bool hilite) override; void drawWidget(bool hilite) override;