mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Implement proper font handling
This commit is contained in:
parent
25945dc539
commit
dceb9f7d60
91 changed files with 902 additions and 194 deletions
66
src/game.cpp
66
src/game.cpp
|
@ -70,6 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/pointedthing.h"
|
||||
#include "drawscene.h"
|
||||
#include "content_cao.h"
|
||||
#include "fontengine.h"
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
#include "touchscreengui.h"
|
||||
|
@ -437,9 +438,8 @@ PointedThing getPointedThing(Client *client, v3f player_position,
|
|||
|
||||
/* Profiler display */
|
||||
|
||||
void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
|
||||
gui::IGUIFont *font, u32 text_height, u32 show_profiler,
|
||||
u32 show_profiler_max)
|
||||
void update_profiler_gui(gui::IGUIStaticText *guitext_profiler, FontEngine *fe,
|
||||
u32 show_profiler, u32 show_profiler_max)
|
||||
{
|
||||
if (show_profiler == 0) {
|
||||
guitext_profiler->setVisible(false);
|
||||
|
@ -451,14 +451,14 @@ void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
|
|||
guitext_profiler->setText(text.c_str());
|
||||
guitext_profiler->setVisible(true);
|
||||
|
||||
s32 w = font->getDimension(text.c_str()).Width;
|
||||
s32 w = fe->getTextWidth(text.c_str());
|
||||
|
||||
if (w < 400)
|
||||
w = 400;
|
||||
|
||||
core::rect<s32> rect(6, 4 + (text_height + 5) * 2, 12 + w,
|
||||
8 + (text_height + 5) * 2 +
|
||||
font->getDimension(text.c_str()).Height);
|
||||
core::rect<s32> rect(6, 4 + (fe->getTextHeight() + 5) * 2, 12 + w,
|
||||
8 + (fe->getTextHeight() + 5) * 2 +
|
||||
fe->getTextHeight());
|
||||
guitext_profiler->setRelativePosition(rect);
|
||||
guitext_profiler->setVisible(true);
|
||||
}
|
||||
|
@ -1136,8 +1136,7 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
|
|||
/******************************************************************************/
|
||||
static void updateChat(Client &client, f32 dtime, bool show_debug,
|
||||
const v2u32 &screensize, bool show_chat, u32 show_profiler,
|
||||
ChatBackend &chat_backend, gui::IGUIStaticText *guitext_chat,
|
||||
gui::IGUIFont *font)
|
||||
ChatBackend &chat_backend, gui::IGUIStaticText *guitext_chat)
|
||||
{
|
||||
// Add chat log output for errors to be shown in chat
|
||||
static LogOutputBuffer chat_log_error_buf(LMT_ERROR);
|
||||
|
@ -1160,9 +1159,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
|
|||
// Display all messages in a static text element
|
||||
unsigned int recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
|
||||
std::wstring recent_chat = chat_backend.getRecentChat();
|
||||
|
||||
// TODO replace by fontengine fcts
|
||||
unsigned int line_height = font->getDimension(L"Ay").Height + font->getKerningHeight();
|
||||
unsigned int line_height = glb_fontengine->getLineHeight();
|
||||
|
||||
guitext_chat->setText(recent_chat.c_str());
|
||||
|
||||
|
@ -1173,7 +1170,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
|
|||
chat_y += line_height;
|
||||
|
||||
// first pass to calculate height of text to be set
|
||||
s32 width = std::min(font->getDimension(recent_chat.c_str()).Width + 10,
|
||||
s32 width = std::min(glb_fontengine->getTextWidth(recent_chat) + 10,
|
||||
porting::getWindowSize().X - 20);
|
||||
core::rect<s32> rect(10, chat_y, width, chat_y + porting::getWindowSize().Y);
|
||||
guitext_chat->setRelativePosition(rect);
|
||||
|
@ -1402,7 +1399,6 @@ public:
|
|||
bool random_input,
|
||||
InputHandler *input,
|
||||
IrrlichtDevice *device,
|
||||
gui::IGUIFont *font,
|
||||
const std::string &map_dir,
|
||||
const std::string &playername,
|
||||
const std::string &password,
|
||||
|
@ -1522,8 +1518,6 @@ private:
|
|||
Client *client;
|
||||
Server *server;
|
||||
|
||||
gui::IGUIFont *font;
|
||||
|
||||
IWritableTextureSource *texture_src;
|
||||
IWritableShaderSource *shader_src;
|
||||
|
||||
|
@ -1558,7 +1552,6 @@ private:
|
|||
IrrlichtDevice *device;
|
||||
video::IVideoDriver *driver;
|
||||
scene::ISceneManager *smgr;
|
||||
u32 text_height;
|
||||
bool *kill;
|
||||
std::wstring *error_message;
|
||||
IGameDef *gamedef; // Convenience (same as *client)
|
||||
|
@ -1592,7 +1585,6 @@ private:
|
|||
Game::Game() :
|
||||
client(NULL),
|
||||
server(NULL),
|
||||
font(NULL),
|
||||
texture_src(NULL),
|
||||
shader_src(NULL),
|
||||
itemdef_manager(NULL),
|
||||
|
@ -1648,7 +1640,6 @@ bool Game::startup(bool *kill,
|
|||
bool random_input,
|
||||
InputHandler *input,
|
||||
IrrlichtDevice *device,
|
||||
gui::IGUIFont *font,
|
||||
const std::string &map_dir,
|
||||
const std::string &playername,
|
||||
const std::string &password,
|
||||
|
@ -1661,7 +1652,6 @@ bool Game::startup(bool *kill,
|
|||
{
|
||||
// "cache"
|
||||
this->device = device;
|
||||
this->font = font;
|
||||
this->kill = kill;
|
||||
this->error_message = error_message;
|
||||
this->random_input = random_input;
|
||||
|
@ -1671,7 +1661,6 @@ bool Game::startup(bool *kill,
|
|||
|
||||
driver = device->getVideoDriver();
|
||||
smgr = device->getSceneManager();
|
||||
text_height = font->getDimension(L"Random test string").Height;
|
||||
|
||||
if (!init(map_dir, address, port, gamespec))
|
||||
return false;
|
||||
|
@ -1934,7 +1923,7 @@ bool Game::createClient(const std::string &playername,
|
|||
}
|
||||
|
||||
// Update cached textures, meshes and materials
|
||||
client->afterContentReceived(device, font);
|
||||
client->afterContentReceived(device, glb_fontengine->getFont());
|
||||
|
||||
/* Camera
|
||||
*/
|
||||
|
@ -1992,8 +1981,8 @@ bool Game::createClient(const std::string &playername,
|
|||
player->hurt_tilt_timer = 0;
|
||||
player->hurt_tilt_strength = 0;
|
||||
|
||||
hud = new Hud(driver, smgr, guienv, font, text_height, gamedef,
|
||||
player, local_inventory);
|
||||
hud = new Hud(driver, smgr, guienv, glb_fontengine->getFont(),
|
||||
glb_fontengine->getTextHeight(), gamedef, player, local_inventory);
|
||||
|
||||
if (!hud) {
|
||||
*error_message = L"Memory error: could not create HUD";
|
||||
|
@ -2022,7 +2011,7 @@ bool Game::initGui(std::wstring *error_message)
|
|||
// Object infos are shown in this
|
||||
guitext_info = guienv->addStaticText(
|
||||
L"",
|
||||
core::rect<s32>(0, 0, 400, text_height * 5 + 5) + v2s32(100, 200),
|
||||
core::rect<s32>(0, 0, 400, glb_fontengine->getTextHeight() * 5 + 5) + v2s32(100, 200),
|
||||
false, true, guiroot);
|
||||
|
||||
// Status text (displays info when showing and hiding GUI stuff, etc.)
|
||||
|
@ -2224,12 +2213,12 @@ bool Game::getServerContent(bool *aborted)
|
|||
if (!client->itemdefReceived()) {
|
||||
wchar_t *text = wgettext("Item definitions...");
|
||||
progress = 0;
|
||||
draw_load_screen(text, device, guienv, font, dtime, progress);
|
||||
draw_load_screen(text, device, guienv, dtime, progress);
|
||||
delete[] text;
|
||||
} else if (!client->nodedefReceived()) {
|
||||
wchar_t *text = wgettext("Node definitions...");
|
||||
progress = 25;
|
||||
draw_load_screen(text, device, guienv, font, dtime, progress);
|
||||
draw_load_screen(text, device, guienv, dtime, progress);
|
||||
delete[] text;
|
||||
} else {
|
||||
std::stringstream message;
|
||||
|
@ -2251,7 +2240,7 @@ bool Game::getServerContent(bool *aborted)
|
|||
|
||||
progress = 50 + client->mediaReceiveProgress() * 50 + 0.5;
|
||||
draw_load_screen(narrow_to_wide(message.str().c_str()), device,
|
||||
guienv, font, dtime, progress);
|
||||
guienv, dtime, progress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2353,7 +2342,7 @@ void Game::updateProfilers(const GameRunData &run_data, const RunStats &stats,
|
|||
g_profiler->print(infostream);
|
||||
}
|
||||
|
||||
update_profiler_gui(guitext_profiler, font, text_height,
|
||||
update_profiler_gui(guitext_profiler, glb_fontengine,
|
||||
run_data.profiler_current_page, run_data.profiler_max_page);
|
||||
|
||||
g_profiler->clear();
|
||||
|
@ -2764,8 +2753,8 @@ void Game::toggleProfiler(float *statustext_time, u32 *profiler_current_page,
|
|||
*profiler_current_page = (*profiler_current_page + 1) % (profiler_max_page + 1);
|
||||
|
||||
// FIXME: This updates the profiler with incomplete values
|
||||
update_profiler_gui(guitext_profiler, font, text_height,
|
||||
*profiler_current_page, profiler_max_page);
|
||||
update_profiler_gui(guitext_profiler, glb_fontengine, *profiler_current_page,
|
||||
profiler_max_page);
|
||||
|
||||
if (*profiler_current_page != 0) {
|
||||
std::wstringstream sstr;
|
||||
|
@ -3805,7 +3794,7 @@ void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
|
|||
|
||||
updateChat(*client, dtime, flags.show_debug, screensize,
|
||||
flags.show_chat, runData->profiler_current_page,
|
||||
*chat_backend, guitext_chat, font);
|
||||
*chat_backend, guitext_chat);
|
||||
|
||||
/*
|
||||
Inventory
|
||||
|
@ -3883,7 +3872,7 @@ void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
|
|||
Profiler graph
|
||||
*/
|
||||
if (flags.show_profiler_graph)
|
||||
graph->draw(10, screensize.Y - 10, driver, font);
|
||||
graph->draw(10, screensize.Y - 10, driver, glb_fontengine->getFont());
|
||||
|
||||
/*
|
||||
Damage flash
|
||||
|
@ -3966,7 +3955,7 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
|
|||
if (guitext->isVisible()) {
|
||||
core::rect<s32> rect(
|
||||
5, 5,
|
||||
screensize.X, 5 + text_height
|
||||
screensize.X, 5 + glb_fontengine->getTextHeight()
|
||||
);
|
||||
guitext->setRelativePosition(rect);
|
||||
}
|
||||
|
@ -3984,8 +3973,8 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
|
|||
guitext2->setVisible(true);
|
||||
|
||||
core::rect<s32> rect(
|
||||
5, 5 + text_height,
|
||||
screensize.X, 5 + text_height * 2
|
||||
5, 5 + glb_fontengine->getTextHeight(),
|
||||
screensize.X, 5 + glb_fontengine->getTextHeight() * 2
|
||||
);
|
||||
guitext2->setRelativePosition(rect);
|
||||
} else {
|
||||
|
@ -4096,7 +4085,7 @@ void Game::showOverlayMessage(const char *msg, float dtime,
|
|||
int percent, bool draw_clouds)
|
||||
{
|
||||
wchar_t *text = wgettext(msg);
|
||||
draw_load_screen(text, device, guienv, font, dtime, percent, draw_clouds);
|
||||
draw_load_screen(text, device, guienv, dtime, percent, draw_clouds);
|
||||
delete[] text;
|
||||
}
|
||||
|
||||
|
@ -4136,7 +4125,6 @@ void the_game(bool *kill,
|
|||
bool random_input,
|
||||
InputHandler *input,
|
||||
IrrlichtDevice *device,
|
||||
gui::IGUIFont *font,
|
||||
|
||||
const std::string &map_dir,
|
||||
const std::string &playername,
|
||||
|
@ -4159,7 +4147,7 @@ void the_game(bool *kill,
|
|||
|
||||
try {
|
||||
|
||||
if (game.startup(kill, random_input, input, device, font, map_dir,
|
||||
if (game.startup(kill, random_input, input, device, map_dir,
|
||||
playername, password, &server_address, port,
|
||||
&error_message, &chat_backend, gamespec,
|
||||
simple_singleplayer_mode)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue