BsGUIColor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "GUI/BsGUIElement.h"
  6. #include "2D/BsImageSprite.h"
  7. #include "GUI/BsGUIContent.h"
  8. namespace bs
  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. /** @name Internal
  41. * @{
  42. */
  43. /** @copydoc GUIElement::_getOptimalSize */
  44. Vector2I _getOptimalSize() const override;
  45. /** @} */
  46. protected:
  47. GUIColor(const String& styleName, const GUIDimensions& dimensions);
  48. virtual ~GUIColor();
  49. /** @copydoc GUIElement::_getNumRenderElements() */
  50. UINT32 _getNumRenderElements() const override;
  51. /** @copydoc GUIElement::_getMaterial() */
  52. const SpriteMaterialInfo& _getMaterial(UINT32 renderElementIdx, SpriteMaterial** material) const override;
  53. /** @copydoc GUIElement::_getMeshInfo() */
  54. void _getMeshInfo(UINT32 renderElementIdx, UINT32& numVertices, UINT32& numIndices, GUIMeshType& type) const override;
  55. /** @copydoc GUIElement::_fillBuffer() */
  56. void _fillBuffer(UINT8* vertices, UINT32* indices, UINT32 vertexOffset, UINT32 indexOffset,
  57. UINT32 maxNumVerts, UINT32 maxNumIndices, UINT32 renderElementIdx) const override;
  58. /** @copydoc GUIElement::updateRenderElementsInternal() */
  59. void updateRenderElementsInternal() override;
  60. /** @copydoc GUIElement::_mouseEvent() */
  61. bool _mouseEvent(const GUIMouseEvent& ev) override;
  62. private:
  63. static const float ALPHA_SPLIT_POSITION;
  64. ImageSprite* mColorSprite;
  65. ImageSprite* mAlphaSprite;
  66. IMAGE_SPRITE_DESC mColorImageDesc;
  67. IMAGE_SPRITE_DESC mAlphaImageDesc;
  68. Color mValue;
  69. };
  70. /** @} */
  71. }