Optimize settings menu

This commit is contained in:
momo5502 2019-01-05 23:55:17 +01:00
parent a18364bfff
commit ba38d467de
9 changed files with 56 additions and 58 deletions

View File

@ -19,7 +19,7 @@ public:
};
html_frame();
~html_frame();
virtual ~html_frame();
void initialize(const HWND window);

View File

@ -1,12 +1,6 @@
#include <std_include.hpp>
#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);
}

View File

@ -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;
};

View File

@ -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);

View File

@ -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);
};

View File

@ -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<LRESULT(UINT, WPARAM, LPARAM)>& callback)
void window::set_callback(const std::function<LRESULT(window*, UINT, WPARAM, LPARAM)>& 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);

View File

@ -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<LRESULT(UINT, WPARAM, LPARAM)>& callback);
void set_callback(const std::function<LRESULT(window*, UINT, WPARAM, LPARAM)>& 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<LRESULT(UINT, WPARAM, LPARAM)> callback_;
std::function<LRESULT(window*, UINT, WPARAM, LPARAM)> 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_;

View File

@ -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 {

View File

@ -28,12 +28,16 @@
overflow: hidden;
}
.content {
text-align: center;
}
</style>
</head>
<body>
<div class="content">
<h1>No settings, yet!</h1>
</div>
</body>