diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-15 19:35:40 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-15 19:35:40 (GMT) |
| commit | 2511afec8bfaa0582928406b37e8b579fa267e4f (patch) | |
| tree | aae1674f5f076db275ec1c6b32271a69cff1489a /src/interface/Button.cpp | |
| parent | 2c9295007a287dc01ff63fcf7b3da141f7474e37 (diff) | |
| download | powder-2511afec8bfaa0582928406b37e8b579fa267e4f.zip powder-2511afec8bfaa0582928406b37e8b579fa267e4f.tar.gz | |
More stuff, better events and starting on interface
Diffstat (limited to 'src/interface/Button.cpp')
| -rw-r--r-- | src/interface/Button.cpp | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index e34f66c..6ea9854 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -9,6 +9,7 @@ #include "interface/Button.h" #include "Graphics.h" +#include "Global.h" namespace ui { @@ -16,7 +17,8 @@ Button::Button(State* parent_state, std::string buttonText): Component(parent_state), ButtonText(buttonText), isMouseInside(false), - isButtonDown(false) + isButtonDown(false), + isTogglable(false) { } @@ -25,7 +27,8 @@ Button::Button(Point position, Point size, std::string buttonText): Component(position, size), ButtonText(buttonText), isMouseInside(false), - isButtonDown(false) + isButtonDown(false), + isTogglable(false) { } @@ -34,17 +37,42 @@ Button::Button(std::string buttonText): Component(), ButtonText(buttonText), isMouseInside(false), - isButtonDown(false) + isButtonDown(false), + isTogglable(false) { } +void Button::SetTogglable(bool togglable) +{ + toggle = false; + isTogglable = togglable; +} + +bool Button::GetTogglable() +{ + return isTogglable; +} + +inline bool Button::GetToggleState() +{ + return toggle; +} + +inline void Button::SetToggleState(bool state) +{ + toggle = state; +} + + + void Button::Draw(const Point& screenPos) { - Graphics * g = ui::Engine::Ref().g; + Graphics * g = Global::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) + if(isButtonDown || (isTogglable && toggle)) { 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); @@ -111,20 +139,21 @@ void Button::OnMouseUnclick(int x, int y, unsigned int button) void Button::OnMouseClick(int x, int y, unsigned int button) { - std::cout << "Click!" << std::endl; if(button != 1) return; //left click only! + if(isTogglable) + { + toggle = !toggle; + } isButtonDown = true; } void Button::OnMouseEnter(int x, int y) { - std::cout << "Enter!"<<std::endl; isMouseInside = true; } void Button::OnMouseLeave(int x, int y) { - std::cout << "Leave!"<<std::endl; isMouseInside = false; } |
