BsGUIColorField.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "BsGUIColorField.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUILabel.h"
  5. #include "BsGUIColor.h"
  6. #include "BsBuiltinResources.h"
  7. #include "BsGUIWidget.h"
  8. #include "BsGUIMouseEvent.h"
  9. #include "BsGUIWidget.h"
  10. #include "BsCmdInputFieldValueChange.h"
  11. using namespace std::placeholders;
  12. namespace BansheeEngine
  13. {
  14. GUIColorField::GUIColorField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  15. const String& style, const GUILayoutOptions& layoutOptions, bool withLabel)
  16. :TGUIField(dummy, labelContent, labelWidth, style, layoutOptions, withLabel),
  17. mLabel(nullptr), mColor(nullptr), mLabelWidth(100)
  18. {
  19. mColor = GUIColor::create(getSubStyleName(getColorInputStyleType()));
  20. mColor->onValueChanged.connect(std::bind(&GUIColorField::valueChanged, this, _1));
  21. mLayout->addElement(mColor);
  22. }
  23. GUIColorField::~GUIColorField()
  24. {
  25. }
  26. void GUIColorField::setValue(const Color& color)
  27. {
  28. mValue = color;
  29. mColor->setColor(color);
  30. }
  31. Vector2I GUIColorField::_getOptimalSize() const
  32. {
  33. Vector2I optimalsize = mColor->_getOptimalSize();
  34. if(mLabel != nullptr)
  35. {
  36. optimalsize.x += mLabel->_getOptimalSize().x;
  37. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  38. }
  39. return optimalsize;
  40. }
  41. void GUIColorField::styleUpdated()
  42. {
  43. if (mLabel != nullptr)
  44. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  45. mColor->setStyle(getSubStyleName(getColorInputStyleType()));
  46. }
  47. void GUIColorField::valueChanged(const Color& newValue)
  48. {
  49. setValue(newValue);
  50. if (!onValueChanged.empty())
  51. onValueChanged(newValue);
  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. }