Button.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  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. #ifndef UI_BUTTON_H
  24. #define UI_BUTTON_H
  25. #include "BorderImage.h"
  26. //! An image that reacts to mouse presses
  27. class Button : public BorderImage
  28. {
  29. DEFINE_TYPE(Button);
  30. public:
  31. //! Construct with name
  32. Button(const std::string& name = std::string());
  33. //! Destruct
  34. virtual ~Button();
  35. //! Set UI element style from XML data
  36. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  37. //! Perform UI element update
  38. virtual void update(float timeStep);
  39. //! Return UI rendering batches
  40. virtual void getBatches(std::vector<UIBatch>& batches, std::vector<UIQuad>& quads, const IntRect& currentScissor);
  41. //! React to mouse hover
  42. virtual void onHover(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers);
  43. //! React to mouse click
  44. virtual void onClick(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers);
  45. //! Set pressed image offset
  46. void setPressedOffset(const IntVector2& offset);
  47. //! Set pressed image offset
  48. void setPressedOffset(int x, int y);
  49. //! Set pressed label offset
  50. void setLabelOffset(const IntVector2& offset);
  51. //! Set pressed label offset
  52. void setLabelOffset(int x, int y);
  53. //! Set pressed event repeat. Rate 0 (default) disables repeat
  54. void setRepeat(float delay, float rate);
  55. //! Return pressed image offset
  56. const IntVector2& getPressedOffset() const { return mPressedOffset; }
  57. //! Return pressed label offset
  58. const IntVector2& getLabelOffset() const { return mLabelOffset; }
  59. //! Return repeat delay
  60. float getRepeatDelay() const { return mRepeatDelay; }
  61. //! Return repeat rate
  62. float getRepeatRate() const { return mRepeatRate; }
  63. protected:
  64. //! Set new pressed state
  65. void setPressed(bool enable);
  66. //! Pressed image offset
  67. IntVector2 mPressedOffset;
  68. //! Pressed label offset
  69. IntVector2 mLabelOffset;
  70. //! Repeat delay
  71. float mRepeatDelay;
  72. //! Repeat rate
  73. float mRepeatRate;
  74. //! Repeat timer
  75. float mRepeatTimer;
  76. //! Current pressed state
  77. bool mPressed;
  78. };
  79. #endif // UI_BUTTON_H