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/checkbox.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/checkbox.cpp')
-rw-r--r-- | src/gui/checkbox.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
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; |