Remove hardcoded paths, allow opening memory cards from menu.
I think sometimes nana deadlocks, not sure what the problem is yet.
This commit is contained in:
parent
2b48b5da41
commit
54371b62f8
2 changed files with 48 additions and 38 deletions
|
@ -3,55 +3,31 @@
|
||||||
#include "memcard/memorycard.hpp"
|
#include "memcard/memorycard.hpp"
|
||||||
#include "make_nana_animation.hpp"
|
#include "make_nana_animation.hpp"
|
||||||
#include "memcard/make_memory_card.hpp"
|
#include "memcard/make_memory_card.hpp"
|
||||||
|
#include "widget/block_grid.hpp"
|
||||||
|
#include <nana/gui/filebox.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <cassert>
|
||||||
|
|
||||||
namespace duck {
|
namespace duck {
|
||||||
MainWindow::MainWindow (int icon_size, int icon_fps, const std::string& caption) :
|
MainWindow::MainWindow (int icon_size, int icon_fps, const std::string& caption) :
|
||||||
m_grid1(*this, 3, true),
|
nana::form(nana::API::make_center(800, 600)),
|
||||||
m_grid2(*this, 3, true),
|
|
||||||
m_label1(*this, "Slot 1"),
|
|
||||||
m_label2(*this, "Slot 2"),
|
|
||||||
m_menubar(*this),
|
m_menubar(*this),
|
||||||
m_icon_size(icon_size),
|
m_icon_size(icon_size),
|
||||||
m_icon_fps(icon_fps)
|
m_icon_fps(icon_fps)
|
||||||
{
|
{
|
||||||
using mc::psx::MemoryCard;
|
|
||||||
|
|
||||||
#if !defined(NDEBUG)
|
|
||||||
m_grid1.bgcolor(nana::colors::azure);
|
|
||||||
#endif
|
|
||||||
this->caption(caption);
|
this->caption(caption);
|
||||||
this->init_menu();
|
this->init_menu();
|
||||||
|
|
||||||
const MemoryCard mc1(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/epsxe000_xa2.mcr"));
|
this->div("vert <menu weight=28><fit margin=3 <fit slots gap=25>>");
|
||||||
const MemoryCard mc2(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/michele_epsxe000.mcr"));
|
|
||||||
|
|
||||||
|
|
||||||
//auto mc1_info = mc1.content_info();
|
|
||||||
//std::cout << "memory card 1:\n";
|
|
||||||
//std::cout << "\tuse byte: 0x" << std::hex << mc1_info.use_byte << std::dec << '\n';
|
|
||||||
//std::cout << "\tavailable blocks: 0x" << std::hex << static_cast<int>(mc1_info.available_blocks) << std::dec << '\n';
|
|
||||||
|
|
||||||
for (int z = 0; z < 15; ++z) {
|
|
||||||
if (mc1[z].has_magic())
|
|
||||||
m_grid1.emplace_back(duck::make_nana_animation(mc1[z], m_icon_size, m_icon_size, m_icon_fps));
|
|
||||||
if (mc2[z].has_magic())
|
|
||||||
m_grid2.emplace_back(duck::make_nana_animation(mc2[z], m_icon_size, m_icon_size, m_icon_fps));
|
|
||||||
}
|
|
||||||
|
|
||||||
this->div("vert <menu weight=28><fit margin=3 <vert fit slot1> <width=25> <vert fit slot2>>");
|
|
||||||
(*this)["menu"] << m_menubar;
|
(*this)["menu"] << m_menubar;
|
||||||
(*this)["slot1"] << m_label1 << m_grid1;
|
|
||||||
(*this)["slot2"] << m_label2 << m_grid2;
|
|
||||||
this->collocate();
|
this->collocate();
|
||||||
|
|
||||||
//const MemoryCard mc(std::ifstream("/home/michele/emu/psx/WipEout 3 - Special Edition (Europe) (En,Fr,De,Es,It).srm", std::ios::binary));
|
|
||||||
//MemoryCard mc(std::ifstream("/home/michele/emu/psx/Rapid Racer (Europe) (En,Fr,De,Es,It).srm", std::ios::binary));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow() noexcept = default;
|
||||||
|
|
||||||
void MainWindow::init_menu() {
|
void MainWindow::init_menu() {
|
||||||
m_menubar.push_back("&File");
|
m_menubar.push_back("&File");
|
||||||
|
m_menubar.at(0).append("&Open...", [this](nana::menu::item_proxy&){this->open_file_from_dialog();});
|
||||||
m_menubar.at(0).append("E&xit", [](nana::menu::item_proxy&){nana::API::exit();});
|
m_menubar.at(0).append("E&xit", [](nana::menu::item_proxy&){nana::API::exit();});
|
||||||
|
|
||||||
m_menubar.push_back("&Help");
|
m_menubar.push_back("&Help");
|
||||||
|
@ -61,4 +37,30 @@ void MainWindow::init_menu() {
|
||||||
win.modality();
|
win.modality();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::open_file_from_dialog() {
|
||||||
|
nana::filebox fb(*this, true);
|
||||||
|
fb.allow_multi_select(true);
|
||||||
|
fb.add_filter(("PSX MemoryCard"), ("*.mcr;*.sav;*.srm"));
|
||||||
|
fb.add_filter(("All files"), ("*.*"));
|
||||||
|
auto files = fb();
|
||||||
|
|
||||||
|
for (const auto& file : files) {
|
||||||
|
m_memcards.push_back(mc::psx::make_memory_card(file));
|
||||||
|
m_grids.emplace_back(*this, 3, true);
|
||||||
|
m_grid_labels.emplace_back(*this, std::string("Slot ") + std::to_string(m_grid_labels.size() + 1));
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
m_grids.back().bgcolor(nana::colors::azure);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto& mc = m_memcards.back();
|
||||||
|
auto& grid = m_grids.back();
|
||||||
|
for (int z = 0; z < 15; ++z) {
|
||||||
|
if (mc[z].has_magic())
|
||||||
|
grid.emplace_back(duck::make_nana_animation(mc[z], m_icon_size, m_icon_size, m_icon_fps));
|
||||||
|
}
|
||||||
|
(*this)["slots"] << m_grids.back();
|
||||||
|
}
|
||||||
|
this->collocate();
|
||||||
|
}
|
||||||
} //namespace duck
|
} //namespace duck
|
||||||
|
|
|
@ -1,26 +1,34 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "widget/block_grid.hpp"
|
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui.hpp>
|
||||||
#include <nana/gui/widgets/label.hpp>
|
#include <nana/gui/widgets/label.hpp>
|
||||||
#include <nana/gui/widgets/menubar.hpp>
|
#include <nana/gui/widgets/menubar.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
namespace mc::psx {
|
||||||
|
class MemoryCard;
|
||||||
|
} //namespace mc::psx
|
||||||
|
|
||||||
namespace duck {
|
namespace duck {
|
||||||
|
namespace widget {
|
||||||
|
class BlockGrid;
|
||||||
|
} //namespace widget
|
||||||
|
|
||||||
class MainWindow : public nana::form {
|
class MainWindow : public nana::form {
|
||||||
public:
|
public:
|
||||||
MainWindow (int icon_size, int icon_fps, const std::string& caption);
|
MainWindow (int icon_size, int icon_fps, const std::string& caption);
|
||||||
|
~MainWindow() noexcept;
|
||||||
|
|
||||||
|
void open_file_from_dialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init_menu();
|
void init_menu();
|
||||||
|
|
||||||
duck::widget::BlockGrid m_grid1;
|
|
||||||
duck::widget::BlockGrid m_grid2;
|
|
||||||
nana::label m_label1;
|
|
||||||
nana::label m_label2;
|
|
||||||
nana::menubar m_menubar;
|
nana::menubar m_menubar;
|
||||||
|
std::list<mc::psx::MemoryCard> m_memcards;
|
||||||
|
std::list<duck::widget::BlockGrid> m_grids;
|
||||||
|
std::list<nana::label> m_grid_labels;
|
||||||
int m_icon_size;
|
int m_icon_size;
|
||||||
int m_icon_fps;
|
int m_icon_fps;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue