fix wrong ttf blending in ppc
authorkoda
Sat, 14 Nov 2009 02:53:04 +0000
changeset 2619 bc2786a00fb8
parent 2618 23ee71bd049b
child 2620 796269129c47
fix wrong ttf blending in ppc
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/SDLh.pas
hedgewars/uChat.pas
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uLand.pas
hedgewars/uMisc.pas
hedgewars/uStats.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/hedgewars/GSHandlers.inc	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Sat Nov 14 02:53:04 2009 +0000
@@ -45,7 +45,7 @@
 		if Gear^.Kind = gtHedgehog then
 			begin
 			Gear^.State:= Gear^.State and (not gstHHDriven);
-			AddCaption(Format(GetEventString(eidDrowned), PHedgehog(Gear^.Hedgehog)^.Name), $FFFFFF, capgrpMessage);
+			AddCaption(Format(GetEventString(eidDrowned), PHedgehog(Gear^.Hedgehog)^.Name), cWhiteColor, capgrpMessage);
 			end
         end;
     PlaySound(sndSplash, false, nil)
@@ -554,7 +554,7 @@
     gtATStartGame: begin
                    AllInactive:= false;
                    if Gear^.Timer = 0 then
-                      AddCaption(trmsg[sidStartFight], $FFFFFF, capgrpGameState);
+                      AddCaption(trmsg[sidStartFight], cWhiteColor, capgrpGameState);
                    end;
  gtATSmoothWindCh: begin
                    if Gear^.Timer = 0 then
@@ -2383,9 +2383,9 @@
 if Gear^.Health < 0 then Gear^.Health:= 0;
 if (GameTicks and $3F) = 0 then
        begin
-//AddCaption('Fuel: '+inttostr(round(Gear^.Health/20))+'%', $FFFFFF, capgrpAmmostate);
+//AddCaption('Fuel: '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
        if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
-       Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', $FFFFFFFF, fntSmall)
+       Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall)
        end;
 
 if HHGear^.Message and (gm_Attack or gm_Up or gm_Precise or gm_Left or gm_Right) <> 0 then Gear^.State:= Gear^.State and not gsttmpFlag;
@@ -2416,8 +2416,8 @@
 	DeleteGear(Gear);
 	isCursorVisible:= false;
 //    if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
-//    Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', $FFFFFFFF, fntSmall)
-    //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', $FFFFFF, capgrpAmmostate);
+//    Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall)
+    //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
 	end
 end;
 
--- a/hedgewars/HHHandlers.inc	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/HHHandlers.inc	Sat Nov 14 02:53:04 2009 +0000
@@ -247,9 +247,7 @@
 		if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= MultiShootAttacks) then
 			begin
 			s:= inttostr(Ammo^[CurSlot, CurAmmo].NumPerTurn + 1 - MultiShootAttacks);
-			AddCaption(format(trmsg[sidRemaining], s),
-				$FFFFFF,
-				capgrpAmmostate);
+			AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate);
 			end;
 		
 		if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= MultiShootAttacks) or
@@ -571,7 +569,7 @@
     inc(Gear^.FlightTime, 1);
 	if Gear^.FlightTime = 2000 then
 		begin
-		AddCaption(GetEventString(eidHomerun), $FFFFFF, capgrpMessage);
+		AddCaption(GetEventString(eidHomerun), cWhiteColor, capgrpMessage);
 		PlaySound(sndHomerun, false, nil)
 		end;
 	end
@@ -734,7 +732,7 @@
 		AllInactive:= false;
 
 		// Death message
-		AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), $FFFFFF, capgrpMessage);
+		AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), cWhiteColor, capgrpMessage);
 		end;
 	exit
 	end;
--- a/hedgewars/SDLh.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/SDLh.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -242,12 +242,12 @@
 	PSDL_Color = ^TSDL_Color;
 	TSDL_Color = record
 		case byte of
-			0: (r: Byte;
+			0: (	r: Byte;
 				g: Byte;
 				b: Byte;
 				unused: Byte;
-				);
-			1: (value: Longword);
+			   );
+			1: (	value: Longword);
 		end;
 
 
--- a/hedgewars/uChat.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uChat.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -84,6 +84,7 @@
 		RMask, GMask, BMask, AMask);
 
 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), color);
+//strSurface:= doSurfaceConversion(strSurface);
 cl.Width:= w + 4;
 SDL_UpperBlit(strSurface, nil, resSurface, nil);
 SDL_FreeSurface(strSurface);
--- a/hedgewars/uConsts.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uConsts.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -1558,7 +1558,7 @@
 			);
 
 
-const convFormat: TSDL_PixelFormat = (
+const conversionFormat: TSDL_PixelFormat = (
 	palette: nil;
 	BitsPerPixel : 32;
 	BytesPerPixel: 4;
--- a/hedgewars/uGears.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uGears.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -541,7 +541,7 @@
         if Gear^.RenderTimer and (Gear^.Timer > 500) and ((Gear^.Timer mod 1000) = 0) then
             begin
             if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
-            Gear^.Tex:= RenderStringTex(inttostr(Gear^.Timer div 1000), $FFFFFFFF, fntSmall);
+            Gear^.Tex:= RenderStringTex(inttostr(Gear^.Timer div 1000), cWhiteColor, fntSmall);
             end;
         Gear^.doStep(Gear);
         end
@@ -602,7 +602,7 @@
 			if (TotalRounds = cSuddenDTurns) and (cHealthDecrease = 0) then
 				begin
 				cHealthDecrease:= 5;
-				AddCaption(trmsg[sidSuddenDeath], $FFFFFF, capgrpGameState);
+				AddCaption(trmsg[sidSuddenDeath], cWhiteColor, capgrpGameState);
 				playSound(sndSuddenDeath, false, nil);
 				end;
 
@@ -1886,7 +1886,7 @@
         FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0);
         FollowGear^.Health:= 25;
         FollowGear^.Pos:= posCaseHealth;
-		AddCaption(GetEventString(eidNewHealthPack), $FFFFFF, capgrpGameState);
+		AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpGameState);
         end;
      7..13: begin
         t:= 0;
@@ -1908,7 +1908,7 @@
               end;
             FollowGear^.Pos:= posCaseAmmo;
             FollowGear^.State:= Longword(i);
-			AddCaption(GetEventString(eidNewAmmoPack), $FFFFFF, capgrpGameState);
+			AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpGameState);
             end
         end;
      14..19: begin
@@ -1931,7 +1931,7 @@
               end;
             FollowGear^.Pos:= posCaseUtility;
             FollowGear^.State:= Longword(i);
-			AddCaption(GetEventString(eidNewUtilityPack), $FFFFFF, capgrpGameState);
+			AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpGameState);
             end
         end;
      end;
--- a/hedgewars/uLand.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uLand.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -688,7 +688,7 @@
                 Land[cpY + y, cpX + x]:= 0
             else if p^[x] = (AMask or RMask) then
                 Land[cpY + y, cpX + x]:= COLOR_INDESTRUCTIBLE
-            else if p^[x] = (AMask or RMask or GMask or BMask) then
+            else if p^[x] = cWhiteColor then
                 Land[cpY + y, cpX + x]:= COLOR_LAND;
 
             end;
@@ -788,7 +788,7 @@
 			if (y + w) mod 32 < 16 then
 				c:= AMask
 			else
-				c:= AMask or RMask or GMask;
+				c:= AMask or RMask or GMask; // FF00FFFF
 			LandPixels[y, leftX + w]:= c;
 			LandPixels[y, rightX - w]:= c;
 			end;
@@ -799,7 +799,7 @@
 			if (x + w) mod 32 < 16 then
 				c:= AMask
 			else
-				c:= AMask or RMask or GMask;
+				c:= AMask or RMask or GMask; // FF00FFFF
 			LandPixels[topY + w, x]:= c;
 			end;
 		end;
--- a/hedgewars/uMisc.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uMisc.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -46,11 +46,11 @@
 	TrainingFlags : Longword = 0;
 	TurnTimeLeft  : Longword = 0;
 	cSuddenDTurns : LongInt = 15;
-	cDamagePercent : LongInt = 100;
+	cDamagePercent  : LongInt = 100;
 	cTemplateFilter : LongInt = 0;
 
 	cHedgehogTurnTime: Longword = 45000;
-	cMinesTime     : LongInt = 3000;
+	cMinesTime       : LongInt = 3000;
 	cMaxAIThinkTime  : Longword = 9000;
 
 	cCloudsNumber    : LongInt = 9;
@@ -71,14 +71,14 @@
 	cTeamHealthWidth : LongInt = 128;
 	cAltDamage       : boolean = true;
 
-	GameTicks     : LongWord = 0;
+	GameTicks      : LongWord = 0;
 	TrainingTimeInc: Longword = 10000;
 	TrainingTimeInD: Longword = 500;
 	TrainingTimeInM: Longword = 5000;
 	TrainingTimeMax: Longword = 60000;
 
 	TimeTrialStartTime: Longword = 0;
-	TimeTrialStopTime: Longword = 0;
+	TimeTrialStopTime : Longword = 0;
 	
 	cSkyColor     : Longword = 0;
 	cWhiteColor   : Longword = $FFFFFFFF;
@@ -94,7 +94,7 @@
 	cSeed         : shortstring = '';
 	cInitVolume   : LongInt = 50;
 	cVolumeDelta  : LongInt = 0;
-	cTimerInterval   : Longword = 8;
+	cTimerInterval: Longword = 8;
 	cHasFocus     : boolean = true;
 	cInactDelay   : Longword = 1250;
 
@@ -130,8 +130,8 @@
 	AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP
 
 type HwColor4f = record
-		r, g, b, a: byte
-		end;
+	r, g, b, a: byte
+	end;
 
 var cWaterOpacity: byte = $80;
 
@@ -164,6 +164,7 @@
 procedure FreeTexture(tex: PTexture);
 function  toPowerOf2(i: Longword): Longword;
 function DecodeBase64(s: shortstring): shortstring;
+function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
 {$IFNDEF IPHONEOS}
 procedure MakeScreenshot(s: shortstring);
 {$ENDIF}
@@ -544,6 +545,19 @@
 {$ENDIF}
 {$ENDIF}
 
+function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
+{* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
+var convertedSurf: PSDL_Surface = nil;
+begin
+	if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then
+	begin
+		convertedSurf:= SDL_ConvertSurface(tmpsurf, @conversionFormat, SDL_SWSURFACE);
+		SDL_FreeSurface(tmpsurf);
+		doSurfaceConversion:= convertedSurf
+	end
+	else doSurfaceConversion:= tmpsurf;
+end;
+
 initialization
 cDrownSpeed.QWordValue:= 257698038;// 0.06
 cMaxWindSpeed.QWordValue:= 2147484;// 0.0005
--- a/hedgewars/uStats.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uStats.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -108,7 +108,7 @@
 	else if CurrentHedgehog^.stats.StepDamageRecv > 0 then
 		begin
 		PlaySound(sndStupid, false, PreviousTeam^.voicepack);
-		if DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then AddCaption(Format(GetEventString(eidHurtSelf), CurrentHedgehog^.Name), $FFFFFF, capgrpGameState);
+		if DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then AddCaption(Format(GetEventString(eidHurtSelf), CurrentHedgehog^.Name), cWhiteColor, capgrpGameState);
 		end
 	else if DamageClan <> 0 then
 		if DamageTotal > DamageClan then
@@ -134,7 +134,7 @@
 	else if isTurnSkipped then
 		begin
 		PlaySound(sndBoring, false, PreviousTeam^.voicepack);
-		AddCaption(Format(GetEventString(eidTurnSkipped), CurrentHedgehog^.Name), $FFFFFF, capgrpGameState);
+		AddCaption(Format(GetEventString(eidTurnSkipped), CurrentHedgehog^.Name), cWhiteColor, capgrpGameState);
 		end
 	else
 		PlaySound(sndCoward, false, PreviousTeam^.voicepack);
@@ -215,4 +215,4 @@
 if KilledHHs > 0 then SendStat(siKilledHHs, inttostr(KilledHHs));
 end;
 
-end.
\ No newline at end of file
+end.
--- a/hedgewars/uStore.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uStore.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -117,26 +117,27 @@
     clr: TSDL_Color;
     Result: TSDL_Rect;
 begin
-TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
-Result.x:= X;
-Result.y:= Y;
-Result.w:= w + FontBorder * 2 + 4;
-Result.h:= h + FontBorder * 2;
-DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true);
-clr.r:= Color shr 16;
-clr.g:= (Color shr 8) and $FF;
-clr.b:= Color and $FF;
-tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value);
-Result.x:= X + FontBorder + 2;
-Result.y:= Y + FontBorder;
-SDLTry(tmpsurf <> nil, true);
-SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
-SDL_FreeSurface(tmpsurf);
-Result.x:= X;
-Result.y:= Y;
-Result.w:= w + FontBorder * 2 + 4;
-Result.h:= h + FontBorder * 2;
-WriteInRoundRect:= Result
+	TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
+	Result.x:= X;
+	Result.y:= Y;
+	Result.w:= w + FontBorder * 2 + 4;
+	Result.h:= h + FontBorder * 2;
+	DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true);
+	clr.r:= Color shr 16;
+	clr.g:= (Color shr 8) and $FF;
+	clr.b:= Color and $FF;
+	tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value);
+	tmpsurf:= doSurfaceConversion(tmpsurf);
+	Result.x:= X + FontBorder + 2;
+	Result.y:= Y + FontBorder;
+	SDLTry(tmpsurf <> nil, true);
+	SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
+	SDL_FreeSurface(tmpsurf);
+	Result.x:= X;
+	Result.y:= Y;
+	Result.w:= w + FontBorder * 2 + 4;
+	Result.h:= h + FontBorder * 2;
+	WriteInRoundRect:= Result
 end;
 
 procedure StoreLoad;
@@ -390,14 +391,16 @@
 for ai:= Low(TAmmoType) to High(TAmmoType) do
 	with Ammoz[ai] do
 		begin
-		tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), $FFFFFF);
+		tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), cWhiteColor);
+		tmpsurf:= doSurfaceConversion(tmpsurf);
 		NameTex:= Surface2Tex(tmpsurf, false);
 		SDL_FreeSurface(tmpsurf)
 		end;
 
 for i:= Low(CountTexz) to High(CountTexz) do
 	begin
-	tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), $FFFFFF);
+	tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColor);
+	tmpsurf:= doSurfaceConversion(tmpsurf);	
 	CountTexz[i]:= Surface2Tex(tmpsurf, false);
 	SDL_FreeSurface(tmpsurf)
 	end;
@@ -988,6 +991,7 @@
         if Length(substr) <> 0 then
            begin
            tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack);
+	   tmpsurf:= doSurfaceConversion(tmpsurf);
            rect.x:= edgeHeight + 1 + ((i - w) div 2);
            // trying to more evenly position the text, vertically
            rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
@@ -1019,7 +1023,6 @@
 function  LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
     s: shortstring;
-    convertedSurf: PSDL_Surface;
 begin
 WriteToConsole(msgLoading + filename + '... ');
 
@@ -1059,13 +1062,7 @@
 		exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
 	end;
 
-//for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7
-if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then
-begin
-	convertedSurf:= SDL_ConvertSurface(tmpsurf, @convFormat, SDL_SWSURFACE);
-	SDL_FreeSurface(tmpsurf);	
-	tmpsurf:= convertedSurf;
-end;
+tmpsurf:= doSurfaceConversion(tmpsurf);
 
 if (imageFlags and ifTransparent) <> 0 then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
 //if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf);
--- a/hedgewars/uTeams.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uTeams.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -134,7 +134,7 @@
 TurnTimeLeft:= 0;
 if AliveCount = 0 then
 	begin // draw
-	AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState);
+	AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState);
 	SendStat(siGameResult, trmsg[sidDraw]);
 	AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
 	end else // win
@@ -152,7 +152,7 @@
 						if (Gear <> nil) then
 							Gear^.State:= gstWinner;
 
-		AddCaption(s, $FFFFFF, capgrpGameState);
+		AddCaption(s, cWhiteColor, capgrpGameState);
 		SendStat(siGameResult, s);
 		AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
 		end;
--- a/hedgewars/uWorld.pas	Fri Nov 13 23:04:23 2009 +0000
+++ b/hedgewars/uWorld.pas	Sat Nov 14 02:53:04 2009 +0000
@@ -573,7 +573,8 @@
       CountTicks:= 0;
       s:= inttostr(FPS) + ' fps';
       if fpsTexture <> nil then FreeTexture(fpsTexture);
-      tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF);
+      tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColor);
+	tmpSurface:= doSurfaceConversion(tmpSurface);
       fpsTexture:= Surface2Tex(tmpSurface, false);
       SDL_FreeSurface(tmpSurface)
       end;
@@ -588,7 +589,7 @@
    if cVolumeDelta <> 0 then
       begin
       str(ChangeVolume(cVolumeDelta), s);
-      AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume)
+      AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
       end
    end;