From 6c79f40e09ceabaaf14fe9e1662971db16c68567 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 1 Oct 2022 19:54:47 +0200 Subject: [PATCH] Fix console by properly handling the brush --- src/client/component/console.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index 47606c72..23a313db 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -74,6 +74,29 @@ namespace console va_end(ap); } + INT_PTR get_gray_brush() + { + static struct brush + { + HBRUSH hbrush; + + brush() + { + hbrush = CreateSolidBrush(RGB(50, 50, 50)); + } + + ~brush() + { + if (hbrush) + { + DeleteObject(hbrush); + } + } + } b; + + return reinterpret_cast(b.hbrush); + } + LRESULT con_wnd_proc(const HWND hwnd, const UINT msg, const WPARAM wparam, const LPARAM lparam) { switch (msg) @@ -82,7 +105,7 @@ namespace console case WM_CTLCOLORSTATIC: SetBkColor(reinterpret_cast(wparam), RGB(50, 50, 50)); SetTextColor(reinterpret_cast(wparam), RGB(232, 230, 227)); - return reinterpret_cast(CreateSolidBrush(RGB(50, 50, 50))); + return get_gray_brush(); case WM_CLOSE: game::Cbuf_AddText(0, "quit\n"); [[fallthrough]]; @@ -215,7 +238,7 @@ namespace console current_queue.pop(); } - std::this_thread::sleep_for(15ms); + std::this_thread::sleep_for(5ms); } });