diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-27 09:38:56 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-27 09:38:56 (GMT) |
| commit | ebd80c73de6b02e1fcf731aa0f377b6085128e57 (patch) | |
| tree | 24c380dbfbde4c3dc34dc1f995f0ad2b177b6e7a /src/interface | |
| parent | e84f0fc6e5301265708a99b13ab898ce45422611 (diff) | |
| download | powder-ebd80c73de6b02e1fcf731aa0f377b6085128e57.zip powder-ebd80c73de6b02e1fcf731aa0f377b6085128e57.tar.gz | |
Some inlines and Checkbox ui component
Diffstat (limited to 'src/interface')
| -rw-r--r-- | src/interface/Button.cpp | 2 | ||||
| -rw-r--r-- | src/interface/Checkbox.cpp | 89 | ||||
| -rw-r--r-- | src/interface/Checkbox.h | 40 |
3 files changed, 131 insertions, 0 deletions
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index 8fe847e..b145b38 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -204,6 +204,8 @@ void Button::DoAction() void Button::SetActionCallback(ButtonAction * action) { + if(actionCallback) + delete actionCallback; actionCallback = action; } diff --git a/src/interface/Checkbox.cpp b/src/interface/Checkbox.cpp new file mode 100644 index 0000000..3244552 --- /dev/null +++ b/src/interface/Checkbox.cpp @@ -0,0 +1,89 @@ +/* + * Checkbox.cpp + * + * Created on: Jan 26, 2012 + * Author: Simon + */ + +#include "Checkbox.h" + +using namespace ui; + +Checkbox::Checkbox(ui::Point position, ui::Point size, std::string text): + Component(position, size), + text(text), + isMouseOver(false), + checked(false), + actionCallback(NULL) +{ + // TODO Auto-generated constructor stub + +} + +void Checkbox::SetText(std::string text) +{ + this->text = text; +} + +void Checkbox::OnMouseClick(int x, int y, unsigned int button) +{ + if(checked) + { + checked = false; + } + else + { + checked = true; + } + if(actionCallback) + actionCallback->ActionCallback(this); +} + +void Checkbox::OnMouseUp(int x, int y, unsigned int button) +{ + +} + + +void Checkbox::OnMouseEnter(int x, int y) +{ + isMouseOver = true; +} + +void Checkbox::OnMouseLeave(int x, int y) +{ + isMouseOver = false; +} + +void Checkbox::Draw(const Point& screenPos) +{ + Graphics * g = Engine::Ref().g; + if(checked) + { + g->fillrect(screenPos.X+4, screenPos.Y+4, 8, 8, 255, 255, 255, 255); + } + if(isMouseOver) + { + g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255); + g->fillrect(screenPos.X+4, screenPos.Y+4, 8, 8, 255, 255, 255, 170); + g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255); + } + else + { + g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200); + g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200); + } +} + +void Checkbox::SetActionCallback(CheckboxAction * action) +{ + if(actionCallback) + delete actionCallback; + actionCallback = action; +} + +Checkbox::~Checkbox() { + if(actionCallback) + delete actionCallback; +} + diff --git a/src/interface/Checkbox.h b/src/interface/Checkbox.h new file mode 100644 index 0000000..ed7dc95 --- /dev/null +++ b/src/interface/Checkbox.h @@ -0,0 +1,40 @@ +/* + * Checkbox.h + * + * Created on: Jan 26, 2012 + * Author: Simon + */ + +#ifndef CHECKBOX_H_ +#define CHECKBOX_H_ + +#include <string> +#include "Component.h" +namespace ui +{ +class Checkbox; +class CheckboxAction +{ +public: + virtual void ActionCallback(ui::Checkbox * sender) {} + virtual ~CheckboxAction() {} +}; +class Checkbox: public ui::Component { + std::string text; + bool checked; + bool isMouseOver; + CheckboxAction * actionCallback; +public: + Checkbox(ui::Point position, ui::Point size, std::string text); + void SetText(std::string text); + void Draw(const Point& screenPos); + virtual void OnMouseEnter(int x, int y); + virtual void OnMouseLeave(int x, int y); + virtual void OnMouseClick(int x, int y, unsigned int button); + virtual void OnMouseUp(int x, int y, unsigned int button); + void SetActionCallback(CheckboxAction * action); + virtual ~Checkbox(); +}; +} + +#endif /* CHECKBOX_H_ */ |
