BsEditorWindow.cpp 2.5 KB

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