WIP: make chat resizing faster ui-scaling
authorsheepluva
Wed, 16 May 2018 10:11:00 +0200
branchui-scaling
changeset 13393 32a1696ca93a
parent 13392 706b34d0ce60
child 13394 24b531dcebe7
WIP: make chat resizing faster hold shift for pixel-precise size changes
hedgewars/uChat.pas
hedgewars/uConsts.pas
--- a/hedgewars/uChat.pas	Tue May 15 23:47:07 2018 +0200
+++ b/hedgewars/uChat.pas	Wed May 16 10:11:00 2018 +0200
@@ -129,8 +129,8 @@
     LastChatScaleValue:= ChatScaleValue;
     LastUIScaleValue:= UIScaleValue;
 
-    // determine font size - note: +0.1 to because I don't trust float inaccuracy combined with floor
-    fntSize:= max(1, floor(UIScaleValue * ChatScaleValue * Fontz[fnt16].Height + 0.1));
+    // determine font size - note: +0.001 to because I don't trust float inaccuracy combined with floor
+    fntSize:= max(1, floor(UIScaleValue * ChatScaleValue * cBaseChatFontHeight + 0.001));
 
     if Fontz[fntChat].Height <> fntSize then
         begin
@@ -154,26 +154,36 @@
     UpdateCursorCoords();
 end;
 
-procedure ChatSizeInc();
+procedure ChatSizeInc(pxprecise: boolean);
+var fntSize: integer;
 begin
-// TODO cChatMinScaleLevel, cChatSizeDelta (probably half of cZoomDelta)
-// TODO always - effectively -- increase font by 1px?
-if ChatScaleValue < cMinZoomLevel then
+if pxprecise then
     begin
-    ChatScaleValue:= ChatScaleValue + cZoomDelta;
-    AdjustToUIScale();
-    end;
+    fntSize:= Fontz[fntChat].Height;
+    inc(fntSize);
+    ChatScaleValue:= 1.0 * fntSize / cBaseChatFontHeight;
+    end
+else
+    ChatScaleValue:= ChatScaleValue * (1.0 + cChatScaleRelDelta);
+if ChatScaleValue > cMaxChatScaleValue then
+    ChatScaleValue:= cMaxChatScaleValue;
+AdjustToUIScale();
 end;
 
-procedure ChatSizeDec();
+procedure ChatSizeDec(pxprecise: boolean);
+var fntSize: integer;
 begin
-// TODO cChatMaxScaleLevel, cChatSizeDelta (probably half of cZoomDelta)
-// TODO always - effectively -- increase font by 1px?
-if ChatScaleValue > cMaxZoomLevel then
+if pxprecise then
     begin
-    ChatScaleValue:= ChatScaleValue - cZoomDelta;
-    AdjustToUIScale();
-    end;
+    fntSize:= Fontz[fntChat].Height;
+    dec(fntSize);
+    ChatScaleValue:= 1.0 * fntSize / cBaseChatFontHeight;
+    end
+else
+    ChatScaleValue:= ChatScaleValue / (1.0 + cChatScaleRelDelta);
+if ChatScaleValue < cMinChatScaleValue then
+    ChatScaleValue:= cMinChatScaleValue;
+AdjustToUIScale();
 end;
 
 procedure chatSizeReset();
@@ -1091,7 +1101,7 @@
             begin
             if ctrl then
                 begin
-                ChatSizeInc();
+                ChatSizeInc(selMode);
                 SkipNextInput:= true;
                 end;
             end;
@@ -1100,7 +1110,7 @@
             begin
             if ctrl then
                 begin
-                ChatSizeDec();
+                ChatSizeDec(selMode);
                 SkipNextInput:= true;
                 end;
             end;
--- a/hedgewars/uConsts.pas	Tue May 15 23:47:07 2018 +0200
+++ b/hedgewars/uConsts.pas	Wed May 16 10:11:00 2018 +0200
@@ -194,7 +194,13 @@
 
     // do not change this value
     cDefaultZoomLevel = 2.0;
+
+    cBaseChatFontHeight = 12;
     cDefaultChatScaleLevel = 1.0;
+    cChatScaleRelDelta = 0.1;
+    cMinChatScaleValue = 0.8;
+    cMaxChatScaleValue = 20;
+
     cDefaultUIScaleLevel = 1.0;
 
     // game flags