Since I'm storing the text string anyway, might as well recreate captions on resize as well
authornemo
Mon, 14 Nov 2011 16:17:58 -0500
changeset 6377 3ce19204b14b
parent 6376 60e2031db563
child 6378 b812bfcfeb49
Since I'm storing the text string anyway, might as well recreate captions on resize as well
hedgewars/uCaptions.pas
hedgewars/uStore.pas
--- a/hedgewars/uCaptions.pas	Mon Nov 14 15:51:02 2011 -0500
+++ b/hedgewars/uCaptions.pas	Mon Nov 14 16:17:58 2011 -0500
@@ -25,6 +25,7 @@
 
 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 procedure DrawCaptions;
+procedure ReloadCaptions;
 
 procedure initModule;
 procedure freeModule;
@@ -36,6 +37,7 @@
                    Tex: PTexture;
                    EndTime: LongWord;
                    Text: shortstring;
+                   Color: Longword
                    end;
 var
     Captions: array[TCapGroup] of TCaptionStr;
@@ -50,6 +52,7 @@
     
     if Captions[Group].Tex = nil then
         begin
+        Captions[Group].Color:= Color;
         Captions[Group].Text:= s;
         Captions[Group].Tex:= RenderStringTex(s, Color, fntBig)
         end;
@@ -60,6 +63,16 @@
         Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
     end;
 end;
+// For uStore texture recreation
+procedure ReloadCaptions;
+var Group: TCapGroup;
+begin
+for Group:= Low(TCapGroup) to High(TCapGroup) do
+    begin
+    if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex);
+    Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig)
+    end
+end;
 
 procedure DrawCaptions;
 var
@@ -75,16 +88,17 @@
     for grp:= Low(TCapGroup) to High(TCapGroup) do
         with Captions[grp] do
             if Tex <> nil then
-            begin
+                begin
                 DrawCentered(0, offset, Tex);
                 inc(offset, Tex^.h + 2);
                 if EndTime <= RealTicks then
-                begin
+                    begin
                     FreeTexture(Tex);
                     Tex:= nil;
+                    Text:= '';
                     EndTime:= 0
+                    end;
                 end;
-            end;
 end;
 
 procedure initModule;
@@ -97,9 +111,10 @@
     group: TCapGroup;
 begin
     for group:= Low(TCapGroup) to High(TCapGroup) do
-    begin
+        begin
         FreeTexture(Captions[group].Tex);
-    end;
+        Captions[group].Tex:= nil
+        end
 end;
 
 end.
--- a/hedgewars/uStore.pas	Mon Nov 14 15:51:02 2011 -0500
+++ b/hedgewars/uStore.pas	Mon Nov 14 16:17:58 2011 -0500
@@ -21,7 +21,7 @@
 
 unit uStore;
 interface
-uses sysutils, uConsts, SDLh, GLunit, uTypes, uLandTexture;
+uses sysutils, uConsts, SDLh, GLunit, uTypes, uLandTexture, uCaptions;
 
 procedure initModule;
 procedure freeModule;
@@ -1042,6 +1042,7 @@
         StoreLoad(true);
 
         ResetLand;
+        ReloadCaptions;
 
         UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT)
         end;