BsGUIColorField.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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->onClicked.connect(std::bind(&GUIColorField::clicked, this));
  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::clicked()
  53. {
  54. onClicked();
  55. }
  56. const String& GUIColorField::getGUITypeName()
  57. {
  58. static String typeName = "GUIColorField";
  59. return typeName;
  60. }
  61. const String& GUIColorField::getColorInputStyleType()
  62. {
  63. static String STYLE_TYPE = "EditorFieldColor";
  64. return STYLE_TYPE;
  65. }
  66. }