Refactor a bit more and add menu bar and version window.

This commit is contained in:
King_DuckZ 2020-03-21 10:32:18 +01:00
parent bcbefd45c9
commit a0581cb7ab
9 changed files with 125 additions and 4 deletions

View file

@ -20,6 +20,7 @@ conf.set('PROJECT_VERSION_PATCH', version_arr[2])
conf.set('COMPILER_NAME', cpp.get_id())
conf.set('COMPILER_VERSION', cpp.version())
conf.set('COPYRIGHT_YEAR', '2020')
conf.set('PROJECT_REPO_URL', 'https://alarmpi.no-ip.org/gitan/King_DuckZ/memoserv')
project_config_file = configure_file(
input: 'src/config.h.in',
output: 'config.h',

View file

@ -24,6 +24,7 @@
#define COMPILER_NAME "@COMPILER_NAME@"
#define COMPILER_VERSION "@COMPILER_VERSION@"
#define COPYRIGHT_YEAR "@COPYRIGHT_YEAR@"
#define PROJECT_REPO_URL "@PROJECT_REPO_URL@"
#if !defined(STRINGIZE)
# define STRINGIZE_IMPL(s) #s

View file

@ -17,6 +17,9 @@
#include "command_line.hpp"
#include "run_gui.hpp"
#if !defined(NDEBUG)
# include <iostream>
#endif
namespace {
const constexpr int g_def_icon_size = 48;
@ -24,9 +27,18 @@ namespace {
} //unnamed namespace
int main(int argc, char* argv[]) {
#if !defined(NDEBUG)
std::cout << "Starting program\n";
#endif
auto command = mc::parse_command_line(argc, argv);
if (command.should_quit)
return 0;
return mc::run_gui(g_def_icon_size, g_def_icon_fps);
const int retval = mc::run_gui(g_def_icon_size, g_def_icon_fps);
#if !defined(NDEBUG)
std::cout << "Leaving program with return code " << retval << '\n';
#endif
return retval;
}

View file

@ -1,4 +1,5 @@
#include "main_window.hpp"
#include "version_window.hpp"
#include "memcard/memorycard.hpp"
#include "make_nana_animation.hpp"
#include "memcard/make_memory_card.hpp"
@ -6,11 +7,12 @@
#include <fstream>
namespace mc {
MainWindow::MainWindow (int icon_size, int icon_fps) :
MainWindow::MainWindow (int icon_size, int icon_fps, const std::string& caption) :
m_grid1(*this, 3, true),
m_grid2(*this, 3, true),
m_label1(*this, "Slot 1"),
m_label2(*this, "Slot 2"),
m_menubar(*this),
m_icon_size(icon_size),
m_icon_fps(icon_fps)
{
@ -19,6 +21,8 @@ MainWindow::MainWindow (int icon_size, int icon_fps) :
#if !defined(NDEBUG)
m_grid1.bgcolor(nana::colors::azure);
#endif
this->caption(caption);
this->init_menu();
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"));
@ -44,4 +48,16 @@ MainWindow::MainWindow (int icon_size, int icon_fps) :
//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::init_menu() {
m_menubar.push_back("&File");
m_menubar.at(0).append("E&xit", [](nana::menu::item_proxy&){nana::API::exit();});
m_menubar.push_back("&Help");
m_menubar.at(1).append("Version info", [this](nana::menu::item_proxy&) {
VersionWindow win(*this);
win.show();
win.modality();
});
}
} //namespace mc

View file

@ -3,17 +3,22 @@
#include "widget/block_grid.hpp"
#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/menubar.hpp>
#include <string>
namespace mc {
class MainWindow : public nana::form {
public:
MainWindow (int icon_size, int icon_fps);
MainWindow (int icon_size, int icon_fps, const std::string& caption);
private:
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;
int m_icon_size;
int m_icon_fps;

View file

@ -39,6 +39,7 @@ executable(app_name,
project_config_file,
'run_gui.cpp',
'main_window.cpp',
'version_window.cpp',
dependencies: [
nana_dep,
x11_dep,

View file

@ -1,9 +1,10 @@
#include "run_gui.hpp"
#include "main_window.hpp"
#include "app_config.h"
namespace mc {
int run_gui(int icon_size, int icon_fps) {
MainWindow win(icon_size, icon_fps);
MainWindow win(icon_size, icon_fps, APP_NAME);
win.show();
nana::exec();

View file

@ -0,0 +1,62 @@
#include "version_window.hpp"
#include "app_config.h"
#include "config.h"
#include <string>
namespace mc {
namespace {
const constexpr char g_gpl_text[] =
APP_SHORT_DESC "\n"
"Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n"
"\n"
"This program is free software: you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation, either version 3 of the License, or\n"
"(at your option) any later version.\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program. If not, see <https://www.gnu.org/licenses/>.\n"
;
} //unnamed namespace
VersionWindow::VersionWindow(nana::window owner) :
nana::form(owner, nana::size{615, 505}),
m_top_label(*this),
m_short_desc(*this),
m_repo_link_1(*this),
m_repo_link_2(*this),
m_main_text(*this),
m_close(*this)
{
using std::string;
m_top_label.format(true);
m_top_label.caption("<size=14 center><bold>" APP_NAME "</></>");
m_short_desc.format(true);
m_short_desc.caption(std::string("is part of <bold>" PROJECT_NAME "</> v") + project_ver());
m_repo_link_1.format(true);
m_repo_link_1.caption("Official source code repository is available here:");
m_repo_link_2.format(true);
m_repo_link_2.caption(string("<url=\"") + PROJECT_REPO_URL + "\">" + PROJECT_REPO_URL + "</>");
m_main_text.editable(false);
m_main_text.caption(g_gpl_text);
m_close.caption("&Close");
m_close.events().click([this]() { this->close(); });
this->div("< vert margin=10 <vert top_label fit> <max=15> <main_text min=300> <max=15> <max=35 min=25 <><close><>> >");
(*this)["top_label"] << m_top_label << m_short_desc << m_repo_link_1 << m_repo_link_2;
(*this)["main_text"] << m_main_text;
(*this)["close"] << m_close;
this->collocate();
}
} //namespace mc

View file

@ -0,0 +1,22 @@
#pragma once
#include <nana/gui.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/textbox.hpp>
namespace mc {
class VersionWindow : public nana::form {
public:
VersionWindow(nana::window owner);
~VersionWindow() noexcept = default;
private:
nana::label m_top_label;
nana::label m_short_desc;
nana::label m_repo_link_1;
nana::label m_repo_link_2;
nana::textbox m_main_text;
nana::button m_close;
};
} //namespace mc