BsGUIColorField.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. void GUIColorField::setTint(const Color& color)
  32. {
  33. if (mLabel != nullptr)
  34. mLabel->setTint(color);
  35. mColor->setTint(color);
  36. }
  37. Vector2I GUIColorField::_getOptimalSize() const
  38. {
  39. Vector2I optimalsize = mColor->_getOptimalSize();
  40. if(mLabel != nullptr)
  41. {
  42. optimalsize.x += mLabel->_getOptimalSize().x;
  43. optimalsize.y = std::max(optimalsize.y, mLabel->_getOptimalSize().y);
  44. }
  45. return optimalsize;
  46. }
  47. void GUIColorField::styleUpdated()
  48. {
  49. if (mLabel != nullptr)
  50. mLabel->setStyle(getSubStyleName(getLabelStyleType()));
  51. mColor->setStyle(getSubStyleName(getColorInputStyleType()));
  52. }
  53. void GUIColorField::valueChanged(const Color& newValue)
  54. {
  55. setValue(newValue);
  56. if (!onValueChanged.empty())
  57. onValueChanged(newValue);
  58. }
  59. const String& GUIColorField::getGUITypeName()
  60. {
  61. static String typeName = "GUIColorField";
  62. return typeName;
  63. }
  64. const String& GUIColorField::getColorInputStyleType()
  65. {
  66. static String STYLE_TYPE = "EditorFieldColor";
  67. return STYLE_TYPE;
  68. }
  69. }