Make hud use fontengine too

Fix non coding style conforming glb_fontengine to g_fontengine
Fix fonts never been deleted due to grabbed to often
This commit is contained in:
sapier 2014-11-28 20:06:34 +01:00
parent d1d6a97b1c
commit 39162de15a
12 changed files with 41 additions and 47 deletions

View File

@ -216,7 +216,7 @@
#tooltip_show_delay = 400 #tooltip_show_delay = 400
# Delay showing tooltips, in miliseconds # Delay showing tooltips, in miliseconds
#screen_dpi = 72 #screen_dpi = 72
# adjust dpi configuration to your screen (PC/MAC only) e.g. for 4k screens # adjust dpi configuration to your screen (Desktop only) e.g. for 4k screens
# Default timeout for cURL, in milliseconds # Default timeout for cURL, in milliseconds
# Only has an effect if compiled with cURL # Only has an effect if compiled with cURL

View File

@ -507,7 +507,7 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
video::IVideoDriver* driver = device->getVideoDriver(); video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = porting::getWindowSize(); v2u32 screensize = porting::getWindowSize();
v2s32 textsize(glb_fontengine->getTextWidth(text), glb_fontengine->getLineHeight()); v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
v2s32 center(screensize.X / 2, screensize.Y / 2); v2s32 center(screensize.X / 2, screensize.Y / 2);
core::rect<s32> textrect(center - textsize / 2, center + textsize / 2); core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
@ -534,7 +534,7 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
// before with default settings // before with default settings
342 * porting::getDisplayDensity() * 342 * porting::getDisplayDensity() *
g_settings->getFloat("gui_scaling"), g_settings->getFloat("gui_scaling"),
glb_fontengine->getTextHeight() * 2); g_fontengine->getTextHeight() * 2);
core::rect<s32> barrect(center - barsize / 2, center + barsize / 2); core::rect<s32> barrect(center - barsize / 2, center + barsize / 2);
driver->draw2DRectangle(video::SColor(255, 255, 255, 255),barrect, NULL); // border driver->draw2DRectangle(video::SColor(255, 255, 255, 255),barrect, NULL); // border

View File

@ -33,11 +33,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAX_FONT_SIZE_OFFSET 10 #define MAX_FONT_SIZE_OFFSET 10
/** reference to access font engine, has to be initialized by main */ /** reference to access font engine, has to be initialized by main */
FontEngine* glb_fontengine = NULL; FontEngine* g_fontengine = NULL;
/** callback to be used on change of font size setting */ /** callback to be used on change of font size setting */
static void font_setting_changed(const std::string) { static void font_setting_changed(const std::string) {
glb_fontengine->readSettings(); g_fontengine->readSettings();
} }
/******************************************************************************/ /******************************************************************************/
@ -349,7 +349,6 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
font_shadow_alpha); font_shadow_alpha);
if (font != NULL) { if (font != NULL) {
font->grab();
m_font_cache[mode][basesize] = font; m_font_cache[mode][basesize] = font;
} }
else { else {
@ -457,7 +456,6 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
} }
if (font != NULL) { if (font != NULL) {
font->grab();
m_font_cache[mode][basesize] = font; m_font_cache[mode][basesize] = font;
} }
} }

View File

@ -135,6 +135,6 @@ private:
}; };
/** interface to access main font engine*/ /** interface to access main font engine*/
extern FontEngine* glb_fontengine; extern FontEngine* g_fontengine;
#endif #endif

View File

@ -1159,7 +1159,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
// Display all messages in a static text element // Display all messages in a static text element
unsigned int recent_chat_count = chat_backend.getRecentBuffer().getLineCount(); unsigned int recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
std::wstring recent_chat = chat_backend.getRecentChat(); std::wstring recent_chat = chat_backend.getRecentChat();
unsigned int line_height = glb_fontengine->getLineHeight(); unsigned int line_height = g_fontengine->getLineHeight();
guitext_chat->setText(recent_chat.c_str()); guitext_chat->setText(recent_chat.c_str());
@ -1170,7 +1170,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
chat_y += line_height; chat_y += line_height;
// first pass to calculate height of text to be set // first pass to calculate height of text to be set
s32 width = std::min(glb_fontengine->getTextWidth(recent_chat) + 10, s32 width = std::min(g_fontengine->getTextWidth(recent_chat) + 10,
porting::getWindowSize().X - 20); porting::getWindowSize().X - 20);
core::rect<s32> rect(10, chat_y, width, chat_y + porting::getWindowSize().Y); core::rect<s32> rect(10, chat_y, width, chat_y + porting::getWindowSize().Y);
guitext_chat->setRelativePosition(rect); guitext_chat->setRelativePosition(rect);
@ -1923,7 +1923,7 @@ bool Game::createClient(const std::string &playername,
} }
// Update cached textures, meshes and materials // Update cached textures, meshes and materials
client->afterContentReceived(device, glb_fontengine->getFont()); client->afterContentReceived(device, g_fontengine->getFont());
/* Camera /* Camera
*/ */
@ -1981,8 +1981,7 @@ bool Game::createClient(const std::string &playername,
player->hurt_tilt_timer = 0; player->hurt_tilt_timer = 0;
player->hurt_tilt_strength = 0; player->hurt_tilt_strength = 0;
hud = new Hud(driver, smgr, guienv, glb_fontengine->getFont(), hud = new Hud(driver, smgr, guienv, gamedef, player, local_inventory);
glb_fontengine->getTextHeight(), gamedef, player, local_inventory);
if (!hud) { if (!hud) {
*error_message = L"Memory error: could not create HUD"; *error_message = L"Memory error: could not create HUD";
@ -2011,7 +2010,7 @@ bool Game::initGui(std::wstring *error_message)
// Object infos are shown in this // Object infos are shown in this
guitext_info = guienv->addStaticText( guitext_info = guienv->addStaticText(
L"", L"",
core::rect<s32>(0, 0, 400, glb_fontengine->getTextHeight() * 5 + 5) + v2s32(100, 200), core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5) + v2s32(100, 200),
false, true, guiroot); false, true, guiroot);
// Status text (displays info when showing and hiding GUI stuff, etc.) // Status text (displays info when showing and hiding GUI stuff, etc.)
@ -2342,7 +2341,7 @@ void Game::updateProfilers(const GameRunData &run_data, const RunStats &stats,
g_profiler->print(infostream); g_profiler->print(infostream);
} }
update_profiler_gui(guitext_profiler, glb_fontengine, update_profiler_gui(guitext_profiler, g_fontengine,
run_data.profiler_current_page, run_data.profiler_max_page); run_data.profiler_current_page, run_data.profiler_max_page);
g_profiler->clear(); g_profiler->clear();
@ -2753,7 +2752,7 @@ void Game::toggleProfiler(float *statustext_time, u32 *profiler_current_page,
*profiler_current_page = (*profiler_current_page + 1) % (profiler_max_page + 1); *profiler_current_page = (*profiler_current_page + 1) % (profiler_max_page + 1);
// FIXME: This updates the profiler with incomplete values // FIXME: This updates the profiler with incomplete values
update_profiler_gui(guitext_profiler, glb_fontengine, *profiler_current_page, update_profiler_gui(guitext_profiler, g_fontengine, *profiler_current_page,
profiler_max_page); profiler_max_page);
if (*profiler_current_page != 0) { if (*profiler_current_page != 0) {
@ -3872,7 +3871,7 @@ void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
Profiler graph Profiler graph
*/ */
if (flags.show_profiler_graph) if (flags.show_profiler_graph)
graph->draw(10, screensize.Y - 10, driver, glb_fontengine->getFont()); graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont());
/* /*
Damage flash Damage flash
@ -3955,7 +3954,7 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
if (guitext->isVisible()) { if (guitext->isVisible()) {
core::rect<s32> rect( core::rect<s32> rect(
5, 5, 5, 5,
screensize.X, 5 + glb_fontengine->getTextHeight() screensize.X, 5 + g_fontengine->getTextHeight()
); );
guitext->setRelativePosition(rect); guitext->setRelativePosition(rect);
} }
@ -3973,8 +3972,8 @@ void Game::updateGui(float *statustext_time, const RunStats& stats,
guitext2->setVisible(true); guitext2->setVisible(true);
core::rect<s32> rect( core::rect<s32> rect(
5, 5 + glb_fontengine->getTextHeight(), 5, 5 + g_fontengine->getTextHeight(),
screensize.X, 5 + glb_fontengine->getTextHeight() * 2 screensize.X, 5 + g_fontengine->getTextHeight() * 2
); );
guitext2->setRelativePosition(rect); guitext2->setRelativePosition(rect);
} else { } else {

View File

@ -92,7 +92,7 @@ GUIChatConsole::GUIChatConsole(
m_background_color.setBlue(255); m_background_color.setBlue(255);
} }
m_font = glb_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono); m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);
if (m_font == NULL) if (m_font == NULL)
{ {

View File

@ -174,7 +174,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
std::wstring t = narrow_to_wide(std::string("Minetest ") + std::wstring t = narrow_to_wide(std::string("Minetest ") +
minetest_version_hash); minetest_version_hash);
core::rect<s32> rect(0, 0, glb_fontengine->getTextWidth(t), glb_fontengine->getTextHeight()); core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
rect += v2s32(4, 0); rect += v2s32(4, 0);
m_irr_toplefttext = m_irr_toplefttext =
@ -260,14 +260,14 @@ void GUIEngine::run()
cloudInit(); cloudInit();
unsigned int text_height = glb_fontengine->getTextHeight(); unsigned int text_height = g_fontengine->getTextHeight();
while(m_device->run() && (!m_startgame) && (!m_kill)) while(m_device->run() && (!m_startgame) && (!m_kill))
{ {
//check if we need to update the "upper left corner"-text //check if we need to update the "upper left corner"-text
if (text_height != glb_fontengine->getTextHeight()) { if (text_height != g_fontengine->getTextHeight()) {
updateTopLeftTextSize(); updateTopLeftTextSize();
text_height = glb_fontengine->getTextHeight(); text_height = g_fontengine->getTextHeight();
} }
driver->beginScene(true, true, video::SColor(255,140,186,250)); driver->beginScene(true, true, video::SColor(255,140,186,250));
@ -590,7 +590,7 @@ void GUIEngine::updateTopLeftTextSize()
{ {
std::wstring text = m_irr_toplefttext->getText(); std::wstring text = m_irr_toplefttext->getText();
core::rect<s32> rect(0, 0, glb_fontengine->getTextWidth(text), glb_fontengine->getTextHeight()); core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(text), g_fontengine->getTextHeight());
rect += v2s32(4, 0); rect += v2s32(4, 0);
m_irr_toplefttext->remove(); m_irr_toplefttext->remove();

View File

@ -91,11 +91,11 @@ static gui::IGUIFont *select_font_by_line_height(double target_line_height)
unsigned int hireq = ceil(target_line_height unsigned int hireq = ceil(target_line_height
/ porting::getDisplayDensity() / porting::getDisplayDensity()
/ g_settings->getFloat("gui_scaling")); / g_settings->getFloat("gui_scaling"));
unsigned int lohgt = font_line_height(glb_fontengine->getFont(loreq)); unsigned int lohgt = font_line_height(g_fontengine->getFont(loreq));
unsigned int hihgt = font_line_height(glb_fontengine->getFont(hireq)); unsigned int hihgt = font_line_height(g_fontengine->getFont(hireq));
while(hireq - loreq > 1 && lohgt != hihgt) { while(hireq - loreq > 1 && lohgt != hihgt) {
unsigned int nureq = (loreq + hireq) >> 1; unsigned int nureq = (loreq + hireq) >> 1;
unsigned int nuhgt = font_line_height(glb_fontengine->getFont(nureq)); unsigned int nuhgt = font_line_height(g_fontengine->getFont(nureq));
if(nuhgt < target_line_height) { if(nuhgt < target_line_height) {
loreq = nureq; loreq = nureq;
lohgt = nuhgt; lohgt = nuhgt;
@ -104,7 +104,7 @@ static gui::IGUIFont *select_font_by_line_height(double target_line_height)
hihgt = nuhgt; hihgt = nuhgt;
} }
} }
return glb_fontengine->getFont(target_line_height - lohgt < hihgt - target_line_height ? loreq : hireq); return g_fontengine->getFont(target_line_height - lohgt < hihgt - target_line_height ? loreq : hireq);
} }
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev, GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
@ -1992,7 +1992,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
// Non-size[] form must consist only of text fields and // Non-size[] form must consist only of text fields and
// implicit "Proceed" button. Use default font, and // implicit "Proceed" button. Use default font, and
// temporary form size which will be recalculated below. // temporary form size which will be recalculated below.
m_font = glb_fontengine->getFont(); m_font = g_fontengine->getFont();
m_btn_height = font_line_height(m_font) * 0.875; m_btn_height = font_line_height(m_font) * 0.875;
DesiredRect = core::rect<s32>( DesiredRect = core::rect<s32>(
mydata.screensize.X/2 - 580/2, mydata.screensize.X/2 - 580/2,

View File

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "localplayer.h" #include "localplayer.h"
#include "camera.h" #include "camera.h"
#include "porting.h" #include "porting.h"
#include "fontengine.h"
#include <IGUIStaticText.h> #include <IGUIStaticText.h>
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
@ -38,14 +39,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif #endif
Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr, Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
gui::IGUIEnvironment* guienv, gui::IGUIFont *font, gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
u32 text_height, IGameDef *gamedef, Inventory *inventory) {
LocalPlayer *player, Inventory *inventory) {
this->driver = driver; this->driver = driver;
this->smgr = smgr; this->smgr = smgr;
this->guienv = guienv; this->guienv = guienv;
this->font = font;
this->text_height = text_height;
this->gamedef = gamedef; this->gamedef = gamedef;
this->player = player; this->player = player;
this->inventory = inventory; this->inventory = inventory;
@ -156,7 +154,7 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect, bool sele
video::SColor bgcolor2(128, 0, 0, 0); video::SColor bgcolor2(128, 0, 0, 0);
if (!use_hotbar_image) if (!use_hotbar_image)
driver->draw2DRectangle(bgcolor2, rect, NULL); driver->draw2DRectangle(bgcolor2, rect, NULL);
drawItemStack(driver, font, item, rect, NULL, gamedef); drawItemStack(driver, g_fontengine->getFont(), item, rect, NULL, gamedef);
} }
//NOTE: selectitem = 0 -> no selected; selectitem 1-based //NOTE: selectitem = 0 -> no selected; selectitem 1-based
@ -240,6 +238,8 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
void Hud::drawLuaElements(v3s16 camera_offset) { void Hud::drawLuaElements(v3s16 camera_offset) {
uint32_t text_height = g_fontengine->getTextHeight();
irr::gui::IGUIFont* font = g_fontengine->getFont();
for (size_t i = 0; i != player->maxHudId(); i++) { for (size_t i = 0; i != player->maxHudId(); i++) {
HudElement *e = player->getHud(i); HudElement *e = player->getHud(i);
if (!e) if (!e)

View File

@ -103,8 +103,6 @@ public:
video::IVideoDriver *driver; video::IVideoDriver *driver;
scene::ISceneManager* smgr; scene::ISceneManager* smgr;
gui::IGUIEnvironment *guienv; gui::IGUIEnvironment *guienv;
gui::IGUIFont *font;
u32 text_height;
IGameDef *gamedef; IGameDef *gamedef;
LocalPlayer *player; LocalPlayer *player;
Inventory *inventory; Inventory *inventory;
@ -120,9 +118,8 @@ public:
v3s16 camera_offset; v3s16 camera_offset;
Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr, Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
gui::IGUIEnvironment* guienv, gui::IGUIFont *font, gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
u32 text_height, IGameDef *gamedef, Inventory *inventory);
LocalPlayer *player, Inventory *inventory);
void drawHotbar(u16 playeritem); void drawHotbar(u16 playeritem);
void resizeHotbar(); void resizeHotbar();

View File

@ -1569,8 +1569,8 @@ ClientLauncher::~ClientLauncher()
if (input) if (input)
delete input; delete input;
if (glb_fontengine) if (g_fontengine)
delete glb_fontengine; delete g_fontengine;
if (device) if (device)
device->drop(); device->drop();
@ -1630,8 +1630,8 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 100, 50)); skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 100, 50));
skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255)); skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));
glb_fontengine = new FontEngine(g_settings, guienv); g_fontengine = new FontEngine(g_settings, guienv);
assert(glb_fontengine != NULL); assert(g_fontengine != NULL);
#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2 #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
// Irrlicht 1.8 input colours // Irrlicht 1.8 input colours