Button.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef BUTTON_H_
  2. #define BUTTON_H_
  3. #include "Container.h"
  4. #include "Label.h"
  5. #include "Touch.h"
  6. #include "Theme.h"
  7. #include "Properties.h"
  8. namespace gameplay
  9. {
  10. /**
  11. * Defines a button UI control. This is essentially a label that can have a callback method set on it.
  12. *
  13. * The following properties are available for buttons:
  14. @verbatim
  15. button <buttonID>
  16. {
  17. style = <styleID>
  18. alignment = <Control::Alignment constant> // Note: 'position' will be ignored.
  19. position = <x, y>
  20. autoWidth = <bool>
  21. autoHeight = <bool>
  22. size = <width, height>
  23. width = <width> // Can be used in place of 'size', e.g. with 'autoHeight = true'
  24. height = <height> // Can be used in place of 'size', e.g. with 'autoWidth = true'
  25. text = <string>
  26. consumeEvents = <bool> // Whether the button propagates input events to the Game's input event handler. Default is true.
  27. }
  28. @endverbatim
  29. */
  30. class Button : public Label
  31. {
  32. friend class Container;
  33. friend class Gamepad;
  34. public:
  35. /**
  36. * Create a new button control.
  37. *
  38. * @param id The control's ID.
  39. * @param style The control's style.
  40. *
  41. * @return The new button.
  42. * @script{create}
  43. */
  44. static Button* create(const char* id, Theme::Style* style);
  45. protected:
  46. /**
  47. * Constructor.
  48. */
  49. Button();
  50. /**
  51. * Destructor.
  52. */
  53. virtual ~Button();
  54. /**
  55. * Create a button with a given style and properties.
  56. *
  57. * @param style The style to apply to this button.
  58. * @param properties The properties to set on this button.
  59. *
  60. * @return The new button.
  61. */
  62. static Button* create(Theme::Style* style, Properties* properties);
  63. /**
  64. * Touch callback on touch events. Controls return true if they consume the touch event.
  65. *
  66. * @param evt The touch event that occurred.
  67. * @param x The x position of the touch in pixels. Left edge is zero.
  68. * @param y The y position of the touch in pixels. Top edge is zero.
  69. * @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
  70. *
  71. * @return Whether the touch event was consumed by the control.
  72. *
  73. * @see Touch::TouchEvent
  74. */
  75. bool touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  76. /**
  77. * @see Control::getType
  78. */
  79. const char* getType() const;
  80. /**
  81. * Gets the data binding index for this control.
  82. *
  83. * @return The data binding index for control.
  84. */
  85. const unsigned int getDataBinding() const;
  86. /**
  87. * Sets the data binding provider for this control.
  88. *
  89. * @param dataBinding The data binding index for control.
  90. */
  91. void setDataBinding(unsigned int dataBinding);
  92. private:
  93. /**
  94. * Constructor.
  95. */
  96. Button(const Button& copy);
  97. unsigned int _dataBinding;
  98. };
  99. }
  100. #endif