]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiEngine.cpp
Biome API: Re-calculate biome at every surface in a mapchunk column
[dragonfireclient.git] / src / guiEngine.cpp
index 03b2766d86ab4148fc04aab81a5ad2644fa72de1..de6f44134ddb835faa3dde924de0e098c26fa794 100644 (file)
@@ -19,7 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "guiEngine.h"
 
+#include <IGUIStaticText.h>
+#include <ICameraSceneNode.h>
 #include "scripting_mainmenu.h"
+#include "util/numeric.h"
 #include "config.h"
 #include "version.h"
 #include "porting.h"
@@ -31,14 +34,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "sound_openal.h"
 #include "clouds.h"
 #include "httpfetch.h"
-#include "util/numeric.h"
+#include "log.h"
+#include "fontengine.h"
+
 #ifdef __ANDROID__
 #include "tile.h"
 #include <GLES/gl.h>
 #endif
 
-#include <IGUIStaticText.h>
-#include <ICameraSceneNode.h>
 
 /******************************************************************************/
 /** TextDestGuiEngine                                                         */
@@ -168,12 +171,14 @@ GUIEngine::GUIEngine(     irr::IrrlichtDevice* dev,
                m_sound_manager = &dummySoundManager;
 
        //create topleft header
-       core::rect<s32> rect(0, 0, 500, 20);
+       std::wstring t = narrow_to_wide(std::string("Minetest ") +
+                       minetest_version_hash);
+
+       core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
        rect += v2s32(4, 0);
-       std::string t = std::string("Minetest ") + minetest_version_hash;
 
        m_irr_toplefttext =
-               m_device->getGUIEnvironment()->addStaticText(narrow_to_wide(t).c_str(),
+               m_device->getGUIEnvironment()->addStaticText(t.c_str(),
                rect,false,true,0,-1);
 
        //create formspecsource
@@ -219,8 +224,7 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
        }
 
        m_menu->quitMenu();
-       m_menu->remove();
-       delete m_menu;
+       m_menu->drop();
        m_menu = NULL;
 }
 
@@ -256,7 +260,16 @@ void GUIEngine::run()
 
        cloudInit();
 
-       while(m_device->run() && (!m_startgame) && (!m_kill)) {
+       unsigned int text_height = g_fontengine->getTextHeight();
+
+       while(m_device->run() && (!m_startgame) && (!m_kill))
+       {
+               //check if we need to update the "upper left corner"-text
+               if (text_height != g_fontengine->getTextHeight()) {
+                       updateTopLeftTextSize();
+                       text_height = g_fontengine->getTextHeight();
+               }
+
                driver->beginScene(true, true, video::SColor(255,140,186,250));
 
                if (m_clouds_enabled)
@@ -351,15 +364,14 @@ void GUIEngine::cloudPostProcess()
 {
        float fps_max = g_settings->getFloat("fps_max");
        // Time of frame without fps limit
-       float busytime;
        u32 busytime_u32;
+
        // not using getRealTime is necessary for wine
        u32 time = m_device->getTimer()->getTime();
        if(time > m_cloud.lasttime)
                busytime_u32 = time - m_cloud.lasttime;
        else
                busytime_u32 = 0;
-       busytime = busytime_u32 / 1000.0;
 
        // FPS limiter
        u32 frametime_min = 1000./fps_max;
@@ -558,14 +570,32 @@ bool GUIEngine::downloadFile(std::string url, std::string target)
 /******************************************************************************/
 void GUIEngine::setTopleftText(std::string append)
 {
-       std::string toset = std::string("Minetest ") + minetest_version_hash;
+       std::wstring toset = narrow_to_wide( std::string("Minetest ") +
+                       minetest_version_hash);
 
-       if (append != "") {
-               toset += " / ";
-               toset += append;
+       if (append != "")
+       {
+               toset += L" / ";
+               toset += narrow_to_wide(append);
        }
 
-       m_irr_toplefttext->setText(narrow_to_wide(toset).c_str());
+       m_irr_toplefttext->setText(toset.c_str());
+
+       updateTopLeftTextSize();
+}
+
+/******************************************************************************/
+void GUIEngine::updateTopLeftTextSize()
+{
+       std::wstring text = m_irr_toplefttext->getText();
+
+       core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(text), g_fontengine->getTextHeight());
+               rect += v2s32(4, 0);
+
+       m_irr_toplefttext->remove();
+       m_irr_toplefttext =
+               m_device->getGUIEnvironment()->addStaticText(text.c_str(),
+               rect,false,true,0,-1);
 }
 
 /******************************************************************************/