summaryrefslogtreecommitdiff
path: root/src/gui/menuitem.cpp
diff options
context:
space:
mode:
authorMateusz Kaduk <mateusz.kaduk@gmail.com>2005-05-16 23:21:30 +0000
committerMateusz Kaduk <mateusz.kaduk@gmail.com>2005-05-16 23:21:30 +0000
commit70d935464b423d3f91af2d83922fea2cbe6f003b (patch)
tree90c3294abebff331d52cffdc66ac91bae5405713 /src/gui/menuitem.cpp
parent5026eca4d9818d32fe69571c1c621aa318bc4d48 (diff)
downloadmana-70d935464b423d3f91af2d83922fea2cbe6f003b.tar.gz
mana-70d935464b423d3f91af2d83922fea2cbe6f003b.tar.bz2
mana-70d935464b423d3f91af2d83922fea2cbe6f003b.tar.xz
mana-70d935464b423d3f91af2d83922fea2cbe6f003b.zip
Added base for Menu and menuitem inherit from gcn::Button
Diffstat (limited to 'src/gui/menuitem.cpp')
-rw-r--r--src/gui/menuitem.cpp51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/gui/menuitem.cpp b/src/gui/menuitem.cpp
index 256f5712..4bc073be 100644
--- a/src/gui/menuitem.cpp
+++ b/src/gui/menuitem.cpp
@@ -23,8 +23,10 @@
#include "menuitem.h"
#include "../resources/resourcemanager.h"
+#include <guichan/mouseinput.hpp>
-MenuItem::MenuItem(const std::string& label)
+MenuItem::MenuItem(const std::string& label):
+ gcn::Button(label)
{
setBorderSize(0);
@@ -36,7 +38,7 @@ MenuItem::MenuItem(const std::string& label)
item[0] = resman->getImage("graphics/gui/menuitemN.png");
item[1] = resman->getImage("graphics/gui/menuitemF.png");
item[2] = resman->getImage("graphics/gui/menuitemP.png");
- item[3] = resman->getImage("graphics/gui/menuitemP.png");
+ item[3] = resman->getImage("graphics/gui/menuitemD.png");
int bgridx[4] = {0, 9, 16, 25};
int bgridy[4] = {0, 4, 19, 24};
@@ -64,14 +66,51 @@ MenuItem::~MenuItem()
void MenuItem::draw(gcn::Graphics* graphics)
{
- int mode = 0;
+ int mode;
+
+ if (!isEnabled()) {
+ mode = 3;
+ }
+ else if (isPressed()) {
+ mode = 2;
+ }
+ else if (hasMouse()) {
+ mode = 1;
+ }
+ else {
+ mode = 0;
+ }
+
int x, y;
getAbsolutePosition(x, y);
((Graphics*)graphics)->drawImageRect(x, y, getWidth(), getHeight(),
menuitem[mode]);
-}
+ graphics->setColor(getForegroundColor());
-void MenuItem::mousePress(int x, int y, int button)
-{
+ int textX;
+ int textY = getHeight() / 2 - getFont()->getHeight() / 2;
+
+ switch (getAlignment()) {
+ case gcn::Graphics::LEFT:
+ textX = 4;
+ break;
+ case gcn::Graphics::CENTER:
+ textX = getWidth() / 2;
+ break;
+ case gcn::Graphics::RIGHT:
+ textX = getWidth() - 4;
+ break;
+ default:
+ throw GCN_EXCEPTION("Button::draw. Uknown alignment.");
+ }
+
+ graphics->setFont(getFont());
+
+ if (isPressed()) {
+ graphics->drawText(getCaption(), textX + 1, textY + 1, getAlignment());
+ }
+ else {
+ graphics->drawText(getCaption(), textX, textY, getAlignment());
+ }
}