BsEditorWindow.cpp 2.1 KB

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