BsGUIColorField.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "BsGUIColorField.h"
  2. #include "BsGUILayout.h"
  3. #include "BsGUILabel.h"
  4. #include "BsGUIColor.h"
  5. #include "BsBuiltinResources.h"
  6. #include "BsCGUIWidget.h"
  7. #include "BsGUIMouseEvent.h"
  8. #include "BsCGUIWidget.h"
  9. #include "BsCmdInputFieldValueChange.h"
  10. using namespace std::placeholders;
  11. namespace BansheeEngine
  12. {
  13. GUIColorField::GUIColorField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  14. const String& style, const GUIDimensions& dimensions, bool withLabel)
  15. :TGUIField(dummy, labelContent, labelWidth, style, dimensions, withLabel),
  16. mLabel(nullptr), mColor(nullptr), mLabelWidth(100)
  17. {
  18. mColor = GUIColor::create(getSubStyleName(getColorInputStyleType()));
  19. mColor->onValueChanged.connect(std::bind(&GUIColorField::valueChanged, this, _1));
  20. mLayout->addElement(mColor);
  21. }
  22. GUIColorField::~GUIColorField()
  23. {
  24. }
  25. void GUIColorField::setValue(const Color& color)
  26. {
  27. mValue = color;
  28. mColor->setColor(color);
  29. }
  30. void GUIColorField::setTint(const Color& color)
  31. {
  32. if (mLabel != nullptr)
  33. mLabel->setTint(color);
  34. mColor->setTint(color);
  35. }
  36. Vector2I GUIColorField::_getOptimalSize() const
  37. {
  38. Vector2I optimalsize = mColor->_getOptimalSize();
  39. if(mLabel != nullptr)
  40. {
  41. optimalsize.x += mLabel->_getOptimalSize().x;
  42. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  43. }
  44. return optimalsize;
  45. }
  46. void GUIColorField::styleUpdated()
  47. {
  48. if (mLabel != nullptr)
  49. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  50. mColor->setStyle(getSubStyleName(getColorInputStyleType()));
  51. }
  52. void GUIColorField::valueChanged(const Color& newValue)
  53. {
  54. setValue(newValue);
  55. if (!onValueChanged.empty())
  56. onValueChanged(newValue);
  57. }
  58. const String& GUIColorField::getGUITypeName()
  59. {
  60. static String typeName = "GUIColorField";
  61. return typeName;
  62. }
  63. const String& GUIColorField::getColorInputStyleType()
  64. {
  65. static String STYLE_TYPE = "EditorFieldColor";
  66. return STYLE_TYPE;
  67. }
  68. }