BsEditorWindow.cpp 1.9 KB

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