hedgewars/uChat.pas
changeset 1116 dd6db8e09f9e
parent 1066 1f1b3686a2b0
child 1118 caf47265d03f
--- a/hedgewars/uChat.pas	Sun Jul 27 15:28:49 2008 +0000
+++ b/hedgewars/uChat.pas	Sun Jul 27 16:03:45 2008 +0000
@@ -35,7 +35,7 @@
 type TChatLine = record
 		s: shortstring;
 		Time: Longword;
-		Tex: PTexture;
+		Texb, Texf: PTexture;
 		end;
 
 var Strs: array[0 .. MaxStrIndex] of TChatLine;
@@ -46,38 +46,33 @@
 	InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
 
 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
-var strSurface, resSurface: PSDL_Surface;
-    r: TSDL_Rect;
-    w, h: LongInt;
+var surf: PSDL_Surface;
 begin
-if cl.Tex <> nil then
-	FreeTexture(cl.Tex);
+if cl.Texb <> nil then
+	begin
+	FreeTexture(cl.Texb);
+	FreeTexture(cl.Texf)
+	end;
 
 cl.s:= str;
 
 if isInput then str:= UserNick + '> ' + str + '_';
 
-TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(str), w, h);
+cl.Time:= RealTicks + 12500;
 
-resSurface:= SDL_CreateRGBSurface(0,
-		toPowerOf2(w + 2),
-		toPowerOf2(h + 2),
-		32,
-		RMask, GMask, BMask, AMask);
+TryDo(str <> '', 'Error: null chat string', true);
 
-strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $202020);
-r.x:= 1;
-r.y:= 1;
-SDL_UpperBlit(strSurface, nil, resSurface, @r);
+surf:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $202020);
+surf:= SDL_DisplayFormatAlpha(surf);
+TryDo(surf <> nil, 'Chat: fail to render string', true);
+cl.Texb:= Surface2Tex(surf);
+SDL_FreeSurface(surf);
 
-strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF);
-SDL_UpperBlit(strSurface, nil, resSurface, nil);
-
-SDL_FreeSurface(strSurface);
-
-cl.Time:= RealTicks + 12500;
-cl.Tex:= Surface2Tex(resSurface);
-SDL_FreeSurface(resSurface)
+surf:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF);
+surf:= SDL_DisplayFormatAlpha(surf);
+TryDo(surf <> nil, 'Chat: fail to render string', true);
+cl.Texf:= Surface2Tex(surf);
+SDL_FreeSurface(surf)
 end;
 
 procedure AddChatString(s: shortstring);
@@ -90,6 +85,7 @@
 end;
 
 procedure DrawChat;
+const shift = 2;
 var i, t, cnt: Longword;
 begin
 cnt:= 0;
@@ -102,9 +98,10 @@
 			((t < MaxStrIndex) and showAll)
 	)
 	and
-		(Strs[i].Tex <> nil) do
+		(Strs[i].Texb <> nil) do
 	begin
-	DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Tex);
+	DrawTexture(8 + shift, (visibleCount - t) * 16 - 6 + shift, Strs[i].Texb);
+	DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Texf);
 	if i = 0 then i:= MaxStrIndex else dec(i);
 	inc(cnt);
 	inc(t)
@@ -113,8 +110,11 @@
 visibleCount:= cnt;
 
 if (GameState = gsChat)
-	and (InputStr.Tex <> nil) then
-	DrawTexture(8, visibleCount * 16 + 10, InputStr.Tex);
+	and (InputStr.Texb <> nil) then
+	begin
+	DrawTexture(8 + shift, visibleCount * 16 + 10 + shift, InputStr.Texb);
+	DrawTexture(8, visibleCount * 16 + 10, InputStr.Texf)
+	end
 end;
 
 procedure AcceptChatString(s: shortstring);
@@ -152,7 +152,7 @@
 			if Length(InputStr.s) > 0 then
 				begin
 				AcceptChatString(InputStr.s);
-				SetLine(InputStr, '', false)
+				SetLine(InputStr, '', true)
 				end;
 			FreezeEnterKey;
 			GameState:= gsGame