BsEditorWindow.cpp 1.9 KB

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