2
0

CmEditorWindow.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "CmEditorWindow.h"
  2. #include "CmRenderWindow.h"
  3. #include "CmApplication.h"
  4. #include "CmSceneObject.h"
  5. #include "CmCursor.h"
  6. #include "BsGUIManager.h"
  7. #include "BsGUIWidget.h"
  8. #include "BsGUILabel.h"
  9. #include "BsGUIWindowFrame.h"
  10. #include "BsGUISkin.h"
  11. #include "BsGUILayout.h"
  12. #include "BsOverlayManager.h"
  13. #include "BsCamera.h"
  14. #include "BsUpdateCallback.h"
  15. #include "BsEngineGUI.h"
  16. #include "BsGUIArea.h"
  17. using namespace CamelotFramework;
  18. using namespace BansheeEngine;
  19. namespace BansheeEditor
  20. {
  21. EditorWindow::EditorWindow(const String& name)
  22. {
  23. RENDER_WINDOW_DESC renderWindowDesc;
  24. renderWindowDesc.width = 200;
  25. renderWindowDesc.height = 200;
  26. renderWindowDesc.title = "EditorWindow";
  27. renderWindowDesc.fullscreen = false;
  28. renderWindowDesc.border = WindowBorder::None;
  29. renderWindowDesc.toolWindow = true;
  30. mRenderWindow = RenderWindow::create(renderWindowDesc, gApplication().getPrimaryWindow());
  31. HSceneObject so = SceneObject::create("EditorWindow-" + name);
  32. GameObjectHandle<UpdateCallback> updateCallback = so->addComponent<UpdateCallback>();
  33. updateCallback->onUpdate.connect(boost::bind(&EditorWindow::update, this));
  34. HCamera camera = so->addComponent<Camera>();
  35. camera->initialize(mRenderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
  36. camera->setNearClipDistance(5);
  37. camera->setAspectRatio(1.0f);
  38. camera->setIgnoreSceneRenderables(true);
  39. mGUI = so->addComponent<GUIWidget>();
  40. mGUI->initialize(camera->getViewport().get(), mRenderWindow.get());
  41. //// DEBUG
  42. mGUI->setSkin(&EngineGUI::instance().getSkin());
  43. //GUIArea* backgroundArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 0);
  44. //GUILayout& layout = backgroundArea->getLayout();
  45. mDbgLabel = GUILabel::create(*mGUI, "Testing test");
  46. /*layout.addElement(mDbgLabel);*/
  47. GUIArea* mainArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 1);
  48. GUILayout& otherLayout = mainArea->getLayout();
  49. otherLayout.addElement(mDbgLabel);
  50. //GUIFixedSpace& space = otherLayout.addSpace(10); // Due to bug in MSVC compiler I need to store return value
  51. //GUIFlexibleSpace& space3 = otherLayout.addFlexibleSpace();
  52. otherLayout.addElement(GUIWindowFrame::create(*mGUI, GUILayoutOptions::expandableX(20, 100)));
  53. //GUIFixedSpace& space2 = otherLayout.addSpace(10);
  54. otherLayout.addElement(GUIWindowFrame::create(*mGUI));
  55. }
  56. EditorWindow::~EditorWindow()
  57. {
  58. mRenderWindow->destroy();
  59. }
  60. void EditorWindow::update()
  61. {
  62. Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
  63. mDbgLabel->setText("Position: " + toString(cursorPos.x) + ", " + toString(cursorPos.y));
  64. }
  65. }