diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 539118a..29a4d5e 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -15,18 +15,8 @@ * along with Memoserv. If not, see . */ -#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 -#include -#include -#include - -#include -#include +#include "run_gui.hpp" namespace { const constexpr int g_def_icon_size = 48; @@ -34,50 +24,9 @@ namespace { } //unnamed namespace int main(int argc, char* argv[]) { - using mc::psx::MemoryCard; - auto command = mc::parse_command_line(argc, argv); if (command.should_quit) return 0; - nana::form frm; - - 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(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 "); - 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; + return mc::run_gui(g_def_icon_size, g_def_icon_fps); } diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp new file mode 100644 index 0000000..ab68312 --- /dev/null +++ b/src/gui/main_window.cpp @@ -0,0 +1,52 @@ +#include "main_window.hpp" +#include "memcard/memorycard.hpp" +#include "make_nana_animation.hpp" +#include "memcard/make_memory_card.hpp" +#include +#include + +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(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 "); + 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 diff --git a/src/gui/main_window.hpp b/src/gui/main_window.hpp new file mode 100644 index 0000000..36ec0cf --- /dev/null +++ b/src/gui/main_window.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "widget/block_grid.hpp" +#include +#include + +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 diff --git a/src/gui/meson.build b/src/gui/meson.build index 96b4eb8..fddf8d7 100644 --- a/src/gui/meson.build +++ b/src/gui/meson.build @@ -37,6 +37,8 @@ executable(app_name, 'command_line.cpp', config_file, project_config_file, + 'run_gui.cpp', + 'main_window.cpp', dependencies: [ nana_dep, x11_dep, diff --git a/src/gui/run_gui.cpp b/src/gui/run_gui.cpp new file mode 100644 index 0000000..585c1a0 --- /dev/null +++ b/src/gui/run_gui.cpp @@ -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 diff --git a/src/gui/run_gui.hpp b/src/gui/run_gui.hpp new file mode 100644 index 0000000..3033ea1 --- /dev/null +++ b/src/gui/run_gui.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace mc { +int run_gui(int icon_size, int icon_fps); +} //namespace mc