Button.h 3.4 KB

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