2
0

PolyUICheckBox.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * PolyUICheckBox.cpp
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 8/8/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. #include "PolyUICheckBox.h"
  10. using namespace Polycode;
  11. UICheckBox::UICheckBox(Font *font, String checkImage, String caption, bool checked) {
  12. buttonImage = new ScreenImage(checkImage.c_str());
  13. buttonImage->setPosition(2, 3);
  14. this->checked = checked;
  15. buttonImage->visible = checked;
  16. captionLabel = new ScreenLabel("", caption, 11, Label::ANTIALIAS_FULL);
  17. addChild(captionLabel);
  18. captionLabel->setPosition(buttonImage->getWidth()+14,0);
  19. buttonRect = new ScreenShape(ScreenShape::SHAPE_RECT, buttonImage->getWidth()+5,buttonImage->getHeight()+5,0,0);
  20. buttonRect->setColor(0.1f, 0.1f, 0.1f, 1.0f);
  21. buttonRect->strokeEnabled = true;
  22. buttonRect->setStrokeColor(1.0f, 1.0f, 1.0f, 0.1f);
  23. addChild(buttonRect);
  24. addChild(buttonImage);
  25. buttonRect->addEventListener(this, InputEvent::EVENT_MOUSEOVER);
  26. buttonRect->addEventListener(this, InputEvent::EVENT_MOUSEOUT);
  27. buttonRect->addEventListener(this, InputEvent::EVENT_MOUSEUP);
  28. buttonRect->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
  29. captionLabel->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
  30. }
  31. UICheckBox::~UICheckBox() {
  32. }
  33. bool UICheckBox::isChecked() {
  34. return checked;
  35. }
  36. void UICheckBox::changeCheck() {
  37. checked = !checked;
  38. buttonImage->visible = checked;
  39. dispatchEvent(new UIEvent(), UIEvent::CHANGE_EVENT);
  40. }
  41. void UICheckBox::handleEvent(Event *event) {
  42. if(event->getDispatcher() == buttonRect || event->getDispatcher() == captionLabel) {
  43. switch(event->getEventCode()) {
  44. case InputEvent::EVENT_MOUSEDOWN:
  45. changeCheck();
  46. break;
  47. }
  48. }
  49. }