faster gdi text rendering
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-07-19 21:04:33 +09:00
commit bc5fc10816
4 changed files with 50 additions and 35 deletions

View file

@ -34,6 +34,7 @@ struct _MwLLGDI {
struct _MwLLGDIColor { struct _MwLLGDIColor {
struct _MwLLCommonColor common; struct _MwLLCommonColor common;
COLORREF color;
HBRUSH brush; HBRUSH brush;
}; };

View file

@ -502,7 +502,8 @@ static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
if(b < 0) b = 0; if(b < 0) b = 0;
if(c->gdi.brush != NULL) DeleteObject(c->gdi.brush); if(c->gdi.brush != NULL) DeleteObject(c->gdi.brush);
c->gdi.brush = CreateSolidBrush(GetNearestColor(dc, RGB(r, g, b))); c->gdi.color = GetNearestColor(dc, RGB(r, g, b));
c->gdi.brush = CreateSolidBrush(c->gdi.color);
c->common.red = r; c->common.red = r;
c->common.green = g; c->common.green = g;
c->common.blue = b; c->common.blue = b;

View file

@ -23,6 +23,20 @@ static int GDI_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c
tw = MwTextWidth(handle, ttf, text); tw = MwTextWidth(handle, ttf, text);
th = MwTextHeight(handle, ttf, text); th = MwTextHeight(handle, ttf, text);
if(handle->lowlevel->common.type == MwLLBackendGDI) {
HFONT old_font = SelectObject(handle->lowlevel->gdi.hDC, ttf->font);
int old_bkmode = SetBkMode(handle->lowlevel->gdi.hDC, TRANSPARENT);
COLORREF old_color = SetTextColor(handle->lowlevel->gdi.hDC, color->gdi.color);
TextOut(handle->lowlevel->gdi.hDC, point->x, point->y - th / 2, t, strlen(t));
SetTextColor(handle->lowlevel->gdi.hDC, old_color);
SetBkMode(handle->lowlevel->gdi.hDC, old_bkmode);
SelectObject(handle->lowlevel->gdi.hDC, old_font);
return 0;
}
px = malloc(tw * th * 4); px = malloc(tw * th * 4);
bmih.biSize = sizeof(bmih); bmih.biSize = sizeof(bmih);
@ -69,7 +83,6 @@ static int GDI_MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const c
free(px); free(px);
DeleteObject(hbm); DeleteObject(hbm);
free(t); free(t);
return 0; return 0;