2
0

BsGUIColor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIElement.h"
  4. #include "BsImageSprite.h"
  5. #include "BsGUIContent.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief GUI element that displays the set color. RGB and alpha
  10. * values are displayed separately.
  11. */
  12. class GUIColor : public GUIElement
  13. {
  14. public:
  15. /**
  16. * Returns type name of the GUI element used for finding GUI element styles.
  17. */
  18. static const String& getGUITypeName();
  19. /**
  20. * @brief Creates a new GUI color element.
  21. *
  22. * @param styleName Optional style to use for the element. Style will be retrieved
  23. * from GUISkin of the GUIWidget the element is used on. If not specified
  24. * default style is used.
  25. */
  26. static GUIColor* create(const String& styleName = StringUtil::BLANK);
  27. /**
  28. * @brief Creates a new GUI color element.
  29. *
  30. * @param options Options that allow you to control how is the element positioned and sized.
  31. * This will override any similar options set by style.
  32. * @param styleName Optional style to use for the element. Style will be retrieved
  33. * from GUISkin of the GUIWidget the element is used on. If not specified
  34. * default style is used.
  35. */
  36. static GUIColor* create(const GUIOptions& options, const String& styleName = StringUtil::BLANK);
  37. /**
  38. * @copydoc GUIElement::_getOptimalSize
  39. */
  40. virtual Vector2I _getOptimalSize() const override;
  41. /**
  42. * @brief Sets the color to display.
  43. */
  44. void setColor(const Color& color);
  45. /**
  46. * @brief Returns the currently displayed color.
  47. */
  48. Color getColor() const { return mValue; }
  49. Event<void()> onClicked; /**< Triggered when the user clicks on the GUI element. */
  50. protected:
  51. GUIColor(const String& styleName, const GUIDimensions& dimensions);
  52. virtual ~GUIColor();
  53. /**
  54. * @copydoc GUIElement::_getNumRenderElements()
  55. */
  56. virtual UINT32 _getNumRenderElements() const override;
  57. /**
  58. * @copydoc GUIElement::_getMaterial()
  59. */
  60. virtual const SpriteMaterialInfo& _getMaterial(UINT32 renderElementIdx) const override;
  61. /**
  62. * @copydoc GUIElement::_getNumQuads()
  63. */
  64. virtual UINT32 _getNumQuads(UINT32 renderElementIdx) const override;
  65. /**
  66. * @copydoc GUIElement::_fillBuffer()
  67. */
  68. virtual void _fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad,
  69. UINT32 maxNumQuads, UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const override;
  70. /**
  71. * @copydoc GUIElement::updateRenderElementsInternal()
  72. */
  73. virtual void updateRenderElementsInternal() override;
  74. /**
  75. * @copydoc GUIElement::_mouseEvent()
  76. */
  77. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  78. private:
  79. static const float ALPHA_SPLIT_POSITION;
  80. ImageSprite* mColorSprite;
  81. ImageSprite* mAlphaSprite;
  82. IMAGE_SPRITE_DESC mColorImageDesc;
  83. IMAGE_SPRITE_DESC mAlphaImageDesc;
  84. Color mValue;
  85. };
  86. }