diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:44:09 (GMT) |
| commit | 058a2edd75debbd0297f92572316daa704bd379f (patch) | |
| tree | ad303f091f9a08b209b91eb34a9fcad996a3de69 /src/interface/Checkbox.cpp | |
| parent | e3594aba9e05c6865d396418c028049cda92c2f3 (diff) | |
| parent | 7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff) | |
| download | powder-058a2edd75debbd0297f92572316daa704bd379f.zip powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/interface/Checkbox.cpp')
| -rw-r--r-- | src/interface/Checkbox.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/interface/Checkbox.cpp b/src/interface/Checkbox.cpp new file mode 100644 index 0000000..22c6a42 --- /dev/null +++ b/src/interface/Checkbox.cpp @@ -0,0 +1,112 @@ +/* + * 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, std::string toolTip): + Component(position, size), + text(text), + toolTip(toolTip), + isMouseOver(false), + checked(false), + actionCallback(NULL) +{ + // TODO Auto-generated constructor stub + +} + +void Checkbox::SetText(std::string text) +{ + this->text = text; +} + +std::string Checkbox::GetText() +{ + return text; +} + +void Checkbox::SetIcon(Icon icon) +{ + Appearance.icon = icon; + iconPosition.X = 16; + iconPosition.Y = 3; +} + +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; + if(toolTip.length()>0 && GetParentWindow()) + { + GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip); + } +} + +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+5, screenPos.Y+5, 6, 6, 255, 255, 255, 255); + } + if(isMouseOver) + { + g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255); + g->fillrect(screenPos.X+5, screenPos.Y+5, 6, 6, 255, 255, 255, 170); + if (!Appearance.icon) + g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255); + else + g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 255); + } + else + { + g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200); + if (!Appearance.icon) + g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200); + else + g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 200); + } +} + +void Checkbox::SetActionCallback(CheckboxAction * action) +{ + if(actionCallback) + delete actionCallback; + actionCallback = action; +} + +Checkbox::~Checkbox() { + if(actionCallback) + delete actionCallback; +} + |
