summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/button.cpp73
-rw-r--r--src/gui/button.h8
-rw-r--r--src/gui/checkbox.cpp39
-rw-r--r--src/gui/checkbox.h16
-rw-r--r--src/gui/gui.h11
-rw-r--r--src/gui/radiobutton.cpp34
-rw-r--r--src/gui/radiobutton.h14
7 files changed, 146 insertions, 49 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index 195fde69..c95ab968 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -24,31 +24,62 @@
#include "button.h"
#include "../resources/resourcemanager.h"
+ImageRect Button::button[4];
+int Button::instances = 0;
+
Button::Button(const std::string& caption):
gcn::Button(caption)
{
setBorderSize(0);
- // Load the skin
- ResourceManager *resman = ResourceManager::getInstance();
- Image *btn[4];
- btn[0] = resman->getImage("graphics/gui/button.png");
- btn[1] = resman->getImage("graphics/gui/buttonhi.png");
- btn[2] = resman->getImage("graphics/gui/buttonpress.png");
- btn[3] = resman->getImage("graphics/gui/button_disabled.png");
- int bgridx[4] = {0, 9, 16, 25};
- int bgridy[4] = {0, 4, 19, 24};
- int a, x, y;
-
- for (int mode = 0; mode < 4; mode++) {
- a = 0;
- for (y = 0; y < 3; y++) {
- for (x = 0; x < 3; x++) {
- button[mode].grid[a] = btn[mode]->getSubImage(
- bgridx[x], bgridy[y],
- bgridx[x + 1] - bgridx[x] + 1,
- bgridy[y + 1] - bgridy[y] + 1);
- a++;
+ if (instances == 0)
+ {
+ // Load the skin
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *btn[4];
+ btn[0] = resman->getImage("graphics/gui/button.png");
+ btn[1] = resman->getImage("graphics/gui/buttonhi.png");
+ btn[2] = resman->getImage("graphics/gui/buttonpress.png");
+ btn[3] = resman->getImage("graphics/gui/button_disabled.png");
+ int bgridx[4] = {0, 9, 16, 25};
+ int bgridy[4] = {0, 4, 19, 24};
+ int a, x, y, mode;
+
+ for (mode = 0; mode < 4; mode++)
+ {
+ a = 0;
+ for (y = 0; y < 3; y++) {
+ for (x = 0; x < 3; x++) {
+ button[mode].grid[a] = btn[mode]->getSubImage(
+ bgridx[x], bgridy[y],
+ bgridx[x + 1] - bgridx[x] + 1,
+ bgridy[y + 1] - bgridy[y] + 1);
+ a++;
+ }
+ }
+ btn[mode]->decRef();
+ }
+ }
+
+ instances++;
+}
+
+Button::~Button()
+{
+ instances--;
+
+ if (instances == 0)
+ {
+ int a, x, y, mode;
+
+ for (mode = 0; mode < 4; mode++)
+ {
+ a = 0;
+ for (y = 0; y < 3; y++) {
+ for (x = 0; x < 3; x++) {
+ delete button[mode].grid[a];
+ a++;
+ }
}
}
}
@@ -102,5 +133,5 @@ void Button::draw(gcn::Graphics* graphics) {
}
else {
graphics->drawText(getCaption(), textX, textY, getAlignment());
- }
+ }
}
diff --git a/src/gui/button.h b/src/gui/button.h
index a9ddd3fa..c3be49f2 100644
--- a/src/gui/button.h
+++ b/src/gui/button.h
@@ -41,12 +41,18 @@ class Button : public gcn::Button {
Button(const std::string& caption);
/**
+ * Destructor.
+ */
+ ~Button();
+
+ /**
* Draws the button.
*/
void draw(gcn::Graphics* graphics);
private:
- ImageRect button[4];
+ static ImageRect button[4]; /**< Button state graphics */
+ static int instances; /**< Number of button instances */
};
#endif
diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp
index 68966376..ab867b0f 100644
--- a/src/gui/checkbox.cpp
+++ b/src/gui/checkbox.cpp
@@ -25,18 +25,45 @@
#include "../resources/resourcemanager.h"
#include "../graphics.h"
+int CheckBox::instances = 0;
+Image *CheckBox::checkBoxNormal;
+Image *CheckBox::checkBoxChecked;
+Image *CheckBox::checkBoxDisabled;
+Image *CheckBox::checkBoxDisabledChecked;
+
CheckBox::CheckBox(const std::string& caption, bool marked):
gcn::CheckBox(caption, marked)
{
ResourceManager *resman = ResourceManager::getInstance();
- Image *checkBox = resman->getImage("graphics/gui/checkbox.png");
- checkBoxNormal = checkBox->getSubImage(0, 0, 9, 10);
- checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10);
- checkBoxDisabled = checkBox->getSubImage(18, 0, 9, 10);
- checkBoxDisabledChecked = checkBox->getSubImage(27, 0, 9, 10);
+
+ if (instances == 0)
+ {
+ Image *checkBox = resman->getImage("graphics/gui/checkbox.png");
+ checkBoxNormal = checkBox->getSubImage(0, 0, 9, 10);
+ checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10);
+ checkBoxDisabled = checkBox->getSubImage(18, 0, 9, 10);
+ checkBoxDisabledChecked = checkBox->getSubImage(27, 0, 9, 10);
+ checkBox->decRef();
+ }
+
+ instances++;
+}
+
+CheckBox::~CheckBox()
+{
+ instances--;
+
+ if (instances == 0)
+ {
+ delete checkBoxNormal;
+ delete checkBoxChecked;
+ delete checkBoxDisabled;
+ delete checkBoxDisabledChecked;
+ }
}
-void CheckBox::drawBox(gcn::Graphics* graphics) {
+void CheckBox::drawBox(gcn::Graphics* graphics)
+{
Image *box = NULL;
int x, y;
diff --git a/src/gui/checkbox.h b/src/gui/checkbox.h
index 80612b71..947e6432 100644
--- a/src/gui/checkbox.h
+++ b/src/gui/checkbox.h
@@ -41,15 +41,21 @@ class CheckBox : public gcn::CheckBox {
CheckBox(const std::string& caption, bool marked = false);
/**
+ * Destructor.
+ */
+ ~CheckBox();
+
+ /**
* Draws the check box, not the caption.
*/
void drawBox(gcn::Graphics* graphics);
-
+
private:
- Image *checkBoxNormal;
- Image *checkBoxChecked;
- Image *checkBoxDisabled;
- Image *checkBoxDisabledChecked;
+ static int instances;
+ static Image *checkBoxNormal;
+ static Image *checkBoxChecked;
+ static Image *checkBoxDisabled;
+ static Image *checkBoxDisabledChecked;
};
#endif
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 35b7e21f..1c8ccb34 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -72,19 +72,16 @@ class Gui : public gcn::Gui, public gcn::MouseListener
void mousePress(int mx, int my, int button);
private:
- gcn::Gui *gui; /**< The GUI system */
#ifdef USE_OPENGL
gcn::ImageLoader *hostImageLoader; /**< For loading images in GL */
#endif
gcn::ImageLoader *imageLoader; /**< For loading images */
gcn::ImageFont *guiFont; /**< The global GUI font */
-
- bool topHasMouse;
};
-extern Gui *gui;
-extern WindowContainer *guiTop; // The top container
-extern Graphics *guiGraphics; // Graphics driver
-extern gcn::SDLInput *guiInput; // GUI input
+extern Gui *gui; /**< The GUI system */
+extern WindowContainer *guiTop; /**< The top container */
+extern Graphics *guiGraphics; /**< Graphics driver */
+extern gcn::SDLInput *guiInput; /**< GUI input */
#endif
diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp
index d04d8586..f03c333f 100644
--- a/src/gui/radiobutton.cpp
+++ b/src/gui/radiobutton.cpp
@@ -24,15 +24,39 @@
#include "radiobutton.h"
#include "../resources/resourcemanager.h"
+int RadioButton::instances = 0;
+Image *RadioButton::radioNormal;
+Image *RadioButton::radioChecked;
+Image *RadioButton::radioDisabled;
+Image *RadioButton::radioDisabledChecked;
+
RadioButton::RadioButton(const std::string& caption, const std::string& group,
bool marked):
gcn::RadioButton(caption, group, marked)
{
- ResourceManager *resman = ResourceManager::getInstance();
- radioNormal = resman->getImage("graphics/gui/radioout.png");
- radioChecked = resman->getImage("graphics/gui/radioin.png");
- radioDisabled = resman->getImage("graphics/gui/radioout.png");
- radioDisabledChecked = resman->getImage("graphics/gui/radioin.png");
+ if (instances == 0)
+ {
+ ResourceManager *resman = ResourceManager::getInstance();
+ radioNormal = resman->getImage("graphics/gui/radioout.png");
+ radioChecked = resman->getImage("graphics/gui/radioin.png");
+ radioDisabled = resman->getImage("graphics/gui/radioout.png");
+ radioDisabledChecked = resman->getImage("graphics/gui/radioin.png");
+ }
+
+ instances++;
+}
+
+RadioButton::~RadioButton()
+{
+ instances--;
+
+ if (instances == 0)
+ {
+ radioNormal->decRef();
+ radioChecked->decRef();
+ radioDisabled->decRef();
+ radioDisabledChecked->decRef();
+ }
}
void RadioButton::drawBox(gcn::Graphics* graphics)
diff --git a/src/gui/radiobutton.h b/src/gui/radiobutton.h
index 3365e013..343854d2 100644
--- a/src/gui/radiobutton.h
+++ b/src/gui/radiobutton.h
@@ -39,15 +39,21 @@ class RadioButton : public gcn::RadioButton {
bool marked = false);
/**
+ * Destructor.
+ */
+ ~RadioButton();
+
+ /**
* Draws the radiobutton, not the caption.
*/
void drawBox(gcn::Graphics* graphics);
private:
- Image *radioNormal;
- Image *radioChecked;
- Image *radioDisabled;
- Image *radioDisabledChecked;
+ static int instances;
+ static Image *radioNormal;
+ static Image *radioChecked;
+ static Image *radioDisabled;
+ static Image *radioDisabledChecked;
};
#endif /* _TMW_RADIOBUTTON_H */