BsEditorWindow.cpp 1.9 KB

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