Button.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef BUTTON_H_
  2. #define BUTTON_H_
  3. #include "Label.h"
  4. #include "Touch.h"
  5. #include "Theme.h"
  6. #include "Properties.h"
  7. namespace gameplay
  8. {
  9. /**
  10. * Defines a button UI control. This is essentially a label that can have a callback method set on it.
  11. *
  12. * The following properties are available for buttons:
  13. @verbatim
  14. button <buttonID>
  15. {
  16. style = <styleID>
  17. alignment = <Control::Alignment constant> // Note: 'position' will be ignored.
  18. position = <x, y>
  19. autoWidth = <bool>
  20. autoHeight = <bool>
  21. size = <width, height>
  22. width = <width> // Can be used in place of 'size', e.g. with 'autoHeight = true'
  23. height = <height> // Can be used in place of 'size', e.g. with 'autoWidth = true'
  24. text = <string>
  25. }
  26. @endverbatim
  27. */
  28. class Button : public Label
  29. {
  30. friend class Container;
  31. protected:
  32. /**
  33. * Constructor.
  34. */
  35. Button();
  36. /**
  37. * Destructor.
  38. */
  39. virtual ~Button();
  40. /**
  41. * Create a button with a given style and properties.
  42. *
  43. * @param style The style to apply to this button.
  44. * @param properties The properties to set on this button.
  45. *
  46. * @return The new button.
  47. */
  48. static Button* create(Theme::Style* style, Properties* properties);
  49. /**
  50. * Touch callback on touch events. Controls return true if they consume the touch event.
  51. *
  52. * @param evt The touch event that occurred.
  53. * @param x The x position of the touch in pixels. Left edge is zero.
  54. * @param y The y position of the touch in pixels. Top edge is zero.
  55. * @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
  56. *
  57. * @return Whether the touch event was consumed by the control.
  58. *
  59. * @see Touch::TouchEvent
  60. */
  61. bool touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  62. private:
  63. /*
  64. * Constructor.
  65. */
  66. Button(const Button& copy);
  67. };
  68. }
  69. #endif