hedgewars/uChat.pas
changeset 1431 21ca09524f9c
parent 1378 1a391883261d
child 1485 51c11e77408a
equal deleted inserted replaced
1430:8b192c18a584 1431:21ca09524f9c
    31 uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys, uTeams;
    31 uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys, uTeams;
    32 
    32 
    33 const MaxStrIndex = 27;
    33 const MaxStrIndex = 27;
    34 
    34 
    35 type TChatLine = record
    35 type TChatLine = record
       
    36 		Tex: PTexture;
       
    37 		Time: Longword;
       
    38 		Width: LongInt;
    36 		s: shortstring;
    39 		s: shortstring;
    37 		Time: Longword;
       
    38 		Tex: PTexture;
       
    39 		end;
    40 		end;
    40 
    41 
    41 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    42 var Strs: array[0 .. MaxStrIndex] of TChatLine;
    42 	lastStr: Longword = 0;
    43 	lastStr: Longword = 0;
    43 	visibleCount: Longword = 0;
    44 	visibleCount: Longword = 0;
    45 	InputStr: TChatLine;
    46 	InputStr: TChatLine;
    46 	InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    47 	InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
    47 
    48 
    48 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
    49 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
    49 var strSurface, resSurface: PSDL_Surface;
    50 var strSurface, resSurface: PSDL_Surface;
    50     r: TSDL_Rect;
    51 	w, h: LongInt;
    51     w, h: LongInt;
       
    52 begin
    52 begin
    53 if cl.Tex <> nil then
    53 if cl.Tex <> nil then
    54 	FreeTexture(cl.Tex);
    54 	FreeTexture(cl.Tex);
    55 
    55 
    56 cl.s:= str;
    56 cl.s:= str;
    58 if isInput then str:= UserNick + '> ' + str + '_';
    58 if isInput then str:= UserNick + '> ' + str + '_';
    59 
    59 
    60 TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(str), w, h);
    60 TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(str), w, h);
    61 
    61 
    62 resSurface:= SDL_CreateRGBSurface(0,
    62 resSurface:= SDL_CreateRGBSurface(0,
    63 		toPowerOf2(w + 2),
    63 		toPowerOf2(w),
    64 		toPowerOf2(h + 2),
    64 		toPowerOf2(h),
    65 		32,
    65 		32,
    66 		RMask, GMask, BMask, AMask);
    66 		RMask, GMask, BMask, AMask);
    67 
    67 
    68 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $202020);
       
    69 r.x:= 1;
       
    70 r.y:= 1;
       
    71 SDL_UpperBlit(strSurface, nil, resSurface, @r);
       
    72 
       
    73 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF);
    68 strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF);
       
    69 cl.Width:= w + 4;
    74 SDL_UpperBlit(strSurface, nil, resSurface, nil);
    70 SDL_UpperBlit(strSurface, nil, resSurface, nil);
    75 
       
    76 SDL_FreeSurface(strSurface);
    71 SDL_FreeSurface(strSurface);
    77 
    72 
    78 cl.Time:= RealTicks + 12500;
    73 cl.Time:= RealTicks + 12500;
    79 cl.Tex:= Surface2Tex(resSurface);
    74 cl.Tex:= Surface2Tex(resSurface);
       
    75 
    80 SDL_FreeSurface(resSurface)
    76 SDL_FreeSurface(resSurface)
    81 end;
    77 end;
    82 
    78 
    83 procedure AddChatString(s: shortstring);
    79 procedure AddChatString(s: shortstring);
    84 begin
    80 begin
    89 inc(visibleCount)
    85 inc(visibleCount)
    90 end;
    86 end;
    91 
    87 
    92 procedure DrawChat;
    88 procedure DrawChat;
    93 var i, t, cnt: Longword;
    89 var i, t, cnt: Longword;
       
    90 	r: TSDL_Rect;
    94 begin
    91 begin
    95 cnt:= 0;
    92 cnt:= 0;
    96 t:= 0;
    93 t:= 0;
    97 i:= lastStr;
    94 i:= lastStr;
       
    95 
       
    96 r.x:= 6;
       
    97 r.y:= (visibleCount - t) * 16 + 10;
       
    98 r.h:= 16;
       
    99 
       
   100 if (GameState = gsChat)
       
   101 	and (InputStr.Tex <> nil) then
       
   102 	begin
       
   103 	r.w:= InputStr.Width;
       
   104 	DrawFillRect(r);
       
   105 	DrawTexture(8, visibleCount * 16 + 10, InputStr.Tex);
       
   106 	end;
       
   107 
       
   108 dec(r.y, 16);
       
   109 
    98 while
   110 while
    99 	(
   111 	(
   100 			((t < 7) and (Strs[i].Time > RealTicks))
   112 			((t < 7) and (Strs[i].Time > RealTicks))
   101 		or
   113 		or
   102 			((t < MaxStrIndex) and showAll)
   114 			((t < MaxStrIndex) and showAll)
   103 	)
   115 	)
   104 	and
   116 	and
   105 		(Strs[i].Tex <> nil) do
   117 		(Strs[i].Tex <> nil) do
   106 	begin
   118 	begin
       
   119 	r.w:= Strs[i].Width;
       
   120 	DrawFillRect(r);
   107 	DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Tex);
   121 	DrawTexture(8, (visibleCount - t) * 16 - 6, Strs[i].Tex);
       
   122 	dec(r.y, 16);
       
   123 	
   108 	if i = 0 then i:= MaxStrIndex else dec(i);
   124 	if i = 0 then i:= MaxStrIndex else dec(i);
   109 	inc(cnt);
   125 	inc(cnt);
   110 	inc(t)
   126 	inc(t)
   111 	end;
   127 	end;
   112 
   128 
   113 visibleCount:= cnt;
   129 visibleCount:= cnt;
   114 
       
   115 if (GameState = gsChat)
       
   116 	and (InputStr.Tex <> nil) then
       
   117 	DrawTexture(8, visibleCount * 16 + 10, InputStr.Tex);
       
   118 end;
   130 end;
   119 
   131 
   120 procedure AcceptChatString(s: shortstring);
   132 procedure AcceptChatString(s: shortstring);
   121 var i: TWave;
   133 var i: TWave;
   122 begin
   134 begin