Skip to content

Commit

Permalink
Use GDI wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
makuke1234 committed Jan 20, 2022
1 parent 9f075de commit f6394e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
43 changes: 22 additions & 21 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ pdfv::MainWindow::MainWindow() noexcept
FF_DONTCARE,
L"Segoe UI"
);

this->m_defaultFontBold = ::CreateFontW(
dip(15, dpi.y),
0,
0,
0,
FW_BOLD,
false,
false,
false,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
FF_DONTCARE,
L"Segoe UI"
);
}

pdfv::MainWindow::~MainWindow() noexcept
Expand All @@ -121,27 +138,6 @@ pdfv::MainWindow::~MainWindow() noexcept
::DestroyWindow(this->m_hwnd);
this->m_hwnd = nullptr;
}
if (this->m_defaultFont != nullptr)
{
::DeleteObject(this->m_defaultFont);
this->m_defaultFont = nullptr;
}

if (this->m_redBrush != nullptr)
{
::DeleteObject(this->m_redBrush);
this->m_redBrush = nullptr;
}
if (this->m_brightRedBrush != nullptr)
{
::DeleteObject(this->m_brightRedBrush);
this->m_brightRedBrush = nullptr;
}
if (this->m_darkRedBrush != nullptr)
{
::DeleteObject(this->m_darkRedBrush);
this->m_darkRedBrush = nullptr;
}
}

[[nodiscard]] bool pdfv::MainWindow::init(HINSTANCE hinst, int argc, wchar_t ** argv) noexcept
Expand Down Expand Up @@ -426,6 +422,11 @@ LRESULT pdfv::MainWindow::wOnDrawItem(DRAWITEMSTRUCT * dis) noexcept
(this->m_closeButtonDown ? this->m_darkRedBrush : this->m_redBrush) :
this->m_brightRedBrush
);

// Draw text on top of close button
::SetTextColor(hdc, RGB(255, 255, 255));
::SelectObject(hdc, this->m_defaultFontBold);
::DrawTextW(hdc, L"X", 1, &closeR, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOCLIP);

// Double-buffering action

Expand Down
12 changes: 8 additions & 4 deletions src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ namespace pdfv
HWND m_hwnd{ nullptr };
WNDCLASSEXW m_wcex{};
std::wstring m_title;
HFONT m_defaultFont{ nullptr };
w::GDI<HFONT> m_defaultFont{ nullptr }, m_defaultFontBold{ nullptr };
bool m_helpAvailable{ true };
pdfv::Tabs m_tabs;
pdfv::OpenDialog m_openDialog{ 2048 };

HBRUSH m_redBrush{ ::CreateSolidBrush(RGB(237, 28, 36)) };
HBRUSH m_brightRedBrush{ ::CreateSolidBrush(RGB(255, 128, 128)) };
HBRUSH m_darkRedBrush{ ::CreateSolidBrush(RGB(200, 0, 0)) };
w::GDI<HBRUSH> m_redBrush{ ::CreateSolidBrush(RGB(237, 28, 36)) };
w::GDI<HBRUSH> m_brightRedBrush{ ::CreateSolidBrush(RGB(255, 128, 128)) };
w::GDI<HBRUSH> m_darkRedBrush{ ::CreateSolidBrush(RGB(200, 0, 0)) };
std::atomic<bool> m_highlighted{ false };
std::atomic<std::size_t> m_highlightedIdx{ 0 };
HANDLE m_moveThread{ nullptr };
Expand Down Expand Up @@ -102,6 +102,10 @@ namespace pdfv
{
return this->m_defaultFont;
}
[[nodiscard]] constexpr const HFONT & getDefaultFontBold() const noexcept
{
return this->m_defaultFontBold;
}

//
// A wrapper function to display messages with this window as the
Expand Down

0 comments on commit f6394e4

Please sign in to comment.