Skip to content

Commit a9b74f4

Browse files
authoredMay 24, 2020
Add chat_font_size setting (#9736)
Default font sizes are used when the setting value is 0 or below (clamped by Settings).
1 parent f51cf7c commit a9b74f4

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed
 

‎builtin/settingtypes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,10 @@ fallback_font_shadow_alpha (Fallback font shadow alpha) int 128 0 255
903903
# This font will be used for certain languages or if the default font is unavailable.
904904
fallback_font_path (Fallback font path) filepath fonts/DroidSansFallbackFull.ttf
905905

906+
# Font size of the recent chat text and chat prompt in point (pt).
907+
# Value 0 will use the default font size.
908+
chat_font_size (Chat font size) int 0
909+
906910
# Path to save screenshots at. Can be an absolute or relative path.
907911
# The folder will be created if it doesn't already exist.
908912
screenshot_path (Screenshot folder) path screenshots

‎src/client/gameui.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ void GameUI::init()
7676
m_guitext_chat = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0),
7777
//false, false); // Disable word wrap as of now
7878
false, true, guiroot);
79+
u16 chat_font_size = g_settings->getU16("chat_font_size");
80+
if (chat_font_size != 0) {
81+
m_guitext_chat->setOverrideFont(g_fontengine->getFont(
82+
chat_font_size, FM_Unspecified));
83+
}
7984

8085
// Profiler text (size is updated when text is updated)
8186
m_guitext_profiler = gui::StaticText::add(guienv, L"<Profiler>",
@@ -213,24 +218,22 @@ void GameUI::showTranslatedStatusText(const char *str)
213218

214219
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
215220
{
216-
setStaticText(m_guitext_chat, chat_text);
217221

218222
// Update gui element size and position
219223
s32 chat_y = 5;
220224

221225
if (m_flags.show_debug)
222226
chat_y += 2 * g_fontengine->getLineHeight();
223227

224-
// first pass to calculate height of text to be set
225228
const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
226-
s32 width = std::min(g_fontengine->getTextWidth(chat_text.c_str()) + 10,
227-
window_size.X - 20);
228-
m_guitext_chat->setRelativePosition(core::rect<s32>(10, chat_y, width,
229-
chat_y + window_size.Y));
230-
231-
// now use real height of text and adjust rect according to this size
232-
m_guitext_chat->setRelativePosition(core::rect<s32>(10, chat_y, width,
233-
chat_y + m_guitext_chat->getTextHeight()));
229+
230+
core::rect<s32> chat_size(10, chat_y,
231+
window_size.X - 20, 0);
232+
chat_size.LowerRightCorner.Y = std::min((s32)window_size.Y,
233+
m_guitext_chat->getTextHeight() + chat_y);
234+
235+
m_guitext_chat->setRelativePosition(chat_size);
236+
setStaticText(m_guitext_chat, chat_text);
234237

235238
m_recent_chat_count = recent_chat_count;
236239
}

‎src/defaultsettings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,12 @@ void set_default_settings(Settings *settings)
321321

322322
std::string font_size_str = std::to_string(DEFAULT_FONT_SIZE);
323323
#endif
324+
// General font settings
324325
settings->setDefault("font_size", font_size_str);
325326
settings->setDefault("mono_font_size", font_size_str);
327+
settings->setDefault("chat_font_size", "0"); // Default "font_size"
328+
329+
// ContentDB
326330
settings->setDefault("contentdb_url", "https://content.minetest.net");
327331
#ifdef __ANDROID__
328332
settings->setDefault("contentdb_flag_blacklist", "nonfree, android_default");

‎src/gui/guiChatConsole.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ GUIChatConsole::GUIChatConsole(
7474
m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
7575
}
7676

77-
m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);
77+
u16 chat_font_size = g_settings->getU16("chat_font_size");
78+
m_font = g_fontengine->getFont(chat_font_size != 0 ?
79+
chat_font_size : FONT_SIZE_UNSPECIFIED, FM_Mono);
7880

7981
if (!m_font) {
8082
errorstream << "GUIChatConsole: Unable to load mono font" << std::endl;

0 commit comments

Comments
 (0)
Please sign in to comment.