Clean html components

This commit is contained in:
momo5502 2019-01-06 01:10:30 +01:00
parent ba38d467de
commit fa76233e1f
10 changed files with 55 additions and 52 deletions

View File

@ -3,7 +3,6 @@
html_argument::html_argument(VARIANT* val) : value_(val) html_argument::html_argument(VARIANT* val) : value_(val)
{ {
} }
bool html_argument::is_empty() const bool html_argument::is_empty() const
@ -13,25 +12,25 @@ bool html_argument::is_empty() const
bool html_argument::is_string() const bool html_argument::is_string() const
{ {
if(this->is_empty()) return false; if (this->is_empty()) return false;
return this->value_->vt == VT_BSTR; return this->value_->vt == VT_BSTR;
} }
bool html_argument::is_number() const bool html_argument::is_number() const
{ {
if(this->is_empty()) return false; if (this->is_empty()) return false;
return this->value_->vt == VT_I4; return this->value_->vt == VT_I4;
} }
std::string html_argument::get_string() const std::string html_argument::get_string() const
{ {
if(!this->is_string()) return {}; if (!this->is_string()) return {};
std::wstring wide_string(this->value_->bstrVal); std::wstring wide_string(this->value_->bstrVal);
return std::string(wide_string.begin(), wide_string.end()); return std::string(wide_string.begin(), wide_string.end());
} }
int html_argument::get_number() const int html_argument::get_number() const
{ {
if(!this->is_number()) return 0; if (!this->is_number()) return 0;
return this->value_->intVal; return this->value_->intVal;
} }

View File

@ -1,18 +1,18 @@
#pragma once #pragma once
class html_argument final class html_argument final
{ {
public: public:
html_argument(VARIANT* val); html_argument(VARIANT* val);
bool is_empty() const; bool is_empty() const;
bool is_string() const; bool is_string() const;
bool is_number() const; bool is_number() const;
std::string get_string() const; std::string get_string() const;
int get_number() const; int get_number() const;
private: private:
VARIANT* value_; VARIANT* value_;
}; };

View File

@ -41,7 +41,7 @@ HRESULT html_dispatch::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
HRESULT html_dispatch::GetIDsOfNames(const IID& riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) HRESULT html_dispatch::GetIDsOfNames(const IID& riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{ {
for(unsigned int i = 0; i < cNames; ++i) for (unsigned int i = 0; i < cNames; ++i)
{ {
std::wstring wide_name(rgszNames[i]); std::wstring wide_name(rgszNames[i]);
std::string name(wide_name.begin(), wide_name.end()); std::string name(wide_name.begin(), wide_name.end());
@ -53,7 +53,7 @@ HRESULT html_dispatch::GetIDsOfNames(const IID& riid, LPOLESTR* rgszNames, UINT
} }
HRESULT html_dispatch::Invoke(DISPID dispIdMember, const IID& riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, HRESULT html_dispatch::Invoke(DISPID dispIdMember, const IID& riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{ {
html_frame::callback_params params(pDispParams, pVarResult); html_frame::callback_params params(pDispParams, pVarResult);
this->frame_->invoke_callback(dispIdMember, &params); this->frame_->invoke_callback(dispIdMember, &params);

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "window.hpp" #include "../window.hpp"
#include "html/html_frame.hpp" #include "html_frame.hpp"
class html_window final : public window, public html_frame class html_window final : public window, public html_frame
{ {

View File

@ -12,13 +12,13 @@ void launcher::create_main_menu()
{ {
this->main_window_.register_callback("selectMode", [this](html_frame::callback_params* params) this->main_window_.register_callback("selectMode", [this](html_frame::callback_params* params)
{ {
if(params->arguments.empty()) return; if (params->arguments.empty()) return;
const auto param = params->arguments[0]; const auto param = params->arguments[0];
if(!param.is_number()) return; if (!param.is_number()) return;
const auto number = param.get_number(); const auto number = param.get_number();
if(number == singleplayer || number == multiplayer) if (number == singleplayer || number == multiplayer)
{ {
this->select_mode(static_cast<mode>(number)); this->select_mode(static_cast<mode>(number));
} }
@ -29,15 +29,16 @@ void launcher::create_main_menu()
this->settings_window_.show(); this->settings_window_.show();
}); });
this->main_window_.set_callback([](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT 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(); if (message == WM_CLOSE)
} {
window::close_all();
}
return DefWindowProcA(*window, message, w_param, l_param); return DefWindowProcA(*window, message, w_param, l_param);
}); });
this->main_window_.create("Open-IW5", 615, 300); this->main_window_.create("Open-IW5", 615, 300);
this->main_window_.load_html(load_content(MENU_MAIN)); this->main_window_.load_html(load_content(MENU_MAIN));
@ -46,18 +47,20 @@ void launcher::create_main_menu()
void launcher::create_settings_menu() void launcher::create_settings_menu()
{ {
this->settings_window_.set_callback([](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT 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(); if (message == WM_CLOSE)
return TRUE; {
} window->hide();
return TRUE;
}
return DefWindowProcA(*window, message, w_param, l_param); return DefWindowProcA(*window, message, w_param, l_param);
}); });
this->settings_window_.create("Open-IW5 Settings", 400, 200); this->settings_window_.create("Open-IW5 Settings", 400, 200,
WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
this->settings_window_.load_html(load_content(MENU_SETTINGS)); this->settings_window_.load_html(load_content(MENU_SETTINGS));
} }

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "html_window.hpp" #include "html/html_window.hpp"
class launcher final class launcher final
{ {

View File

@ -22,7 +22,7 @@ window::window()
RegisterClassEx(&this->wc_); RegisterClassEx(&this->wc_);
} }
void window::create(const std::string& title, const int width, const int height) void window::create(const std::string& title, const int width, const int height, const long flags)
{ {
{ {
std::lock_guard _(mutex_); std::lock_guard _(mutex_);
@ -32,9 +32,8 @@ void window::create(const std::string& title, const int width, const int height)
const auto x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2; const auto x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
const auto y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2; const auto y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
this->handle_ = CreateWindowExA(NULL, this->wc_.lpszClassName, title.data(), this->handle_ = CreateWindowExA(NULL, this->wc_.lpszClassName, title.data(), flags, x, y, width, height, nullptr,
WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX), x, y, width, nullptr, this->wc_.hInstance, this);
height, nullptr, nullptr, this->wc_.hInstance, this);
} }
window::~window() window::~window()

View File

@ -8,7 +8,8 @@ public:
window(); window();
virtual ~window(); virtual ~window();
void create(const std::string& title, int width, int height); void create(const std::string& title, int width, int height,
long flags = (WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX)));
void close(); void close();

View File

@ -39,8 +39,9 @@
.button>span { .button>span {
display: block; display: block;
margin-bottom: 10px; margin-top: -15px;
font-size: 20px; margin-bottom: 15px;
font-size: 25px;
} }
.button>img { .button>img {
@ -73,17 +74,17 @@
#settings { #settings {
position: fixed; position: fixed;
right: 3px; right: 5px;
top: 3px; top: 5px;
width: 25px; width: 25px;
height: 25px; height: 25px;
cursor:pointer; cursor:pointer;
opacity: 0.1; opacity: 0.1;
transition: all 0.08s ease-out; transition: all 0.1s ease-out;
} }
#settings:hover { #settings:hover {
opacity: 0.4; opacity: 0.3;
} }
</style> </style>
</head> </head>