yo dawg, I herd you like PChar...
authorsheepluva
Tue, 04 Feb 2014 15:23:37 +0100
changeset 10104 cb0b750bd8a3
parent 10103 9c24233ca1c5
child 10105 8c5fa1d15bd5
yo dawg, I herd you like PChar...
hedgewars/uChat.pas
hedgewars/uRenderUtils.pas
hedgewars/uStore.pas
hedgewars/uUtils.pas
--- a/hedgewars/uChat.pas	Tue Feb 04 14:04:24 2014 +0100
+++ b/hedgewars/uChat.pas	Tue Feb 04 15:23:37 2014 +0100
@@ -100,7 +100,7 @@
     delete(str, 1, 1)
     end;
 
-font:= CheckCJKFont(str, fnt16);
+font:= CheckCJKFont(Str2PChar(str), fnt16);
 w:= 0; h:= 0; // avoid compiler hints
 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(str), @w, @h);
 
--- a/hedgewars/uRenderUtils.pas	Tue Feb 04 14:04:24 2014 +0100
+++ b/hedgewars/uRenderUtils.pas	Tue Feb 04 15:23:37 2014 +0100
@@ -35,7 +35,8 @@
 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
 
 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
-function  RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
+function  RenderStringTexPChar(s: PChar; Color: Longword; font: THWFont): PTexture;
+function  RenderStringTexLim(s: PChar; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
 function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
 
 implementation
@@ -270,17 +271,22 @@
 
 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
 begin
-    RenderStringTex:= RenderStringTexLim(s, Color, font, 0);
+    RenderStringTex:= RenderStringTexLim(Str2PChar(s), Color, font, 0);
 end;
 
-function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
+function RenderStringTexPChar(s: PChar; Color: Longword; font: THWFont): PTexture;
+begin
+    RenderStringTexPChar:= RenderStringTexLim(s, Color, font, 0);
+end;
+
+function RenderStringTexLim(s: PChar; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
 var w, h: LongInt;
     finalSurface: PSDL_Surface;
 begin
-    if length(s) = 0 then s:= _S' ';
+    if StrLength(s) = 0 then s:= Str2PChar(''); // conversion because pas2c ain't smart enough yet;
     font:= CheckCJKFont(s, font);
     w:= 0; h:= 0; // avoid compiler hints
-    TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
+    TTF_SizeUTF8(Fontz[font].Handle, s, @w, @h);
     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
 
     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
@@ -336,7 +342,7 @@
 
     if length(s) = 0 then
         s:= '...';
-    font:= CheckCJKFont(s, font);
+    font:= CheckCJKFont(Str2PChar(s), font);
     w:= 0; h:= 0; // avoid compiler hints
     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
     if w<8 then
--- a/hedgewars/uStore.pas	Tue Feb 04 14:04:24 2014 +0100
+++ b/hedgewars/uStore.pas	Tue Feb 04 15:23:37 2014 +0100
@@ -185,9 +185,9 @@
 for t:= 0 to Pred(TeamsCount) do
     with TeamsArray[t]^ do
         begin
-        NameTagTex:= RenderStringTexLim(TeamName, Clan^.Color, Font, cTeamHealthWidth);
+        NameTagTex:= RenderStringTexLim(Str2PChar(TeamName), Clan^.Color, Font, cTeamHealthWidth);
         if length(Owner) > 0 then
-            OwnerTex:= RenderStringTexLim(Owner, Clan^.Color, Font, cTeamHealthWidth);
+            OwnerTex:= RenderStringTexLim(Str2PChar(Owner), Clan^.Color, Font, cTeamHealthWidth);
 
         r.x:= 0;
         r.y:= 0;
@@ -261,7 +261,7 @@
             with Hedgehogs[i] do
                 if Gear <> nil then
                     begin
-                    NameTagTex:= RenderStringTexLim(Name, Clan^.Color, fnt16, cTeamHealthWidth);
+                    NameTagTex:= RenderStringTexLim(Str2PChar(Name), Clan^.Color, fnt16, cTeamHealthWidth);
                     if Hat = 'NoHat' then
                         begin
                         if (month = 4) and (md = 20) then
@@ -438,10 +438,10 @@
 
 InitHealth;
 
-PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig);
-AFKTexture:= RenderStringTex(trmsg[sidAFK], cYellowColor, fntBig);
-ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
-SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig);
+PauseTexture:= RenderStringTexPChar(trmsg[sidPaused], cYellowColor, fntBig);
+AFKTexture:= RenderStringTexPChar(trmsg[sidAFK], cYellowColor, fntBig);
+ConfirmTexture:= RenderStringTexPChar(trmsg[sidConfirm], cYellowColor, fntBig);
+SyncTexture:= RenderStringTexPChar(trmsg[sidSync], cYellowColor, fntBig);
 
 if not reload then
     AddProgress;
@@ -450,8 +450,8 @@
 for ai:= Low(TAmmoType) to High(TAmmoType) do
     with Ammoz[ai] do
         begin
-        TryDo(trAmmo[NameId] <> '','No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
-        tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
+        TryDo(trAmmo[NameId][0] <> #0,'No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
+        tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, trAmmo[NameId], cWhiteColorChannels);
         TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
         tmpsurf:= doSurfaceConversion(tmpsurf);
         FreeTexture(NameTex);
@@ -1238,10 +1238,10 @@
     tmpline, tmpline2, tmpdesc: ansistring;
 begin
 // make sure there is a caption as well as a sub caption - description is optional
-if caption = '' then
-    caption:= '???';
-if subcaption = '' then
-    subcaption:= _S' ';
+if caption[0] = #0 then
+    caption:= Str2PChar(_S'???');
+if subcaption[0] = #0 then
+    subcaption:= Str2PChar(_S' ');
 
 font:= CheckCJKFont(caption,fnt16);
 font:= CheckCJKFont(subcaption,font);
@@ -1285,7 +1285,7 @@
         end
     end;
 
-if extra <> '' then
+if extra[0] <> #0 then
     begin
     // get extra label's dimensions
     TTF_SizeUTF8(Fontz[font].Handle, extra, @i, @j);
@@ -1332,7 +1332,7 @@
         end
     end;
 
-if extra <> '' then
+if extra[0] <> #0 then
     r:= WriteInRect(tmpsurf, cFontBorder + 2, r.y + r.h, extracolor, font, extra);
 
 r.x:= cFontBorder + 6;
@@ -1370,7 +1370,7 @@
 r.h:= 32;
 
 // default (no extra text)
-extra:= _S'';
+extra:= Str2PChar(''); // conversion because pas2c ain't smart enough yet
 extracolor:= 0;
 
 if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available
@@ -1385,7 +1385,7 @@
     end
 else
     begin
-    extra:= _S'';
+    extra:= Str2PChar(''); // conversion because pas2c ain't smart enough yet
     extracolor:= 0;
     end;
 
--- a/hedgewars/uUtils.pas	Tue Feb 04 14:04:24 2014 +0100
+++ b/hedgewars/uUtils.pas	Tue Feb 04 15:23:37 2014 +0100
@@ -60,7 +60,7 @@
 
 function  endian(independent: LongWord): LongWord; inline;
 
-function  CheckCJKFont(s: ansistring; font: THWFont): THWFont;
+function  CheckCJKFont(s: PChar; font: THWFont): THWFont;
 
 procedure AddFileLog(s: shortstring);
 procedure AddFileLogRaw(s: pchar); cdecl;
@@ -364,7 +364,7 @@
 {$ENDIF}
 end;
 
-function CheckCJKFont(s: ansistring; font: THWFont): THWFont;
+function CheckCJKFont(s: PChar; font: THWFont): THWFont;
 var l, i : LongInt;
     u: WideChar;
     tmpstr: array[0..256] of WideChar;
@@ -373,11 +373,11 @@
 
 {$IFNDEF MOBILE}
 // remove chinese fonts for now
-if (font >= CJKfnt16) or (length(s) = 0) then
+if (font >= CJKfnt16) or (StrLength(s) = 0) then
 {$ENDIF}
     exit;
 
-l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1;
+l:= Utf8ToUnicode(@tmpstr, s, StrLength(s))-1;
 i:= 0;
 
 while i < l do