BsEditorWindow.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "BsEditorWindow.h"
  2. #include "BsEditorWidgetContainer.h"
  3. #include "BsEditorWindowManager.h"
  4. using namespace CamelotFramework;
  5. using namespace BansheeEngine;
  6. namespace BansheeEditor
  7. {
  8. EditorWindow::EditorWindow()
  9. :EditorWindowBase(), mWidgets(cm_new<EditorWidgetContainer>(mGUI.get(), mRenderWindow.get()))
  10. {
  11. updateSize();
  12. mWidgets->onWidgetClosed.connect(boost::bind(&EditorWindow::widgetRemoved, this));
  13. }
  14. EditorWindow::~EditorWindow()
  15. {
  16. cm_delete(mWidgets);
  17. }
  18. void EditorWindow::resized()
  19. {
  20. EditorWindowBase::resized();
  21. updateSize();
  22. }
  23. void EditorWindow::updateSize()
  24. {
  25. mWidgets->setPosition(1, 1);
  26. UINT32 widgetWidth = (UINT32)std::max(0, (INT32)getWidth() - 2);
  27. UINT32 widgetHeight = (UINT32)std::max(0, (INT32)getHeight() - 2);
  28. mWidgets->setSize(widgetWidth, widgetHeight);
  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(mWidgets->_isHandlingWidgetDragAndDrop())
  39. {
  40. hide();
  41. // Get notified when drag and drop is done
  42. mWidgets->_addCallbackOnDraggedWidgetDropped(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. }