iw5-mod/src/launcher/launcher.cpp

110 lines
2.8 KiB
C++
Raw Normal View History

2018-12-23 07:17:08 -05:00
#include <std_include.hpp>
#include "launcher.hpp"
2018-12-23 12:25:22 -05:00
launcher::launcher() : window_("Open-IW5", 265, 432), image_sp_(IMAGE_SP), image_mp_(IMAGE_MP)
2018-12-23 07:17:08 -05:00
{
2018-12-23 12:25:22 -05:00
this->image_sp_.set_position({75, 50});
this->image_mp_.set_position({75, 252});
2018-12-23 07:17:08 -05:00
2018-12-23 12:25:22 -05:00
this->image_sp_.set_size({100, 100});
this->image_mp_.set_size({100, 100});
this->image_sp_.set_click_listener(std::bind(&launcher::select_mode, this, mode::SINGLEPLAYER));
this->image_mp_.set_click_listener(std::bind(&launcher::select_mode, this, mode::MULTIPLAYER));
this->window_.set_callback(std::bind(&launcher::handler, this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3));
2018-12-23 07:17:08 -05:00
}
2018-12-23 12:25:22 -05:00
launcher::mode launcher::run() const
2018-12-23 07:17:08 -05:00
{
this->window_.run();
2018-12-23 12:25:22 -05:00
return this->mode_;
}
LRESULT launcher::handler(const UINT message, const WPARAM w_param, const LPARAM l_param)
{
if (message == WM_PAINT)
{
this->paint();
}
else if (message == WM_MOUSEMOVE)
{
this->mouse_move(l_param);
}
else if (message == WM_LBUTTONDOWN)
{
this->image_sp_.click(this->mouse_, true);
this->image_mp_.click(this->mouse_, true);
}
else if (message == WM_LBUTTONUP)
{
this->image_sp_.click(this->mouse_, false);
this->image_mp_.click(this->mouse_, false);
}
else if (message == WM_ERASEBKGND)
{
return TRUE;
}
return DefWindowProc(this->window_, message, w_param, l_param);
}
void launcher::select_mode(const mode mode)
{
this->mode_ = mode;
this->window_.close();
}
void launcher::draw_text(const HDC hdc)
{
Gdiplus::Graphics graphics(hdc);
Gdiplus::SolidBrush color(Gdiplus::Color(255, 150, 150, 150));
Gdiplus::FontFamily font_family(L"Segoe UI");
Gdiplus::Font font(&font_family, 18, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
graphics.DrawString(L"Singleplayer", -1, &font, {75, 20}, &color);
graphics.DrawString(L"Multiplayer", -1, &font, {75, 222}, &color);
Gdiplus::Pen pen(Gdiplus::Color(50, 255, 255, 255), 2);
graphics.DrawLine(&pen, 0, 200, 500, 200);
}
void launcher::paint() const
{
RECT rect;
GetClientRect(this->window_, &rect);
const int width = rect.right - rect.left;
const int height = rect.bottom + rect.left;
PAINTSTRUCT ps;
const auto hdc = BeginPaint(this->window_, &ps);
const auto hdc_copy = CreateCompatibleDC(hdc);
const auto bitmap = CreateCompatibleBitmap(hdc, width, height);
SelectObject(hdc_copy, bitmap);
this->window_.clear(hdc_copy);
this->draw_text(hdc_copy);
this->image_sp_.paint(hdc_copy, this->mouse_);
this->image_mp_.paint(hdc_copy, this->mouse_);
BitBlt(hdc, 0, 0, width, height, hdc_copy, 0, 0, SRCCOPY);
DeleteObject(bitmap);
DeleteDC(hdc_copy);
EndPaint(this->window_, &ps);
}
void launcher::mouse_move(LPARAM l_param)
{
this->mouse_.x = GET_X_LPARAM(l_param);
this->mouse_.y = GET_Y_LPARAM(l_param);
InvalidateRect(this->window_, nullptr, FALSE);
2018-12-23 07:17:08 -05:00
}