summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-15 22:55:02 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-15 22:55:02 +0200
commitddd7f8acbbfbe7cf2787279babdb5c1279c7fd73 (patch)
treeb803ae0a601e46cfa0539f79f76c731dc28652f2 /src
parent2a3f16f5673e6482e422a65f6f23f958dd78955f (diff)
downloadmana-ddd7f8acbbfbe7cf2787279babdb5c1279c7fd73.tar.gz
mana-ddd7f8acbbfbe7cf2787279babdb5c1279c7fd73.tar.bz2
mana-ddd7f8acbbfbe7cf2787279babdb5c1279c7fd73.tar.xz
mana-ddd7f8acbbfbe7cf2787279babdb5c1279c7fd73.zip
Made the PopupMenu a Popup subclass
It's a natural better fit. The SkinLoader was changed into a singleton, since it's used by both Window and Popup classes.
Diffstat (limited to 'src')
-rw-r--r--src/gui/chat.cpp4
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/popupmenu.cpp9
-rw-r--r--src/gui/popupmenu.h4
-rw-r--r--src/gui/skin.cpp17
-rw-r--r--src/gui/skin.h11
-rw-r--r--src/gui/widgets/popup.cpp4
-rw-r--r--src/gui/widgets/window.cpp10
-rw-r--r--src/gui/widgets/window.h1
9 files changed, 33 insertions, 29 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 14a2dd49..9580ffe1 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -70,8 +70,8 @@ class ChatInput : public TextField, public gcn::FocusListener
ChatWindow::ChatWindow():
Window(_("Chat")),
- mCurrentTab(NULL),
- mTmpVisible(false)
+ mTmpVisible(false),
+ mCurrentTab(NULL)
{
setWindowName("Chat");
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 8a4e4aec..f1bb1022 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -161,6 +161,8 @@ Gui::~Gui()
delete getTop();
delete guiInput;
+
+ SkinLoader::deleteInstance();
}
void Gui::logic()
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index a78e620d..d3298961 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -50,24 +50,17 @@
extern std::string tradePartnerName;
PopupMenu::PopupMenu():
- Window("PopupMenu"),
+ Popup("PopupMenu"),
mBeingId(0),
mFloorItem(NULL),
mItem(NULL)
{
- setDefaultSize(0, 0, 0, 0);
- setResizable(false);
- setTitleBarHeight(0);
- setShowTitle(false);
-
mBrowserBox = new BrowserBox;
mBrowserBox->setPosition(4, 4);
mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND);
mBrowserBox->setOpaque(false);
mBrowserBox->setLinkHandler(this);
add(mBrowserBox);
-
- loadWindowState();
}
void PopupMenu::showPopup(int x, int y, Being *being)
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 338f9044..1caa00af 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -23,7 +23,7 @@
#define POPUP_MENU_H
#include "gui/linkhandler.h"
-#include "gui/widgets/window.h"
+#include "gui/widgets/popup.h"
class Being;
class BrowserBox;
@@ -33,7 +33,7 @@ class Item;
/**
* Window showing popup menu.
*/
-class PopupMenu : public Window, public LinkHandler
+class PopupMenu : public Popup, public LinkHandler
{
public:
/**
diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp
index 6fcbb0e2..b1665f59 100644
--- a/src/gui/skin.cpp
+++ b/src/gui/skin.cpp
@@ -36,7 +36,7 @@
#include <algorithm>
-SkinLoader *skinLoader = 0;
+SkinLoader *SkinLoader::mInstance = 0;
class SkinConfigListener : public ConfigListener
@@ -113,7 +113,6 @@ int Skin::getMinHeight() const
mBorder.grid[ImageRect::LOWER_LEFT]->getHeight();
}
-
SkinLoader::SkinLoader()
: mSkinConfigListener(new SkinConfigListener(this))
{
@@ -125,6 +124,20 @@ SkinLoader::~SkinLoader()
delete mSkinConfigListener;
}
+SkinLoader *SkinLoader::instance()
+{
+ if (!mInstance)
+ mInstance = new SkinLoader;
+
+ return mInstance;
+}
+
+void SkinLoader::deleteInstance()
+{
+ delete mInstance;
+ mInstance = 0;
+}
+
Skin *SkinLoader::load(const std::string &filename,
const std::string &defaultPath)
{
diff --git a/src/gui/skin.h b/src/gui/skin.h
index 25a9f0e4..c56072d3 100644
--- a/src/gui/skin.h
+++ b/src/gui/skin.h
@@ -98,8 +98,8 @@ class Skin
class SkinLoader
{
public:
- SkinLoader();
- ~SkinLoader();
+ static SkinLoader *instance();
+ static void deleteInstance();
/**
* Loads a skin.
@@ -113,6 +113,9 @@ class SkinLoader
void updateAlpha();
private:
+ SkinLoader();
+ ~SkinLoader();
+
Skin *readSkin(const std::string &filename);
// Map containing all window skins
@@ -125,8 +128,8 @@ class SkinLoader
* The config listener that listens to changes relevant to all skins.
*/
ConfigListener *mSkinConfigListener;
-};
-extern SkinLoader *skinLoader;
+ static SkinLoader *mInstance;
+};
#endif
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 7d73e749..41d60ab6 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -50,7 +50,7 @@ Popup::Popup(const std::string &name, const std::string &skin):
setPadding(3);
// Loads the skin
- mSkin = skinLoader->load(skin, mDefaultSkinPath);
+ mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath);
// Add this window to the window container
windowContainer->add(this);
@@ -85,7 +85,7 @@ void Popup::loadPopupConfiguration()
if (skinName.compare(mSkin->getFilePath()) != 0)
{
mSkin->instances--;
- mSkin = skinLoader->load(skinName, mDefaultSkinPath);
+ mSkin = SkinLoader::instance()->load(skinName, mDefaultSkinPath);
}
}
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 1d7961f3..f252c5f6 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -61,9 +61,6 @@ Window::Window(const std::string &caption, bool modal, Window *parent, const std
if (!windowContainer)
throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
- if (instances == 0)
- skinLoader = new SkinLoader;
-
instances++;
setFrameSize(0);
@@ -71,7 +68,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, const std
setTitleBarHeight(20);
// Loads the skin
- mSkin = skinLoader->load(skin, mDefaultSkinPath);
+ mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath);
// Add this window to the window container
windowContainer->add(this);
@@ -104,9 +101,6 @@ Window::~Window()
instances--;
mSkin->instances--;
-
- if (instances == 0)
- delete skinLoader;
}
void Window::setWindowContainer(WindowContainer *wc)
@@ -511,7 +505,7 @@ void Window::loadWindowState()
if (skinName.compare(mSkin->getFilePath()) != 0)
{
mSkin->instances--;
- mSkin = skinLoader->load(skinName, mDefaultSkinPath);
+ mSkin = SkinLoader::instance()->load(skinName, mDefaultSkinPath);
}
if (mGrip)
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index f53bc483..510b0f04 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -34,7 +34,6 @@ class Layout;
class LayoutCell;
class ResizeGrip;
class Skin;
-class SkinLoader;
class WindowContainer;
/**