BsEditorWindow.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "BsEditorWindow.h"
  2. #include "BsEditorWidgetContainer.h"
  3. #include "BsEditorWindowManager.h"
  4. #include "BsDragAndDropManager.h"
  5. #include "BsRenderWindow.h"
  6. #include "BsCoreThread.h"
  7. namespace BansheeEngine
  8. {
  9. EditorWindow::EditorWindow()
  10. :EditorWindowBase(), mWidgets(bs_new<EditorWidgetContainer>(mGUI.get(), this))
  11. {
  12. updateSize();
  13. mWidgets->onWidgetAdded.connect(std::bind(&EditorWindow::widgetAdded, this));
  14. mWidgets->onWidgetClosed.connect(std::bind(&EditorWindow::widgetRemoved, this));
  15. mWidgets->onMaximized.connect(std::bind(&EditorWindow::maximizeClicked, this));
  16. }
  17. EditorWindow::~EditorWindow()
  18. {
  19. bs_delete(mWidgets);
  20. }
  21. void EditorWindow::update()
  22. {
  23. mWidgets->update();
  24. }
  25. void EditorWindow::resized()
  26. {
  27. EditorWindowBase::resized();
  28. updateSize();
  29. }
  30. void EditorWindow::updateSize()
  31. {
  32. mWidgets->setPosition(1, 1);
  33. UINT32 widgetWidth = (UINT32)std::max(0, (INT32)getWidth() - 2);
  34. UINT32 widgetHeight = (UINT32)std::max(0, (INT32)getHeight() - 2);
  35. mWidgets->setSize(widgetWidth, widgetHeight);
  36. Platform::setCaptionNonClientAreas(*mRenderWindow->getCore().get(), mWidgets->getDraggableAreas());
  37. }
  38. void EditorWindow::widgetAdded()
  39. {
  40. Platform::setCaptionNonClientAreas(*mRenderWindow->getCore().get(), mWidgets->getDraggableAreas());
  41. }
  42. void EditorWindow::widgetRemoved()
  43. {
  44. if(mWidgets->getNumWidgets() == 0)
  45. {
  46. // HACK - If widget is being handled by drag and drop we don't want to
  47. // destroy its parent window just yet because Windows doesn't approve of
  48. // windows being destroyed while mouse is being held down (some events won't get
  49. // fired). I should probably handle this at a lower level, in RenderWindowManager.
  50. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::EditorWidget)
  51. {
  52. hide();
  53. // Get notified when drag and drop is done
  54. DragAndDropManager::instance().addDropCallback(std::bind(&EditorWindow::closeWindowDelayed, this));
  55. }
  56. else
  57. close();
  58. }
  59. }
  60. void EditorWindow::maximizeClicked()
  61. {
  62. if (mRenderWindow->getProperties().isMaximized())
  63. mRenderWindow->restore(gCoreAccessor());
  64. else
  65. mRenderWindow->maximize(gCoreAccessor());
  66. }
  67. void EditorWindow::closeWindowDelayed()
  68. {
  69. close();
  70. }
  71. EditorWindow* EditorWindow::create()
  72. {
  73. return EditorWindowManager::instance().create();
  74. }
  75. }