]> git.lizzy.rs Git - minetest.git/blobdiff - src/guiEngine.cpp
Implement proper font handling
[minetest.git] / src / guiEngine.cpp
index f71c6a515b8d1d7cf0e3df7c20c15e3d6d90598b..e941003fadb4ca799dfd0786aac38f0005753717 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,15 +34,15 @@ 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"
 
-#include <IGUIStaticText.h>
-#include <ICameraSceneNode.h>
-
-#if USE_CURL
-#include <curl/curl.h>
+#ifdef __ANDROID__
+#include "tile.h"
+#include <GLES/gl.h>
 #endif
 
+
 /******************************************************************************/
 /** TextDestGuiEngine                                                         */
 /******************************************************************************/
@@ -87,6 +90,16 @@ video::ITexture* MenuTextureSource::getTexture(const std::string &name, u32 *id)
        if(name.empty())
                return NULL;
        m_to_delete.insert(name);
+
+#ifdef __ANDROID__
+       video::IImage *image = m_driver->createImageFromFile(name.c_str());
+       if (image) {
+               image = Align2Npot2(image, m_driver);
+               video::ITexture* retval = m_driver->addTexture(name.c_str(), image);
+               image->drop();
+               return retval;
+       }
+#endif
        return m_driver->getTexture(name.c_str());
 }
 
@@ -158,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, glb_fontengine->getTextWidth(t), glb_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
@@ -210,7 +225,7 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
 
        m_menu->quitMenu();
        m_menu->drop();
-       m_menu = 0;
+       m_menu = NULL;
 }
 
 /******************************************************************************/
@@ -245,7 +260,16 @@ void GUIEngine::run()
 
        cloudInit();
 
-       while(m_device->run() && (!m_startgame) && (!m_kill)) {
+       unsigned int text_height = glb_fontengine->getTextHeight();
+
+       while(m_device->run() && (!m_startgame) && (!m_kill))
+       {
+               //check if we need to update the "upper left corner"-text
+               if (text_height != glb_fontengine->getTextHeight()) {
+                       updateTopLeftTextSize();
+                       text_height = glb_fontengine->getTextHeight();
+               }
+
                driver->beginScene(true, true, video::SColor(255,140,186,250));
 
                if (m_clouds_enabled)
@@ -269,6 +293,10 @@ void GUIEngine::run()
                        sleep_ms(25);
 
                m_script->step();
+
+#ifdef __ANDROID__
+               m_menu->getAndroidUIInput();
+#endif
        }
 }
 
@@ -283,8 +311,6 @@ GUIEngine::~GUIEngine()
                m_sound_manager = NULL;
        }
 
-       //TODO: clean up m_menu here
-
        infostream<<"GUIEngine: Deinitializing scripting"<<std::endl;
        delete m_script;
 
@@ -297,7 +323,7 @@ GUIEngine::~GUIEngine()
        }
 
        delete m_texture_source;
-       
+
        if (m_cloud.clouds)
                m_cloud.clouds->drop();
 }
@@ -515,26 +541,26 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
 }
 
 /******************************************************************************/
-bool GUIEngine::downloadFile(std::string url,std::string target)
+bool GUIEngine::downloadFile(std::string url, std::string target)
 {
 #if USE_CURL
-       std::ofstream targetfile(target.c_str(), std::ios::out | std::ios::binary);
+       std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
 
-       if (!targetfile.good()) {
+       if (!target_file.good()) {
                return false;
        }
 
-       HTTPFetchRequest fetchrequest;
-       HTTPFetchResult fetchresult;
-       fetchrequest.url = url;
-       fetchrequest.caller = HTTPFETCH_SYNC;
-       httpfetch_sync(fetchrequest, fetchresult);
+       HTTPFetchRequest fetch_request;
+       HTTPFetchResult fetch_result;
+       fetch_request.url = url;
+       fetch_request.caller = HTTPFETCH_SYNC;
+       fetch_request.timeout = g_settings->getS32("curl_file_download_timeout");
+       httpfetch_sync(fetch_request, fetch_result);
 
-       if (fetchresult.succeeded) {
-               targetfile << fetchresult.data;
-       } else {
+       if (!fetch_result.succeeded) {
                return false;
        }
+       target_file << fetch_result.data;
 
        return true;
 #else
@@ -545,14 +571,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, glb_fontengine->getTextWidth(text), glb_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);
 }
 
 /******************************************************************************/