BsGUIGameObjectField.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "BsGUIGameObjectField.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUILabel.h"
  5. #include "BsGUIDropButton.h"
  6. #include "BsGUIButton.h"
  7. #include "BsBuiltinResources.h"
  8. #include "BsGUIWidget.h"
  9. #include "BsGUIMouseEvent.h"
  10. #include "BsGUISceneTreeView.h"
  11. #include "BsGUIWidget.h"
  12. #include "BsGameObjectManager.h"
  13. using namespace std::placeholders;
  14. namespace BansheeEngine
  15. {
  16. const UINT32 GUIGameObjectField::DEFAULT_LABEL_WIDTH = 100;
  17. const String GUIGameObjectField::DROP_BUTTON_STYLE = "DropButton";
  18. const String GUIGameObjectField::CLEAR_BUTTON_STYLE = "ObjectClearButton";
  19. GUIGameObjectField::GUIGameObjectField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  20. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle, const GUILayoutOptions& layoutOptions, bool withLabel)
  21. :GUIElementContainer(layoutOptions), mLabel(nullptr), mClearButton(nullptr), mDropButton(nullptr), mInstanceId(0)
  22. {
  23. mLayout = &addLayoutXInternal(this);
  24. if(withLabel)
  25. {
  26. mLabel = GUILabel::create(labelContent, GUIOptions(GUIOption::fixedWidth(labelWidth)), labelStyle);
  27. mLayout->addElement(mLabel);
  28. }
  29. const String* curDropButtonStyle = &dropButtonStyle;
  30. const String* curClearButtonStyle = &clearButtonStyle;
  31. if(*curDropButtonStyle == StringUtil::BLANK)
  32. curDropButtonStyle = &DROP_BUTTON_STYLE;
  33. if(*curClearButtonStyle == StringUtil::BLANK)
  34. curClearButtonStyle = &CLEAR_BUTTON_STYLE;
  35. mDropButton = GUIDropButton::create((UINT32)DragAndDropType::SceneObject, GUIOptions(GUIOption::flexibleWidth()), *curDropButtonStyle);
  36. mClearButton = GUIButton::create(HString(L""), *curClearButtonStyle);
  37. mLayout->addElement(mDropButton);
  38. mLayout->addElement(mClearButton);
  39. mDropButton->onDataDropped.connect(std::bind(&GUIGameObjectField::dataDropped, this, _1));
  40. }
  41. GUIGameObjectField::~GUIGameObjectField()
  42. {
  43. }
  44. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent, UINT32 labelWidth, const GUIOptions& layoutOptions,
  45. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  46. {
  47. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  48. GUILayoutOptions::create(layoutOptions), true);
  49. }
  50. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent, const GUIOptions& layoutOptions,
  51. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  52. {
  53. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  54. GUILayoutOptions::create(layoutOptions), true);
  55. }
  56. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText, UINT32 labelWidth, const GUIOptions& layoutOptions,
  57. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  58. {
  59. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  60. GUILayoutOptions::create(layoutOptions), true);
  61. }
  62. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText, const GUIOptions& layoutOptions,
  63. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  64. {
  65. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  66. GUILayoutOptions::create(layoutOptions), true);
  67. }
  68. GUIGameObjectField* GUIGameObjectField::create(const GUIOptions& layoutOptions, const String& dropButtonStyle,
  69. const String& clearButtonStyle)
  70. {
  71. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(), 0, nullptr, dropButtonStyle, clearButtonStyle,
  72. GUILayoutOptions::create(layoutOptions), false);
  73. }
  74. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent, UINT32 labelWidth,
  75. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  76. {
  77. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  78. GUILayoutOptions::create(), true);
  79. }
  80. GUIGameObjectField* GUIGameObjectField::create(const GUIContent& labelContent,
  81. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  82. {
  83. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), labelContent, DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  84. GUILayoutOptions::create(), true);
  85. }
  86. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText, UINT32 labelWidth,
  87. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  88. {
  89. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), labelWidth, labelStyle, dropButtonStyle, clearButtonStyle,
  90. GUILayoutOptions::create(), true);
  91. }
  92. GUIGameObjectField* GUIGameObjectField::create(const HString& labelText,
  93. const String& labelStyle, const String& dropButtonStyle, const String& clearButtonStyle)
  94. {
  95. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(labelText), DEFAULT_LABEL_WIDTH, labelStyle, dropButtonStyle, clearButtonStyle,
  96. GUILayoutOptions::create(), true);
  97. }
  98. GUIGameObjectField* GUIGameObjectField::create(const String& dropButtonStyle, const String& clearButtonStyle)
  99. {
  100. return bs_new<GUIGameObjectField>(PrivatelyConstruct(), GUIContent(), 0, nullptr, dropButtonStyle, clearButtonStyle,
  101. GUILayoutOptions::create(), false);
  102. }
  103. HGameObject GUIGameObjectField::getValue() const
  104. {
  105. HGameObject obj;
  106. if(mInstanceId != 0)
  107. GameObjectManager::instance().tryGetObject(mInstanceId, obj);
  108. return obj;
  109. }
  110. void GUIGameObjectField::setValue(const HGameObject& value)
  111. {
  112. if(value)
  113. {
  114. mInstanceId = value->getInstanceId();
  115. mDropButton->setContent(GUIContent(HString(toWString(value->getName()))));
  116. }
  117. else
  118. {
  119. mInstanceId = 0;
  120. mDropButton->setContent(GUIContent(HString(L"None")));
  121. }
  122. }
  123. void GUIGameObjectField::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  124. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  125. {
  126. mLayout->_updateLayoutInternal(x, y, width, height, clipRect, widgetDepth, areaDepth);
  127. }
  128. Vector2I GUIGameObjectField::_getOptimalSize() const
  129. {
  130. return mLayout->_getOptimalSize();
  131. }
  132. void GUIGameObjectField::dataDropped(void* data)
  133. {
  134. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(data);
  135. // TODO
  136. }
  137. const String& GUIGameObjectField::getGUITypeName()
  138. {
  139. static String typeName = "GUIGameObjectField";
  140. return typeName;
  141. }
  142. }