hedgewars/uChat.pas
changeset 10985 c5348fe9077c
parent 10926 43612076e989
child 11004 bd62cdbea391
equal deleted inserted replaced
10984:c828cabe33af 10985:c5348fe9077c
   150     ResetSelection();
   150     ResetSelection();
   151     cursorPos:= 0;
   151     cursorPos:= 0;
   152     UpdateCursorCoords();
   152     UpdateCursorCoords();
   153 end;
   153 end;
   154 
   154 
       
   155 (* This procedure [re]renders a texture showing str for the chat line cl.
       
   156  * It will use the color stored in cl and update width
       
   157  *)
   155 procedure RenderChatLineTex(var cl: TChatLine; var str: shortstring);
   158 procedure RenderChatLineTex(var cl: TChatLine; var str: shortstring);
   156 var strSurface,
   159 var strSurface,
   157     resSurface: PSDL_Surface;
   160     resSurface: PSDL_Surface;
   158     dstrect   : TSDL_Rect; // destination rectangle for blitting
   161     dstrect   : TSDL_Rect; // destination rectangle for blitting
   159     font      : THWFont;
   162     font      : THWFont;
   160 const
   163 const
   161     shadowint  = $80 shl AShift;
   164     shadowint  = $80 shl AShift;
   162 begin
   165 begin
   163 
   166 
       
   167 FreeAndNilTexture(cl.Tex);
       
   168 
   164 font:= CheckCJKFont(ansistring(str), fnt16);
   169 font:= CheckCJKFont(ansistring(str), fnt16);
   165 
   170 
   166 // get render size of text
   171 // get render size of text
   167 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @cl.Width, nil);
   172 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @cl.Width, nil);
   168 
   173 
   197 const ClDisplayDuration = 12500;
   202 const ClDisplayDuration = 12500;
   198 
   203 
   199 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
   204 procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean);
   200 var color  : TSDL_Color;
   205 var color  : TSDL_Color;
   201 begin
   206 begin
   202 if cl.Tex <> nil then
       
   203     FreeAndNilTexture(cl.Tex);
       
   204 
       
   205 if isInput then
   207 if isInput then
   206     begin
   208     begin
   207     cl.s:= str;
   209     cl.s:= str;
   208     color:= colors[#6];
   210     color:= colors[#6];
   209     str:= str + ' ';
   211     str:= str + ' ';
   230 cl.Time:= RealTicks + ClDisplayDuration;
   232 cl.Time:= RealTicks + ClDisplayDuration;
   231 end;
   233 end;
   232 
   234 
   233 // For uStore texture recreation
   235 // For uStore texture recreation
   234 procedure ReloadLines;
   236 procedure ReloadLines;
   235 var i, t: LongWord;
   237 var i: LongWord;
   236 begin
   238 begin
   237     if InputStr.s <> '' then
   239     if InputStr.s <> '' then
   238         SetLine(InputStr, InputStr.s, true);
   240         SetLine(InputStr, InputStr.s, true);
   239     for i:= 0 to MaxStrIndex do
   241     for i:= 0 to MaxStrIndex do
   240         if Strs[i].s <> '' then
   242         if Strs[i].s <> '' then
   241             begin
   243             begin
   242             t:= Strs[i].Time;
   244             RenderChatLineTex(Strs[i], Strs[i].s);
   243             SetLine(Strs[i], Strs[i].s, false);
       
   244             Strs[i].Time:= t
       
   245             end;
   245             end;
   246 end;
   246 end;
   247 
   247 
   248 procedure AddChatString(s: shortstring);
   248 procedure AddChatString(s: shortstring);
   249 begin
   249 begin