Invert colors if clan color is very dark
authorWuzzy <Wuzzy2@mail.ru>
Mon, 01 Apr 2019 22:07:42 +0200
changeset 14736 8563cc40fc1e
parent 14735 2d859d34e6f6
child 14737 123aaa2bf4b5
Invert colors if clan color is very dark
hedgewars/uConsts.pas
hedgewars/uGearsRender.pas
hedgewars/uRenderUtils.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
hedgewars/uWorld.pas
share/hedgewars/Data/Graphics/Finger.png
share/hedgewars/Data/Graphics/FingerBack.png
share/hedgewars/Data/Graphics/FingerBackInv.png
share/hedgewars/Data/Graphics/Targetp.png
share/hedgewars/Data/Graphics/Targetp@2x.png
share/hedgewars/Data/Graphics/TargetpBack.png
share/hedgewars/Data/Graphics/TargetpBack@2x.png
share/hedgewars/Data/Graphics/TargetpBackInv.png
share/hedgewars/Data/Graphics/TargetpBackInv@2x.png
share/hedgewars/Data/Graphics/sliderInverted.png
--- a/hedgewars/uConsts.pas	Mon Apr 01 20:08:34 2019 +0200
+++ b/hedgewars/uConsts.pas	Mon Apr 01 22:07:42 2019 +0200
@@ -71,6 +71,7 @@
     // color constants
     cWhiteColorChannels : TSDL_Color = (r:$FF; g:$FF; b:$FF; a:$FF);
     cNearBlackColorChannels : TSDL_Color = (r:$00; g:$00; b:$10; a:$FF);
+    cInvertTextColorAt    : Byte = 64;
 
     cWhiteColor           : Longword = $FFFFFFFF; // white
     cNearBlackColor       : Longword = $FF000010; // nearly black
--- a/hedgewars/uGearsRender.pas	Mon Apr 01 20:08:34 2019 +0200
+++ b/hedgewars/uGearsRender.pas	Mon Apr 01 22:07:42 2019 +0200
@@ -53,7 +53,7 @@
                 end;
 
 implementation
-uses uRender, uUtils, uVariables, uAmmos, Math, uVisualGearsList;
+uses uRender, uRenderUtils, uUtils, uVariables, uAmmos, Math, uVisualGearsList;
 
 procedure DrawRopeLinesRQ(Gear: PGear);
 var n: LongInt;
@@ -303,6 +303,10 @@
 
         dAngle := DxDy2Angle(int2hwfloat(ty - oy), int2hwfloat(tx - ox)) + 90;
 
+        if (IsTooDarkToRead(HH^.Team^.Clan^.Color)) then
+            DrawSpriteRotatedF(sprFingerBackInv, tx, ty, RealTicks div 32 mod 16, 1, dAngle)
+        else
+            DrawSpriteRotatedF(sprFingerBack, tx, ty, RealTicks div 32 mod 16, 1, dAngle);
         Tint(HH^.Team^.Clan^.Color shl 8 or $FF);
         DrawSpriteRotatedF(sprFinger, tx, ty, RealTicks div 32 mod 16, 1, dAngle);
         untint;
@@ -1259,7 +1263,13 @@
     else
         begin
         if CurrentHedgehog <> nil then
+            begin
+            if (IsTooDarkToRead(CurrentHedgehog^.Team^.Clan^.Color)) then
+                DrawSpriteRotatedF(sprTargetPBackInv, Gear^.Target.X + WorldDx, Gear^.Target.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360)
+            else
+                DrawSpriteRotatedF(sprTargetPBack, Gear^.Target.X + WorldDx, Gear^.Target.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
             Tint(CurrentHedgehog^.Team^.Clan^.Color shl 8 or $FF);
+            end;
         DrawSpriteRotatedF(sprTargetP, Gear^.Target.X + WorldDx, Gear^.Target.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
         if CurrentHedgehog <> nil then
             untint;
--- a/hedgewars/uRenderUtils.pas	Mon Apr 01 20:08:34 2019 +0200
+++ b/hedgewars/uRenderUtils.pas	Mon Apr 01 22:07:42 2019 +0200
@@ -38,6 +38,8 @@
 function  RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
 function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
 
+function IsTooDarkToRead(TextColor: Longword): boolean; inline;
+
 implementation
 uses uVariables, uConsts, uTextures, SysUtils, uUtils, uDebug;
 
@@ -76,11 +78,25 @@
     WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0);
 end;*)
 
+function IsTooDarkToRead(TextColor: LongWord): boolean;
+var clr: TSDL_Color;
+begin
+    clr.r:= (TextColor shr 16) and $FF;
+    clr.g:= (TextColor shr 8) and $FF;
+    clr.b:= TextColor and $FF;
+    IsTooDarkToRead:= ((clr.r >= cInvertTextColorAt) or (clr.g >= cInvertTextColorAt) or (clr.b >= cInvertTextColorAt));
+end;
+
+function IsTooDarkToRead(TextColor: TSDL_COLOR): boolean;
+begin
+    IsTooDarkToRead:= (not ((TextColor.r >= cInvertTextColorAt) or (TextColor.g >= cInvertTextColorAt) or (TextColor.b >= cInvertTextColorAt)));
+end;
+
 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord): TSDL_Rect;
 var w, h: Longword;
     tmpsurf: PSDL_Surface;
+    finalRect, textRect: TSDL_Rect;
     clr: TSDL_Color;
-    finalRect, textRect: TSDL_Rect;
 begin
     TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), @w, @h);
     if (maxLength > 0) and (w > maxLength * HDPIScaleFactor) then w := maxLength * HDPIScaleFactor;
@@ -92,10 +108,13 @@
     textRect.y:= Y;
     textRect.w:= w;
     textRect.h:= h;
-    DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true);
     clr.r:= (Color shr 16) and $FF;
     clr.g:= (Color shr 8) and $FF;
     clr.b:= Color and $FF;
+    if (not IsTooDarkToRead(clr)) then
+        DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true)
+    else
+        DrawRoundRect(@finalRect, cNearBlackColor, cWhiteColor, Surface, true);
     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr);
     finalRect.x:= X + cFontBorder + cFontPadding;
     finalRect.y:= Y + cFontBorder;
--- a/hedgewars/uTypes.pas	Mon Apr 01 20:08:34 2019 +0200
+++ b/hedgewars/uTypes.pas	Mon Apr 01 22:07:42 2019 +0200
@@ -91,7 +91,8 @@
             sprSlider, sprBotlevels, sprHandKnife, sprKnife, sprStar, sprIceTexture, sprIceGun,
             sprFrozenHog, sprAmRubber, sprBoing, sprCustom1, sprCustom2, sprCustom3, sprCustom4,
             sprCustom5, sprCustom6, sprCustom7, sprCustom8, sprFrozenAirMine, sprAirMine, sprHandAirMine,
-            sprFlakeL, sprSDFlakeL, sprCloudL, sprSDCloudL, sprCreeper, sprHandCreeper, sprMinigun
+            sprFlakeL, sprSDFlakeL, sprCloudL, sprSDCloudL, sprCreeper, sprHandCreeper, sprMinigun,
+            sprSliderInverted, sprFingerBack, sprFingerBackInv, sprTargetPBack, sprTargetPBackInv
             );
 
     // Gears that interact with other Gears and/or Land
--- a/hedgewars/uVariables.pas	Mon Apr 01 20:08:34 2019 +0200
+++ b/hedgewars/uVariables.pas	Mon Apr 01 22:07:42 2019 +0200
@@ -807,9 +807,20 @@
             (FileName:    'amDuck'; Path: ptHedgehog; AltPath: ptNone; Texture: nil; Surface: nil;
             Width:  64; Height: 64; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true), // sprHandCreeper
             (FileName: 'amMinigun'; Path: ptHedgehog; AltPath: ptNone; Texture: nil; Surface: nil;
-            Width:  64; Height: 32; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true) // sprMinigun
+            Width:  64; Height: 32; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true), // sprMinigun
+            (FileName:  'sliderInverted'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 3; Height: 17; imageWidth: 3; imageHeight: 17; saveSurf: false; critical: true; checkSum: false; priority: tpLow; getDimensions: false; getImageDimensions: false), // sprSliderInverted
+            (FileName:     'FingerBack'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width:  32; Height: 48; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true), // sprFingerBack
+            (FileName:     'FingerBackInv'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width:  32; Height: 48; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true),// sprFingerBackInv
+            (FileName:    'TargetpBack'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width:  32; Height: 32; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true),// sprTargetPBack
+            (FileName:    'TargetpBackInv'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width:  32; Height: 32; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpMedium; getDimensions: false; getImageDimensions: true)// sprTargetPBackInv
             );
 
+
 const
     Wavez: array [TWave] of record
             Sprite: TSprite;
--- a/hedgewars/uWorld.pas	Mon Apr 01 20:08:34 2019 +0200
+++ b/hedgewars/uWorld.pas	Mon Apr 01 22:07:42 2019 +0200
@@ -1096,25 +1096,29 @@
 
         TeamHealthBarWidth:= cTeamHealthWidth * TeamHealthBarHealth div MaxTeamHealth;
 
-        // draw health bar
+        // draw team health bar
         r.x:= 0;
         r.y:= 0;
         r.w:= 2 + TeamHealthBarWidth;
         r.h:= htex^.h;
         DrawTextureFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, htex);
 
-        // draw health bars right border
+        // draw health bar's right border
         inc(r.x, cTeamHealthWidth + 2);
         r.w:= 3;
         DrawTextureFromRect(TeamHealthBarWidth + 15, cScreenHeight + DrawHealthY + smallScreenOffset, @r, htex);
 
+        // draw hedgehog health separators in team health bar
         h:= 0;
         if not hasGone then
             for i:= 0 to cMaxHHIndex do
                 begin
                 inc(h, Hedgehogs[i].HealthBarHealth);
                 if (h < TeamHealthBarHealth) and (Hedgehogs[i].HealthBarHealth > 0) then
-                    DrawTexture(15 + h * TeamHealthBarWidth div TeamHealthBarHealth, cScreenHeight + DrawHealthY + smallScreenOffset + 1, SpritesData[sprSlider].Texture);
+                    if (IsTooDarkToRead(Clan^.Color)) then
+                        DrawTexture(15 + h * TeamHealthBarWidth div TeamHealthBarHealth, cScreenHeight + DrawHealthY + smallScreenOffset + 1, SpritesData[sprSlider].Texture)
+                    else
+                        DrawTexture(15 + h * TeamHealthBarWidth div TeamHealthBarHealth, cScreenHeight + DrawHealthY + smallScreenOffset + 1, SpritesData[sprSliderInverted].Texture);
                 end;
 
         // draw Lua value, if set
@@ -1170,6 +1174,10 @@
             h:= -NameTagTex^.w - 24;
             if OwnerTex <> nil then
                 h:= h - OwnerTex^.w - 4;
+            if (IsTooDarkToRead(TeamsArray[t]^.Clan^.Color)) then
+                DrawSpriteRotatedF(sprFingerBackInv, h, cScreenHeight + DrawHealthY + smallScreenOffset + 2 + SpritesData[sprFingerBackInv].Width div 4, 0, 1, -90)
+            else
+                DrawSpriteRotatedF(sprFingerBack, h, cScreenHeight + DrawHealthY + smallScreenOffset + 2 + SpritesData[sprFingerBack].Width div 4, 0, 1, -90);
             Tint(TeamsArray[t]^.Clan^.Color shl 8 or $FF);
             DrawSpriteRotatedF(sprFinger, h, cScreenHeight + DrawHealthY + smallScreenOffset + 2 + SpritesData[sprFinger].Width div 4, 0, 1, -90);
             untint;
Binary file share/hedgewars/Data/Graphics/Finger.png has changed
Binary file share/hedgewars/Data/Graphics/FingerBack.png has changed
Binary file share/hedgewars/Data/Graphics/FingerBackInv.png has changed
Binary file share/hedgewars/Data/Graphics/Targetp.png has changed
Binary file share/hedgewars/Data/Graphics/Targetp@2x.png has changed
Binary file share/hedgewars/Data/Graphics/TargetpBack.png has changed
Binary file share/hedgewars/Data/Graphics/TargetpBack@2x.png has changed
Binary file share/hedgewars/Data/Graphics/TargetpBackInv.png has changed
Binary file share/hedgewars/Data/Graphics/TargetpBackInv@2x.png has changed
Binary file share/hedgewars/Data/Graphics/sliderInverted.png has changed