BsGUIColor.h 3.1 KB

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