From a0581cb7ab61754359461cdb759b29b8be7a7208 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 21 Mar 2020 10:32:18 +0100 Subject: [PATCH] Refactor a bit more and add menu bar and version window. --- meson.build | 1 + src/config.h.in | 1 + src/gui/main.cpp | 14 ++++++++- src/gui/main_window.cpp | 18 ++++++++++- src/gui/main_window.hpp | 7 ++++- src/gui/meson.build | 1 + src/gui/run_gui.cpp | 3 +- src/gui/version_window.cpp | 62 ++++++++++++++++++++++++++++++++++++++ src/gui/version_window.hpp | 22 ++++++++++++++ 9 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 src/gui/version_window.cpp create mode 100644 src/gui/version_window.hpp diff --git a/meson.build b/meson.build index 2e45960..28086b5 100644 --- a/meson.build +++ b/meson.build @@ -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', diff --git a/src/config.h.in b/src/config.h.in index bd230fa..a5e20ed 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -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 diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 29a4d5e..7dfa06f 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -17,6 +17,9 @@ #include "command_line.hpp" #include "run_gui.hpp" +#if !defined(NDEBUG) +# include +#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; } diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp index 1d629d0..b2c9d8d 100644 --- a/src/gui/main_window.cpp +++ b/src/gui/main_window.cpp @@ -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 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 diff --git a/src/gui/main_window.hpp b/src/gui/main_window.hpp index 32f189e..2cad5d5 100644 --- a/src/gui/main_window.hpp +++ b/src/gui/main_window.hpp @@ -3,17 +3,22 @@ #include "widget/block_grid.hpp" #include #include +#include +#include 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; diff --git a/src/gui/meson.build b/src/gui/meson.build index fddf8d7..0ad481a 100644 --- a/src/gui/meson.build +++ b/src/gui/meson.build @@ -39,6 +39,7 @@ executable(app_name, project_config_file, 'run_gui.cpp', 'main_window.cpp', + 'version_window.cpp', dependencies: [ nana_dep, x11_dep, diff --git a/src/gui/run_gui.cpp b/src/gui/run_gui.cpp index 585c1a0..9ae131f 100644 --- a/src/gui/run_gui.cpp +++ b/src/gui/run_gui.cpp @@ -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(); diff --git a/src/gui/version_window.cpp b/src/gui/version_window.cpp new file mode 100644 index 0000000..523da28 --- /dev/null +++ b/src/gui/version_window.cpp @@ -0,0 +1,62 @@ +#include "version_window.hpp" +#include "app_config.h" +#include "config.h" +#include + +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 .\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("" APP_NAME ""); + + m_short_desc.format(true); + m_short_desc.caption(std::string("is part of " 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("" + 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 <>> >"); + (*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 diff --git a/src/gui/version_window.hpp b/src/gui/version_window.hpp new file mode 100644 index 0000000..c2c09f6 --- /dev/null +++ b/src/gui/version_window.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +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