fix chat-scaling being awkward due to font size pt/px confusion ui-scaling
authorsheepluva
Sat, 04 Jul 2020 02:46:06 +0200
branchui-scaling
changeset 15686 0b99e220568a
parent 15685 d92eeb468dad
child 15687 63e2b7b2ec47
child 15693 f28ca5a87682
fix chat-scaling being awkward due to font size pt/px confusion
hedgewars/uChat.pas
hedgewars/uConsts.pas
--- a/hedgewars/uChat.pas	Fri Jul 03 23:51:47 2020 +0200
+++ b/hedgewars/uChat.pas	Sat Jul 04 02:46:06 2020 +0200
@@ -94,7 +94,7 @@
             );
 
 
-const PaddingFactor = (1/6); // relative to font size
+const PaddingFactor = 0.125; // relative to font size in pixels
 
 var Padding, ClHeight: integer;
     LastChatScaleValue, LastUIScaleValue: real;
@@ -121,7 +121,7 @@
 end;
 
 procedure AdjustToUIScale();
-var fntSize: integer;
+var fntSize, fntSizePx: integer;
 begin
     // don't do anything if no change
     if (ChatScaleValue = LastChatScaleValue) and (UIScaleValue = LastUIScaleValue) then
@@ -130,8 +130,7 @@
     LastChatScaleValue:= ChatScaleValue;
     LastUIScaleValue:= UIScaleValue;
 
-    // determine font size - note: +0.001 to because I don't trust float inaccuracy combined with trunc
-    fntSize:= max(1, trunc(UIScaleValue * ChatScaleValue * cBaseChatFontHeight + 0.001));
+    fntSize:= max(1, round(UIScaleValue * ChatScaleValue * cBaseChatFontHeight));
 
     if Fontz[fntChat].Height <> fntSize then
         begin
@@ -146,8 +145,10 @@
         end;
 
     // adjust line height etc.
-    Padding:= max(1, trunc(PaddingFactor * fntSize + 0.1));
-    ClHeight:= 2 * Padding + fntSize;
+    fntSizePx:= round(cFontPxToPtRatio * fntSize);
+    Padding:= max(1, round(PaddingFactor * fntSizePx));
+
+    ClHeight:= 2 * Padding + fntSizePx;
 
     // clear cache of already rendered lines
     ReloadLines();
@@ -285,7 +286,7 @@
 if strSurface <> nil then tmpSurface:= SDL_ConvertSurface(strSurface, resSurface^.format, 0);
 SDL_FreeSurface(strSurface);
 //SDL_UpperBlit(strSurface, nil, resSurface, @dstrect);
-if tmpSurface <> nil then copyToXY(tmpSurface, resSurface, Padding, 2);
+if tmpSurface <> nil then copyToXY(tmpSurface, resSurface, Padding, Padding);
 SDL_FreeSurface(tmpSurface);
 
 cl.Tex:= Surface2Tex(resSurface, false);
@@ -417,7 +418,7 @@
         begin
         // draw cursor
         if ((RealTicks - LastKeyPressTick) and 512) < 256 then
-            DrawLineOnScreen(left + cursorX, top + Padding, left + cursorX, top + ClHeight - Padding, 2.0, $00, $FF, $FF, $FF);
+            DrawLineOnScreen(left + cursorX, top + Padding, left + cursorX, top + ClHeight - Padding, max(2, round(UIScaleValue * ChatScaleValue * 2.0)), $00, $FF, $FF, $FF);
         end
     else // draw selection
         begin
--- a/hedgewars/uConsts.pas	Fri Jul 03 23:51:47 2020 +0200
+++ b/hedgewars/uConsts.pas	Sat Jul 04 02:46:06 2020 +0200
@@ -230,10 +230,11 @@
     // do not change this value
     cDefaultZoomLevel = 2.0; // 100% zoom
 
+    cFontPxToPtRatio   = 1.3281472327365;
     cBaseChatFontHeight = 12;
     cChatScaleRelDelta = 0.1;
     cMinChatScaleValue = 0.8;
-    cMaxChatScaleValue = 20.0;
+    cMaxChatScaleValue = 10.0;
 
     cDefaultUIScaleLevel = 1.0;