added option to scale tooltip rendering

This commit is contained in:
NorthFury
2023-05-27 21:52:35 -03:00
committed by majcosta
parent c13a44c445
commit 456cfa18cf
10 changed files with 232 additions and 248 deletions
+148 -83
View File
@@ -1361,32 +1361,32 @@ void SetRegionFastHelpText( MOUSE_REGION *region, const STR16 szText )
//region->FastHelpTimer = gsFastHelpDelay;
}
INT16 GetNumberOfLinesInHeight( const STR16 pStringA )
bool isScalingEnabled() {
return fTooltipScaleFactor > 1;
}
UINT16 GetScaledFontHeight()
{
STR16 pToken;
INT16 sCounter = 0;
CHAR16 pString[ 4096 ];
return isScalingEnabled()
? GetWinFontHeight(TOOLTIP_IFONT)
: GetFontHeight(FONT10ARIAL);
}
wcscpy( pString, pStringA );
// 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();
// tokenize
pToken = wcstok( pString, L"\n" );
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++;*/
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 * fTooltipScaleFactor;
iH = (INT32)(GetNumberOfLinesInHeight(region->FastHelpText) * (GetScaledFontHeight() + 1) + 8 * fTooltipScaleFactor);
iW = (INT32)GetWidthOfString( region->FastHelpText ) + 10;
iH = (INT32)( GetNumberOfLinesInHeight( region->FastHelpText ) * (GetFontHeight(FONT10ARIAL)+1) + 8 );
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;
// tokenize
pToken = wcstok( pString, L"\n" );
INT32 iFontHeight = GetScaledFontHeight();
while( pToken != NULL )
{
if( sWidth < StringPixLength( pToken, FONT10ARIAL ) )
{
sWidth = StringPixLength( pToken, FONT10ARIAL );
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];
pToken = wcstok( NULL, 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] == '|')) {
// set string ending character
stringBuffer[bufferIndex] = '\0';
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;
if (i + 1 >= stringLength || inputString[i + 1] == '\n') {
if (width < lineWidth) {
width = lineWidth;
}
}
}
}
}
return( sWidth );
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 );
INT16 xDelta = 0;
//iLength = (INT32)wcslen( pToken );
for( i = 0; i < iLength; i++ )
{
uiCursorXPos = StringPixLengthArgFastHelp( FONT10ARIAL, FONT10ARIALBOLD, i, pToken );
if( pToken[ i ] == '|' )
{
i++;
SetFont( FONT10ARIALBOLD );
SetFontForeground( 146 );
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;
}
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;
}
else
{
SetFont( FONT10ARIAL );
SetFontForeground( FONT_BEIGE );
}
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;
}
}