From ba38d467dea2bf91fdc0bd936d2526106b478dfa Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 5 Jan 2019 23:55:17 +0100 Subject: [PATCH] Optimize settings menu --- src/launcher/html/html_frame.hpp | 2 +- src/launcher/html_window.cpp | 10 ++------ src/launcher/html_window.hpp | 3 +-- src/launcher/launcher.cpp | 43 +++++++++++++++++++++++++------- src/launcher/launcher.hpp | 3 +++ src/launcher/window.cpp | 29 +++------------------ src/launcher/window.hpp | 16 +++++------- src/resources/main.html | 2 +- src/resources/settings.html | 6 ++++- 9 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/launcher/html/html_frame.hpp b/src/launcher/html/html_frame.hpp index 5fe7da2..893954e 100644 --- a/src/launcher/html/html_frame.hpp +++ b/src/launcher/html/html_frame.hpp @@ -19,7 +19,7 @@ public: }; html_frame(); - ~html_frame(); + virtual ~html_frame(); void initialize(const HWND window); diff --git a/src/launcher/html_window.cpp b/src/launcher/html_window.cpp index 39c871a..bf01098 100644 --- a/src/launcher/html_window.cpp +++ b/src/launcher/html_window.cpp @@ -1,12 +1,6 @@ #include #include "html_window.hpp" -html_window::html_window() -{ - this->set_callback(std::bind(&html_window::handler, this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)); -} - window* html_window::get_window() { return this; @@ -17,7 +11,7 @@ html_frame* html_window::get_html_frame() return this; } -LRESULT html_window::handler(const UINT message, const WPARAM w_param, const LPARAM l_param) +LRESULT html_window::processor(const UINT message, const WPARAM w_param, const LPARAM l_param) { if (message == WM_SIZE) { @@ -31,5 +25,5 @@ LRESULT html_window::handler(const UINT message, const WPARAM w_param, const LPA return 0; } - return DefWindowProc(*this, message, w_param, l_param); + return window::processor(message, w_param, l_param); } diff --git a/src/launcher/html_window.hpp b/src/launcher/html_window.hpp index 14bacce..526518b 100644 --- a/src/launcher/html_window.hpp +++ b/src/launcher/html_window.hpp @@ -5,12 +5,11 @@ class html_window final : public window, public html_frame { public: - html_window(); ~html_window() = default; window* get_window(); html_frame* get_html_frame(); private: - LRESULT handler(const UINT message, const WPARAM w_param, const LPARAM l_param); + LRESULT processor(UINT message, WPARAM w_param, LPARAM l_param) override; }; diff --git a/src/launcher/launcher.cpp b/src/launcher/launcher.cpp index 05027e5..4711854 100644 --- a/src/launcher/launcher.cpp +++ b/src/launcher/launcher.cpp @@ -3,6 +3,12 @@ #include "utils/nt.hpp" launcher::launcher() +{ + this->create_settings_menu(); + this->create_main_menu(); +} + +void launcher::create_main_menu() { this->main_window_.register_callback("selectMode", [this](html_frame::callback_params* params) { @@ -23,25 +29,44 @@ launcher::launcher() this->settings_window_.show(); }); - this->settings_window_.set_hide_on_close(true); - this->settings_window_.create("Open-IW5 Settings", 615, 300); - this->settings_window_.load_html(load_content(MENU_SETTINGS)); + this->main_window_.set_callback([](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT + { + if(message == WM_CLOSE) + { + window::close_all(); + } + + return DefWindowProcA(*window, message, w_param, l_param); + }); - this->main_window_.set_close_all_on_close(true); this->main_window_.create("Open-IW5", 615, 300); this->main_window_.load_html(load_content(MENU_MAIN)); this->main_window_.show(); } +void launcher::create_settings_menu() +{ + this->settings_window_.set_callback([](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT + { + if(message == WM_CLOSE) + { + window->hide(); + return TRUE; + } + + return DefWindowProcA(*window, message, w_param, l_param); + }); + + this->settings_window_.create("Open-IW5 Settings", 400, 200); + this->settings_window_.load_html(load_content(MENU_SETTINGS)); +} + launcher::mode launcher::run() const { window::run(); - return this->mode_; } - - void launcher::select_mode(const mode mode) { this->mode_ = mode; @@ -49,9 +74,9 @@ void launcher::select_mode(const mode mode) this->main_window_.close(); } -std::string launcher::load_content(int res) +std::string launcher::load_content(const int res) { - const auto resource = FindResource(::utils::nt::module(), MAKEINTRESOURCE(res), RT_RCDATA); + const auto resource = FindResource(utils::nt::module(), MAKEINTRESOURCE(res), RT_RCDATA); if (!res) return {}; const auto handle = LoadResource(nullptr, resource); diff --git a/src/launcher/launcher.hpp b/src/launcher/launcher.hpp index d18dfc4..4333bb6 100644 --- a/src/launcher/launcher.hpp +++ b/src/launcher/launcher.hpp @@ -24,5 +24,8 @@ private: void select_mode(mode mode); + void create_main_menu(); + void create_settings_menu(); + static std::string load_content(int res); }; diff --git a/src/launcher/window.cpp b/src/launcher/window.cpp index 1abd3d5..7a3f814 100644 --- a/src/launcher/window.cpp +++ b/src/launcher/window.cpp @@ -125,36 +125,13 @@ void window::hide() const UpdateWindow(this->handle_); } -void window::set_hide_on_close(const bool value) -{ - this->hide_on_close_ = value; -} - -void window::set_close_all_on_close(const bool value) -{ - this->close_all_on_close_ = value; -} - -void window::set_callback(const std::function& callback) +void window::set_callback(const std::function& callback) { this->callback_ = callback; } -LRESULT CALLBACK window::processor(const UINT message, const WPARAM w_param, const LPARAM l_param) const +LRESULT window::processor(const UINT message, const WPARAM w_param, const LPARAM l_param) { - if (message == WM_CLOSE) - { - if (this->hide_on_close_) - { - this->hide(); - return TRUE; - } - else if (this->close_all_on_close_) - { - close_all(); - } - } - if (message == WM_DESTROY) { remove_window(this); @@ -175,7 +152,7 @@ LRESULT CALLBACK window::processor(const UINT message, const WPARAM w_param, con if (this->callback_) { - return this->callback_(message, w_param, l_param); + return this->callback_(this, message, w_param, l_param); } return DefWindowProc(*this, message, w_param, l_param); diff --git a/src/launcher/window.hpp b/src/launcher/window.hpp index 22f3a4f..a4471d7 100644 --- a/src/launcher/window.hpp +++ b/src/launcher/window.hpp @@ -6,7 +6,7 @@ class window { public: window(); - ~window(); + virtual ~window(); void create(const std::string& title, int width, int height); @@ -15,26 +15,22 @@ public: void show() const; void hide() const; - void set_hide_on_close(bool value); - void set_close_all_on_close(bool value); - - void set_callback(const std::function& callback); + void set_callback(const std::function& callback); operator HWND() const; static void run(); static void close_all(); -private: - bool hide_on_close_ = false; - bool close_all_on_close_ = false; +protected: + virtual LRESULT processor(UINT message, WPARAM w_param, LPARAM l_param); +private: WNDCLASSEX wc_{}; HWND handle_ = nullptr; std::string classname_; - std::function callback_; + std::function callback_; - LRESULT CALLBACK processor(UINT message, WPARAM w_param, LPARAM l_param) const; static LRESULT CALLBACK static_processor(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param); static std::mutex mutex_; diff --git a/src/resources/main.html b/src/resources/main.html index ab5236a..b69a53d 100644 --- a/src/resources/main.html +++ b/src/resources/main.html @@ -49,7 +49,7 @@ border-radius: 7px; transition: all 0.08s ease-out; cursor: pointer; - box-shadow: 0px 2px 40px 10px rgba(0, 0, 0, 0.3); + box-shadow: 0px 2px 30px 10px rgba(0, 0, 0, 0.3); } .button>img:hover { diff --git a/src/resources/settings.html b/src/resources/settings.html index f5049b9..86093fa 100644 --- a/src/resources/settings.html +++ b/src/resources/settings.html @@ -28,12 +28,16 @@ overflow: hidden; } + + .content { + text-align: center; + }
- +

No settings, yet!