CheckBox.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. using UIElement::setStyle;
  31. public:
  32. //! Construct with name
  33. CheckBox(const std::string& name = std::string());
  34. //! Destruct
  35. virtual ~CheckBox();
  36. //! Set UI element style from XML data
  37. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  38. //! Return UI rendering batches
  39. virtual void getBatches(std::vector<UIBatch>& batches, std::vector<UIQuad>& quads, const IntRect& currentScissor);
  40. //! React to mouse click
  41. virtual void onClick(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  42. //! Set checked state
  43. void setChecked(bool enable);
  44. //! Set checked image offset
  45. void setCheckedOffset(const IntVector2& rect);
  46. //! Set checked image offset
  47. void setCheckedOffset(int x, int y);
  48. //! Return whether is checked
  49. bool isChecked() const { return mChecked; }
  50. //! Return checked image offset
  51. const IntVector2& getCheckedOffset() const { return mCheckedOffset; }
  52. protected:
  53. //! Checked image offset
  54. IntVector2 mCheckedOffset;
  55. //! Current checked state
  56. bool mChecked;
  57. };
  58. #endif // UI_CHECKBOX_H