2
0

BsEditorWindow.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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()))
  11. {
  12. updateSize();
  13. mWidgets->onWidgetClosed.connect(boost::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. }
  31. void EditorWindow::widgetRemoved()
  32. {
  33. if(mWidgets->getNumWidgets() == 0)
  34. {
  35. // HACK - If widget is being handled by drag and drop we don't want to
  36. // destroy its parent window just yet because Windows doesn't approve of
  37. // windows being destroyed while mouse is being held down (some events won't get
  38. // fired). I should probably handle this at a lower level, in RenderWindowManager.
  39. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::EditorWidget)
  40. {
  41. hide();
  42. // Get notified when drag and drop is done
  43. DragAndDropManager::instance().addDropCallback(std::bind(&EditorWindow::closeWindowDelayed, this));
  44. }
  45. else
  46. close();
  47. }
  48. }
  49. void EditorWindow::closeWindowDelayed()
  50. {
  51. close();
  52. }
  53. EditorWindow* EditorWindow::create()
  54. {
  55. return EditorWindowManager::instance().create();
  56. }
  57. }