CheckBox.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_CHECKBOX_H
  24. #define UI_CHECKBOX_H
  25. #include "BorderImage.h"
  26. //! An image that can be toggled between unchecked and checked state
  27. class CheckBox : public BorderImage
  28. {
  29. DEFINE_TYPE(CheckBox);
  30. public:
  31. //! Construct with name
  32. CheckBox(const std::string& name = std::string());
  33. //! Destruct
  34. virtual ~CheckBox();
  35. //! Set UI element style from XML data
  36. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  37. //! Return UI rendering batches
  38. virtual void getBatches(std::vector<UIBatch>& batches, std::vector<UIQuad>& quads, const IntRect& currentScissor);
  39. //! React to mouse click
  40. virtual void onClick(const IntVector2& position, const IntVector2& screenPosition, unsigned buttons);
  41. //! Set checked state
  42. void setChecked(bool enable);
  43. //! Set unchecked image rectangle
  44. void setUncheckedRect(const IntRect& rect);
  45. //! Set unchecked image rectangle
  46. void setUncheckedRect(int left, int top, int right, int bottom);
  47. //! Set checked image rectangle
  48. void setCheckedRect(const IntRect& rect);
  49. //! Set checked image rectangle
  50. void setCheckedRect(int left, int top, int right, int bottom);
  51. //! Return whether is checked
  52. bool isChecked() const { return mChecked; }
  53. //! Return unchecked image rectangle
  54. const IntRect& getUncheckedRect() const { return mUncheckedRect; }
  55. //! Return checked image rectangle
  56. const IntRect& getCheckedRect() const { return mCheckedRect; }
  57. protected:
  58. //! Unchecked image rectangle
  59. IntRect mUncheckedRect;
  60. //! Checked image rectangle
  61. IntRect mCheckedRect;
  62. //! Current checked state
  63. bool mChecked;
  64. };
  65. #endif // UI_CHECKBOX_H