diff -r 2d859d34e6f6 -r 8563cc40fc1e hedgewars/uRenderUtils.pas --- 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;