diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-06-23 23:33:34 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-06-23 23:33:34 +0000 |
commit | 4b0172d1f666a12cffbdd6bd331e95a92d8f652f (patch) | |
tree | dde7ab71fd5d02200be35e041b00e5649f9cd3a8 /src/gui | |
parent | 33587089cf7d87bbc2104e80746fdddc7a5498e1 (diff) | |
download | mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.tar.gz mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.tar.bz2 mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.tar.xz mana-4b0172d1f666a12cffbdd6bd331e95a92d8f652f.zip |
Finishing resource manager ability to clean up resources. Still work to do on
resources other than images.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/slider.cpp | 76 | ||||
-rw-r--r-- | src/gui/slider.h | 10 |
2 files changed, 60 insertions, 26 deletions
diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index 85fcf2d7..1a4482a5 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -25,6 +25,10 @@ #include "../resources/resourcemanager.h" #include "../graphics.h" +Image *Slider::hStart, *Slider::hMid, *Slider::hEnd, *Slider::hGrip; +Image *Slider::vStart, *Slider::vMid, *Slider::vEnd, *Slider::vGrip; +int Slider::mInstances = 0; + Slider::Slider(double scaleEnd): gcn::Slider(scaleEnd) { @@ -37,36 +41,60 @@ Slider::Slider(double scaleStart, double scaleEnd): init(); } +Slider::~Slider() +{ + mInstances--; + + if (mInstances == 0) + { + delete hStart; + delete hMid; + delete hEnd; + delete hGrip; + delete vStart; + delete vMid; + delete vEnd; + delete vGrip; + } +} + void Slider::init() { int x, y, w, h,o1,o2; setBorderSize(0); // Load resources - ResourceManager *resman = ResourceManager::getInstance(); - Image *slider = resman->getImage("graphics/gui/slider.png"); - - x = 0; y = 0; - w = 15; h = 6; - o1 = 4; o2 = 11; - hStart = slider->getSubImage(x, y, o1 - x, h); - hMid = slider->getSubImage(o1, y, o2 - o1, h); - hEnd = slider->getSubImage(o2, y, w - o2 + x, h); - - x = 0; y = 6; - w = 6; h = 21; - o1 = 10; o2 = 18; - vStart = slider->getSubImage(x, y, w, o1 - y); - vMid = slider->getSubImage(x, o1, w, o2 - o1); - vEnd = slider->getSubImage(x, o2, w, h - o2 + y); - - x = 6; y = 8; - w = 9; h = 10; - vGrip = slider->getSubImage(x, y, w, h); - - x = 6; y = 8; - w = 9; h = 10; - hGrip = slider->getSubImage(x, y, w, h); + if (mInstances == 0) + { + ResourceManager *resman = ResourceManager::getInstance(); + Image *slider = resman->getImage("graphics/gui/slider.png"); + + x = 0; y = 0; + w = 15; h = 6; + o1 = 4; o2 = 11; + hStart = slider->getSubImage(x, y, o1 - x, h); + hMid = slider->getSubImage(o1, y, o2 - o1, h); + hEnd = slider->getSubImage(o2, y, w - o2 + x, h); + + x = 6; y = 8; + w = 9; h = 10; + hGrip = slider->getSubImage(x, y, w, h); + + x = 0; y = 6; + w = 6; h = 21; + o1 = 10; o2 = 18; + vStart = slider->getSubImage(x, y, w, o1 - y); + vMid = slider->getSubImage(x, o1, w, o2 - o1); + vEnd = slider->getSubImage(x, o2, w, h - o2 + y); + + x = 6; y = 8; + w = 9; h = 10; + vGrip = slider->getSubImage(x, y, w, h); + + slider->decRef(); + } + + mInstances++; setMarkerLength(hGrip->getWidth()); } diff --git a/src/gui/slider.h b/src/gui/slider.h index 4e3c799c..dcfc8005 100644 --- a/src/gui/slider.h +++ b/src/gui/slider.h @@ -45,6 +45,11 @@ class Slider : public gcn::Slider { Slider(double scaleStart, double scaleEnd); /** + * Destructor. + */ + ~Slider(); + + /** * Draws the slider. */ void draw(gcn::Graphics *graphics); @@ -60,8 +65,9 @@ class Slider : public gcn::Slider { */ void init(); - Image *hStart, *hMid, *hEnd, *hGrip; - Image *vStart, *vMid, *vEnd, *vGrip; + static Image *hStart, *hMid, *hEnd, *hGrip; + static Image *vStart, *vMid, *vEnd, *vGrip; + static int mInstances; }; #endif |