From d0cf1e22ee149708e307fc02008d183d8858efb7 Mon Sep 17 00:00:00 2001 From: NorthFury Date: Tue, 23 May 2023 22:12:51 +0200 Subject: [PATCH 1/5] added option to scale tooltip rendering --- Screens.cpp | 1 + Standard Gaming Platform/Font.cpp | 2 +- Standard Gaming Platform/WinFont.cpp | 104 +++++----- Standard Gaming Platform/WinFont.h | 8 +- Standard Gaming Platform/mousesystem.cpp | 235 +++++++++++++++-------- Standard Gaming Platform/sgp.cpp | 4 + Strategic/Map Screen Interface.cpp | 79 -------- Tactical/SoldierTooltips.cpp | 44 ++--- Utils/Font Control.cpp | 2 + local.h | 3 +- 10 files changed, 233 insertions(+), 249 deletions(-) diff --git a/Screens.cpp b/Screens.cpp index 723e2126dd..6ddd8c47f1 100644 --- a/Screens.cpp +++ b/Screens.cpp @@ -4,6 +4,7 @@ int iResolution; // INI file int iPlayIntro; int iDisableMouseScrolling; int iUseWinFonts; +float fTooltipScaleFactor; /* WANNE, Sgt.Kolja * INI file (Windowed or Fullscreen) * REPLACE all defines WINDOWED_MODE with this variable diff --git a/Standard Gaming Platform/Font.cpp b/Standard Gaming Platform/Font.cpp index 89bb60fc4a..5caa433b7c 100644 --- a/Standard Gaming Platform/Font.cpp +++ b/Standard Gaming Platform/Font.cpp @@ -721,7 +721,7 @@ UINT16 GetFontHeight(INT32 FontNum) MapFont = WinFontMap[FontNum]; if (FontNum != -1) { - return (GetWinFontHeight(L"A", MapFont)); + return (GetWinFontHeight(MapFont)); } } return((UINT16)GetHeight(FontObjs[FontNum], 0)); diff --git a/Standard Gaming Platform/WinFont.cpp b/Standard Gaming Platform/WinFont.cpp index 7368987141..aa97f278eb 100644 --- a/Standard Gaming Platform/WinFont.cpp +++ b/Standard Gaming Platform/WinFont.cpp @@ -26,11 +26,6 @@ #include INT32 FindFreeWinFont( void ); -BOOLEAN gfEnumSucceed = FALSE; - -#ifdef CHINESE -#define DEC_INTERNAL_LEADING -#endif // Private struct not to be exported // to other modules @@ -41,13 +36,12 @@ typedef struct COLORVAL ForeColor; COLORVAL BackColor; UINT8 Height; - UINT8 Width[0x80]; -#ifdef DEC_INTERNAL_LEADING UINT8 InternalLeading; +#ifdef CHINESE + UINT8 Width[0x80]; #endif } HWINFONT; -LOGFONT gLogFont; LONG gWinFontAdjust; HWINFONT WinFonts[WIN_LASTFONT]; @@ -80,6 +74,10 @@ struct { {"HugeFont", {-19, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255, 0)} }; +LOGFONT TooltipLogFont = { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "Arial" }; +INT32 TOOLTIP_IFONT = -1; +INT32 TOOLTIP_IFONT_BOLD = -1; + void Convert16BitStringTo8Bit( CHAR8 *dst, CHAR16 *src ) { //hope 'dst' is big enough @@ -288,6 +286,29 @@ void ShutdownWinFonts( ) {DeleteWinFont(i);} } +void InitTooltipFonts() +{ + LOGFONT adjustedLogFont = TooltipLogFont; + adjustedLogFont.lfHeight = adjustedLogFont.lfHeight * fTooltipScaleFactor; + + LOGFONT adjustedBoldTooltipLogFont = adjustedLogFont; + adjustedBoldTooltipLogFont.lfWeight = FW_BOLD; + + + TOOLTIP_IFONT = CreateWinFont(adjustedLogFont); + TOOLTIP_IFONT_BOLD = CreateWinFont(adjustedBoldTooltipLogFont); + + COLORVAL regularColor = FROMRGB(201, 197, 143); + COLORVAL boldColor = FROMRGB(223, 176, 1); + SetWinFontForeColor(TOOLTIP_IFONT, ®ularColor); + SetWinFontForeColor(TOOLTIP_IFONT_BOLD, &boldColor); +} + +void ShutdownTooltipFonts() +{ + ShutdownWinFonts(); +} + INT32 FindFreeWinFont( void ) { INT32 iCount; @@ -347,8 +368,10 @@ INT32 CreateWinFont( LOGFONT &logfont ) WinFonts[ iFont ].hFont = hFont; HDC hdc = GetDC(NULL); + SelectObject(hdc, hFont); + +#ifdef CHINESE SIZE RectSize; - SelectObject(hdc, hFont ); wchar_t str[2]=L"\1"; for (int i = 1; i<0x80; i++) { @@ -359,12 +382,12 @@ INT32 CreateWinFont( LOGFONT &logfont ) str[0] = L'啊'; GetTextExtentPoint32W( hdc, str, 1, &RectSize ); WinFonts[iFont].Width[0] = (UINT8)RectSize.cx; +#endif + TEXTMETRIC tm; GetTextMetrics(hdc, &tm); WinFonts[ iFont ].Height = (UINT8)tm.tmAscent; -#ifdef DEC_INTERNAL_LEADING WinFonts[ iFont ].InternalLeading = (UINT8)tm.tmInternalLeading; -#endif ReleaseDC(NULL, hdc); return( iFont ); @@ -444,12 +467,10 @@ void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontS SetBkMode(hdc, TRANSPARENT); SetTextAlign(hdc, TA_TOP|TA_LEFT); -#ifdef DEC_INTERNAL_LEADING if (y - pWinFont->InternalLeading >=0) { y -= pWinFont->InternalLeading; } -#endif TextOutW( hdc, x, y, string, len ); IDirectDrawSurface2_ReleaseDC( pDDSurface, hdc ); @@ -458,17 +479,10 @@ void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontS INT16 WinFontStringPixLength( STR16 string2, INT32 iFont ) { - HWINFONT *pWinFont; -#ifndef CHINESE - HDC hdc; - SIZE RectSize; -#endif + HWINFONT *pWinFont; pWinFont = GetWinFont( iFont ); - if ( pWinFont == NULL ) - { - return( 0 ); - } + if (pWinFont == NULL) return(0); #ifdef CHINESE wchar_t *p=string2; @@ -486,7 +500,9 @@ INT16 WinFontStringPixLength( STR16 string2, INT32 iFont ) } return size; #else - hdc = GetDC(NULL); + SIZE RectSize; + HDC hdc = GetDC(NULL); + SelectObject(hdc, pWinFont->hFont ); GetTextExtentPoint32W( hdc, string2, lstrlenW(string2), &RectSize ); ReleaseDC(NULL, hdc); @@ -496,44 +512,18 @@ INT16 WinFontStringPixLength( STR16 string2, INT32 iFont ) } -INT16 GetWinFontHeight( STR16 string2, INT32 iFont ) +INT16 GetWinFontHeight(INT32 iFont) { - HWINFONT *pWinFont; -// HDC hdc; -// SIZE RectSize; + HWINFONT* pWinFont; - pWinFont = GetWinFont( iFont ); + pWinFont = GetWinFont(iFont); - if ( pWinFont == NULL ) + if (pWinFont == NULL) return(0); +#ifdef CHINESE //zwwooooo: Correct tactical interface font height to fixed Chinese characters smearing bug + if (iFont == WinFontMap[TINYFONT1] || iFont == WinFontMap[SMALLFONT1] || iFont == WinFontMap[WIN_14POINTARIAL]) { - return( 0 ); + return pWinFont->Height + 2; } - else - { -#ifdef CHINESE //zwwooooo: Correct tactical interface font height to fixed Chinese characters smearing bug - if (iFont==WIN_TINYFONT1 || iFont==WIN_SMALLFONT1 || iFont==WIN_14POINTARIAL) return pWinFont->Height+2; #endif - return pWinFont->Height; - } - /* - hdc = GetDC(NULL); - SelectObject(hdc, pWinFont->hFont ); - GetTextExtentPoint32W( hdc, string2, lstrlenW(string2), &RectSize ); - ReleaseDC(NULL, hdc); - - return( (INT16)RectSize.cy );*/ -} - -UINT32 WinFont_mprintf( INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...) -{ - va_list argptr; - CHAR16 string[512]; - - va_start(argptr, pFontString); // Set up variable argument pointer - vswprintf(string, pFontString, argptr); // process gprintf string (get output str) - va_end(argptr); - - PrintWinFont( FontDestBuffer, iFont, x, y, string ); - - return( 1 ); + return pWinFont->Height; } diff --git a/Standard Gaming Platform/WinFont.h b/Standard Gaming Platform/WinFont.h index 77fceb6a44..751e42e37b 100644 --- a/Standard Gaming Platform/WinFont.h +++ b/Standard Gaming Platform/WinFont.h @@ -5,6 +5,9 @@ void InitWinFonts( ); void ShutdownWinFonts( ); +void InitTooltipFonts(); +void ShutdownTooltipFonts(); + INT32 CreateWinFont( LOGFONT &logfont ); void DeleteWinFont( INT32 iFont ); @@ -14,8 +17,7 @@ void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor ); void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...); INT16 WinFontStringPixLength( STR16 string, INT32 iFont ); -INT16 GetWinFontHeight( STR16 string, INT32 iFont ); -UINT32 WinFont_mprintf( INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...); +INT16 GetWinFontHeight( INT32 iFont ); //if you cahnge this enum, you must change FontInfo struct in WinFont.cpp too. enum { @@ -43,5 +45,7 @@ WIN_LASTFONT }; #define MAX_WINFONTMAP 25 extern INT32 WinFontMap[MAX_WINFONTMAP]; +extern INT32 TOOLTIP_IFONT; +extern INT32 TOOLTIP_IFONT_BOLD; #endif diff --git a/Standard Gaming Platform/mousesystem.cpp b/Standard Gaming Platform/mousesystem.cpp index d6cb3828eb..ffa479b849 100644 --- a/Standard Gaming Platform/mousesystem.cpp +++ b/Standard Gaming Platform/mousesystem.cpp @@ -1361,32 +1361,32 @@ void SetRegionFastHelpText( MOUSE_REGION *region, const STR16 szText ) //region->FastHelpTimer = gsFastHelpDelay; } -INT16 GetNumberOfLinesInHeight( const STR16 pStringA ) -{ - STR16 pToken; - INT16 sCounter = 0; - CHAR16 pString[ 4096 ]; - - wcscpy( pString, pStringA ); +bool isScalingEnabled() { + return fTooltipScaleFactor > 1; +} - // tokenize - pToken = wcstok( pString, L"\n" ); +UINT16 GetScaledFontHeight() +{ + return isScalingEnabled() + ? GetWinFontHeight(TOOLTIP_IFONT) + : GetFontHeight(FONT10ARIAL); +} - while( pToken != NULL ) - { - // WANNE: Fix by Headrock - if ( (sCounter+1) * (GetFontHeight(FONT10ARIAL)+1) > (SCREEN_HEIGHT - 10) ) - { - break; - } - pToken = wcstok( NULL, L"\n" ); - sCounter++; - - /*pToken = wcstok( NULL, L"\n" ); - sCounter++;*/ +// this function returns the number of lines the input string has +// that can be renderered within the screen height +INT16 GetNumberOfLinesInHeight(const STR16 inputString) { + INT32 fontHeight = GetScaledFontHeight(); + + INT32 i; + INT32 count = 1; + INT32 stringLength = (INT32)wcslen(inputString); + for (i = 0; i < stringLength && count * (fontHeight + 1) < (SCREEN_HEIGHT - 10); i++) { + if (inputString[i] == '\n' && i + 1 < stringLength) { + count++; + } } - return( sCounter ); + return(count); } @@ -1398,17 +1398,14 @@ INT16 GetNumberOfLinesInHeight( const STR16 pStringA ) // void DisplayFastHelp( MOUSE_REGION *region ) { - UINT16 usFillColor; INT32 iX,iY,iW,iH; if ( region->uiFlags & MSYS_FASTHELP ) { - usFillColor = Get16BPPColor(FROMRGB(250, 240, 188)); - - iW = (INT32)GetWidthOfString( region->FastHelpText ) + 10; - iH = (INT32)( GetNumberOfLinesInHeight( region->FastHelpText ) * (GetFontHeight(FONT10ARIAL)+1) + 8 ); + iW = (INT32)GetWidthOfString(region->FastHelpText) + 10 * fTooltipScaleFactor; + iH = (INT32)(GetNumberOfLinesInHeight(region->FastHelpText) * (GetScaledFontHeight() + 1) + 8 * fTooltipScaleFactor); - iX = (INT32)region->RegionTopLeftX + 10; + iX = (INT32)region->RegionTopLeftX + 10 * fTooltipScaleFactor; if (iX < 0) iX = 0; @@ -1424,7 +1421,7 @@ void DisplayFastHelp( MOUSE_REGION *region ) iY = 0; if ( (iY + iH) >= SCREEN_HEIGHT ) - iY = (SCREEN_HEIGHT - iH - 15); + iY = (SCREEN_HEIGHT - iH - 10); if ( !(region->uiFlags & MSYS_GOT_BACKGROUND) ) { @@ -1445,83 +1442,151 @@ void DisplayFastHelp( MOUSE_REGION *region ) ShadowVideoSurfaceRect( FRAME_BUFFER, iX + 2, iY + 2, iX + iW - 3, iY + iH - 3 ); ShadowVideoSurfaceRect( FRAME_BUFFER, iX + 2, iY + 2, iX + iW - 3, iY + iH - 3 ); - SetFont( FONT10ARIAL ); - SetFontShadow( FONT_NEARBLACK ); - DisplayHelpTokenizedString( region->FastHelpText ,( INT16 )( iX + 5 ), ( INT16 )( iY + 5 ) ); + DisplayHelpTokenizedString( + region->FastHelpText, + (INT16)(iX + (isScalingEnabled() ? 5 * fTooltipScaleFactor : 5)), + (INT16)(iY + (isScalingEnabled() ? 4 * fTooltipScaleFactor : 5)) + ); InvalidateRegion( iX, iY, (iX + iW) , (iY + iH) ); } } } -INT16 GetWidthOfString( const STR16 pStringA ) +INT16 GetWidthOfString(const STR16 inputString) { - CHAR16 pString[ 4096 ]; - STR16 pToken; - INT16 sWidth = 0; - wcscpy( pString, pStringA ); + INT16 width = 0; + CHAR16 stringBuffer[256] = L""; + INT32 bufferIndex = 0; + bool isBold = false; + + INT32 iFontHeight = GetScaledFontHeight(); + + INT16 lineWidth = 0; + + INT32 lineCounter = 0; + INT32 i; + INT32 stringLength = (INT32)wcslen(inputString); + for (i = 0; i < stringLength; i++) { + if (inputString[i] == '\n') { + // if the lines don't fit the screen the last line is ... + if ((lineCounter + 2) * (iFontHeight + 1) > (SCREEN_HEIGHT - 10)) { + lineWidth = isScalingEnabled() + ? WinFontStringPixLength(L"...", TOOLTIP_IFONT) + : StringPixLength(L"...", FONT10ARIAL); + if (width < lineWidth) { + width = lineWidth; + } + break; + } + lineWidth = 0; + lineCounter++; + } + else if (inputString[i] == '|') { + isBold = true; + } + else { + stringBuffer[bufferIndex++] = inputString[i]; - // tokenize - pToken = wcstok( pString, L"\n" ); + // look ahead to see if we need to flush the string buffer + if (i + 1 >= stringLength + || inputString[i + 1] == '\n' + || (isBold && inputString[i + 1] != '|') + || (!isBold && inputString[i + 1] == '|')) { - while( pToken != NULL ) - { - if( sWidth < StringPixLength( pToken, FONT10ARIAL ) ) - { - sWidth = StringPixLength( pToken, FONT10ARIAL ); - } + // set string ending character + stringBuffer[bufferIndex] = '\0'; - pToken = wcstok( NULL, L"\n" ); - } + if (isScalingEnabled()) { + INT32 iFont = isBold ? TOOLTIP_IFONT_BOLD : TOOLTIP_IFONT; + lineWidth += WinFontStringPixLength(stringBuffer, iFont); + } + else { + INT32 iFont = isBold ? FONT10ARIALBOLD : FONT10ARIAL; + SetFont(iFont); + lineWidth += StringPixLength(stringBuffer, iFont); + } + bufferIndex = 0; + isBold = false; - return( sWidth ); + if (i + 1 >= stringLength || inputString[i + 1] == '\n') { + if (width < lineWidth) { + width = lineWidth; + } + } + } + } + } + return width; } -void DisplayHelpTokenizedString( const STR16 pStringA, INT16 sX, INT16 sY ) +void DisplayHelpTokenizedString(const STR16 inputString, INT16 sX, INT16 sY) { - STR16 pToken; - INT32 iCounter = 0, i; - UINT32 uiCursorXPos; - CHAR16 pString[ 4096 ]; - INT32 iLength; + SetFontShadow(FONT_NEARBLACK); - wcscpy( pString, pStringA ); + INT32 fontHeight = GetScaledFontHeight(); - // tokenize - pToken = wcstok( pString, L"\n" ); + CHAR16 stringBuffer[256] = L""; + INT32 bufferIndex = 0; + bool isBold = false; - while( pToken != NULL ) - { - // WANNE: Fix by Headrock - if ( (iCounter+2) * (GetFontHeight(FONT10ARIAL)+1) > (SCREEN_HEIGHT - 10) ) - { - mprintf( sX, sY + iCounter * (GetFontHeight(FONT10ARIAL)+1), L"..." ); - break; - } - iLength = (INT32)wcslen( pToken ); - - //iLength = (INT32)wcslen( pToken ); - for( i = 0; i < iLength; i++ ) - { - uiCursorXPos = StringPixLengthArgFastHelp( FONT10ARIAL, FONT10ARIALBOLD, i, pToken ); - if( pToken[ i ] == '|' ) - { - i++; - SetFont( FONT10ARIALBOLD ); - SetFontForeground( 146 ); + INT16 xDelta = 0; + + INT32 lineCounter = 0; + INT32 i; + INT32 stringLength = (INT32)wcslen(inputString); + for (i = 0; i < stringLength; i++) { + if (inputString[i] == '\n') { + // if the lines don't fit the screen the last line is ... + if ((lineCounter + 2) * (fontHeight + 1) > (SCREEN_HEIGHT - 10)) { + if (isScalingEnabled()) { + PrintWinFont(FontDestBuffer, TOOLTIP_IFONT, sX, sY + lineCounter * (fontHeight + 1), L"..."); + } + else { + SetFont(FONT10ARIAL); + mprintf(sX, sY + lineCounter * (fontHeight + 1), L"..."); + } + break; } - else - { - SetFont( FONT10ARIAL ); - SetFontForeground( FONT_BEIGE ); + xDelta = 0; + lineCounter++; + } + else if (inputString[i] == '|') { + isBold = true; + } + else { + stringBuffer[bufferIndex++] = inputString[i]; + + // look ahead to see if we need to flush the string buffer + if (i + 1 >= stringLength + || inputString[i + 1] == '\n' + || (isBold && inputString[i + 1] != '|') + || (!isBold && inputString[i + 1] == '|')) { + + // set string ending character + stringBuffer[bufferIndex] = '\0'; + + if (isScalingEnabled()) { + // the font color is set on font initialization + INT32 iFont = isBold ? TOOLTIP_IFONT_BOLD : TOOLTIP_IFONT; + PrintWinFont(FontDestBuffer, iFont, sX + xDelta, sY + lineCounter * (fontHeight + 1), L"%s", stringBuffer); + xDelta += WinFontStringPixLength(stringBuffer, iFont); + } + else { + INT32 iFont = isBold ? FONT10ARIALBOLD : FONT10ARIAL; + SetFont(iFont); + SetFontForeground(isBold ? 146 : FONT_BEIGE); + mprintf(sX + xDelta, sY + lineCounter * (fontHeight + 1), L"%s", stringBuffer); + xDelta += StringPixLength(stringBuffer, iFont); + } + bufferIndex = 0; + isBold = false; } - mprintf( sX + uiCursorXPos, sY + iCounter * (GetFontHeight(FONT10ARIAL)+1), L"%c", pToken[ i ] ); } - pToken = wcstok( NULL, L"\n" ); - iCounter++; } - SetFontDestBuffer( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE ); + + SetFontDestBuffer(FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, FALSE); } void RenderFastHelp() @@ -1819,4 +1884,4 @@ MOUSE_REGION *get_next_entry_in_MSYS_RegList(MOUSE_REGION *current_region) void ResetWheelState( MOUSE_REGION *region ) { region->WheelState = 0; -} \ No newline at end of file +} diff --git a/Standard Gaming Platform/sgp.cpp b/Standard Gaming Platform/sgp.cpp index daa082fe1d..91f5d5453e 100644 --- a/Standard Gaming Platform/sgp.cpp +++ b/Standard Gaming Platform/sgp.cpp @@ -1329,6 +1329,8 @@ void GetRuntimeSettings( ) // WANNE: Should we play the intro? iPlayIntro = (int) GetPrivateProfileInt( "Ja2 Settings","PLAY_INTRO", iPlayIntro, INIFile ); iUseWinFonts = (int) GetPrivateProfileInt( "Ja2 Settings","USE_WINFONTS", iUseWinFonts, INIFile,); + fTooltipScaleFactor = ((int)GetPrivateProfileInt("Ja2 Settings", "TOOLTIP_SCALE_FACTOR", 100, INIFile, )) / 100; + if (fTooltipScaleFactor < 1) fTooltipScaleFactor = 1; // haydent: mouse scrolling iDisableMouseScrolling = (int) GetPrivateProfileInt( "Ja2 Settings","DISABLE_MOUSE_SCROLLING", iDisableMouseScrolling, INIFile ); @@ -1371,6 +1373,8 @@ void GetRuntimeSettings( ) iPlayIntro = (int)oProps.getIntProperty("Ja2 Settings","PLAY_INTRO", iPlayIntro); iUseWinFonts= (int)oProps.getIntProperty("Ja2 Settings","USE_WINFONTS", iUseWinFonts); + fTooltipScaleFactor = ((float)oProps.getFloatProperty("Ja2 Settings", "TOOLTIP_SCALE_FACTOR", 100)) / 100; + if (fTooltipScaleFactor < 1) fTooltipScaleFactor = 1; // haydent: mouse scrolling iDisableMouseScrolling = (int)oProps.getIntProperty("Ja2 Settings","DISABLE_MOUSE_SCROLLING", iDisableMouseScrolling); diff --git a/Strategic/Map Screen Interface.cpp b/Strategic/Map Screen Interface.cpp index 95315861a3..37eb3087b2 100644 --- a/Strategic/Map Screen Interface.cpp +++ b/Strategic/Map Screen Interface.cpp @@ -2959,85 +2959,6 @@ void DisplayUserDefineHelpTextRegions( FASTHELPREGION *pRegion ) -extern void DisplayHelpTokenizedString( const STR16 pStringA, INT16 sX, INT16 sY ); -extern INT16 GetNumberOfLinesInHeight( const STR16 pStringA ); -extern INT16 GetWidthOfString( const STR16 pStringA ); - -void DisplaySoldierToolTip( FASTHELPREGION *pRegion ) -{ - UINT16 usFillColor; - INT32 iX,iY,iW,iH; - UINT8 *pDestBuf; - UINT32 uiDestPitchBYTES; - - - // grab the color for the background region - usFillColor = Get16BPPColor(FROMRGB(250, 240, 188)); - - - iX = pRegion->iX; - iY = pRegion->iY; - // get the width and height of the string - //iW = (INT32)( pRegion->iW ) + 14; - iW = (INT32)GetWidthOfString( pRegion->FastHelpText ) + 10; - - //iH = IanWrappedStringHeight( ( UINT16 )iX, ( UINT16 )iY, ( UINT16 )( pRegion->iW ), 0, FONT10ARIAL, FONT_BLACK, pRegion->FastHelpText, FONT_BLACK, TRUE, 0 ); - iH = (INT32)( GetNumberOfLinesInHeight( pRegion->FastHelpText ) * (GetFontHeight(FONT10ARIAL)+1) + 8 ); - - // tack on the outer border - iH += 14; - - // gone not far enough? - if ( iX < 0 ) - iX = 0; - - // gone too far - if ( ( pRegion->iX + iW ) >= SCREEN_WIDTH ) - iX = (SCREEN_WIDTH - iW - 4); - - // what about the y value? - iY = (INT32)pRegion->iY - ( iH * 3 / 4); - - // not far enough - if (iY < 0) - iY = 0; - - // too far - if ( (iY + iH) >= SCREEN_HEIGHT ) - iY = (SCREEN_HEIGHT - iH - 15); - - pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES ); - SetClippingRegionAndImageWidth( uiDestPitchBYTES, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); - RectangleDraw( TRUE, iX + 1, iY + 1, iX + iW - 1, iY + iH - 1, Get16BPPColor( FROMRGB( 65, 57, 15 ) ), pDestBuf ); - RectangleDraw( TRUE, iX, iY, iX + iW - 2, iY + iH - 2, Get16BPPColor( FROMRGB( 227, 198, 88 ) ), pDestBuf ); - UnLockVideoSurface( FRAME_BUFFER ); - ShadowVideoSurfaceRect( FRAME_BUFFER, iX + 2, iY + 2, iX + iW - 3, iY + iH - 3 ); - ShadowVideoSurfaceRect( FRAME_BUFFER, iX + 2, iY + 2, iX + iW - 3, iY + iH - 3 ); - - // fillt he video surface areas - //ColorFillVideoSurfaceArea(FRAME_BUFFER, iX, iY, (iX + iW), (iY + iH), 0); - //ColorFillVideoSurfaceArea(FRAME_BUFFER, (iX + 1), (iY + 1), (iX + iW - 1), (iY + iH - 1), usFillColor); - - SetFont( FONT10ARIAL ); - SetFontForeground( FONT_BEIGE ); - - //iH = ( INT32 )DisplayWrappedString( ( INT16 )( iX + 10 ), ( INT16 )( iY + 6 ), ( INT16 )pRegion->iW, 0, FONT10ARIAL, FONT_BEIGE, pRegion->FastHelpText, FONT_NEARBLACK, TRUE, 0 ); - - DisplayHelpTokenizedString( pRegion->FastHelpText ,( INT16 )( iX + 5 ), ( INT16 )( iY + 5 ) ); - - iHeightOfInitFastHelpText = iH + 20; - - InvalidateRegion( iX, iY, (iX + iW) , (iY + iH + 20 ) ); -} - - - - - - - - - void DisplayFastHelpForInitialTripInToMapScreen( FASTHELPREGION *pRegion ) { if( gTacticalStatus.fDidGameJustStart ) diff --git a/Tactical/SoldierTooltips.cpp b/Tactical/SoldierTooltips.cpp index 0651785199..706d64e8d7 100644 --- a/Tactical/SoldierTooltips.cpp +++ b/Tactical/SoldierTooltips.cpp @@ -752,29 +752,23 @@ void DrawMouseTooltip() extern void DisplayTooltipString( const STR16 pStringA, INT16 sX, INT16 sY ); extern void j_log(PTR,...); - iX = mouseTT.iX;iY = mouseTT.iY; - iW = (INT32)GetWidthOfString( mouseTT.FastHelpText ) + 10; - iH = (INT32)( GetNumberOfLinesInHeight( mouseTT.FastHelpText ) * (GetFontHeight(FONT10ARIAL)+1) + 8 ); + UINT16 fontHeight = fTooltipScaleFactor > 1 + ? GetWinFontHeight(TOOLTIP_IFONT) + : GetFontHeight(FONT10ARIAL); - if(1)//draw at cursor - { - iY -= (iH / 2); - if (gusMouseXPos > (SCREEN_WIDTH / 2)) - iX = gusMouseXPos - iW - 24; - else - iX = gusMouseXPos + 24; - //if (gusMouseYPos > (SCREEN_HEIGHT / 2)) - // iY -= 32; + iX = mouseTT.iX;iY = mouseTT.iY; + iW = (INT32)(GetWidthOfString(mouseTT.FastHelpText) + 10 * fTooltipScaleFactor); + iH = (INT32)(GetNumberOfLinesInHeight(mouseTT.FastHelpText) * (fontHeight + 1) + 8 * fTooltipScaleFactor); - if (iY <= 0) iY += 32; - } + iY -= (iH / 2); + if (gusMouseXPos > (SCREEN_WIDTH / 2)) + iX = gusMouseXPos - iW - 24; else - { //draw in panel - //502,485 658,596 160*110 580,540 - iX = 580 - (iW / 2); - iY = 540 - (iH/2); - if (iY + iH > SCREEN_HEIGHT) iY = SCREEN_HEIGHT - iH - 3 ; - } + iX = gusMouseXPos + 24; + //if (gusMouseYPos > (SCREEN_HEIGHT / 2)) + // iY -= 32; + + if (iY <= 0) iY += 32; pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES ); SetClippingRegionAndImageWidth( uiDestPitchBYTES, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); @@ -784,10 +778,12 @@ void DrawMouseTooltip() ShadowVideoSurfaceRect( FRAME_BUFFER, iX + 2, iY + 2, iX + iW - 3, iY + iH - 3 ); ShadowVideoSurfaceRect( FRAME_BUFFER, iX + 2, iY + 2, iX + iW - 3, iY + iH - 3 ); - SetFont( FONT10ARIAL ); - SetFontShadow( FONT_NEARBLACK ); - DisplayHelpTokenizedString( mouseTT.FastHelpText ,( INT16 )( iX + 5 ), ( INT16 )( iY + 5 ) ); + DisplayHelpTokenizedString( + mouseTT.FastHelpText, + (INT16)(iX + (fTooltipScaleFactor > 1 ? 5 * fTooltipScaleFactor : 5)), + (INT16)(iY + (fTooltipScaleFactor > 1 ? 4 * fTooltipScaleFactor : 5)) + ); InvalidateRegion( iX, iY, (iX + iW) , (iY + iH) ); //InvalidateScreen(); -} \ No newline at end of file +} diff --git a/Utils/Font Control.cpp b/Utils/Font Control.cpp index 945fe2a394..87c140f549 100644 --- a/Utils/Font Control.cpp +++ b/Utils/Font Control.cpp @@ -231,6 +231,7 @@ BOOLEAN InitializeFonts( ) if ( iUseWinFonts ) { InitWinFonts( ); } + InitTooltipFonts(); return( TRUE ); } @@ -261,6 +262,7 @@ void ShutdownFonts( ) if ( iUseWinFonts ) { ShutdownWinFonts(); } + ShutdownTooltipFonts(); } // Set shades for fonts diff --git a/local.h b/local.h index cf0bba6f23..c52e262f42 100644 --- a/local.h +++ b/local.h @@ -32,6 +32,7 @@ extern UINT16 SCREEN_HEIGHT; extern int iResolution; // Resolution id from the ini file extern int iPlayIntro; extern int iUseWinFonts; +extern float fTooltipScaleFactor; extern int iDisableMouseScrolling; extern INT16 iScreenWidthOffset; extern INT16 iScreenHeightOffset; @@ -82,4 +83,4 @@ extern BOOLEAN fDisplayOverheadMap; #define PIXEL_DEPTH 16 -#endif \ No newline at end of file +#endif From c2460e033431830f88ffbc02db3abd932b9c3182 Mon Sep 17 00:00:00 2001 From: NorthFury Date: Sat, 27 May 2023 16:56:27 +0200 Subject: [PATCH 2/5] fix tooltip scaling when winfonts are enabled --- Standard Gaming Platform/WinFont.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Standard Gaming Platform/WinFont.cpp b/Standard Gaming Platform/WinFont.cpp index aa97f278eb..cb60ab1659 100644 --- a/Standard Gaming Platform/WinFont.cpp +++ b/Standard Gaming Platform/WinFont.cpp @@ -43,7 +43,7 @@ typedef struct } HWINFONT; LONG gWinFontAdjust; -HWINFONT WinFonts[WIN_LASTFONT]; +HWINFONT WinFonts[WIN_LASTFONT + 2]; // extra space for the tooltip fonts INT32 WinFontMap[MAX_WINFONTMAP]; @@ -327,7 +327,7 @@ INT32 FindFreeWinFont( void ) HWINFONT *GetWinFont( INT32 iFont ) { - if ( iFont == -1 || iFont >=WIN_LASTFONT) + if (iFont == -1 || iFont >= sizeof(WinFonts) ) { return( NULL ); } From 9e8bad177d90257a23158da9299e611af5dfae51 Mon Sep 17 00:00:00 2001 From: NorthFury Date: Sat, 27 May 2023 17:10:57 +0200 Subject: [PATCH 3/5] inline the tooltip log font --- Standard Gaming Platform/WinFont.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Standard Gaming Platform/WinFont.cpp b/Standard Gaming Platform/WinFont.cpp index cb60ab1659..bfed0c1bef 100644 --- a/Standard Gaming Platform/WinFont.cpp +++ b/Standard Gaming Platform/WinFont.cpp @@ -74,7 +74,6 @@ struct { {"HugeFont", {-19, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "ja2font3"}, FROMRGB(0, 255, 0)} }; -LOGFONT TooltipLogFont = { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, "Arial" }; INT32 TOOLTIP_IFONT = -1; INT32 TOOLTIP_IFONT_BOLD = -1; @@ -288,15 +287,17 @@ void ShutdownWinFonts( ) void InitTooltipFonts() { - LOGFONT adjustedLogFont = TooltipLogFont; - adjustedLogFont.lfHeight = adjustedLogFont.lfHeight * fTooltipScaleFactor; + LOGFONT logFont = { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, + DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH | FF_DONTCARE, + "Arial" + }; + logFont.lfHeight = logFont.lfHeight * fTooltipScaleFactor; - LOGFONT adjustedBoldTooltipLogFont = adjustedLogFont; - adjustedBoldTooltipLogFont.lfWeight = FW_BOLD; + LOGFONT boldTooltipLogFont = logFont; + boldTooltipLogFont.lfWeight = FW_BOLD; - - TOOLTIP_IFONT = CreateWinFont(adjustedLogFont); - TOOLTIP_IFONT_BOLD = CreateWinFont(adjustedBoldTooltipLogFont); + TOOLTIP_IFONT = CreateWinFont(logFont); + TOOLTIP_IFONT_BOLD = CreateWinFont(boldTooltipLogFont); COLORVAL regularColor = FROMRGB(201, 197, 143); COLORVAL boldColor = FROMRGB(223, 176, 1); From 7fd342f1aba514ad411cf7e653b46fbf85dd6e27 Mon Sep 17 00:00:00 2001 From: NorthFury Date: Sat, 27 May 2023 17:17:14 +0200 Subject: [PATCH 4/5] inline for loop variable --- Standard Gaming Platform/mousesystem.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Standard Gaming Platform/mousesystem.cpp b/Standard Gaming Platform/mousesystem.cpp index ffa479b849..55109c5754 100644 --- a/Standard Gaming Platform/mousesystem.cpp +++ b/Standard Gaming Platform/mousesystem.cpp @@ -1377,10 +1377,9 @@ UINT16 GetScaledFontHeight() INT16 GetNumberOfLinesInHeight(const STR16 inputString) { INT32 fontHeight = GetScaledFontHeight(); - INT32 i; INT32 count = 1; INT32 stringLength = (INT32)wcslen(inputString); - for (i = 0; i < stringLength && count * (fontHeight + 1) < (SCREEN_HEIGHT - 10); i++) { + for (int i = 0; i < stringLength && count * (fontHeight + 1) < (SCREEN_HEIGHT - 10); i++) { if (inputString[i] == '\n' && i + 1 < stringLength) { count++; } @@ -1465,9 +1464,8 @@ INT16 GetWidthOfString(const STR16 inputString) INT16 lineWidth = 0; INT32 lineCounter = 0; - INT32 i; INT32 stringLength = (INT32)wcslen(inputString); - for (i = 0; i < stringLength; i++) { + for (int i = 0; i < stringLength; i++) { if (inputString[i] == '\n') { // if the lines don't fit the screen the last line is ... if ((lineCounter + 2) * (iFontHeight + 1) > (SCREEN_HEIGHT - 10)) { @@ -1534,9 +1532,8 @@ void DisplayHelpTokenizedString(const STR16 inputString, INT16 sX, INT16 sY) INT16 xDelta = 0; INT32 lineCounter = 0; - INT32 i; INT32 stringLength = (INT32)wcslen(inputString); - for (i = 0; i < stringLength; i++) { + for (int i = 0; i < stringLength; i++) { if (inputString[i] == '\n') { // if the lines don't fit the screen the last line is ... if ((lineCounter + 2) * (fontHeight + 1) > (SCREEN_HEIGHT - 10)) { From a4135842ac69ca2ca72cff0ec7f5742e38d5d57a Mon Sep 17 00:00:00 2001 From: NorthFury Date: Sat, 27 May 2023 17:41:38 +0200 Subject: [PATCH 5/5] use isTooltipScalingEnabled for soldier tooltips --- Standard Gaming Platform/mousesystem.cpp | 17 +++++++++-------- Tactical/SoldierTooltips.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Standard Gaming Platform/mousesystem.cpp b/Standard Gaming Platform/mousesystem.cpp index 55109c5754..a9fb22c2d4 100644 --- a/Standard Gaming Platform/mousesystem.cpp +++ b/Standard Gaming Platform/mousesystem.cpp @@ -56,6 +56,7 @@ extern void ReleaseAnchorMode(); //private function used here (implemented in Bu INT16 GetNumberOfLinesInHeight( const STR16 pStringA ); INT16 GetWidthOfString( const STR16 pStringA ); void DisplayHelpTokenizedString( const STR16 pStringA, INT16 sX, INT16 sY ); +bool isTooltipScalingEnabled(); @@ -1361,13 +1362,13 @@ void SetRegionFastHelpText( MOUSE_REGION *region, const STR16 szText ) //region->FastHelpTimer = gsFastHelpDelay; } -bool isScalingEnabled() { +bool isTooltipScalingEnabled() { return fTooltipScaleFactor > 1; } UINT16 GetScaledFontHeight() { - return isScalingEnabled() + return isTooltipScalingEnabled() ? GetWinFontHeight(TOOLTIP_IFONT) : GetFontHeight(FONT10ARIAL); } @@ -1443,8 +1444,8 @@ void DisplayFastHelp( MOUSE_REGION *region ) DisplayHelpTokenizedString( region->FastHelpText, - (INT16)(iX + (isScalingEnabled() ? 5 * fTooltipScaleFactor : 5)), - (INT16)(iY + (isScalingEnabled() ? 4 * fTooltipScaleFactor : 5)) + (INT16)(iX + (isTooltipScalingEnabled() ? 5 * fTooltipScaleFactor : 5)), + (INT16)(iY + (isTooltipScalingEnabled() ? 4 * fTooltipScaleFactor : 5)) ); InvalidateRegion( iX, iY, (iX + iW) , (iY + iH) ); } @@ -1469,7 +1470,7 @@ INT16 GetWidthOfString(const STR16 inputString) if (inputString[i] == '\n') { // if the lines don't fit the screen the last line is ... if ((lineCounter + 2) * (iFontHeight + 1) > (SCREEN_HEIGHT - 10)) { - lineWidth = isScalingEnabled() + lineWidth = isTooltipScalingEnabled() ? WinFontStringPixLength(L"...", TOOLTIP_IFONT) : StringPixLength(L"...", FONT10ARIAL); if (width < lineWidth) { @@ -1495,7 +1496,7 @@ INT16 GetWidthOfString(const STR16 inputString) // set string ending character stringBuffer[bufferIndex] = '\0'; - if (isScalingEnabled()) { + if (isTooltipScalingEnabled()) { INT32 iFont = isBold ? TOOLTIP_IFONT_BOLD : TOOLTIP_IFONT; lineWidth += WinFontStringPixLength(stringBuffer, iFont); } @@ -1537,7 +1538,7 @@ void DisplayHelpTokenizedString(const STR16 inputString, INT16 sX, INT16 sY) if (inputString[i] == '\n') { // if the lines don't fit the screen the last line is ... if ((lineCounter + 2) * (fontHeight + 1) > (SCREEN_HEIGHT - 10)) { - if (isScalingEnabled()) { + if (isTooltipScalingEnabled()) { PrintWinFont(FontDestBuffer, TOOLTIP_IFONT, sX, sY + lineCounter * (fontHeight + 1), L"..."); } else { @@ -1564,7 +1565,7 @@ void DisplayHelpTokenizedString(const STR16 inputString, INT16 sX, INT16 sY) // set string ending character stringBuffer[bufferIndex] = '\0'; - if (isScalingEnabled()) { + if (isTooltipScalingEnabled()) { // the font color is set on font initialization INT32 iFont = isBold ? TOOLTIP_IFONT_BOLD : TOOLTIP_IFONT; PrintWinFont(FontDestBuffer, iFont, sX + xDelta, sY + lineCounter * (fontHeight + 1), L"%s", stringBuffer); diff --git a/Tactical/SoldierTooltips.cpp b/Tactical/SoldierTooltips.cpp index 706d64e8d7..b1b08ccf2a 100644 --- a/Tactical/SoldierTooltips.cpp +++ b/Tactical/SoldierTooltips.cpp @@ -743,6 +743,7 @@ void DrawMouseTooltip() UINT32 uiDestPitchBYTES; static INT32 iX, iY, iW, iH; + extern bool isTooltipScalingEnabled(); extern INT16 GetWidthOfString(const STR16); extern INT16 GetNumberOfLinesInHeight(const STR16); extern void DisplayHelpTokenizedString(const STR16,INT16,INT16); @@ -752,7 +753,7 @@ void DrawMouseTooltip() extern void DisplayTooltipString( const STR16 pStringA, INT16 sX, INT16 sY ); extern void j_log(PTR,...); - UINT16 fontHeight = fTooltipScaleFactor > 1 + UINT16 fontHeight = isTooltipScalingEnabled() ? GetWinFontHeight(TOOLTIP_IFONT) : GetFontHeight(FONT10ARIAL); @@ -780,8 +781,8 @@ void DrawMouseTooltip() DisplayHelpTokenizedString( mouseTT.FastHelpText, - (INT16)(iX + (fTooltipScaleFactor > 1 ? 5 * fTooltipScaleFactor : 5)), - (INT16)(iY + (fTooltipScaleFactor > 1 ? 4 * fTooltipScaleFactor : 5)) + (INT16)(iX + (isTooltipScalingEnabled() ? 5 * fTooltipScaleFactor : 5)), + (INT16)(iY + (isTooltipScalingEnabled() ? 4 * fTooltipScaleFactor : 5)) ); InvalidateRegion( iX, iY, (iX + iW) , (iY + iH) );