diff options
-rw-r--r-- | data/graphics/gui/deepbox.png | bin | 257 -> 266 bytes | |||
-rw-r--r-- | src/gui/playerbox.cpp | 48 | ||||
-rw-r--r-- | src/gui/playerbox.h | 11 | ||||
-rw-r--r-- | src/gui/scrollarea.cpp | 154 | ||||
-rw-r--r-- | src/gui/scrollarea.h | 20 | ||||
-rw-r--r-- | src/gui/textfield.cpp | 54 | ||||
-rw-r--r-- | src/gui/textfield.h | 8 |
7 files changed, 205 insertions, 90 deletions
diff --git a/data/graphics/gui/deepbox.png b/data/graphics/gui/deepbox.png Binary files differindex 3c86d562..814236ed 100644 --- a/data/graphics/gui/deepbox.png +++ b/data/graphics/gui/deepbox.png diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index b97b37b3..9514d335 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -27,6 +27,9 @@ #include "../main.h" #include "../resources/resourcemanager.h" +int PlayerBox::instances = 0; +ImageRect PlayerBox::background; + PlayerBox::PlayerBox(): hairColor(0), hairStyle(0), @@ -34,20 +37,39 @@ PlayerBox::PlayerBox(): { setBorderSize(2); - // Load the background skin - ResourceManager *resman = ResourceManager::getInstance(); - Image *textbox = resman->getImage("graphics/gui/textbox.png"); - int bggridx[4] = {0, 9, 16, 25}; - int bggridy[4] = {0, 4, 19, 24}; - int a = 0, x, y; + if (instances == 0) + { + // Load the background skin + ResourceManager *resman = ResourceManager::getInstance(); + Image *textbox = resman->getImage("graphics/gui/deepbox.png"); + int bggridx[4] = {0, 3, 28, 31}; + int bggridy[4] = {0, 3, 28, 31}; + int a = 0, x, y; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + background.grid[a] = textbox->getSubImage( + bggridx[x], bggridy[y], + bggridx[x + 1] - bggridx[x] + 1, + bggridy[y + 1] - bggridy[y] + 1); + a++; + } + } + + textbox->decRef(); + } + + instances++; +} - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - background.grid[a] = textbox->getSubImage( - bggridx[x], bggridy[y], - bggridx[x + 1] - bggridx[x] + 1, - bggridy[y + 1] - bggridy[y] + 1); - a++; +PlayerBox::~PlayerBox() +{ + instances--; + + if (instances == 0) + { + for (int a = 0; a < 9; a++) { + delete background.grid[a]; } } } diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h index cf7c3995..39fa39b4 100644 --- a/src/gui/playerbox.h +++ b/src/gui/playerbox.h @@ -33,7 +33,8 @@ * * \ingroup GUI */ -class PlayerBox : public gcn::ScrollArea { +class PlayerBox : public gcn::ScrollArea +{ public: /** * Constructor. @@ -41,6 +42,11 @@ class PlayerBox : public gcn::ScrollArea { PlayerBox(); /** + * Destructor. + */ + ~PlayerBox(); + + /** * Draws the scroll area. */ void draw(gcn::Graphics *graphics); @@ -55,7 +61,8 @@ class PlayerBox : public gcn::ScrollArea { bool showPlayer; /**< Wether to show the player or not */ private: - ImageRect background; + static int instances; + static ImageRect background; }; #endif diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index b1afa183..a5c5542f 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -26,6 +26,18 @@ #include "../resources/resourcemanager.h" #include "../main.h" +int ScrollArea::instances = 0; +ImageRect ScrollArea::background; +ImageRect ScrollArea::vMarker; +Image *ScrollArea::hscroll_left_default; +Image *ScrollArea::hscroll_right_default; +Image *ScrollArea::vscroll_down_default; +Image *ScrollArea::vscroll_up_default; +Image *ScrollArea::hscroll_left_pressed; +Image *ScrollArea::hscroll_right_pressed; +Image *ScrollArea::vscroll_down_pressed; +Image *ScrollArea::vscroll_up_pressed; + ScrollArea::ScrollArea(): gcn::ScrollArea() { @@ -38,59 +50,91 @@ ScrollArea::ScrollArea(gcn::Widget *widget): init(); } +ScrollArea::~ScrollArea() +{ + instances--; + + if (instances == 0) + { + for (int a = 0; a < 9; a++) { + delete background.grid[a]; + delete vMarker.grid[a]; + } + + hscroll_left_default->decRef(); + hscroll_right_default->decRef(); + vscroll_down_default->decRef(); + vscroll_up_default->decRef(); + hscroll_left_pressed->decRef(); + hscroll_right_pressed->decRef(); + vscroll_down_pressed->decRef(); + vscroll_up_pressed->decRef(); + } +} + void ScrollArea::init() { // Draw background by default - setBorderSize(2); - opaque = true; - - // Load the background skin - ResourceManager *resman = ResourceManager::getInstance(); - Image *textbox = resman->getImage("graphics/gui/textbox.png"); - int bggridx[4] = {0, 9, 16, 25}; - int bggridy[4] = {0, 4, 19, 24}; - int a = 0, x, y; - - // Load GUI alpha setting - guiAlpha = config.getValue("guialpha", 0.8f); - - // Set GUI alpha level - textbox->setAlpha(guiAlpha); - - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - background.grid[a] = textbox->getSubImage( - bggridx[x], bggridy[y], - bggridx[x + 1] - bggridx[x] + 1, - bggridy[y + 1] - bggridy[y] + 1); - a++; + setOpaque(true); + + if (instances == 0) + { + // Load the background skin + ResourceManager *resman = ResourceManager::getInstance(); + Image *textbox = resman->getImage("graphics/gui/deepbox.png"); + int bggridx[4] = {0, 3, 28, 31}; + int bggridy[4] = {0, 3, 28, 31}; + int a = 0, x, y; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + background.grid[a] = textbox->getSubImage( + bggridx[x], bggridy[y], + bggridx[x + 1] - bggridx[x] + 1, + bggridy[y + 1] - bggridy[y] + 1); + a++; + } } - } - // Load vertical scrollbar skin - Image *vscroll = resman->getImage("graphics/gui/vscroll_grey.png"); - int vsgridx[4] = {0, 4, 7, 11}; - int vsgridy[4] = {0, 4, 15, 19}; - a = 0; - - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - vMarker.grid[a] = vscroll->getSubImage( - vsgridx[x], vsgridy[y], - vsgridx[x + 1] - vsgridx[x], - vsgridy[y + 1] - vsgridy[y]); - a++; + textbox->decRef(); + + // Load vertical scrollbar skin + Image *vscroll = resman->getImage("graphics/gui/vscroll_grey.png"); + int vsgridx[4] = {0, 4, 7, 11}; + int vsgridy[4] = {0, 4, 15, 19}; + a = 0; + + for (y = 0; y < 3; y++) { + for (x = 0; x < 3; x++) { + vMarker.grid[a] = vscroll->getSubImage( + vsgridx[x], vsgridy[y], + vsgridx[x + 1] - vsgridx[x], + vsgridy[y + 1] - vsgridy[y]); + a++; + } } + + vscroll->decRef(); + + hscroll_left_default = + resman->getImage("graphics/gui/hscroll_left_default.png"); + hscroll_right_default = + resman->getImage("graphics/gui/hscroll_right_default.png"); + vscroll_down_default = + resman->getImage("graphics/gui/vscroll_down_default.png"); + vscroll_up_default = + resman->getImage("graphics/gui/vscroll_up_default.png"); + hscroll_left_pressed = + resman->getImage("graphics/gui/hscroll_left_pressed.png"); + hscroll_right_pressed = + resman->getImage("graphics/gui/hscroll_right_pressed.png"); + vscroll_down_pressed = + resman->getImage("graphics/gui/vscroll_down_pressed.png"); + vscroll_up_pressed = + resman->getImage("graphics/gui/vscroll_up_pressed.png"); } - hscroll_left_default = resman->getImage("graphics/gui/hscroll_left_default.png"); - hscroll_right_default = resman->getImage("graphics/gui/hscroll_right_default.png"); - vscroll_down_default = resman->getImage("graphics/gui/vscroll_down_default.png"); - vscroll_up_default = resman->getImage("graphics/gui/vscroll_up_default.png"); - hscroll_left_pressed = resman->getImage("graphics/gui/hscroll_left_pressed.png"); - hscroll_right_pressed = resman->getImage("graphics/gui/hscroll_right_pressed.png"); - vscroll_down_pressed = resman->getImage("graphics/gui/vscroll_down_pressed.png"); - vscroll_up_pressed = resman->getImage("graphics/gui/vscroll_up_pressed.png"); + instances++; } void ScrollArea::draw(gcn::Graphics *graphics) @@ -233,22 +277,26 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics) void ScrollArea::drawVBar(gcn::Graphics *graphics) { - int x, y; + //int x, y; gcn::Rectangle dim = getVerticalBarDimension(); - getAbsolutePosition(x, y); + //getAbsolutePosition(x, y); - ((Graphics*)graphics)->drawImageRect( - x + dim.x, y + dim.y, dim.width, dim.height, background); + graphics->setColor(gcn::Color(0, 0, 0, 32)); + graphics->fillRectangle(dim); + //((Graphics*)graphics)->drawImageRect( + // x + dim.x, y + dim.y, dim.width, dim.height, background); } void ScrollArea::drawHBar(gcn::Graphics *graphics) { - int x, y; + //int x, y; gcn::Rectangle dim = getHorizontalBarDimension(); - getAbsolutePosition(x, y); + //getAbsolutePosition(x, y); - ((Graphics*)graphics)->drawImageRect( - x + dim.x, y + dim.y, dim.width, dim.height, background); + graphics->setColor(gcn::Color(0, 0, 0, 32)); + graphics->fillRectangle(dim); + //((Graphics*)graphics)->drawImageRect( + // x + dim.x, y + dim.y, dim.width, dim.height, background); } void ScrollArea::drawVMarker(gcn::Graphics *graphics) diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h index ce745ba8..e3e57ae2 100644 --- a/src/gui/scrollarea.h +++ b/src/gui/scrollarea.h @@ -46,6 +46,11 @@ class ScrollArea : public gcn::ScrollArea { ScrollArea(gcn::Widget *content); /** + * Destructor. + */ + ~ScrollArea(); + + /** * Draws the scroll area. */ void draw(gcn::Graphics *graphics); @@ -80,13 +85,14 @@ class ScrollArea : public gcn::ScrollArea { void drawVMarker(gcn::Graphics *graphics); void drawHMarker(gcn::Graphics *graphics); - ImageRect background; - ImageRect vMarker; - Image *hscroll_left_default, *hscroll_right_default, - *vscroll_down_default, *vscroll_up_default; - Image *hscroll_left_pressed, *hscroll_right_pressed, - *vscroll_down_pressed, *vscroll_up_pressed; - float guiAlpha; + static int instances; + static ImageRect background; + static ImageRect vMarker; + static Image *hscroll_left_default, *hscroll_right_default; + static Image *vscroll_down_default, *vscroll_up_default; + static Image *hscroll_left_pressed, *hscroll_right_pressed; + static Image *vscroll_down_pressed, *vscroll_up_pressed; + bool opaque; }; 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) diff --git a/src/gui/textfield.h b/src/gui/textfield.h index a9be41e7..808b73ab 100644 --- a/src/gui/textfield.h +++ b/src/gui/textfield.h @@ -40,6 +40,11 @@ class TextField : public gcn::TextField { TextField(const std::string& text = ""); /** + * Destructor. + */ + ~TextField(); + + /** * Draws the text field. */ virtual void draw(gcn::Graphics *graphics); @@ -50,7 +55,8 @@ class TextField : public gcn::TextField { void drawBorder(gcn::Graphics *graphics); private: - ImageRect skin; + static int instances; + static ImageRect skin; }; #endif |