diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-05-21 13:36:56 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-05-21 13:36:56 +0000 |
commit | e5f70463119360222400e6b3529b7ab8748317ae (patch) | |
tree | 143f1fabdc6ea5532326b9e1fd1e0266b460f169 /src/gui/textfield.cpp | |
parent | 7267fc408fd21dbc01a621aaa5a9e2115e297ff0 (diff) | |
download | mana-e5f70463119360222400e6b3529b7ab8748317ae.tar.gz mana-e5f70463119360222400e6b3529b7ab8748317ae.tar.bz2 mana-e5f70463119360222400e6b3529b7ab8748317ae.tar.xz mana-e5f70463119360222400e6b3529b7ab8748317ae.zip |
Only load resources once for player box, scroll area and text field. Also
tweaked the look a little, needs to be checked for opaque problem.
Diffstat (limited to 'src/gui/textfield.cpp')
-rw-r--r-- | src/gui/textfield.cpp | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 56ad8ab0..c89b7ea4 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -24,24 +24,50 @@ #include "textfield.h" #include "../resources/resourcemanager.h" +int TextField::instances = 0; +ImageRect TextField::skin; + TextField::TextField(const std::string& text): gcn::TextField(text) { setBorderSize(2); - // Load the skin - ResourceManager *resman = ResourceManager::getInstance(); - Image *textbox = resman->getImage("graphics/gui/textbox.png"); - int gridx[4] = {0, 9, 16, 25}; - int gridy[4] = {0, 4, 19, 24}; - int a = 0, x, y; + if (instances == 0) + { + // Load the skin + ResourceManager *resman = ResourceManager::getInstance(); + Image *textbox = resman->getImage("graphics/gui/deepbox.png"); + int gridx[4] = {0, 3, 28, 31}; + int gridy[4] = {0, 3, 28, 31}; + //Image *textbox = resman->getImage("graphics/gui/textbox.png"); + //int gridx[4] = {0, 5, 26, 31}; + //int gridy[4] = {0, 5, 26, 31}; + int a = 0, x, y; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + skin.grid[a] = textbox->getSubImage( + gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, + gridy[y + 1] - gridy[y] + 1); + a++; + } + } + + textbox->decRef(); + } + + instances++; +} + +TextField::~TextField() +{ + instances--; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - skin.grid[a] = textbox->getSubImage( - gridx[x], gridy[y], - gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1); - a++; + if (instances == 0) + { + for (int a = 0; a < 9; a++) { + delete skin.grid[a]; } } } @@ -53,7 +79,7 @@ void TextField::draw(gcn::Graphics *graphics) w = getWidth(); h = getHeight(); - if (hasFocus()) { + if (hasFocus()) { drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); @@ -61,7 +87,7 @@ void TextField::draw(gcn::Graphics *graphics) graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); - graphics->drawText(mText, 1 - mXScroll, 1); + graphics->drawText(mText, 1 - mXScroll, 1); } void TextField::drawBorder(gcn::Graphics *graphics) |