hedgewars/uChat.pas
changeset 945 4ead9cde4e14
parent 942 b41af014d85e
child 946 42c5cc87cbd1
equal deleted inserted replaced
944:9299c0ebfdbc 945:4ead9cde4e14
    22 
    22 
    23 procedure AddChatString(s: shortstring);
    23 procedure AddChatString(s: shortstring);
    24 procedure DrawChat;
    24 procedure DrawChat;
    25 
    25 
    26 implementation
    26 implementation
    27 uses uMisc, uStore, uConsts;
    27 uses uMisc, uStore, uConsts, SDLh;
    28 
    28 
    29 const MaxStrIndex = 7;
    29 const MaxStrIndex = 7;
    30 
    30 
    31 type TStr = record
    31 type TStr = record
    32 		Time: Longword;
    32 		Time: Longword;
    33 		Tex: PTexture;
    33 		Tex: PTexture;
    34 		end;
    34 		end;
    35 
    35 
    36 var Strs: array[0 .. MaxStrIndex] of TStr;
    36 var Strs: array[0 .. MaxStrIndex] of TStr;
    37 	lastStr: Longword = 0;
    37 	lastStr: Longword = 0;
       
    38 	visibleCount: Longword = 0;
    38 
    39 
    39 procedure AddChatString(s: shortstring);
    40 procedure AddChatString(s: shortstring);
       
    41 var strSurface, resSurface: PSDL_Surface;
       
    42     r: TSDL_Rect;
       
    43     w, h: LongInt;
    40 begin
    44 begin
    41 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1);
    45 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1);
    42 
    46 
       
    47 TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(s), w, h);
       
    48 
       
    49 resSurface:= SDL_CreateRGBSurface(0,
       
    50 		toPowerOf2(w + 2),
       
    51 		toPowerOf2(h + 2),
       
    52 		32,
       
    53 		RMask, GMask, BMask, AMask);
       
    54 
       
    55 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $202020);
       
    56 r.x:= 1;
       
    57 r.y:= 1;
       
    58 SDL_UpperBlit(strSurface, nil, resSurface, @r);
       
    59 
       
    60 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF);
       
    61 SDL_UpperBlit(strSurface, nil, resSurface, nil);
       
    62 
       
    63 SDL_FreeSurface(strSurface);
       
    64 
       
    65 
    43 Strs[lastStr].Time:= RealTicks + 7500;
    66 Strs[lastStr].Time:= RealTicks + 7500;
    44 Strs[lastStr].Tex:= RenderStringTex(s, $FFFFFF, fnt16)
    67 Strs[lastStr].Tex:= Surface2Tex(resSurface);
       
    68 SDL_FreeSurface(resSurface);
       
    69 
       
    70 inc(visibleCount)
    45 end;
    71 end;
    46 
    72 
    47 procedure DrawChat;
    73 procedure DrawChat;
       
    74 var i, t, cnt: Longword;
    48 begin
    75 begin
    49 if Strs[lastStr].Tex <> nil then DrawTexture(10, 10, Strs[lastStr].Tex)
    76 cnt:= 0;
       
    77 t:= 0;
       
    78 i:= lastStr;
       
    79 while (t <= MaxStrIndex)
       
    80 	and (Strs[i].Tex <> nil)
       
    81 	and (Strs[i].Time > RealTicks) do
       
    82 	begin
       
    83 	DrawTexture(8, (visibleCount - t) * 16 - 8, Strs[i].Tex);
       
    84 	if i = 0 then i:= MaxStrIndex else dec(i);
       
    85 	inc(cnt);
       
    86 	inc(t)
       
    87 	end;
       
    88 
       
    89 visibleCount:= cnt
    50 end;
    90 end;
    51 
    91 
    52 end.
    92 end.