Skip to content

Commit baad839

Browse files
committed
use UpdateLayeredWindow with ULW_COLORKEY instead of
SetLayeredWindowAttributes with LWA_COLORKEY
1 parent 6c3eaa2 commit baad839

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Views.Win32/lua/LuaRenderer.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static void draw_lua()
4242

4343
bool success = true;
4444

45+
// D2D Graphics
4546
if (!lua->rctx.presenter)
4647
{
4748
// NOTE: We have to invoke the callback because we're waiting for the script to issue a d2d call
@@ -54,12 +55,20 @@ static void draw_lua()
5455
lua->rctx.presenter->end_present();
5556
}
5657

58+
// GDI Graphics. Ugh.
5759
success &= LuaCallbacks::invoke_callbacks_with_key(lua, LuaCallbacks::REG_ATUPDATESCREEN);
5860

5961
if (lua->rctx.has_gdi_content)
6062
{
61-
BitBlt(lua->rctx.gdi_front_dc, 0, 0, lua->rctx.dc_size.width, lua->rctx.dc_size.height,
62-
lua->rctx.gdi_back_dc, 0, 0, SRCCOPY);
63+
SIZE size = {(LONG)lua->rctx.dc_size.width, (LONG)lua->rctx.dc_size.height};
64+
POINT src_pt = {0, 0};
65+
66+
BLENDFUNCTION bf = {};
67+
bf.BlendOp = AC_SRC_OVER;
68+
bf.SourceConstantAlpha = 255;
69+
bf.AlphaFormat = 0;
70+
UpdateLayeredWindow(lua->rctx.gdi_overlay_hwnd, nullptr, &src_pt, &size, lua->rctx.gdi_back_dc, &src_pt,
71+
LuaRenderer::LUA_GDI_COLOR_MASK, &bf, ULW_COLORKEY);
6372
}
6473

6574
lua->rctx.last_render_time = now;
@@ -168,7 +177,7 @@ static LRESULT CALLBACK overlay_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR
168177
void LuaRenderer::init()
169178
{
170179
WNDCLASS wndclass = {0};
171-
wndclass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
180+
wndclass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
172181
wndclass.lpfnWndProc = (WNDPROC)overlay_wndproc;
173182
wndclass.hInstance = g_main_ctx.hinst;
174183
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
@@ -248,9 +257,6 @@ void LuaRenderer::create_renderer(t_lua_rendering_context *ctx, t_lua_environmen
248257
ctx->gdi_overlay_hwnd =
249258
CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT, OVERLAY_CLASS, L"", WS_CHILD | WS_VISIBLE, 0, 0,
250259
ctx->dc_size.width, ctx->dc_size.height, g_main_ctx.hwnd, nullptr, g_main_ctx.hinst, nullptr);
251-
SetLayeredWindowAttributes(ctx->gdi_overlay_hwnd, LUA_GDI_COLOR_MASK, 0, LWA_COLORKEY);
252-
253-
ctx->gdi_front_dc = GetDC(ctx->gdi_overlay_hwnd);
254260

255261
// If we don't fill up the DC with the key first, it never becomes "transparent"
256262
FillRect(ctx->gdi_back_dc, &window_rect, g_alpha_mask_brush);
@@ -309,7 +315,6 @@ void LuaRenderer::destroy_renderer(t_lua_rendering_context *ctx)
309315

310316
if (ctx->gdi_back_dc)
311317
{
312-
ReleaseDC(ctx->gdi_overlay_hwnd, ctx->gdi_front_dc);
313318
DestroyWindow(ctx->gdi_overlay_hwnd);
314319
SelectObject(ctx->gdi_back_dc, nullptr);
315320
DeleteDC(ctx->gdi_back_dc);

src/Views.Win32/lua/LuaTypes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ struct t_lua_rendering_context
2525

2626
bool has_gdi_content{};
2727

28-
HDC gdi_front_dc{};
29-
3028
// The DC for GDI/GDI+ drawings
3129
// This DC is special, since commands can be issued to it anytime and it's never cleared
3230
HDC gdi_back_dc{};
@@ -115,4 +113,4 @@ struct t_lua_key_event_args
115113
std::optional<bool> pressed;
116114
std::optional<std::wstring> text;
117115
bool repeat{};
118-
};
116+
};

0 commit comments

Comments
 (0)