2
0

BsGUIColorField.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "GUI/BsGUIColorField.h"
  4. #include "GUI/BsGUILayout.h"
  5. #include "GUI/BsGUILabel.h"
  6. #include "GUI/BsGUIColor.h"
  7. using namespace std::placeholders;
  8. namespace bs
  9. {
  10. GUIColorField::GUIColorField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  11. const String& style, const GUIDimensions& dimensions, bool withLabel)
  12. : TGUIField(dummy, labelContent, labelWidth, style, dimensions, withLabel)
  13. , mLabelWidth(100), mLabel(nullptr), mColor(nullptr)
  14. {
  15. mColor = GUIColor::create(getSubStyleName(getColorInputStyleType()));
  16. mColor->onClicked.connect(std::bind(&GUIColorField::clicked, this));
  17. mLayout->addElement(mColor);
  18. }
  19. GUIColorField::~GUIColorField()
  20. {
  21. }
  22. void GUIColorField::setValue(const Color& color)
  23. {
  24. mValue = color;
  25. mColor->setColor(color);
  26. }
  27. void GUIColorField::setTint(const Color& color)
  28. {
  29. if (mLabel != nullptr)
  30. mLabel->setTint(color);
  31. mColor->setTint(color);
  32. }
  33. Vector2I GUIColorField::_getOptimalSize() const
  34. {
  35. Vector2I optimalsize = mColor->_getOptimalSize();
  36. if(mLabel != nullptr)
  37. {
  38. optimalsize.x += mLabel->_getOptimalSize().x;
  39. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  40. }
  41. return optimalsize;
  42. }
  43. void GUIColorField::styleUpdated()
  44. {
  45. if (mLabel != nullptr)
  46. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  47. mColor->setStyle(getSubStyleName(getColorInputStyleType()));
  48. }
  49. void GUIColorField::clicked()
  50. {
  51. onClicked();
  52. }
  53. const String& GUIColorField::getGUITypeName()
  54. {
  55. static String typeName = "GUIColorField";
  56. return typeName;
  57. }
  58. const String& GUIColorField::getColorInputStyleType()
  59. {
  60. static String STYLE_TYPE = "EditorFieldColor";
  61. return STYLE_TYPE;
  62. }
  63. }