CmTestTextSprite.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "CmTestTextSprite.h"
  2. #include "CmSceneObject.h"
  3. #include "BsRenderable.h"
  4. #include "CmMesh.h"
  5. #include "CmVector2.h"
  6. #include "BsTextSprite.h"
  7. #include "CmFont.h"
  8. #include "CmMaterial.h"
  9. #include "BsGUILabel.h"
  10. #include "BsGUIListBox.h"
  11. #include "BsGUISkin.h"
  12. #include "BsOverlayManager.h"
  13. #include "BsSpriteTexture.h"
  14. #include "BsEditorGUI.h"
  15. #include "BsGUITexture.h"
  16. #include "BsGUIRenderTexture.h"
  17. #include "BsGUIArea.h"
  18. #include "BsGUILayout.h"
  19. #include "BsGUISpace.h"
  20. #include "BsGUIViewport.h"
  21. #include "BsGUIButton.h"
  22. #include "BsCamera.h"
  23. #include "CmInput.h"
  24. #include "CmPlatform.h"
  25. #include "BsGUIContent.h"
  26. #include "CmStringTable.h"
  27. #include "BsGUISceneTreeView.h"
  28. #include "BsGUIScrollArea.h"
  29. using namespace CamelotFramework;
  30. using namespace BansheeEngine;
  31. namespace BansheeEditor
  32. {
  33. TestTextSprite::TestTextSprite(const HSceneObject& parent, CM::Viewport* target)
  34. :GUIWidget(parent, target), mListBox(nullptr)
  35. {
  36. }
  37. TestTextSprite::~TestTextSprite()
  38. {
  39. }
  40. void TestTextSprite::init(const HCamera& camera, const String& text, CM::RenderTexturePtr sceneView)
  41. {
  42. setSkin(BansheeEditor::EditorGUI::instance().getSkin());
  43. setDepth(128);
  44. GUIArea* area = GUIArea::createStretchedXY(*this, 0, 0, 0, 0);
  45. mSceneTreeView = GUISceneTreeView::create(*this, GUIOptions(GUIOption::flexibleWidth(), GUIOption::flexibleHeight()));
  46. GUILayout& sceneTreeViewLayout = area->getLayout().addLayoutY();
  47. //sceneTreeViewLayout.addElement(mSceneTreeView);
  48. SceneObject::create("FILLER_A");
  49. SceneObject::create("FILLER_B");
  50. SceneObject::create("FILLER_C");
  51. SceneObject::create("FILLER_D");
  52. SceneObject::create("FILLER_E");
  53. SceneObject::create("FILLER_F");
  54. SceneObject::create("FILLER_G");
  55. SceneObject::create("FILLER_H");
  56. SceneObject::create("FILLER_I");
  57. SceneObject::create("FILLER_J");
  58. SceneObject::create("FILLER_K");
  59. SceneObject::create("FILLER_L");
  60. area->getLayout().addElement(GUIRenderTexture::create(*this, sceneView, GUIOptions(GUIOption::fixedWidth(800), GUIOption::fixedHeight(600))));
  61. //mLabel = GUILabel::create(*this, HString(L""));
  62. //area->getLayout().addElement(mLabel);
  63. //Vector<HString>::type dropDownElements;
  64. //dropDownElements.push_back(HString(L"Ejlement #1"));
  65. //dropDownElements.push_back(HString(L"Element #2"));
  66. //dropDownElements.push_back(HString(L"Element #3"));
  67. //mListBox = GUIListBox::create(*this, dropDownElements, GUIOptions(GUIOption::fixedWidth(50), GUIOption::fixedHeight(13)));
  68. //area->getLayout().addElement(mListBox);
  69. GUIScrollArea* scrollArea = GUIScrollArea::create(*this, GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100)));
  70. sceneTreeViewLayout.addFlexibleSpace();
  71. area->getLayout().addElement(scrollArea);
  72. sceneTreeViewLayout.addFlexibleSpace();
  73. scrollArea->getLayout().addElement(mSceneTreeView);
  74. GUIButton* button = GUIButton::create(*this, HString(L"dbgBtn"));
  75. button->onClick.connect(boost::bind(&TestTextSprite::dbgBtn, this));
  76. area->getLayout().addElement(button);
  77. button = GUIButton::create(*this, HString(L"Add GameObjects"));
  78. button->onClick.connect(boost::bind(&TestTextSprite::dbgAdd, this));
  79. area->getLayout().addElement(button);
  80. button = GUIButton::create(*this, HString(L"Rename GameObject"));
  81. button->onClick.connect(boost::bind(&TestTextSprite::dbgRename, this));
  82. area->getLayout().addElement(button);
  83. button = GUIButton::create(*this, HString(L"Remove child GameObjects"));
  84. button->onClick.connect(boost::bind(&TestTextSprite::dbgRemoveChildren, this));
  85. area->getLayout().addElement(button);
  86. button = GUIButton::create(*this, HString(L"Remove parent GameObjects"));
  87. button->onClick.connect(boost::bind(&TestTextSprite::dbgRemoveParents, this));
  88. area->getLayout().addElement(button);
  89. area->getLayout().addFlexibleSpace();
  90. labelString = HString(L"\\{0}, {1}");
  91. //mLabel->setContent(GUIContent(labelString));
  92. }
  93. void TestTextSprite::update()
  94. {
  95. labelString.setParameter(0, toWString(Input::instance().getCursorPosition().x));
  96. mSceneTreeView->update();
  97. //labelString.setParameter(1, toWString(Input::instance().getCursorPosition().y));
  98. }
  99. void TestTextSprite::dbgBtn()
  100. {
  101. static int dbg = 0;
  102. if(dbg == 0)
  103. {
  104. //Vector<HString>::type dropDownElements;
  105. //dropDownElements.push_back(HString(L"Element #4"));
  106. //dropDownElements.push_back(HString(L"Element #5"));
  107. //dropDownElements.push_back(HString(L"Element #6"));
  108. //mListBox->setElements(dropDownElements);
  109. //StringTable::instance().setString(L"dbgBtn", Language::Abkhazian, L"ALOALO");
  110. //StringTable::instance().setActiveLanguage(Language::Abkhazian);
  111. }
  112. else if(dbg == 1)
  113. {
  114. //StringTable::instance().removeString(L"dbgBtn");
  115. }
  116. dbg++;
  117. }
  118. void TestTextSprite::dbgAdd()
  119. {
  120. mDbgMainA = SceneObject::create("DEBUG_A");
  121. mDbgChildA = SceneObject::create("DEBUG_CHILD_0");
  122. mDbgChildA->setParent(mDbgMainA);
  123. mDbgChildB = SceneObject::create("DEBUG_CHILD_1");
  124. mDbgChildB->setParent(mDbgMainA);
  125. mDbgChildC = SceneObject::create("DEBUG_CHILD_2");
  126. mDbgChildC->setParent(mDbgMainA);
  127. mDbgMainB = SceneObject::create("DEBUG_B");
  128. }
  129. void TestTextSprite::dbgRename()
  130. {
  131. mDbgMainA->setName("Z_DEBUG_RENAMED_A");
  132. }
  133. void TestTextSprite::dbgRemoveChildren()
  134. {
  135. mDbgChildA->destroy();
  136. mDbgChildB->destroy();
  137. }
  138. void TestTextSprite::dbgRemoveParents()
  139. {
  140. mDbgMainA->destroy();
  141. mDbgMainB->destroy();
  142. }
  143. }