DEADSOFTWARE

60b14c1f6b12c38b485691b6dc483d51a4e646d3
[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, utils, conbuf,
33 g_game, g_options, g_console,
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 Background := r_Textures_LoadFromFile(GameWad + ':TEXTURES/CONSOLE');
60 end;
62 procedure r_Console_Free;
63 begin
64 Background.Free;
65 end;
67 procedure r_Console_Update;
68 var step, miny: Integer;
69 begin
70 step := MAX(1, Round(Floor(gScreenHeight * ConsoleHeight) * ConsoleStep));
71 miny := Round(-Floor(gScreenHeight * ConsoleHeight));
72 if gConsoleShow then
73 Cons_Y := Cons_Y + step
74 else
75 Cons_Y := Cons_Y - step;
76 Cons_Y := MIN(MAX(Cons_Y, miny), 0);
77 Cons_Shown := Cons_Y > miny;
78 end;
80 procedure r_Console_DrawLog;
81 var cw, ch, ty, skip: Integer; sp, ep: LongWord;
83 procedure PutLine (sp, ep: LongWord);
84 var p: LongWord; w, chw: Integer;
85 begin
86 p := sp; w := 0; chw := 0;
87 while (p <> ep) and (w + chw <= gScreenWidth - 8) do
88 begin
89 chw := stdfont.GetWidth(cbufAt(p));
90 INC(w, chw);
91 cbufNext(p);
92 end;
93 if p <> ep then
94 PutLine(p, ep);
95 if skip = 0 then
96 begin
97 ep := p; p := sp; w := 2;
98 while p <> ep do
99 begin
100 r_Draw_Text(cbufAt(p), w, ty, 255, 255, 255, 255, stdfont);
101 chw := stdfont.GetWidth(cbufAt(p));
102 INC(w, chw);
103 cbufNext(p);
104 end;
105 DEC(ty, ch);
106 end
107 else
108 begin
109 DEC(skip);
110 end;
111 end;
113 begin
114 cw := stdfont.GetMaxWidth();
115 ch := stdfont.GetMaxHeight();
116 ty := Floor(gScreenHeight * ConsoleHeight) - 4 - 2 * ch - Abs(Cons_Y);
117 skip := conSkipLines;
118 cbufLastLine(sp, ep);
119 repeat
120 PutLine(sp, ep);
121 until (ty + ch <= 0) or (cbufLineUp(sp, ep) = false);
122 end;
124 procedure r_Console_Draw (MessagesOnly: Boolean);
125 var cw, ch, y, i: Integer; s: AnsiString;
126 begin
127 cw := stdfont.GetMaxWidth();
128 ch := stdfont.GetMaxHeight();
130 if ChatTop and gChatShow then y := ch else y := 0;
132 for i := 0 to High(MsgArray) do
133 if MsgArray[i].time > 0 then
134 r_Draw_Text(MsgArray[i].msg, 0, y + ch * i, 255, 255, 255, 255, stdfont);
136 if MessagesOnly = false then
137 begin
138 if gChatShow then
139 begin
140 if ChatTop then y := 0 else y := gScreenHeight - ch - 1;
141 if gChatTeam then s := 'say team> ' else s := 'say> ';
142 r_Draw_Text(s + Line, 0, y, 255, 255, 255, 255, stdfont);
143 r_Draw_Text('_', (CPos + 4) * cw, y, 255, 255, 255, 255, stdfont);
144 end;
146 if Cons_Shown then
147 begin
148 if gDebugMode then
149 begin
150 // TODO draw debug string
151 end;
153 if Background <> nil then
154 r_Draw_Texture(Background, 0, Cons_Y, gScreenWidth, Floor(gScreenHeight * ConsoleHeight), false, 255, 255, 255, Round((1.0 - ConsoleTrans) * 255), false);
156 r_Console_DrawLog;
158 r_Draw_Text('> ' + Line, 0, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - ch - 4, 255, 255, 255, 255, stdfont);
159 r_Draw_Text('_', (CPos + 1) * cw, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - 21, 255, 255, 255, 255, stdfont);
160 end;
161 end;
162 end;
164 initialization
165 conRegVar('chat_at_top', @ChatTop, 'draw chat at top border', 'draw chat at top border');
166 conRegVar('console_height', @ConsoleHeight, 0.0, 1.0, 'set console size', 'set console size');
167 conRegVar('console_step', @ConsoleStep, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
168 conRegVar('console_trans', @ConsoleTrans, 0.0, 1.0, 'set console transparency', 'set console transparency');
169 {$IFDEF ANDROID}
170 ChatTop := True;
171 ConsoleHeight := 0.35;
172 {$ELSE}
173 ChatTop := False;
174 ConsoleHeight := 0.5;
175 {$ENDIF}
176 ConsoleStep := 0.07;
177 ConsoleTrans := 0.1;
178 end.