|
|
@@ -1,6 +1,10 @@
|
|
|
#include "BsEditorWidgetContainer.h"
|
|
|
#include "BsGUITabbedTitleBar.h"
|
|
|
#include "BsEditorWidget.h"
|
|
|
+#include "BsDragAndDropManager.h"
|
|
|
+#include "BsEditorWindow.h"
|
|
|
+#include "CmMath.h"
|
|
|
+#include "CmInput.h"
|
|
|
|
|
|
using namespace CamelotFramework;
|
|
|
using namespace BansheeEngine;
|
|
|
@@ -15,6 +19,8 @@ namespace BansheeEditor
|
|
|
mTitleBar = cm_new<GUITabbedTitleBar>(parent);
|
|
|
mTitleBar->onTabActivated.connect(boost::bind(&EditorWidgetContainer::tabActivated, this, _1));
|
|
|
mTitleBar->onTabClosed.connect(boost::bind(&EditorWidgetContainer::tabClosed, this, _1));
|
|
|
+ mTitleBar->onTabDraggedOff.connect(boost::bind(&EditorWidgetContainer::tabDraggedOff, this, _1));
|
|
|
+ mTitleBar->onTabDraggedOn.connect(boost::bind(&EditorWidgetContainer::tabDraggedOn, this, _1));
|
|
|
}
|
|
|
|
|
|
EditorWidgetContainer::~EditorWidgetContainer()
|
|
|
@@ -29,20 +35,7 @@ namespace BansheeEditor
|
|
|
|
|
|
void EditorWidgetContainer::add(EditorWidget& widget)
|
|
|
{
|
|
|
- for(auto& curWidget : mWidgets)
|
|
|
- {
|
|
|
- if(curWidget == &widget)
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- mTitleBar->addTab(widget.getName());
|
|
|
- mWidgets.push_back(&widget);
|
|
|
- widget._changeParent(this);
|
|
|
-
|
|
|
- if(mActiveWidget == -1)
|
|
|
- setActiveWidget((UINT32)mWidgets.size() - 1);
|
|
|
- else
|
|
|
- widget._disable();
|
|
|
+ insert((UINT32)mWidgets.size(), widget);
|
|
|
}
|
|
|
|
|
|
void EditorWidgetContainer::remove(EditorWidget& widget)
|
|
|
@@ -65,6 +58,7 @@ namespace BansheeEditor
|
|
|
|
|
|
mWidgets.erase(mWidgets.begin() + widgetIdx);
|
|
|
mTitleBar->removeTab((UINT32)widgetIdx);
|
|
|
+ widget._changeParent(nullptr);
|
|
|
|
|
|
if(widgetIdx == mActiveWidget)
|
|
|
{
|
|
|
@@ -75,9 +69,24 @@ namespace BansheeEditor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void EditorWidgetContainer::move(EditorWidget& widget, UINT32 newPosition)
|
|
|
+ void EditorWidgetContainer::insert(CM::UINT32 idx, EditorWidget& widget)
|
|
|
{
|
|
|
- // TODO
|
|
|
+ for(auto& curWidget : mWidgets)
|
|
|
+ {
|
|
|
+ if(curWidget == &widget)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ idx = Math::Clamp(idx, 0U, (UINT32)mWidgets.size());
|
|
|
+
|
|
|
+ mTitleBar->insertTab(idx, widget.getName());
|
|
|
+ mWidgets.insert(mWidgets.begin() + idx, &widget);
|
|
|
+ widget._changeParent(this);
|
|
|
+
|
|
|
+ if(mActiveWidget == -1)
|
|
|
+ setActiveWidget((UINT32)mWidgets.size() - 1);
|
|
|
+ else
|
|
|
+ widget._disable();
|
|
|
}
|
|
|
|
|
|
void EditorWidgetContainer::setSize(UINT32 width, UINT32 height)
|
|
|
@@ -149,6 +158,47 @@ namespace BansheeEditor
|
|
|
onWidgetClosed();
|
|
|
}
|
|
|
|
|
|
+ void EditorWidgetContainer::tabDraggedOff(CM::UINT32 idx)
|
|
|
+ {
|
|
|
+ EditorWidget* widget = mWidgets[idx];
|
|
|
+ remove(*widget);
|
|
|
+
|
|
|
+ // TODO - Hook up drag and drop texture
|
|
|
+ DragAndDropManager::instance().startDrag(HTexture(), (UINT32)DragAndDropType::EditorWidget, (void*)widget, boost::bind(&EditorWidgetContainer::tabDroppedCallback, this, _1));
|
|
|
+
|
|
|
+ if(!onWidgetClosed.empty())
|
|
|
+ onWidgetClosed();
|
|
|
+ }
|
|
|
+
|
|
|
+ void EditorWidgetContainer::tabDraggedOn(CM::UINT32 idx)
|
|
|
+ {
|
|
|
+#if CM_DEBUG_MODE
|
|
|
+ if(!DragAndDropManager::instance().isDragInProgress())
|
|
|
+ CM_EXCEPT(InternalErrorException, "Tab drag and drop reported but no drag in progress.");
|
|
|
+
|
|
|
+ if(DragAndDropManager::instance().getDragTypeId() != (UINT32)DragAndDropType::EditorWidget)
|
|
|
+ CM_EXCEPT(InternalErrorException, "Tab drag and drop reported but drag type is invalid.");
|
|
|
+#endif
|
|
|
+
|
|
|
+ EditorWidget* draggedWidget = static_cast<EditorWidget*>(DragAndDropManager::instance().getDragData());
|
|
|
+
|
|
|
+ insert(idx, *draggedWidget);
|
|
|
+ }
|
|
|
+
|
|
|
+ void EditorWidgetContainer::tabDroppedCallback(bool wasDragProcessed)
|
|
|
+ {
|
|
|
+ if(!wasDragProcessed)
|
|
|
+ {
|
|
|
+ EditorWindow* newWindow = EditorWindow::create();
|
|
|
+
|
|
|
+ EditorWidget* draggedWidget = static_cast<EditorWidget*>(DragAndDropManager::instance().getDragData());
|
|
|
+ newWindow->widgets().add(*draggedWidget);
|
|
|
+
|
|
|
+ Int2 mousePos = Input::instance().getMousePosition();
|
|
|
+ newWindow->setPosition(mousePos.x, mousePos.y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
void EditorWidgetContainer::_notifyWidgetDestroyed(EditorWidget* widget)
|
|
|
{
|
|
|
for(auto& curWidget : mWidgets)
|