From cf8b53de012c96471c1e243d47e8718939e1c16a Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Thu, 21 Oct 2021 16:47:45 +0300 Subject: [PATCH] Added scaling support in grtext_draw_ttext_in_box. Issue #56. --- SpaceCadetPinball/TTextBox.cpp | 3 +-- SpaceCadetPinball/gdrv.cpp | 34 ++++++++++++++++++++++++++++------ SpaceCadetPinball/gdrv.h | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/SpaceCadetPinball/TTextBox.cpp b/SpaceCadetPinball/TTextBox.cpp index 5311592..1dc8ced 100644 --- a/SpaceCadetPinball/TTextBox.cpp +++ b/SpaceCadetPinball/TTextBox.cpp @@ -211,8 +211,7 @@ void TTextBox::Draw() render::vscreen.XPosition + OffsetX, render::vscreen.YPosition + OffsetY, Width, - Height, - 255); + Height); return; } diff --git a/SpaceCadetPinball/gdrv.cpp b/SpaceCadetPinball/gdrv.cpp index cf354a3..d135d5d 100644 --- a/SpaceCadetPinball/gdrv.cpp +++ b/SpaceCadetPinball/gdrv.cpp @@ -287,7 +287,7 @@ void gdrv::end_blit_sequence() ReleaseDC(hwnd, sequence_hdc); } -void gdrv::blit(gdrv_bitmap8* bmp, int xSrc, int ySrcOff, int xDest, int yDest, int DestWidth, int DestHeight) +void gdrv::blit(gdrv_bitmap8* bmp, int xSrc, int ySrc, int xDest, int yDest, int DestWidth, int DestHeight) { HDC dc = winmain::_GetDC(hwnd); SetStretchBltMode(dc, stretchMode); @@ -303,7 +303,7 @@ void gdrv::blit(gdrv_bitmap8* bmp, int xSrc, int ySrcOff, int xDest, int yDest, DestWidth, DestHeight, xSrc, - bmp->Height - ySrcOff - DestHeight, + bmp->Height - ySrc - DestHeight, DestWidth, DestHeight, bmp, @@ -413,11 +413,24 @@ void gdrv::copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int heigh } -void gdrv::grtext_draw_ttext_in_box(LPCSTR text, int xOff, int yOff, int width, int height, int a6) +void gdrv::grtext_draw_ttext_in_box(LPCSTR text, int xOff, int yOff, int width, int height) { - tagRECT rc{}; + // Original font was 16 points, used with lowest table resolution + static const int fontSizes[3] = + { + 16, + 22, + 28 + }; + + xOff = static_cast(xOff * fullscrn::ScaleX) + fullscrn::OffsetX; + yOff = static_cast(yOff * fullscrn::ScaleY) + fullscrn::OffsetY; + width = static_cast(width * fullscrn::ScaleX); + height = static_cast(height * fullscrn::ScaleY); + auto fontSize = static_cast(round(fontSizes[fullscrn::GetResolution()] * fullscrn::ScaleY)); HDC dc = GetDC(hwnd); + tagRECT rc{}; rc.left = xOff; rc.right = width + xOff; rc.top = yOff; @@ -431,9 +444,18 @@ void gdrv::grtext_draw_ttext_in_box(LPCSTR text, int xOff, int yOff, int width, if (fontColor) sscanf_s(fontColor, "%d %d %d", &grtext_red, &grtext_green, &grtext_blue); } - int prevMode = SetBkMode(dc, 1); + + // Default font does not scale well + auto hNewFont = CreateFont(fontSize, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial"); + HFONT hOldFont = (HFONT)SelectObject(dc, hNewFont); + int prevMode = SetBkMode(dc, TRANSPARENT); COLORREF color = SetTextColor(dc, grtext_red | grtext_green << 8 | grtext_blue << 16); - DrawTextA(dc, text, lstrlenA(text), &rc, 0x810u); + + DrawTextA(dc, text, lstrlenA(text), &rc, DT_NOPREFIX | DT_WORDBREAK); + + SelectObject(dc, hOldFont); + DeleteObject(hNewFont); SetBkMode(dc, prevMode); SetTextColor(dc, color); ReleaseDC(hwnd, dc); diff --git a/SpaceCadetPinball/gdrv.h b/SpaceCadetPinball/gdrv.h index 6a5e1cc..d158f39 100644 --- a/SpaceCadetPinball/gdrv.h +++ b/SpaceCadetPinball/gdrv.h @@ -64,7 +64,7 @@ public: int srcXOff, int srcYOff); static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff, gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff); - static void grtext_draw_ttext_in_box(LPCSTR text, int xOff, int yOff, int width, int height, int a6); + static void grtext_draw_ttext_in_box(LPCSTR text, int xOff, int yOff, int width, int height); private: /*COLORONCOLOR or HALFTONE*/ static const int stretchMode = COLORONCOLOR;