BsEditorWindow.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(cm_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. cm_delete(mWidgets);
  16. }
  17. void EditorWindow::resized()
  18. {
  19. EditorWindowBase::resized();
  20. updateSize();
  21. }
  22. void EditorWindow::updateSize()
  23. {
  24. mWidgets->setPosition(1, 1);
  25. UINT32 widgetWidth = (UINT32)std::max(0, (INT32)getWidth() - 2);
  26. UINT32 widgetHeight = (UINT32)std::max(0, (INT32)getHeight() - 2);
  27. mWidgets->setSize(widgetWidth, widgetHeight);
  28. Platform::setCaptionNonClientAreas(*mRenderWindow.get(), mWidgets->getDraggableAreas());
  29. }
  30. void EditorWindow::widgetRemoved()
  31. {
  32. if(mWidgets->getNumWidgets() == 0)
  33. {
  34. // HACK - If widget is being handled by drag and drop we don't want to
  35. // destroy its parent window just yet because Windows doesn't approve of
  36. // windows being destroyed while mouse is being held down (some events won't get
  37. // fired). I should probably handle this at a lower level, in RenderWindowManager.
  38. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::EditorWidget)
  39. {
  40. hide();
  41. // Get notified when drag and drop is done
  42. DragAndDropManager::instance().addDropCallback(std::bind(&EditorWindow::closeWindowDelayed, this));
  43. }
  44. else
  45. close();
  46. }
  47. }
  48. void EditorWindow::closeWindowDelayed()
  49. {
  50. close();
  51. }
  52. EditorWindow* EditorWindow::create()
  53. {
  54. return EditorWindowManager::instance().create();
  55. }
  56. }