summaryrefslogtreecommitdiff
path: root/src/gui/button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/button.cpp')
-rw-r--r--src/gui/button.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index 40ecd1b7..1d3a04e4 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -1,32 +1,30 @@
/*
* The Mana World
- * Copyright 2004 The Mana World Development Team
+ * Copyright (C) 2004 The Mana World Development Team
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
+ * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
#include <guichan/exception.hpp>
-#include <guichan/graphics.hpp>
-#include <guichan/imagefont.hpp>
+#include <guichan/font.hpp>
#include "button.h"
+#include "../configuration.h"
#include "../graphics.h"
#include "../resources/image.h"
@@ -35,6 +33,7 @@
#include "../utils/dtor.h"
int Button::mInstances = 0;
+float Button::mAlpha = config.getValue("guialpha", 0.8);
enum{
BUTTON_STANDARD, // 0
@@ -52,10 +51,10 @@ struct ButtonData
};
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}
+ { "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];
@@ -100,6 +99,7 @@ void Button::init()
data[x].gridX, data[y].gridY,
data[x + 1].gridX - data[x].gridX + 1,
data[y + 1].gridY - data[y].gridY + 1);
+ button[mode].grid[a]->setAlpha(mAlpha);
a++;
}
}
@@ -122,22 +122,29 @@ Button::~Button()
}
}
-void
-Button::draw(gcn::Graphics *graphics)
+void Button::draw(gcn::Graphics *graphics)
{
int mode;
- if (!isEnabled()) {
+ if (!isEnabled())
mode = BUTTON_DISABLED;
- }
- else if (isPressed() || mIsLogged) {
+ else if (isPressed() || mIsLogged)
mode = BUTTON_PRESSED;
- }
- else if (mHasMouse || isFocused()) {
+ else if (mHasMouse || isFocused())
mode = BUTTON_HIGHLIGHTED;
- }
- else {
+ else
mode = BUTTON_STANDARD;
+
+ if (config.getValue("guialpha", 0.8) != mAlpha)
+ {
+ mAlpha = config.getValue("guialpha", 0.8);
+ for (int a = 0; a < 9; a++)
+ {
+ button[BUTTON_DISABLED].grid[a]->setAlpha(mAlpha);
+ button[BUTTON_PRESSED].grid[a]->setAlpha(mAlpha);
+ button[BUTTON_HIGHLIGHTED].grid[a]->setAlpha(mAlpha);
+ button[BUTTON_STANDARD].grid[a]->setAlpha(mAlpha);
+ }
}
static_cast<Graphics*>(graphics)->
@@ -148,7 +155,8 @@ Button::draw(gcn::Graphics *graphics)
int textX;
int textY = getHeight() / 2 - getFont()->getHeight() / 2;
- switch (getAlignment()) {
+ switch (getAlignment())
+ {
case gcn::Graphics::LEFT:
textX = 4;
break;
@@ -164,10 +172,8 @@ Button::draw(gcn::Graphics *graphics)
graphics->setFont(getFont());
- if (isPressed()) {
+ if (isPressed())
graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
- }
- else {
+ else
graphics->drawText(getCaption(), textX, textY, getAlignment());
- }
}