Button.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../UI/BorderImage.h"
  24. namespace Urho3D
  25. {
  26. /// Push button %UI element.
  27. class URHO3D_API Button : public BorderImage
  28. {
  29. URHO3D_OBJECT(Button, BorderImage);
  30. public:
  31. /// Construct.
  32. Button(Context* context);
  33. /// Destruct.
  34. virtual ~Button() override;
  35. /// Register object factory.
  36. static void RegisterObject(Context* context);
  37. /// Perform UI element update.
  38. virtual void Update(float timeStep) override;
  39. /// Return UI rendering batches.
  40. virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor) override;
  41. /// React to mouse click begin.
  42. virtual void OnClickBegin
  43. (const IntVector2& position, const IntVector2& screenPosition, int button, int buttons, int qualifiers, Cursor* cursor) override;
  44. /// React to mouse click end.
  45. virtual void OnClickEnd
  46. (const IntVector2& position, const IntVector2& screenPosition, int button, int buttons, int qualifiers, Cursor* cursor,
  47. UIElement* beginElement) override;
  48. /// React to mouse drag motion.
  49. virtual void OnDragMove
  50. (const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, int buttons, int qualifiers,
  51. Cursor* cursor) override;
  52. /// React to a key press.
  53. virtual void OnKey(int key, int buttons, int qualifiers) override;
  54. /// Set offset to image rectangle used when pressed.
  55. void SetPressedOffset(const IntVector2& offset);
  56. /// Set offset to image rectangle used when pressed.
  57. void SetPressedOffset(int x, int y);
  58. /// Set offset to image rectangle used when disabled.
  59. void SetDisabledOffset(const IntVector2& offset);
  60. /// Set offset to image rectangle used when disabled.
  61. void SetDisabledOffset(int x, int y);
  62. /// Set offset of child elements when pressed.
  63. void SetPressedChildOffset(const IntVector2& offset);
  64. /// Set offset of child elements when pressed.
  65. void SetPressedChildOffset(int x, int y);
  66. /// Set repeat properties. Rate 0 (default) disables repeat.
  67. void SetRepeat(float delay, float rate);
  68. /// Set repeat delay.
  69. void SetRepeatDelay(float delay);
  70. /// Set repeat rate.
  71. void SetRepeatRate(float rate);
  72. /// Return pressed image offset.
  73. const IntVector2& GetPressedOffset() const { return pressedOffset_; }
  74. /// Return disabled image offset.
  75. const IntVector2& GetDisabledOffset() const { return disabledOffset_; }
  76. /// Return offset of child elements when pressed.
  77. const IntVector2& GetPressedChildOffset() const { return pressedChildOffset_; }
  78. /// Return repeat delay.
  79. float GetRepeatDelay() const { return repeatDelay_; }
  80. /// Return repeat rate.
  81. float GetRepeatRate() const { return repeatRate_; }
  82. /// Return whether is currently pressed.
  83. bool IsPressed() const { return pressed_; }
  84. protected:
  85. /// Set new pressed state.
  86. void SetPressed(bool enable);
  87. /// Pressed image offset.
  88. IntVector2 pressedOffset_;
  89. /// Disabled image offset.
  90. IntVector2 disabledOffset_;
  91. /// Pressed label offset.
  92. IntVector2 pressedChildOffset_;
  93. /// Repeat delay.
  94. float repeatDelay_;
  95. /// Repeat rate.
  96. float repeatRate_;
  97. /// Repeat timer.
  98. float repeatTimer_;
  99. /// Current pressed state.
  100. bool pressed_;
  101. };
  102. }