DEADSOFTWARE

gl: more animation checks
[d2df-sdl.git] / src / game / renders / opengl / r_console.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_console;
18 interface
20 procedure r_Console_Initialize;
21 procedure r_Console_Finalize;
23 procedure r_Console_Load;
24 procedure r_Console_Free;
26 procedure r_Console_Update;
27 procedure r_Console_Draw (MessagesOnly: Boolean);
29 implementation
31 uses
32 Math, SysUtils, utils, conbuf,
33 g_game, g_options, g_console, g_language,
34 r_draw, r_textures, r_fonts, r_common
35 ;
37 var
38 Background: TGLTexture;
40 ConsoleTrans: Single;
41 ChatTop: BOOLEAN;
43 Cons_Y: SmallInt;
44 ConsoleHeight: Single;
45 ConsoleStep: Single;
46 Cons_Shown: Boolean; // draw console
48 procedure r_Console_Initialize;
49 begin
50 Cons_Y := Round(-Floor(gScreenHeight * ConsoleHeight));
51 end;
53 procedure r_Console_Finalize;
54 begin
55 end;
57 procedure r_Console_Load;
58 begin
59 r_Common_SetLoading(_lc[I_LOAD_CONSOLE], 1);
60 Background := r_Textures_LoadFromFile(GameWad + ':TEXTURES/CONSOLE', [TGLHints.txNoRepeat]);
61 end;
63 procedure r_Console_Free;
64 begin
65 r_Common_FreeAndNil(Background);
66 end;
68 procedure r_Console_Update;
69 var step, miny: Integer;
70 begin
71 step := MAX(1, Round(Floor(gScreenHeight * ConsoleHeight) * ConsoleStep));
72 miny := Round(-Floor(gScreenHeight * ConsoleHeight));
73 if gConsoleShow then
74 Cons_Y := Cons_Y + step
75 else
76 Cons_Y := Cons_Y - step;
77 Cons_Y := MIN(MAX(Cons_Y, miny), 0);
78 Cons_Shown := Cons_Y > miny;
79 end;
81 procedure r_Console_DrawLog;
82 var cw, ch, ty, skip: Integer; sp, ep: LongWord;
84 procedure PutLine (sp, ep: LongWord);
85 var p: LongWord; w, chw: Integer;
86 begin
87 p := sp; w := 0; chw := 0;
88 while (p <> ep) and (w + chw <= gScreenWidth - 8) do
89 begin
90 chw := stdfont.GetWidth(cbufAt(p));
91 INC(w, chw);
92 cbufNext(p);
93 end;
94 if p <> ep then
95 PutLine(p, ep);
96 if skip = 0 then
97 begin
98 ep := p; p := sp; w := 2;
99 while p <> ep do
100 begin
101 r_Draw_Text(cbufAt(p), w, ty, 255, 255, 255, 255, stdfont);
102 chw := stdfont.GetWidth(cbufAt(p));
103 INC(w, chw);
104 cbufNext(p);
105 end;
106 DEC(ty, ch);
107 end
108 else
109 begin
110 DEC(skip);
111 end;
112 end;
114 begin
115 cw := stdfont.GetMaxWidth();
116 ch := stdfont.GetMaxHeight();
117 ty := Floor(gScreenHeight * ConsoleHeight) - 4 - 2 * ch - Abs(Cons_Y);
118 skip := conSkipLines;
119 cbufLastLine(sp, ep);
120 repeat
121 PutLine(sp, ep);
122 until (ty + ch <= 0) or (cbufLineUp(sp, ep) = false);
123 end;
125 procedure r_Console_Draw (MessagesOnly: Boolean);
126 var cw, ch, y, i: Integer; s: AnsiString;
127 begin
128 cw := stdfont.GetMaxWidth();
129 ch := stdfont.GetMaxHeight();
131 if ChatTop and gChatShow then y := ch else y := 0;
133 for i := 0 to High(MsgArray) do
134 if MsgArray[i].time > 0 then
135 r_Draw_Text(MsgArray[i].msg, 0, y + ch * i, 255, 255, 255, 255, stdfont);
137 if MessagesOnly = false then
138 begin
139 if gChatShow then
140 begin
141 if ChatTop then y := 0 else y := gScreenHeight - ch - 1;
142 if gChatTeam then s := 'say team> ' else s := 'say> ';
143 r_Draw_Text(s + Line, 0, y, 255, 255, 255, 255, stdfont);
144 r_Draw_Text('_', (CPos + 4) * cw, y, 255, 255, 255, 255, stdfont);
145 end;
147 if Cons_Shown then
148 begin
149 if gDebugMode then
150 begin
151 // TODO draw debug string
152 end;
154 if Background <> nil then
155 r_Draw_Texture(Background, 0, Cons_Y, gScreenWidth, Floor(gScreenHeight * ConsoleHeight), false, 255, 255, 255, Round((1.0 - ConsoleTrans) * 255), false);
157 r_Console_DrawLog;
159 r_Draw_Text('> ' + Line, 0, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - ch - 4, 255, 255, 255, 255, stdfont);
160 r_Draw_Text('_', (CPos + 1) * cw, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - 21, 255, 255, 255, 255, stdfont);
161 end;
162 end;
163 end;
165 initialization
166 conRegVar('chat_at_top', @ChatTop, 'draw chat at top border', 'draw chat at top border');
167 conRegVar('console_height', @ConsoleHeight, 0.0, 1.0, 'set console size', 'set console size');
168 conRegVar('console_step', @ConsoleStep, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
169 conRegVar('console_trans', @ConsoleTrans, 0.0, 1.0, 'set console transparency', 'set console transparency');
170 {$IFDEF ANDROID}
171 ChatTop := True;
172 ConsoleHeight := 0.35;
173 {$ELSE}
174 ChatTop := False;
175 ConsoleHeight := 0.5;
176 {$ENDIF}
177 ConsoleStep := 0.07;
178 ConsoleTrans := 0.1;
179 end.