GSDump: implement dump preview

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2021-01-30 04:46:04 +01:00 committed by Kojin
parent 1f5c0639b9
commit f1df1de64f
2 changed files with 20 additions and 15 deletions

View File

@ -35,6 +35,7 @@
#include <wx/treectrl.h> #include <wx/treectrl.h>
#include <wx/checkbox.h> #include <wx/checkbox.h>
#include <wx/dir.h> #include <wx/dir.h>
#include <wx/image.h>
using namespace pxSizerFlags; using namespace pxSizerFlags;
@ -44,7 +45,8 @@ using namespace pxSizerFlags;
Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent) Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent)
: wxDialogWithHelpers(parent, _("GSDumpGov"), pxDialogFlags()) : wxDialogWithHelpers(parent, _("GSDumpGov"), pxDialogFlags())
, m_dump_list(new wxListView(this, wxID_ANY, wxDefaultPosition, wxSize(250, 200))) , m_dump_list(new wxListView(this, ID_DUMP_LIST, wxDefaultPosition, wxSize(250, 200)))
, m_preview_image(new wxStaticBitmap(this, wxID_ANY, wxBitmap(EmbeddedImage<res_NoIcon>().Get())))
{ {
const float scale = MSW_GetDPIScale(); const float scale = MSW_GetDPIScale();
SetMinWidth(scale * 460); SetMinWidth(scale * 460);
@ -90,9 +92,7 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent)
dumps_list += m_dump_list; dumps_list += m_dump_list;
dump_preview += new wxStaticText(this, wxID_ANY, _("Preview")); dump_preview += new wxStaticText(this, wxID_ANY, _("Preview"));
wxImage img = EmbeddedImage<res_NoIcon>().Get(); dump_preview += m_preview_image;
img.Rescale(250 * scale, 200 * scale, wxIMAGE_QUALITY_HIGH);
dump_preview += new wxStaticBitmap(this, wxID_ANY, wxBitmap(img));
dumps += dumps_list; dumps += dumps_list;
@ -113,26 +113,30 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent)
void Dialogs::GSDumpDialog::GetDumpsList() void Dialogs::GSDumpDialog::GetDumpsList()
{ {
wxDir snaps(g_Conf->Folders.Snapshots.GetFilename().GetName()); wxDir snaps(g_Conf->Folders.Snapshots.ToAscii());
wxString filename; wxString filename;
bool cont = snaps.GetFirst(&filename, "*.gs", wxDIR_DEFAULT); bool cont = snaps.GetFirst(&filename, "*.gs", wxDIR_DEFAULT);
int i = 0; int i = 0;
m_dump_list->AppendColumn("Dumps");
while (cont) while (cont)
{ {
m_dump_list->InsertItem(i, filename.c_str()); m_dump_list->InsertItem(i, filename.substr(0, filename.find_last_of(".")));
i++; i++;
cont = snaps.GetNext(&filename); cont = snaps.GetNext(&filename);
} }
} }
Dialogs::GSDumpDialog::~GSDumpDialog()
{
// we can't use smart pointers because of wxWidgets operator overload so we
// do the next best thing and handle the manual memory management ourselves
delete m_dump_list;
}
void Dialogs::GSDumpDialog::SelectedDump(wxListEvent& evt) void Dialogs::GSDumpDialog::SelectedDump(wxListEvent& evt)
{ {
//evt->GetText(); wxString filename = g_Conf->Folders.Snapshots.ToAscii() + ("/" + evt.GetText()) + ".png";
if (wxFileExists(filename))
{
auto img = wxImage(filename);
img.Rescale(250 * MSW_GetDPIScale(), 200 * MSW_GetDPIScale(), wxIMAGE_QUALITY_HIGH);
m_preview_image->SetBitmap(wxBitmap(img));
}
else
{
m_preview_image->SetBitmap(EmbeddedImage<res_NoIcon>().Get());
}
} }

View File

@ -72,7 +72,7 @@ namespace Dialogs
{ {
public: public:
GSDumpDialog(wxWindow* parent = NULL); GSDumpDialog(wxWindow* parent = NULL);
virtual ~GSDumpDialog(); virtual ~GSDumpDialog() = default;
static wxString GetNameStatic() static wxString GetNameStatic()
{ {
@ -85,6 +85,7 @@ namespace Dialogs
protected: protected:
wxListView* m_dump_list; wxListView* m_dump_list;
wxStaticBitmap* m_preview_image;
void GetDumpsList(); void GetDumpsList();
void SelectedDump(wxListEvent& evt); void SelectedDump(wxListEvent& evt);
enum enum