CmEditorWindow.cpp 3.0 KB

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