Refactor window creation stuff outside of main()
This commit is contained in:
parent
5d5cba5e3f
commit
1c3de27a16
6 changed files with 96 additions and 53 deletions
|
@ -15,18 +15,8 @@
|
||||||
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
* along with Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "memcard/memorycard.hpp"
|
|
||||||
#include "widget/block_grid.hpp"
|
|
||||||
#include "make_nana_animation.hpp"
|
|
||||||
#include "memcard/make_memory_card.hpp"
|
|
||||||
#include "command_line.hpp"
|
#include "command_line.hpp"
|
||||||
#include <nana/gui.hpp>
|
#include "run_gui.hpp"
|
||||||
#include <nana/gui/widgets/label.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const constexpr int g_def_icon_size = 48;
|
const constexpr int g_def_icon_size = 48;
|
||||||
|
@ -34,50 +24,9 @@ namespace {
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
using mc::psx::MemoryCard;
|
|
||||||
|
|
||||||
auto command = mc::parse_command_line(argc, argv);
|
auto command = mc::parse_command_line(argc, argv);
|
||||||
if (command.should_quit)
|
if (command.should_quit)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
nana::form frm;
|
return mc::run_gui(g_def_icon_size, g_def_icon_fps);
|
||||||
|
|
||||||
const MemoryCard mc1(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/epsxe000_xa2.mcr"));
|
|
||||||
const MemoryCard mc2(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/michele_epsxe000.mcr"));
|
|
||||||
|
|
||||||
#if !defined(NDEBUG)
|
|
||||||
//grid1.bgcolor(nana::colors::azure);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
duck::widget::BlockGrid grid1{frm, 3, true};
|
|
||||||
duck::widget::BlockGrid grid2{frm, 3, true};
|
|
||||||
|
|
||||||
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())
|
|
||||||
grid1.emplace_back(duck::make_nana_animation(mc1[z], g_def_icon_size, g_def_icon_size, g_def_icon_fps));
|
|
||||||
if (mc2[z].has_magic())
|
|
||||||
grid2.emplace_back(duck::make_nana_animation(mc2[z], g_def_icon_size, g_def_icon_size, g_def_icon_fps));
|
|
||||||
}
|
|
||||||
|
|
||||||
nana::label label1 {frm, "Slot 1"};
|
|
||||||
nana::label label2 {frm, "Slot 2"};
|
|
||||||
|
|
||||||
std::cout << "Hello world\n";
|
|
||||||
frm.div("fit margin=3 <vert fit slot1> <width=25> <vert fit slot2>");
|
|
||||||
frm["slot1"] << label1 << grid1;
|
|
||||||
frm["slot2"] << label2 << grid2;
|
|
||||||
frm.collocate();
|
|
||||||
frm.show();
|
|
||||||
|
|
||||||
//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));
|
|
||||||
|
|
||||||
|
|
||||||
nana::exec();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
52
src/gui/main_window.cpp
Normal file
52
src/gui/main_window.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#include "main_window.hpp"
|
||||||
|
#include "memcard/memorycard.hpp"
|
||||||
|
#include "make_nana_animation.hpp"
|
||||||
|
#include "memcard/make_memory_card.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace mc {
|
||||||
|
MainWindow::MainWindow (int icon_size, int icon_fps) :
|
||||||
|
m_frm(),
|
||||||
|
m_grid1(m_frm, 3, true),
|
||||||
|
m_grid2(m_frm, 3, true),
|
||||||
|
m_label1(m_frm, "Slot 1"),
|
||||||
|
m_label2(m_frm, "Slot 2"),
|
||||||
|
m_icon_size(icon_size),
|
||||||
|
m_icon_fps(icon_fps)
|
||||||
|
{
|
||||||
|
using mc::psx::MemoryCard;
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
m_grid1.bgcolor(nana::colors::azure);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const MemoryCard mc1(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/epsxe000_xa2.mcr"));
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_frm.div("fit margin=3 <vert fit slot1> <width=25> <vert fit slot2>");
|
||||||
|
m_frm["slot1"] << m_label1 << m_grid1;
|
||||||
|
m_frm["slot2"] << m_label2 << m_grid2;
|
||||||
|
m_frm.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));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::show() {
|
||||||
|
m_frm.show();
|
||||||
|
}
|
||||||
|
} //namespace mc
|
23
src/gui/main_window.hpp
Normal file
23
src/gui/main_window.hpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "widget/block_grid.hpp"
|
||||||
|
#include <nana/gui.hpp>
|
||||||
|
#include <nana/gui/widgets/label.hpp>
|
||||||
|
|
||||||
|
namespace mc {
|
||||||
|
class MainWindow {
|
||||||
|
public:
|
||||||
|
MainWindow (int icon_size, int icon_fps);
|
||||||
|
void show();
|
||||||
|
|
||||||
|
private:
|
||||||
|
nana::form m_frm;
|
||||||
|
duck::widget::BlockGrid m_grid1;
|
||||||
|
duck::widget::BlockGrid m_grid2;
|
||||||
|
nana::label m_label1;
|
||||||
|
nana::label m_label2;
|
||||||
|
|
||||||
|
int m_icon_size;
|
||||||
|
int m_icon_fps;
|
||||||
|
};
|
||||||
|
} //namespace mc
|
|
@ -37,6 +37,8 @@ executable(app_name,
|
||||||
'command_line.cpp',
|
'command_line.cpp',
|
||||||
config_file,
|
config_file,
|
||||||
project_config_file,
|
project_config_file,
|
||||||
|
'run_gui.cpp',
|
||||||
|
'main_window.cpp',
|
||||||
dependencies: [
|
dependencies: [
|
||||||
nana_dep,
|
nana_dep,
|
||||||
x11_dep,
|
x11_dep,
|
||||||
|
|
12
src/gui/run_gui.cpp
Normal file
12
src/gui/run_gui.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include "run_gui.hpp"
|
||||||
|
#include "main_window.hpp"
|
||||||
|
|
||||||
|
namespace mc {
|
||||||
|
int run_gui(int icon_size, int icon_fps) {
|
||||||
|
MainWindow win(icon_size, icon_fps);
|
||||||
|
win.show();
|
||||||
|
|
||||||
|
nana::exec();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} //namespace mc
|
5
src/gui/run_gui.hpp
Normal file
5
src/gui/run_gui.hpp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace mc {
|
||||||
|
int run_gui(int icon_size, int icon_fps);
|
||||||
|
} //namespace mc
|
Loading…
Add table
Reference in a new issue