BsMainEditorWindow.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "BsMainEditorWindow.h"
  2. #include "BsEditorWindowManager.h"
  3. #include "BsDockManager.h"
  4. #include "BsGUIMenuBar.h"
  5. #include "BsCamera.h"
  6. #include "BsSceneObject.h"
  7. #include "BsRenderTexture.h"
  8. #include "BsApplication.h"
  9. #include "BsProfilingManager.h"
  10. #include "BsGUIArea.h"
  11. #include "BsGUILayout.h"
  12. #include "BsEditorTestSuite.h"
  13. #include "BsTestOutput.h"
  14. #include "BsVirtualInput.h"
  15. #include "BsSceneCameraController.h"
  16. // DEBUG ONLY
  17. #include "BsTestTextSprite.h"
  18. #include "BsDebugCamera.h"
  19. #include "BsDrawHelper2D.h"
  20. #include "BsDrawHelper3D.h"
  21. #include "BsRectF.h"
  22. #include "BsProfilerOverlay.h"
  23. #include "BsPlatform.h"
  24. namespace BansheeEngine
  25. {
  26. MainEditorWindow* MainEditorWindow::create(const RenderWindowPtr& renderWindow)
  27. {
  28. return EditorWindowManager::instance().createMain(renderWindow);
  29. }
  30. MainEditorWindow::MainEditorWindow(const RenderWindowPtr& renderWindow)
  31. :EditorWindowBase(renderWindow), mDockManager(nullptr),
  32. mMenuBar(bs_new<GUIMenuBar>(mGUI.get(), mRenderWindow.get()))
  33. {
  34. mDockManager = DockManager::create(mRenderWindow.get());
  35. GUIArea* dockArea = GUIArea::createStretchedXY(*mGUI.get(), 0, 0, 0, 0);
  36. dockArea->getLayout().addElement(mDockManager);
  37. updateAreas();
  38. mMenuBar->addMenuItem(L"File/New project", nullptr);
  39. mMenuBar->addMenuItem(L"File/Open project", nullptr);
  40. mMenuBar->addSeparator(L"File");
  41. mMenuBar->addMenuItem(L"File/Recent projects/Project A", nullptr);
  42. mMenuBar->addMenuItem(L"File/Recent projects/Project B", nullptr);
  43. mMenuBar->addMenuItem(L"File/Recent projects/Project C", nullptr);
  44. mMenuBar->addSeparator(L"File");
  45. mMenuBar->addMenuItem(L"File/Exit", nullptr);
  46. mMenuBar->addMenuItem(L"Window/Scene", nullptr);
  47. // Set up default editor input
  48. auto inputConfig = VirtualInput::instance().getConfiguration();
  49. inputConfig->registerButton(SceneCameraController::MOVE_FORWARD_BTN, BC_W);
  50. inputConfig->registerButton(SceneCameraController::MOVE_BACKWARD_BTN, BC_S);
  51. inputConfig->registerButton(SceneCameraController::MOVE_LEFT_BTN, BC_A);
  52. inputConfig->registerButton(SceneCameraController::MOVE_RIGHT_BTN, BC_D);
  53. inputConfig->registerButton(SceneCameraController::MOVE_FORWARD_BTN, BC_UP);
  54. inputConfig->registerButton(SceneCameraController::MOVE_BACKWARD_BTN, BC_BACK);
  55. inputConfig->registerButton(SceneCameraController::MOVE_LEFT_BTN, BC_LEFT);
  56. inputConfig->registerButton(SceneCameraController::MOVE_RIGHT_BTN, BC_RIGHT);
  57. inputConfig->registerButton(SceneCameraController::FAST_MOVE_BTN, BC_LSHIFT);
  58. inputConfig->registerButton(SceneCameraController::ROTATE_BTN, BC_MOUSE_RIGHT);
  59. inputConfig->registerAxis(SceneCameraController::HORIZONTAL_AXIS, VIRTUAL_AXIS_DESC((UINT32)InputAxis::MouseX));
  60. inputConfig->registerAxis(SceneCameraController::VERTICAL_AXIS, VIRTUAL_AXIS_DESC((UINT32)InputAxis::MouseY));
  61. //GameObjectHandle<TestTextSprite> textSprite = mSceneObject->addComponent<TestTextSprite>(mCamera->getViewport().get());
  62. //textSprite->init(sceneCamera, "Testing in a new row, does this work?", sceneRenderTarget);
  63. //DrawHelper2D::instance().drawQuad(sceneCamera, FRect(0.0f, 0.2f, 0.75f, 0.5f), Color::White, DebugDrawCoordType::Normalized, 250.0f);
  64. //DrawHelper2D::instance().drawQuad(sceneCamera, FRect(50.0f, 50.0f, 100.0f, 50.0f), Color::Blue, DebugDrawCoordType::Pixel, 250.0f);
  65. //DrawHelper2D::instance().drawLine_Pixel(sceneCamera, Vector2(0, 0), Vector2(20, 20), Color::Blue, DebugDrawCoordType::Pixel, 250.0f);
  66. //DrawHelper2D::instance().drawLine_AA(sceneCamera, Vector2(100, 10), Vector2(120, 40), 1.0f, 1.0f, Color::Blue, DebugDrawCoordType::Pixel, 250.0f);
  67. AABox dbgBox(Vector3(-300, -200, 1000), Vector3(300, 300, 1500));
  68. //DrawHelper3D::instance().drawAABox(sceneCamera, dbgBox, Color::Green, 250.0f);
  69. //mProfilerOverlay = mSceneObject->addComponent<ProfilerOverlay>(sceneCamera->getViewport());
  70. //mProfilerOverlay->show(ProfilerOverlayType::CPUSamples);
  71. TestSuitePtr testSuite = TestSuite::create<EditorTestSuite>();
  72. testSuite->run(ExceptionTestOutput());
  73. }
  74. MainEditorWindow::~MainEditorWindow()
  75. {
  76. mDockManager->closeAll();
  77. GUIElement::destroy(mDockManager);
  78. bs_delete(mMenuBar);
  79. }
  80. void MainEditorWindow::resized()
  81. {
  82. EditorWindowBase::resized();
  83. updateAreas();
  84. }
  85. void MainEditorWindow::updateAreas()
  86. {
  87. UINT32 widgetWidth = (UINT32)std::max(0, (INT32)getWidth() - 2);
  88. UINT32 widgetHeight = (UINT32)std::max(0, (INT32)getHeight() - 2);
  89. UINT32 menuBarHeight = 15;
  90. mMenuBar->setArea(1, 1, widgetWidth, menuBarHeight);
  91. UINT32 dockHeight = (UINT32)std::max(0, (INT32)widgetHeight - (INT32)menuBarHeight);
  92. mDockManager->setArea(1, menuBarHeight + 1, widgetWidth, dockHeight);
  93. }
  94. void MainEditorWindow::update()
  95. {
  96. mDockManager->update();
  97. }
  98. }