summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/menuitem.cpp51
-rw-r--r--src/gui/menuitem.h7
3 files changed, 48 insertions, 12 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 75519286..549bf637 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,6 +39,8 @@ tmw_SOURCES = graphic/spriteset.cpp \
gui/login.h \
gui/menuitem.h \
gui/menuitem.cpp \
+ gui/menu.h \
+ gui/menu.cpp \
gui/minimap.cpp \
gui/minimap.h \
gui/newskill.cpp \
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());
+ }
}
diff --git a/src/gui/menuitem.h b/src/gui/menuitem.h
index dcfdf11f..d83a9095 100644
--- a/src/gui/menuitem.h
+++ b/src/gui/menuitem.h
@@ -28,7 +28,7 @@
#include "../resources/image.h"
#include "../graphics.h"
-class MenuItem : public gcn::Widget, public gcn::MouseListener
+class MenuItem : public gcn::Button
{
public:
/**
@@ -46,11 +46,6 @@ class MenuItem : public gcn::Widget, public gcn::MouseListener
*/
void draw(gcn::Graphics* graphics);
- /**
- * Handles mouse
- */
- void mousePress(int x, int y, int button);
-
private:
ImageRect menuitem[4];
};