Draw dark background under chat text
authorunc0rr
Mon, 27 Oct 2008 16:49:42 +0000
changeset 1431 21ca09524f9c
parent 1430 8b192c18a584
child 1432 ab212288d34d
Draw dark background under chat text
hedgewars/uChat.pas
hedgewars/uStore.pas
--- a/hedgewars/uChat.pas	Mon Oct 27 14:54:38 2008 +0000
+++ b/hedgewars/uChat.pas	Mon Oct 27 16:49:42 2008 +0000
@@ -33,9 +33,10 @@
 const MaxStrIndex = 27;
 
 type TChatLine = record
-		s: shortstring;
+		Tex: PTexture;
 		Time: Longword;
-		Tex: PTexture;
+		Width: LongInt;
+		s: shortstring;
 		end;
 
 var Strs: array[0 .. MaxStrIndex] of TChatLine;
@@ -47,8 +48,7 @@
 
 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
 var strSurface, resSurface: PSDL_Surface;
-    r: TSDL_Rect;
-    w, h: LongInt;
+	w, h: LongInt;
 begin
 if cl.Tex <> nil then
 	FreeTexture(cl.Tex);
@@ -60,23 +60,19 @@
 TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(str), w, h);
 
 resSurface:= SDL_CreateRGBSurface(0,
-		toPowerOf2(w + 2),
-		toPowerOf2(h + 2),
+		toPowerOf2(w),
+		toPowerOf2(h),
 		32,
 		RMask, GMask, BMask, AMask);
 
-strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $202020);
-r.x:= 1;
-r.y:= 1;
-SDL_UpperBlit(strSurface, nil, resSurface, @r);
-
 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF);
+cl.Width:= w + 4;
 SDL_UpperBlit(strSurface, nil, resSurface, nil);
-
 SDL_FreeSurface(strSurface);
 
 cl.Time:= RealTicks + 12500;
 cl.Tex:= Surface2Tex(resSurface);
+
 SDL_FreeSurface(resSurface)
 end;
 
@@ -91,10 +87,26 @@
 
 procedure DrawChat;
 var i, t, cnt: Longword;
+	r: TSDL_Rect;
 begin
 cnt:= 0;
 t:= 0;
 i:= lastStr;
+
+r.x:= 6;
+r.y:= (visibleCount - t) * 16 + 10;
+r.h:= 16;
+
+if (GameState = gsChat)
+	and (InputStr.Tex <> nil) then
+	begin
+	r.w:= InputStr.Width;
+	DrawFillRect(r);
+	DrawTexture(8, visibleCount * 16 + 10, InputStr.Tex);
+	end;
+
+dec(r.y, 16);
+
 while
 	(
 			((t < 7) and (Strs[i].Time > RealTicks))
@@ -104,17 +116,17 @@
 	and
 		(Strs[i].Tex <> nil) do
 	begin
+	r.w:= Strs[i].Width;
+	DrawFillRect(r);
 	DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Tex);
+	dec(r.y, 16);
+	
 	if i = 0 then i:= MaxStrIndex else dec(i);
 	inc(cnt);
 	inc(t)
 	end;
 
 visibleCount:= cnt;
-
-if (GameState = gsChat)
-	and (InputStr.Tex <> nil) then
-	DrawTexture(8, visibleCount * 16 + 10, InputStr.Tex);
 end;
 
 procedure AcceptChatString(s: shortstring);
--- a/hedgewars/uStore.pas	Mon Oct 27 14:54:38 2008 +0000
+++ b/hedgewars/uStore.pas	Mon Oct 27 16:49:42 2008 +0000
@@ -37,6 +37,7 @@
 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
+procedure DrawFillRect(r: TSDL_Rect);
 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
 procedure RenderHealth(var Hedgehog: THedgehog);
 procedure AddProgress;
@@ -542,6 +543,25 @@
 glPopMatrix
 end;
 
+procedure DrawFillRect(r: TSDL_Rect);
+begin
+glDisable(GL_TEXTURE_2D);
+
+glColor4ub(0, 0, 0, 127);
+
+glBegin(GL_QUADS);
+
+glVertex2i(r.x       , r.y      );
+glVertex2i(r.x + r.w , r.y      );
+glVertex2i(r.x + r.w , r.y + r.h);
+glVertex2i(r.x       , r.y + r.h);
+
+glEnd();
+
+glColor4f(1, 1, 1, 1);
+glEnable(GL_TEXTURE_2D)
+end;
+
 procedure StoreRelease;
 var ii: TSprite;
 begin