summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 64cf710)
raw | patch | inline | side by side (parent: 64cf710)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 12 Jun 2022 10:17:57 +0000 (13:17 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 9 Jun 2023 08:43:55 +0000 (11:43 +0300) |
src/game/Doom2DF.lpr | patch | blob | history | |
src/game/renders/opengl/r_console.pas | [new file with mode: 0644] | patch | blob |
src/game/renders/opengl/r_draw.pas | patch | blob | history | |
src/game/renders/opengl/r_render.pas | patch | blob | history | |
src/game/renders/opengl/r_textures.pas | patch | blob | history |
diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr
index 5eb2229bbddc44ab96eb3019f47fc3da7bb31ab7..d5e43767143bf0f5fbe8c4df0f705948acc526f7 100644 (file)
--- a/src/game/Doom2DF.lpr
+++ b/src/game/Doom2DF.lpr
r_map in 'renders/opengl/r_map.pas',
r_fonts in 'renders/opengl/r_fonts.pas',
r_common in 'renders/opengl/r_common.pas',
+ r_console in 'renders/opengl/r_console.pas',
r_gui in 'renders/opengl/r_gui.pas',
{$ELSE}
{$FATAL render driver not selected}
diff --git a/src/game/renders/opengl/r_console.pas b/src/game/renders/opengl/r_console.pas
--- /dev/null
@@ -0,0 +1,178 @@
+(* Copyright (C) Doom 2D: Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../../../shared/a_modes.inc}
+unit r_console;
+
+interface
+
+ procedure r_Console_Initialize;
+ procedure r_Console_Finalize;
+
+ procedure r_Console_Load;
+ procedure r_Console_Free;
+
+ procedure r_Console_Update;
+ procedure r_Console_Draw (MessagesOnly: Boolean);
+
+implementation
+
+ uses
+ Math, utils, conbuf,
+ g_game, g_options, g_console,
+ r_draw, r_textures, r_fonts, r_common
+ ;
+
+ var
+ Background: TGLTexture;
+
+ ConsoleTrans: Single;
+ ChatTop: BOOLEAN;
+
+ Cons_Y: SmallInt;
+ ConsoleHeight: Single;
+ ConsoleStep: Single;
+ Cons_Shown: Boolean; // draw console
+
+ procedure r_Console_Initialize;
+ begin
+ Cons_Y := Round(-Floor(gScreenHeight * ConsoleHeight));
+ end;
+
+ procedure r_Console_Finalize;
+ begin
+ end;
+
+ procedure r_Console_Load;
+ begin
+ Background := r_Textures_LoadFromFile(GameWad + ':TEXTURES/CONSOLE');
+ end;
+
+ procedure r_Console_Free;
+ begin
+ Background.Free;
+ end;
+
+ procedure r_Console_Update;
+ var step, miny: Integer;
+ begin
+ step := MAX(1, Round(Floor(gScreenHeight * ConsoleHeight) * ConsoleStep));
+ miny := Round(-Floor(gScreenHeight * ConsoleHeight));
+ if gConsoleShow then
+ Cons_Y := Cons_Y + step
+ else
+ Cons_Y := Cons_Y - step;
+ Cons_Y := MIN(MAX(Cons_Y, miny), 0);
+ Cons_Shown := Cons_Y > miny;
+ end;
+
+ procedure r_Console_DrawLog;
+ var cw, ch, ty, skip: Integer; sp, ep: LongWord;
+
+ procedure PutLine (sp, ep: LongWord);
+ var p: LongWord; w, chw: Integer;
+ begin
+ p := sp; w := 0; chw := 0;
+ while (p <> ep) and (w + chw <= gScreenWidth - 8) do
+ begin
+ chw := stdfont.GetWidth(cbufAt(p));
+ INC(w, chw);
+ cbufNext(p);
+ end;
+ if p <> ep then
+ PutLine(p, ep);
+ if skip = 0 then
+ begin
+ ep := p; p := sp; w := 2;
+ while p <> ep do
+ begin
+ r_Draw_Text(cbufAt(p), w, ty, 255, 255, 255, 255, stdfont);
+ chw := stdfont.GetWidth(cbufAt(p));
+ INC(w, chw);
+ cbufNext(p);
+ end;
+ DEC(ty, ch);
+ end
+ else
+ begin
+ DEC(skip);
+ end;
+ end;
+
+ begin
+ cw := stdfont.GetMaxWidth();
+ ch := stdfont.GetMaxHeight();
+ ty := Floor(gScreenHeight * ConsoleHeight) - 4 - 2 * ch - Abs(Cons_Y);
+ skip := conSkipLines;
+ cbufLastLine(sp, ep);
+ repeat
+ PutLine(sp, ep);
+ until (ty + ch <= 0) or (cbufLineUp(sp, ep) = false);
+ end;
+
+ procedure r_Console_Draw (MessagesOnly: Boolean);
+ var cw, ch, y, i: Integer; s: AnsiString;
+ begin
+ cw := stdfont.GetMaxWidth();
+ ch := stdfont.GetMaxHeight();
+
+ if ChatTop and gChatShow then y := ch else y := 0;
+
+ for i := 0 to High(MsgArray) do
+ if MsgArray[i].time > 0 then
+ r_Draw_Text(MsgArray[i].msg, 0, y + ch * i, 255, 255, 255, 255, stdfont);
+
+ if MessagesOnly = false then
+ begin
+ if gChatShow then
+ begin
+ if ChatTop then y := 0 else y := gScreenHeight - ch - 1;
+ if gChatTeam then s := 'say team> ' else s := 'say> ';
+ r_Draw_Text(s + Line, 0, y, 255, 255, 255, 255, stdfont);
+ r_Draw_Text('_', (CPos + 4) * cw, y, 255, 255, 255, 255, stdfont);
+ end;
+
+ if Cons_Shown then
+ begin
+ if gDebugMode then
+ begin
+ // TODO draw debug string
+ end;
+
+ if Background <> nil then
+ r_Draw_Texture(Background, 0, Cons_Y, gScreenWidth, Floor(gScreenHeight * ConsoleHeight), false, 255, 255, 255, Round((1.0 - ConsoleTrans) * 255), false);
+
+ r_Console_DrawLog;
+
+ r_Draw_Text('> ' + Line, 0, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - ch - 4, 255, 255, 255, 255, stdfont);
+ r_Draw_Text('_', (CPos + 1) * cw, Cons_Y + Floor(gScreenHeight * ConsoleHeight) - 21, 255, 255, 255, 255, stdfont);
+ end;
+ end;
+ end;
+
+initialization
+ conRegVar('chat_at_top', @ChatTop, 'draw chat at top border', 'draw chat at top border');
+ conRegVar('console_height', @ConsoleHeight, 0.0, 1.0, 'set console size', 'set console size');
+ conRegVar('console_step', @ConsoleStep, 0.0, 1.0, 'set console animation speed', 'set console animation speed');
+ conRegVar('console_trans', @ConsoleTrans, 0.0, 1.0, 'set console transparency', 'set console transparency');
+{$IFDEF ANDROID}
+ ChatTop := True;
+ ConsoleHeight := 0.35;
+{$ELSE}
+ ChatTop := False;
+ ConsoleHeight := 0.5;
+{$ENDIF}
+ ConsoleStep := 0.07;
+ ConsoleTrans := 0.1;
+end.
index 0091169d71d2ef99dc51b587961e1c9b810659e8..bdd60714db8713181a7d91a49bb096b56f687bcf 100644 (file)
end;
procedure r_Draw_Text (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont);
- var i, xoff: Integer; t: TGLTexture; ch: AnsiChar;
+ var i, xoff, spc: Integer; t: TGLTexture; ch: AnsiChar;
begin
- xoff := x;
+ xoff := x; spc := MAX(0, f.GetSpace());
for i := 1 to Length(text) do
begin
ch := text[i];
t := f.GetChar(ch);
if t <> nil then
r_Draw_Texture(t, xoff, y, t.width, t.height, false, r, g, b, a, false);
- Inc(xoff, f.GetWidth(ch) + f.GetSpace());
+ Inc(xoff, f.GetWidth(ch) + spc);
end;
end;
len := Length(text);
if len > 0 then
begin
- spc := f.GetSpace();
+ spc := MAX(0, f.GetSpace());
for i := 1 to len - 1 do
Inc(w, f.GetWidth(text[i]) + spc);
Inc(w, f.GetWidth(text[len]));
- if spc < 0 then
- Inc(w, spc)
end;
end;
index 6e9b96c8a813d6a7abbc1bee72a90c6db064399a..fb65ab5fa3d8ac66951c9ce1795015a8627c648b 100644 (file)
e_log, utils,
g_game, g_options, g_console, g_player, g_weapons, g_language,
g_net,
- r_draw, r_textures, r_fonts, r_common, r_map
+ r_draw, r_textures, r_fonts, r_common, r_console, r_map
;
type
hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
+ r_Console_Load;
r_Map_Load;
{$IFDEF ENABLE_MENU}
r_GUI_Load;
r_GUI_Free;
{$ENDIF}
r_Map_Free;
+ r_Console_Free;
hudjet.Free;
hudair.Free;
hudkey[0].Free;
sys_EnableVSync(gVSync);
{$ENDIF}
r_Textures_Initialize;
+ r_Console_Initialize;
r_Map_Initialize;
end;
procedure r_Render_Finalize;
begin
r_Map_Finalize;
+ r_Console_Finalize;
r_Textures_Finalize;
end;
procedure r_Render_Update;
begin
+ r_Console_Update;
r_Map_Update;
end;
end;
{$ENDIF}
- // TODO draw console
+ r_Console_Draw(false);
// TODO draw holmes interface
index 8df881acebef45500174bfb4790c7daddc8e0873..64d4f533ab39c7fd89e4704d808258864489a51e 100644 (file)
result := self.info.ch[c].w;
if result = 0 then
result := self.info.w;
+ if self.info.kern < 0 then
+ result := result + self.info.kern;
end;
function TGLFont.GetMaxWidth (): Integer;