diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-09-27 14:54:09 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-09-27 14:54:09 +0000 |
commit | 285da0d05eb2e6b680a8dfc497cf4ecab75b7aa4 (patch) | |
tree | 0a4e4169ffada0fbdc25fd91822a8c0fe678571c /src/gui/button.cpp | |
parent | c24856707233ceb3995e43f8f7da63e65999df1e (diff) | |
download | mana-285da0d05eb2e6b680a8dfc497cf4ecab75b7aa4.tar.gz mana-285da0d05eb2e6b680a8dfc497cf4ecab75b7aa4.tar.bz2 mana-285da0d05eb2e6b680a8dfc497cf4ecab75b7aa4.tar.xz mana-285da0d05eb2e6b680a8dfc497cf4ecab75b7aa4.zip |
Merged another bunch of changes from trunk to 0.0 to reduce the difference.
Diffstat (limited to 'src/gui/button.cpp')
-rw-r--r-- | src/gui/button.cpp | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp index a9212e83..0379ebc0 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -34,9 +34,32 @@ #include "../utils/dtor.h" -ImageRect Button::button[4]; int Button::mInstances = 0; +enum{ + BUTTON_STANDARD, // 0 + BUTTON_HIGHLIGHTED, // 1 + BUTTON_PRESSED, // 2 + BUTTON_DISABLED, // 3 + BUTTON_COUNT // 4 - Must be last. +}; + +struct ButtonData +{ + char const *file; + int gridX; + int gridY; +}; + +static ButtonData const data[BUTTON_COUNT] = { + {"graphics/gui/button.png", 0, 0}, + {"graphics/gui/buttonhi.png", 9, 4}, + {"graphics/gui/buttonpress.png", 16, 19}, + {"graphics/gui/button_disabled.png", 25, 23} +}; + +ImageRect Button::button[BUTTON_COUNT]; + Button::Button(): mIsLogged(false) { @@ -63,24 +86,20 @@ void Button::init() { // 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}; + Image *btn[BUTTON_COUNT]; + int a, x, y, mode; - for (mode = 0; mode < 4; mode++) + for (mode = 0; mode < BUTTON_COUNT; mode++) { + btn[mode] = resman->getImage(data[mode].file); 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); + data[x].gridX, data[y].gridY, + data[x + 1].gridX - data[x].gridX + 1, + data[y + 1].gridY - data[y].gridY + 1); a++; } } @@ -96,7 +115,7 @@ Button::~Button() if (mInstances == 0) { - for (int mode = 0; mode < 4; mode++) + for (int mode = 0; mode < BUTTON_COUNT; mode++) { for_each(button[mode].grid, button[mode].grid + 9, dtor<Image*>()); } @@ -109,21 +128,20 @@ Button::draw(gcn::Graphics *graphics) int mode; if (!isEnabled()) { - mode = 3; + mode = BUTTON_DISABLED; } else if (isPressed() || mIsLogged) { - mode = 2; + mode = BUTTON_PRESSED; } - else if (mHasMouse) { - mode = 1; + else if (mHasMouse || isFocused()) { + mode = BUTTON_HIGHLIGHTED; } else { - mode = 0; + mode = BUTTON_STANDARD; } - dynamic_cast<Graphics*>(graphics)->drawImageRect(0, 0, - getWidth(), getHeight(), - button[mode]); + static_cast<Graphics*>(graphics)-> + drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); graphics->setColor(getForegroundColor()); |