CheckBox.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef CHECKBOX_H_
  2. #define CHECKBOX_H_
  3. #include "Theme.h"
  4. #include "Properties.h"
  5. #include "Touch.h"
  6. #include "Button.h"
  7. namespace gameplay
  8. {
  9. /**
  10. * Defines a checkbox UI control. This is a button that toggles between two icons when clicked.
  11. *
  12. * The following properties are available for checkboxes:
  13. *
  14. * checkBox <CheckBox ID>
  15. * {
  16. * style = <Style ID>
  17. * position = <x, y>
  18. * size = <width, height>
  19. * text = <string>
  20. * checked = <bool>
  21. * iconSize = <width, height> // The size to draw the checkbox icon, if different from its size in the texture.
  22. * }
  23. */
  24. class CheckBox : public Button
  25. {
  26. friend class Container;
  27. public:
  28. /**
  29. * Gets whether this checkbox is checked.
  30. *
  31. * @return Whether this checkbox is checked.
  32. */
  33. bool isChecked();
  34. /**
  35. * Set the size to draw the checkbox icon.
  36. *
  37. * @param width The width to draw the checkbox icon.
  38. * @param height The height to draw the checkbox icon.
  39. */
  40. void setIconSize(float width, float height);
  41. /**
  42. * Get the size at which the checkbox icon will be drawn.
  43. *
  44. * @return The size of the checkbox icon.
  45. */
  46. const Vector2& getIconSize() const;
  47. protected:
  48. CheckBox();
  49. ~CheckBox();
  50. /**
  51. * Create a checkbox with a given style and properties.
  52. *
  53. * @param style The style to apply to this checkbox.
  54. * @param properties The properties to set on this checkbox.
  55. *
  56. * @return The new checkbox.
  57. */
  58. static CheckBox* create(Theme::Style* style, Properties* properties);
  59. /**
  60. * Touch callback on touch events. Controls return true if they consume the touch event.
  61. *
  62. * @param evt The touch event that occurred.
  63. * @param x The x position of the touch in pixels. Left edge is zero.
  64. * @param y The y position of the touch in pixels. Top edge is zero.
  65. * @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
  66. *
  67. * @return Whether the touch event was consumed by the control.
  68. *
  69. * @see Touch::TouchEvent
  70. */
  71. bool touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  72. /**
  73. * Called when a control's properties change. Updates this control's internal rendering
  74. * properties, such as its text viewport.
  75. *
  76. * @param position The control's position within its container.
  77. */
  78. void update(const Rectangle& clip);
  79. /**
  80. * Draw the checkbox icon associated with this control.
  81. *
  82. * @param spriteBatch The sprite batch containing this control's icons.
  83. * @param position The container position this control is relative to.
  84. */
  85. void drawSprites(SpriteBatch* spriteBatch, const Rectangle& clip);
  86. /**
  87. * Draw this control's text.
  88. *
  89. * @param position The container position this control is relative to.
  90. */
  91. void drawText(const Rectangle& clip);
  92. bool _checked; // Whether this checkbox is currently checked.
  93. Vector2 _iconSize; // The size to draw the checkbox icon, if different from its size in the texture.
  94. private:
  95. CheckBox(const CheckBox& copy);
  96. };
  97. }
  98. #endif