diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-05-16 21:53:10 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-05-16 21:53:10 +0000 |
commit | f80bf2dfb4de682a56abe79b7b0e5e0459804b30 (patch) | |
tree | cc45a8a6dfa7abe41b9f13fabffbb6287513cf46 /src/gui/button.cpp | |
parent | 6a25f872d6102058c8186398627abc5d84f2363a (diff) | |
download | mana-f80bf2dfb4de682a56abe79b7b0e5e0459804b30.tar.gz mana-f80bf2dfb4de682a56abe79b7b0e5e0459804b30.tar.bz2 mana-f80bf2dfb4de682a56abe79b7b0e5e0459804b30.tar.xz mana-f80bf2dfb4de682a56abe79b7b0e5e0459804b30.zip |
Made button, checkbox and radiobutton count their instances and only load their
resources once. Other widgets will follow later.
Diffstat (limited to 'src/gui/button.cpp')
-rw-r--r-- | src/gui/button.cpp | 73 |
1 files changed, 52 insertions, 21 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()); - } + } } |