Make the console font configurable

This commit is contained in:
Dunedan
2025-05-16 08:13:47 +02:00
parent 13c00d1869
commit d549cbeeaa
3 changed files with 6 additions and 5 deletions
+1
View File
@@ -190,6 +190,7 @@ server.port = "8000" ; Use a free port on your machine.
server.threads = "6" ; Enough for the browser's parallel connection limit server.threads = "6" ; Enough for the browser's parallel connection limit
[console] [console]
font = "mono-10"
history.size = 200 history.size = 200
[hotkey] [hotkey]
+3 -4
View File
@@ -52,8 +52,6 @@ namespace
// For text being typed into the console. // For text being typed into the console.
constexpr int CONSOLE_BUFFER_SIZE = 1024; constexpr int CONSOLE_BUFFER_SIZE = 1024;
const char* CONSOLE_FONT = "mono-10";
} // anonymous namespace } // anonymous namespace
CConsole* g_Console = 0; CConsole* g_Console = 0;
@@ -87,6 +85,7 @@ void CConsole::Init()
{ {
// Initialise console history file // Initialise console history file
m_MaxHistoryLines = g_ConfigDB.Get("console.history.size", 200); m_MaxHistoryLines = g_ConfigDB.Get("console.history.size", 200);
m_consoleFont = g_ConfigDB.Get("console.font", std::string{"mono-10"});
m_HistoryFile = L"config/console.txt"; m_HistoryFile = L"config/console.txt";
LoadHistory(); LoadHistory();
@@ -94,7 +93,7 @@ void CConsole::Init()
UpdateScreenSize(g_xres, g_yres); UpdateScreenSize(g_xres, g_yres);
// Calculate and store the line spacing // Calculate and store the line spacing
const CFontMetrics font{CStrIntern(CONSOLE_FONT)}; const CFontMetrics font{CStrIntern(m_consoleFont)};
m_FontHeight = font.GetLineSpacing(); m_FontHeight = font.GetLineSpacing();
m_FontWidth = font.GetCharacterWidth(L'C'); m_FontWidth = font.GetCharacterWidth(L'C');
m_CharsPerPage = static_cast<size_t>(g_xres / m_FontWidth); m_CharsPerPage = static_cast<size_t>(g_xres / m_FontWidth);
@@ -200,7 +199,7 @@ void CConsole::Render(CCanvas2D& canvas)
DrawWindow(canvas); DrawWindow(canvas);
CTextRenderer textRenderer; CTextRenderer textRenderer;
textRenderer.SetCurrentFont(CStrIntern(CONSOLE_FONT)); textRenderer.SetCurrentFont(CStrIntern(m_consoleFont));
// Animation: slide in from top of screen. // Animation: slide in from top of screen.
const float deltaY = (1.0f - m_VisibleFrac) * m_Height; const float deltaY = (1.0f - m_VisibleFrac) * m_Height;
textRenderer.Translate(m_X, m_Y - deltaY); textRenderer.Translate(m_X, m_Y - deltaY);
+2 -1
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games. /* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@@ -103,6 +103,7 @@ private:
VfsPath m_HistoryFile; VfsPath m_HistoryFile;
int m_MaxHistoryLines; int m_MaxHistoryLines;
std::string m_consoleFont;
bool m_Visible; // console is to be drawn bool m_Visible; // console is to be drawn
bool m_Toggle; // show/hide animation is currently active bool m_Toggle; // show/hide animation is currently active