summaryrefslogtreecommitdiff
path: root/src/interface/Button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/interface/Button.cpp')
-rw-r--r--src/interface/Button.cpp81
1 files changed, 47 insertions, 34 deletions
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index a357c36..e34f66c 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -12,32 +12,49 @@
namespace ui {
-Button::Button(int x, int y, int width, int height, const std::string& buttonText):
- Component(x, y, width, height),
- Toggleable(false),
- ButtonText(buttonText),
- isMouseInside(false),
- isButtonDown(false),
- state(false)
+Button::Button(State* parent_state, std::string buttonText):
+ Component(parent_state),
+ ButtonText(buttonText),
+ isMouseInside(false),
+ isButtonDown(false)
{
}
-void Button::Draw(void* userdata)
+Button::Button(Point position, Point size, std::string buttonText):
+ Component(position, size),
+ ButtonText(buttonText),
+ isMouseInside(false),
+ isButtonDown(false)
{
- Graphics * g = reinterpret_cast<Graphics*>(userdata);
+
+}
+
+Button::Button(std::string buttonText):
+ Component(),
+ ButtonText(buttonText),
+ isMouseInside(false),
+ isButtonDown(false)
+{
+
+}
+
+void Button::Draw(const Point& screenPos)
+{
+ Graphics * g = ui::Engine::Ref().g;
+ // = reinterpret_cast<Graphics*>(userdata);
//TODO: Cache text location, that way we don't have the text alignment code here
if(isButtonDown)
{
- g->fillrect(X, Y, Width, Height, 255, 255, 255, 255);
- g->drawtext(X+(Width-Graphics::textwidth((char *)ButtonText.c_str()))/2, Y+(Height-10)/2, ButtonText, 0, 0, 0, 255);
+ g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 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
{
if(isMouseInside)
- g->fillrect(X, Y, Width, Height, 20, 20, 20, 255);
- g->drawrect(X, Y, Width, Height, 255, 255, 255, 255);
- g->drawtext(X+(Width-Graphics::textwidth((char *)ButtonText.c_str()))/2, Y+(Height-10)/2, ButtonText, 255, 255, 255, 255);
+ g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
+ g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
+ g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2, ButtonText, 255, 255, 255, 255);
}
/*sf::RenderWindow* rw = reinterpret_cast<sf::RenderWindow*>(userdata); //it better be a RenderWindow or so help your god
@@ -71,6 +88,7 @@ void Button::Draw(void* userdata)
void Button::OnMouseUnclick(int x, int y, unsigned int button)
{
+ std::cout << "Unclick!" << std::endl;
if(button != 1)
{
return; //left click only!
@@ -78,44 +96,35 @@ void Button::OnMouseUnclick(int x, int y, unsigned int button)
if(isButtonDown)
{
- if(state)
- {
- state = false;
- }
- else
- {
- if(Toggleable)
- {
- state = true;
- }
- DoAction();
- }
+ DoAction();
}
isButtonDown = false;
}
-void Button::OnMouseUp(int x, int y, unsigned int button) //mouse unclick is called before this
-{
- if(button != 1) return; //left click only!
+//void Button::OnMouseUp(int x, int y, unsigned int button) //mouse unclick is called before this
+//{
+ // if(button != 1) return; //left click only!
- isButtonDown = false;
-}
+// isButtonDown = false;
+//}
void Button::OnMouseClick(int x, int y, unsigned int button)
{
+ std::cout << "Click!" << std::endl;
if(button != 1) return; //left click only!
-
isButtonDown = true;
}
-void Button::OnMouseEnter(int x, int y, int dx, int dy)
+void Button::OnMouseEnter(int x, int y)
{
+ std::cout << "Enter!"<<std::endl;
isMouseInside = true;
}
-void Button::OnMouseLeave(int x, int y, int dx, int dy)
+void Button::OnMouseLeave(int x, int y)
{
+ std::cout << "Leave!"<<std::endl;
isMouseInside = false;
}
@@ -124,4 +133,8 @@ void Button::DoAction()
std::cout << "Do action!"<<std::endl;
}
+Button::~Button()
+{
+}
+
} /* namespace ui */