summaryrefslogtreecommitdiff
path: root/src/interface/Button.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-17 20:46:06 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-17 20:46:06 (GMT)
commit4a60b97c700c2f1843b7e99313554cb89fb5da4e (patch)
tree3b33ef6f74a4e8a4ff5968a81b9c4c429ccaa7c6 /src/interface/Button.cpp
parent6273089bf486bf46ad325d72c7290ebb272bd3d8 (diff)
downloadpowder-4a60b97c700c2f1843b7e99313554cb89fb5da4e.zip
powder-4a60b97c700c2f1843b7e99313554cb89fb5da4e.tar.gz
Some minor changes
Diffstat (limited to 'src/interface/Button.cpp')
-rw-r--r--src/interface/Button.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index 6ea9854..a3f76b9 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -10,15 +10,17 @@
#include "interface/Button.h"
#include "Graphics.h"
#include "Global.h"
+#include "Engine.h"
namespace ui {
-Button::Button(State* parent_state, std::string buttonText):
+Button::Button(Window* parent_state, std::string buttonText):
Component(parent_state),
ButtonText(buttonText),
isMouseInside(false),
isButtonDown(false),
- isTogglable(false)
+ isTogglable(false),
+ actionCallback(NULL)
{
}
@@ -28,7 +30,8 @@ Button::Button(Point position, Point size, std::string buttonText):
ButtonText(buttonText),
isMouseInside(false),
isButtonDown(false),
- isTogglable(false)
+ isTogglable(false),
+ actionCallback(NULL)
{
}
@@ -38,7 +41,8 @@ Button::Button(std::string buttonText):
ButtonText(buttonText),
isMouseInside(false),
isButtonDown(false),
- isTogglable(false)
+ isTogglable(false),
+ actionCallback(NULL)
{
}
@@ -68,13 +72,13 @@ inline void Button::SetToggleState(bool state)
void Button::Draw(const Point& screenPos)
{
- Graphics * g = Global::Ref().g;
+ Graphics * g = ui::Engine::Ref().g;
Point Position = screenPos;
// = reinterpret_cast<Graphics*>(userdata);
//TODO: Cache text location, that way we don't have the text alignment code here
if(isButtonDown || (isTogglable && toggle))
{
- g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
+ g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255);
g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2, ButtonText, 0, 0, 0, 255);
}
else
@@ -116,7 +120,6 @@ void Button::Draw(const Point& screenPos)
void Button::OnMouseUnclick(int x, int y, unsigned int button)
{
- std::cout << "Unclick!" << std::endl;
if(button != 1)
{
return; //left click only!
@@ -160,6 +163,15 @@ void Button::OnMouseLeave(int x, int y)
void Button::DoAction()
{
std::cout << "Do action!"<<std::endl;
+ //if(actionCallback)
+ // (*(actionCallback))();
+ if(actionCallback)
+ actionCallback->ActionCallback(this);
+}
+
+void Button::SetActionCallback(ButtonAction * action)
+{
+ actionCallback = action;
}
Button::~Button()