1 (* 2 * Hedgewars, a free turn based strategy game 3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 *) 18 19 {$INCLUDE "options.inc"} 20 21 unit uCaptions; 22 23 interface 24 uses uTypes; 25 26 procedure AddCaption(s: ansistring; Color: Longword; Group: TCapGroup); 27 procedure DrawCaptions; 28 procedure ReloadCaptions(unload: boolean); 29 30 procedure initModule; 31 procedure freeModule; 32 33 implementation 34 uses uTextures, uRenderUtils, uVariables, uRender; 35 36 type TCaptionStr = record 37 Tex: PTexture; 38 EndTime: LongWord; 39 Text: ansistring; 40 Color: Longword 41 end; 42 var 43 Captions: array[TCapGroup] of TCaptionStr; 44 45 procedure AddCaption(s: ansistring; Color: Longword; Group: TCapGroup); 46 begin 47 if cOnlyStats then exit; 48 if Length(s) = 0 then 49 exit; 50 if (Captions[Group].Text <> s) or (Captions[Group].Color <> Color) then 51 FreeAndNilTexture(Captions[Group].Tex); 52 53 if Captions[Group].Tex = nil then 54 begin 55 Captions[Group].Color:= Color; 56 Captions[Group].Text:= s; 57 Captions[Group].Tex:= RenderStringTex(s, Color, fntBig) 58 end; 59 60 case Group of 61 capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200 62 else 63 Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3; 64 end; 65 end; 66 67 // For uStore texture recreation 68 procedure ReloadCaptions(unload: boolean); 69 var Group: TCapGroup; 70 begin 71 for Group:= Low(TCapGroup) to High(TCapGroup) do 72 if unload then 73 FreeAndNilTexture(Captions[Group].Tex) 74 else if length(Captions[Group].Text) > 0 then 75 Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig) 76 end; 77 78 procedure DrawCaptions; 79 var 80 grp: TCapGroup; 81 offset: LongInt; 82 begin 83 {$IFDEF USE_TOUCH_INTERFACE} 84 offset:= 48; 85 {$ELSE} 86 offset:= 8; 87 {$ENDIF} 88 89 for grp:= Low(TCapGroup) to High(TCapGroup) do 90 with Captions[grp] do 91 if Tex <> nil then 92 begin 93 DrawTextureCentered(0, offset, Tex); 94 inc(offset, Tex^.h + 2); 95 if EndTime <= RealTicks then 96 begin 97 FreeAndNilTexture(Tex); 98 Text:= ansistring(''); 99 EndTime:= 0 100 end; 101 end; 102 end; 103 104 procedure initModule; 105 begin 106 FillChar(Captions, sizeof(Captions), 0) 107 end; 108 109 procedure freeModule; 110 var group: TCapGroup; 111 begin 112 for group:= Low(TCapGroup) to High(TCapGroup) do 113 FreeAndNilTexture(Captions[group].Tex); 114 end; 115 116 end. 117