summaryrefslogtreecommitdiff
path: root/src/guiEngine.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2013-08-20 22:38:14 +0200
committerKahrl <kahrl@gmx.net>2013-09-11 00:08:56 +0200
commit3c4734d69a44aea133e5bd7df66a5dedb87785fb (patch)
treef3961c8855c0d864b672ae79857de9b993c3e95c /src/guiEngine.cpp
parentda9fe6485134ec81cc3628b1bc4847c3b2226c76 (diff)
downloadminetest-3c4734d69a44aea133e5bd7df66a5dedb87785fb.tar.gz
minetest-3c4734d69a44aea133e5bd7df66a5dedb87785fb.tar.bz2
minetest-3c4734d69a44aea133e5bd7df66a5dedb87785fb.zip
Change mainmenu texture handling + small misc changes
Texture names must now be escaped in formspec elements image[], background[], image_button[], image_button_exit[]. Instead of special-case handling of texture loading (and unloading which was missing) in guiFormSpecMenu.cpp, use the newly created ISimpleTextureSource interface which is a minimal subset of ITextureSource. There is an implementation of this interface used by GUIEngine (MenuTextureSource). Fix an off-by-one bug in unescape_string; it caused requests for a texture called "\0".
Diffstat (limited to 'src/guiEngine.cpp')
-rw-r--r--src/guiEngine.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp
index f00cd039c..547f393a4 100644
--- a/src/guiEngine.cpp
+++ b/src/guiEngine.cpp
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiMainMenu.h"
#include "sound.h"
#include "sound_openal.h"
+#include "clouds.h"
#include <IGUIStaticText.h>
#include <ICameraSceneNode.h>
@@ -37,6 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
/******************************************************************************/
+/** TextDestGuiEngine */
+/******************************************************************************/
TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine)
{
m_engine = engine;
@@ -55,6 +58,38 @@ void TextDestGuiEngine::gotText(std::wstring text)
}
/******************************************************************************/
+/** MenuTextureSource */
+/******************************************************************************/
+MenuTextureSource::MenuTextureSource(video::IVideoDriver *driver)
+{
+ m_driver = driver;
+}
+
+/******************************************************************************/
+MenuTextureSource::~MenuTextureSource()
+{
+ for (std::set<std::string>::iterator it = m_to_delete.begin();
+ it != m_to_delete.end(); ++it) {
+ const char *tname = (*it).c_str();
+ video::ITexture *texture = m_driver->getTexture(tname);
+ m_driver->removeTexture(texture);
+ }
+}
+
+/******************************************************************************/
+video::ITexture* MenuTextureSource::getTexture(const std::string &name, u32 *id)
+{
+ if(id)
+ *id = 0;
+ if(name.empty())
+ return NULL;
+ m_to_delete.insert(name);
+ return m_driver->getTexture(name.c_str());
+}
+
+/******************************************************************************/
+/** MenuMusicFetcher */
+/******************************************************************************/
void MenuMusicFetcher::fetchSounds(const std::string &name,
std::set<std::string> &dst_paths,
std::set<std::string> &dst_datas)
@@ -75,6 +110,8 @@ void MenuMusicFetcher::fetchSounds(const std::string &name,
}
/******************************************************************************/
+/** GUIEngine */
+/******************************************************************************/
GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
gui::IGUIElement* parent,
IMenuManager *menumgr,
@@ -86,6 +123,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
m_menumanager(menumgr),
m_smgr(smgr),
m_data(data),
+ m_texture_source(NULL),
m_sound_manager(NULL),
m_formspecgui(0),
m_buttonhandler(0),
@@ -105,6 +143,9 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
// is deleted by guiformspec!
m_buttonhandler = new TextDestGuiEngine(this);
+ //create texture source
+ m_texture_source = new MenuTextureSource(m_device->getVideoDriver());
+
//create soundmanager
MenuMusicFetcher soundfetcher;
#if USE_SOUND
@@ -132,7 +173,8 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
-1,
m_menumanager,
0 /* &client */,
- 0 /* gamedef */);
+ 0 /* gamedef */,
+ m_texture_source);
m_menu->allowClose(false);
m_menu->lockSize(true,v2u32(800,600));
@@ -264,11 +306,13 @@ GUIEngine::~GUIEngine()
m_irr_toplefttext->setText(L"");
- //initialize texture pointers
+ //clean up texture pointers
for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
if (m_textures[i] != 0)
driver->removeTexture(m_textures[i]);
}
+
+ delete m_texture_source;
if (m_cloud.clouds)
m_cloud.clouds->drop();