2015-10-01 02:22:51 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2015 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on ImWindow code from:
|
|
|
|
* https://github.com/thennequin/ImWindow
|
|
|
|
*
|
|
|
|
* MIT license:
|
|
|
|
* https://github.com/thennequin/ImWindow/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "imgui_wm.h"
|
|
|
|
#include "imgui_internal.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
2015-10-03 10:47:52 +03:00
|
|
|
#define IMGUI_NEW(type) new (ImGui::MemAlloc(sizeof(type) ) ) type
|
|
|
|
#define IMGUI_DELETE(type, obj) reinterpret_cast<type*>(obj)->~type(), ImGui::MemFree(obj)
|
2015-10-05 21:36:14 +03:00
|
|
|
#define IMGUI_DELETE_NULL(type, obj) for (;;) { if (NULL != obj) { IMGUI_DELETE(type, obj); obj = NULL; } break; }
|
2015-10-01 02:22:51 +03:00
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
namespace ImGuiWM
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 08:10:41 +03:00
|
|
|
enum EPlatformWindowAction
|
|
|
|
{
|
|
|
|
E_PLATFORM_WINDOW_ACTION_DESTOY = 1,
|
|
|
|
E_PLATFORM_WINDOW_ACTION_SHOW = 2,
|
|
|
|
E_PLATFORM_WINDOW_ACTION_HIDE = 4,
|
|
|
|
E_PLATFORM_WINDOW_ACTION_SET_POSITION = 8,
|
|
|
|
E_PLATFORM_WINDOW_ACTION_SET_SIZE = 16,
|
|
|
|
};
|
|
|
|
|
2015-10-01 02:22:51 +03:00
|
|
|
static const ImVec2 IM_VEC2_0 = ImVec2(0, 0);
|
|
|
|
static const ImVec2 IM_VEC2_N1 = ImVec2(-1, -1);
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
int Id::s_iNextId = 0;
|
2015-10-01 02:22:51 +03:00
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Id::Id()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_iId = s_iNextId++;
|
|
|
|
ImFormatString(m_pId, 11, "0x%8X", m_iId);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
ImU32 Id::GetId() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_iId;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
const char* Id::GetStr() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pId;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Window::Window()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_pTitle = NULL;
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->AddWindow(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Window::~Window()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->RemoveWindow(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
ImGui::MemFree(m_pTitle);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void Window::Destroy()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->DestroyWindow(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void Window::SetTitle(const char* pTitle)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
ImGui::MemFree(m_pTitle);
|
|
|
|
m_pTitle = ImStrdup(pTitle);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
const char* Window::GetTitle() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pTitle;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
const ImVec2& Window::GetLastPosition() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_oLastPosition;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
const ImVec2& Window::GetLastSize() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_oLastSize;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container::Container(Container* pParent)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT(NULL != pParent);
|
|
|
|
m_pSplits[0] = NULL;
|
|
|
|
m_pSplits[1] = NULL;
|
|
|
|
m_bVerticalSplit = false;
|
|
|
|
m_iActiveWindow = 0;
|
|
|
|
m_fSplitRatio = 0.5f;
|
|
|
|
m_bIsDrag = false;
|
|
|
|
m_pParent = pParent;
|
|
|
|
m_pParentWindow = (NULL != pParent) ? pParent->m_pParentWindow : NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container::Container(PlatformWindow* pParent)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT(NULL != pParent);
|
|
|
|
m_pSplits[0] = NULL;
|
|
|
|
m_pSplits[1] = NULL;
|
|
|
|
m_bVerticalSplit = false;
|
|
|
|
m_iActiveWindow = 0;
|
|
|
|
m_fSplitRatio = 0.5f;
|
|
|
|
m_bIsDrag = false;
|
|
|
|
m_pParent = NULL;
|
|
|
|
m_pParentWindow = pParent;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container::~Container()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
while (m_lWindows.begin() != m_lWindows.end())
|
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
Window* window = *m_lWindows.begin();
|
|
|
|
WindowManager::GetInstance()->RemoveWindow(window);
|
|
|
|
IMGUI_DELETE(Window, window);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_lWindows.erase(m_lWindows.begin());
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[0]);
|
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[1]);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void Container::CreateSplits()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
m_pSplits[0] = IMGUI_NEW(Container)(this);
|
|
|
|
m_pSplits[1] = IMGUI_NEW(Container)(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void Container::Dock(Window* pWindow, EDockOrientation eOrientation)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT(NULL != pWindow);
|
|
|
|
|
|
|
|
if (NULL != pWindow)
|
|
|
|
{
|
|
|
|
IM_ASSERT(eOrientation != E_DOCK_ORIENTATION_CENTER || !IsSplit());
|
|
|
|
|
|
|
|
if (!IsSplit())
|
|
|
|
{
|
|
|
|
if (m_lWindows.size() == 0)
|
|
|
|
{
|
|
|
|
eOrientation = E_DOCK_ORIENTATION_CENTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (eOrientation)
|
|
|
|
{
|
|
|
|
case E_DOCK_ORIENTATION_CENTER:
|
|
|
|
{
|
|
|
|
m_lWindows.push_back(pWindow);
|
|
|
|
m_iActiveWindow = int(m_lWindows.size() - 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_TOP:
|
|
|
|
{
|
|
|
|
m_bVerticalSplit = true;
|
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[0]->Dock(pWindow);
|
|
|
|
m_pSplits[1]->m_lWindows.insert(m_pSplits[1]->m_lWindows.begin(), m_lWindows.begin(), m_lWindows.end());
|
|
|
|
m_lWindows.clear();
|
|
|
|
m_iActiveWindow = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_LEFT:
|
|
|
|
{
|
|
|
|
m_bVerticalSplit = false;
|
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[0]->Dock(pWindow);
|
|
|
|
m_pSplits[1]->m_lWindows.insert(m_pSplits[1]->m_lWindows.begin(), m_lWindows.begin(), m_lWindows.end());
|
|
|
|
m_lWindows.clear();
|
|
|
|
m_iActiveWindow = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_RIGHT:
|
|
|
|
{
|
|
|
|
m_bVerticalSplit = false;
|
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[0]->m_lWindows.insert(m_pSplits[0]->m_lWindows.begin(), m_lWindows.begin(), m_lWindows.end());
|
|
|
|
m_pSplits[1]->Dock(pWindow);
|
|
|
|
m_lWindows.clear();
|
|
|
|
m_iActiveWindow = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_BOTTOM:
|
|
|
|
{
|
|
|
|
m_bVerticalSplit = true;
|
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[0]->m_lWindows.insert(m_pSplits[0]->m_lWindows.begin(), m_lWindows.begin(), m_lWindows.end());
|
|
|
|
m_pSplits[1]->Dock(pWindow);
|
|
|
|
m_lWindows.clear();
|
|
|
|
m_iActiveWindow = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (eOrientation)
|
|
|
|
{
|
|
|
|
case E_DOCK_ORIENTATION_CENTER:
|
|
|
|
IM_ASSERT(false);
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_TOP:
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pSplit0 = m_pSplits[0];
|
|
|
|
Container* pSplit1 = m_pSplits[1];
|
2015-10-01 02:22:51 +03:00
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[0]->m_lWindows.push_back(pWindow);
|
|
|
|
m_pSplits[1]->m_bVerticalSplit = m_bVerticalSplit;
|
|
|
|
m_pSplits[1]->m_fSplitRatio = m_fSplitRatio;
|
|
|
|
m_pSplits[1]->m_pSplits[0] = pSplit0;
|
|
|
|
m_pSplits[1]->m_pSplits[1] = pSplit1;
|
|
|
|
m_pSplits[1]->m_pSplits[0]->m_pParent = m_pSplits[1];
|
|
|
|
m_pSplits[1]->m_pSplits[1]->m_pParent = m_pSplits[1];
|
2015-10-01 08:36:56 +03:00
|
|
|
m_fSplitRatio = WindowManager::GetInstance()->GetConfig().m_fDragMarginSizeRatio;
|
2015-10-01 02:22:51 +03:00
|
|
|
m_bVerticalSplit = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_LEFT:
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pSplit0 = m_pSplits[0];
|
|
|
|
Container* pSplit1 = m_pSplits[1];
|
2015-10-01 02:22:51 +03:00
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[0]->m_lWindows.push_back(pWindow);
|
|
|
|
m_pSplits[1]->m_bVerticalSplit = m_bVerticalSplit;
|
|
|
|
m_pSplits[1]->m_fSplitRatio = m_fSplitRatio;
|
|
|
|
m_pSplits[1]->m_pSplits[0] = pSplit0;
|
|
|
|
m_pSplits[1]->m_pSplits[1] = pSplit1;
|
|
|
|
m_pSplits[1]->m_pSplits[0]->m_pParent = m_pSplits[1];
|
|
|
|
m_pSplits[1]->m_pSplits[1]->m_pParent = m_pSplits[1];
|
2015-10-01 08:36:56 +03:00
|
|
|
m_fSplitRatio = WindowManager::GetInstance()->GetConfig().m_fDragMarginSizeRatio;
|
2015-10-01 02:22:51 +03:00
|
|
|
m_bVerticalSplit = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_RIGHT:
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pSplit0 = m_pSplits[0];
|
|
|
|
Container* pSplit1 = m_pSplits[1];
|
2015-10-01 02:22:51 +03:00
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[1]->m_lWindows.push_back(pWindow);
|
|
|
|
m_pSplits[0]->m_bVerticalSplit = m_bVerticalSplit;
|
|
|
|
m_pSplits[0]->m_fSplitRatio = m_fSplitRatio;
|
|
|
|
m_pSplits[0]->m_pSplits[0] = pSplit0;
|
|
|
|
m_pSplits[0]->m_pSplits[1] = pSplit1;
|
|
|
|
m_pSplits[0]->m_pSplits[0]->m_pParent = m_pSplits[0];
|
|
|
|
m_pSplits[0]->m_pSplits[1]->m_pParent = m_pSplits[0];
|
2015-10-01 08:36:56 +03:00
|
|
|
m_fSplitRatio = 1.f - WindowManager::GetInstance()->GetConfig().m_fDragMarginSizeRatio;
|
2015-10-01 02:22:51 +03:00
|
|
|
m_bVerticalSplit = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case E_DOCK_ORIENTATION_BOTTOM:
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pSplit0 = m_pSplits[0];
|
|
|
|
Container* pSplit1 = m_pSplits[1];
|
2015-10-01 02:22:51 +03:00
|
|
|
CreateSplits();
|
|
|
|
m_pSplits[1]->m_lWindows.push_back(pWindow);
|
|
|
|
m_pSplits[0]->m_bVerticalSplit = m_bVerticalSplit;
|
|
|
|
m_pSplits[0]->m_fSplitRatio = m_fSplitRatio;
|
|
|
|
m_pSplits[0]->m_pSplits[0] = pSplit0;
|
|
|
|
m_pSplits[0]->m_pSplits[1] = pSplit1;
|
|
|
|
m_pSplits[0]->m_pSplits[0]->m_pParent = m_pSplits[0];
|
|
|
|
m_pSplits[0]->m_pSplits[1]->m_pParent = m_pSplits[0];
|
2015-10-01 08:36:56 +03:00
|
|
|
m_fSplitRatio = 1.f - WindowManager::GetInstance()->GetConfig().m_fDragMarginSizeRatio;
|
2015-10-01 02:22:51 +03:00
|
|
|
m_bVerticalSplit = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool Container::UnDock(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (std::find(m_lWindows.begin(), m_lWindows.end(), pWindow) != m_lWindows.end())
|
|
|
|
{
|
|
|
|
m_lWindows.remove(pWindow);
|
|
|
|
if (m_iActiveWindow >= int(m_lWindows.size()))
|
|
|
|
{
|
|
|
|
m_iActiveWindow = int(m_lWindows.size() - 1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-03 10:47:52 +03:00
|
|
|
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != m_pSplits[0] && NULL != m_pSplits[1])
|
|
|
|
{
|
|
|
|
if (m_pSplits[0]->UnDock(pWindow))
|
|
|
|
{
|
|
|
|
if (m_pSplits[0]->IsEmpty())
|
|
|
|
{
|
|
|
|
if (m_pSplits[1]->IsSplit())
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pSplit = m_pSplits[1];
|
2015-10-01 02:22:51 +03:00
|
|
|
m_bVerticalSplit = pSplit->m_bVerticalSplit;
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[0]);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_pSplits[0] = pSplit->m_pSplits[0];
|
|
|
|
m_pSplits[1] = pSplit->m_pSplits[1];
|
|
|
|
pSplit->m_pSplits[0] = NULL;
|
|
|
|
pSplit->m_pSplits[1] = NULL;
|
|
|
|
m_pSplits[0]->m_pParent = this;
|
|
|
|
m_pSplits[1]->m_pParent = this;
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, pSplit);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lWindows.insert(m_lWindows.end(), m_pSplits[1]->m_lWindows.begin(), m_pSplits[1]->m_lWindows.end());
|
|
|
|
m_pSplits[1]->m_lWindows.clear();
|
|
|
|
m_pSplits[1]->m_iActiveWindow = 0;
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[0]);
|
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[1]);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_pSplits[1]->UnDock(pWindow))
|
|
|
|
{
|
|
|
|
if (m_pSplits[1]->IsEmpty())
|
|
|
|
{
|
|
|
|
if (m_pSplits[0]->IsSplit())
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pSplit = m_pSplits[0];
|
2015-10-01 02:22:51 +03:00
|
|
|
m_bVerticalSplit = pSplit->m_bVerticalSplit;
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[1]);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_pSplits[0] = pSplit->m_pSplits[0];
|
|
|
|
m_pSplits[1] = pSplit->m_pSplits[1];
|
|
|
|
pSplit->m_pSplits[0] = NULL;
|
|
|
|
pSplit->m_pSplits[1] = NULL;
|
|
|
|
m_pSplits[0]->m_pParent = this;
|
|
|
|
m_pSplits[1]->m_pParent = this;
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, pSplit);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lWindows.insert(m_lWindows.end(), m_pSplits[0]->m_lWindows.begin(), m_pSplits[0]->m_lWindows.end());
|
|
|
|
m_pSplits[0]->m_lWindows.clear();
|
|
|
|
m_pSplits[0]->m_iActiveWindow = 0;
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[0]);
|
|
|
|
IMGUI_DELETE_NULL(Container, m_pSplits[1]);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool Container::IsEmpty()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
//IM_ASSERT(IsSplit() != HasWindowTabbed());
|
|
|
|
return !(IsSplit() || HasWindowTabbed());
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool Container::IsSplit()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT((NULL == m_pSplits[0]) == (NULL == m_pSplits[1]));
|
|
|
|
return (NULL != m_pSplits[0] && NULL != m_pSplits[1]);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool Container::HasWindowTabbed()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_lWindows.size() > 0;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* Container::HasWindow(const Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (std::find(m_lWindows.begin(), m_lWindows.end(), pWindow) != m_lWindows.end())
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NULL != m_pSplits[0])
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pContainer = m_pSplits[0]->HasWindow(pWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
|
|
|
return pContainer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NULL != m_pSplits[1])
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pContainer = m_pSplits[1]->HasWindow(pWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
|
|
|
return pContainer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* Container::GetPlatformWindowParent() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pParentWindow;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void Container::Paint()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager* pWindowManager = WindowManager::GetInstance();
|
2015-10-01 02:22:51 +03:00
|
|
|
ImGuiWindow* pWindow = ImGui::GetCurrentWindow();
|
|
|
|
const ImGuiStyle& oStyle = ImGui::GetStyle();
|
2015-10-03 08:10:41 +03:00
|
|
|
ImDrawList* pDrawList = ImGui::GetWindowDrawList();
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
const ImVec2 oPos = ImGui::GetWindowPos();
|
|
|
|
const ImVec2 oSize = ImGui::GetWindowSize();
|
2015-10-03 08:10:41 +03:00
|
|
|
const ImVec2 oMin = ImVec2(oPos.x + 1, oPos.y + 1);
|
|
|
|
const ImVec2 oMax = ImVec2(oPos.x + oSize.x - 2, oPos.y + oSize.y - 2);
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
m_oLastPosition = oPos;
|
|
|
|
m_oLastSize = oSize;
|
|
|
|
|
|
|
|
const int iSeparatorHalfSize = 2;
|
|
|
|
const int iSeparatorSize = iSeparatorHalfSize * 2;
|
|
|
|
|
|
|
|
if (IsSplit())
|
|
|
|
{
|
|
|
|
if (m_bVerticalSplit)
|
|
|
|
{
|
|
|
|
float iFirstHeight = oSize.y * m_fSplitRatio - iSeparatorHalfSize - pWindow->WindowPadding.x;
|
|
|
|
|
|
|
|
ImGui::BeginChild("Split1", ImVec2(0, iFirstHeight), false, ImGuiWindowFlags_NoScrollbar);
|
|
|
|
m_pSplits[0]->Paint();
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
|
|
|
ImRect oSeparatorRect(0, iFirstHeight, oSize.x, iFirstHeight + iSeparatorSize);
|
|
|
|
ImGui::Button("", oSeparatorRect.GetSize());
|
|
|
|
if (ImGui::IsItemHovered() || m_bIsDrag)
|
|
|
|
{
|
|
|
|
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
|
|
|
|
}
|
|
|
|
ImGui::PopStyleVar(1);
|
|
|
|
|
|
|
|
if (ImGui::IsItemActive())
|
|
|
|
{
|
|
|
|
if (!m_bIsDrag)
|
|
|
|
{
|
|
|
|
m_bIsDrag = true;
|
|
|
|
}
|
|
|
|
m_fSplitRatio += ImGui::GetIO().MouseDelta.y / oSize.y;
|
|
|
|
m_fSplitRatio = ImClamp(m_fSplitRatio, 0.05f, 0.95f);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bIsDrag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::BeginChild("Split2", ImVec2(0, 0), false, ImGuiWindowFlags_NoScrollbar);
|
|
|
|
m_pSplits[1]->Paint(/*iX, iY + iFirstHeight, iWidth, iSecondHeight*/);
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float iFirstWidth = oSize.x * m_fSplitRatio - iSeparatorHalfSize - pWindow->WindowPadding.y;
|
|
|
|
ImGui::BeginChild("Split1", ImVec2(iFirstWidth, 0), false, ImGuiWindowFlags_NoScrollbar);
|
|
|
|
m_pSplits[0]->Paint();
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
ImRect oSeparatorRect(iFirstWidth, 0, iFirstWidth + iSeparatorSize, oSize.y);
|
|
|
|
ImGui::Button("", oSeparatorRect.GetSize());
|
|
|
|
|
|
|
|
if (ImGui::IsItemHovered() || m_bIsDrag)
|
|
|
|
{
|
|
|
|
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
|
|
|
|
}
|
|
|
|
ImGui::PopStyleVar(1);
|
|
|
|
|
|
|
|
if (ImGui::IsItemActive())
|
|
|
|
{
|
|
|
|
if (!m_bIsDrag)
|
|
|
|
{
|
|
|
|
m_bIsDrag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fSplitRatio += ImGui::GetIO().MouseDelta.x / oSize.x;
|
|
|
|
m_fSplitRatio = ImClamp(m_fSplitRatio, 0.05f, 0.95f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bIsDrag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
ImGui::BeginChild("Split2", ImVec2(0, 0), false, ImGuiWindowFlags_NoScrollbar);
|
|
|
|
m_pSplits[1]->Paint();
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (HasWindowTabbed())
|
|
|
|
{
|
|
|
|
ImGui::InvisibleButton("TabListButton", ImVec2(16, 16));
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::BeginPopupContextItem("TabListMenu", 0))
|
|
|
|
{
|
|
|
|
int iIndex = 0;
|
2015-10-01 08:36:56 +03:00
|
|
|
for (WindowList::const_iterator itWindow = m_lWindows.begin(); itWindow != m_lWindows.end(); ++itWindow, ++iIndex)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (ImGui::Selectable((*itWindow)->GetTitle()))
|
|
|
|
{
|
|
|
|
m_iActiveWindow = iIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImColor oLinesColor = ImColor(160, 160, 160, 255);
|
|
|
|
if (ImGui::IsItemHovered())
|
|
|
|
{
|
|
|
|
oLinesColor = ImColor(255, 255, 255, 255);
|
|
|
|
}
|
|
|
|
ImVec2 oButtonMin = ImGui::GetItemRectMin();
|
|
|
|
ImVec2 oButtonMax = ImGui::GetItemRectMax();
|
|
|
|
ImVec2 oButtonSize = ImVec2(oButtonMax.x - oButtonMin.x, oButtonMax.y - oButtonMin.y);
|
2015-10-03 08:10:41 +03:00
|
|
|
pDrawList->AddLine(
|
2015-10-01 02:22:51 +03:00
|
|
|
ImVec2(oButtonMin.x + 1, oButtonMin.y + oButtonSize.y / 2),
|
|
|
|
ImVec2(oButtonMax.x - 1, oButtonMin.y + oButtonSize.y / 2),
|
|
|
|
oLinesColor);
|
|
|
|
|
2015-10-03 08:10:41 +03:00
|
|
|
pDrawList->AddLine(
|
2015-10-01 02:22:51 +03:00
|
|
|
ImVec2(oButtonMin.x + 1, oButtonMin.y + oButtonSize.y / 2 - 4),
|
|
|
|
ImVec2(oButtonMax.x - 1, oButtonMin.y + oButtonSize.y / 2 - 4),
|
|
|
|
oLinesColor);
|
|
|
|
|
2015-10-03 08:10:41 +03:00
|
|
|
pDrawList->AddLine(
|
2015-10-01 02:22:51 +03:00
|
|
|
ImVec2(oButtonMin.x + 1, oButtonMin.y + oButtonSize.y / 2 + 4),
|
|
|
|
ImVec2(oButtonMax.x - 1, oButtonMin.y + oButtonSize.y / 2 + 4),
|
|
|
|
oLinesColor);
|
|
|
|
|
2015-10-03 08:10:41 +03:00
|
|
|
pDrawList->ChannelsSplit(2);
|
|
|
|
|
2015-10-01 02:22:51 +03:00
|
|
|
//Tabs
|
|
|
|
int iIndex = 0;
|
|
|
|
int iNewActive = m_iActiveWindow;
|
|
|
|
int iSize = int(m_lWindows.size());
|
2015-10-01 08:36:56 +03:00
|
|
|
for (WindowList::iterator it = m_lWindows.begin(); it != m_lWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
const ImVec2 oTextSize = ImGui::CalcTextSize((*it)->GetTitle());
|
2015-10-03 08:10:41 +03:00
|
|
|
ImVec2 oRectSize(oTextSize.x + 15, 25);
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
ImGui::PushID(iIndex);
|
|
|
|
|
|
|
|
bool bSelected = iIndex == m_iActiveWindow;
|
2015-10-03 08:10:41 +03:00
|
|
|
if (ImGui::InvisibleButton((*it)->GetId(), oRectSize))
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
iNewActive = iIndex;
|
|
|
|
}
|
|
|
|
if (iIndex < (iSize - 1))
|
|
|
|
{
|
|
|
|
ImGui::SameLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::IsItemActive())
|
|
|
|
{
|
|
|
|
if (ImGui::IsMouseDragging())
|
|
|
|
{
|
|
|
|
pWindowManager->StartDragWindow(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 08:10:41 +03:00
|
|
|
ImColor oNormalTab(50, 50, 50, 255); // normal
|
|
|
|
ImColor oSelectedTab(37, 37, 37, 255); // selected
|
|
|
|
ImColor oBorderColor(72, 72, 72, 255); // border
|
|
|
|
|
|
|
|
ImVec2 oRectMin = ImGui::GetItemBoxMin();
|
|
|
|
ImVec2 oRectMax = ImGui::GetItemBoxMax();
|
|
|
|
|
|
|
|
const float fOverlap = 10.f;
|
|
|
|
const float fSlopWidth = 30.f;
|
|
|
|
const float sSlopP1Ratio = 0.6f;
|
|
|
|
const float fSlopP2Ratio = 0.4f;
|
|
|
|
const float fSlopHRatio = 0.f;
|
|
|
|
const float fShadowDropSize = 15.f;
|
|
|
|
const float fShadowSlopRatio = 0.6f;
|
|
|
|
const float fShadowAlpha = 0.75f;
|
|
|
|
|
|
|
|
pDrawList->PathClear();
|
|
|
|
if (bSelected)
|
|
|
|
{
|
|
|
|
pDrawList->ChannelsSetCurrent(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pDrawList->ChannelsSetCurrent(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Drop shadows
|
|
|
|
const ImVec2 uv = GImGui->FontTexUvWhitePixel;
|
|
|
|
pDrawList->PrimReserve(3, 3);
|
|
|
|
pDrawList->PrimWriteIdx((ImDrawIdx)(pDrawList->_VtxCurrentIdx)); pDrawList->PrimWriteIdx((ImDrawIdx)(pDrawList->_VtxCurrentIdx + 1)); pDrawList->PrimWriteIdx((ImDrawIdx)(pDrawList->_VtxCurrentIdx + 2));
|
|
|
|
pDrawList->PrimWriteVtx(ImVec2(oRectMin.x - fOverlap - fShadowDropSize, oRectMax.y), uv, ImColor(0.f, 0.f, 0.f, 0.f));
|
|
|
|
pDrawList->PrimWriteVtx(ImVec2(oRectMin.x - fOverlap + fSlopWidth * fShadowSlopRatio, oRectMin.y), uv, ImColor(0.f, 0.f, 0.f, 0.f));
|
|
|
|
pDrawList->PrimWriteVtx(ImVec2(oRectMin.x - fOverlap + fSlopWidth * fShadowSlopRatio, oRectMax.y), uv, ImColor(0.f, 0.f, 0.f, fShadowAlpha));
|
|
|
|
if (bSelected)
|
|
|
|
{
|
|
|
|
pDrawList->PrimReserve(3, 3);
|
|
|
|
pDrawList->PrimWriteIdx((ImDrawIdx)(pDrawList->_VtxCurrentIdx)); pDrawList->PrimWriteIdx((ImDrawIdx)(pDrawList->_VtxCurrentIdx + 1)); pDrawList->PrimWriteIdx((ImDrawIdx)(pDrawList->_VtxCurrentIdx + 2));
|
|
|
|
pDrawList->PrimWriteVtx(ImVec2(oRectMax.x + fOverlap + fShadowDropSize, oRectMax.y), uv, ImColor(0.f, 0.f, 0.f, 0.f));
|
|
|
|
pDrawList->PrimWriteVtx(ImVec2(oRectMax.x + fOverlap - fSlopWidth * fShadowSlopRatio, oRectMin.y), uv, ImColor(0.f, 0.f, 0.f, 0.f));
|
|
|
|
pDrawList->PrimWriteVtx(ImVec2(oRectMax.x + fOverlap - fSlopWidth * fShadowSlopRatio, oRectMax.y), uv, ImColor(0.f, 0.f, 0.f, fShadowAlpha));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw tab and border
|
|
|
|
if (bSelected)
|
|
|
|
{
|
|
|
|
pDrawList->PathLineTo(ImVec2(oMin.x, oRectMax.y));
|
|
|
|
}
|
|
|
|
pDrawList->PathLineTo(ImVec2(oRectMin.x - fOverlap, oRectMax.y));
|
|
|
|
pDrawList->PathBezierCurveTo(
|
|
|
|
ImVec2(oRectMin.x + fSlopWidth * sSlopP1Ratio - fOverlap, oRectMin.y + (oRectMax.y - oRectMin.y) * fSlopHRatio),
|
|
|
|
ImVec2(oRectMin.x + fSlopWidth * fSlopP2Ratio - fOverlap, oRectMin.y),
|
|
|
|
ImVec2(oRectMin.x + fSlopWidth - fOverlap, oRectMin.y)
|
|
|
|
);
|
|
|
|
pDrawList->PathLineTo(ImVec2(oRectMax.x - fSlopWidth + fOverlap, oRectMin.y));
|
|
|
|
pDrawList->PathBezierCurveTo(
|
|
|
|
ImVec2(oRectMax.x - fSlopWidth * fSlopP2Ratio + fOverlap, oRectMin.y),
|
|
|
|
ImVec2(oRectMax.x - fSlopWidth * sSlopP1Ratio + fOverlap, oRectMin.y + (oRectMax.y - oRectMin.y) * fSlopHRatio),
|
|
|
|
ImVec2(oRectMax.x + fOverlap, oRectMax.y)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (bSelected)
|
|
|
|
{
|
|
|
|
pDrawList->AddConvexPolyFilled(pDrawList->_Path.Data + 1, pDrawList->_Path.Size - 1, bSelected ? oSelectedTab : oNormalTab, true);
|
|
|
|
if (oMax.x > (oRectMax.x + fOverlap))
|
|
|
|
{
|
|
|
|
pDrawList->PathLineTo(ImVec2(oMax.x, oRectMax.y));
|
|
|
|
}
|
|
|
|
pDrawList->AddPolyline(pDrawList->_Path.Data, pDrawList->_Path.Size, oBorderColor, false, 1.5f, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pDrawList->AddConvexPolyFilled(pDrawList->_Path.Data, pDrawList->_Path.Size, bSelected ? oSelectedTab : oNormalTab, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
pDrawList->PathClear();
|
|
|
|
|
|
|
|
ImGui::RenderTextClipped(oRectMin, ImVec2(oRectMax.x, oRectMax.y), (*it)->GetTitle(), NULL, &oTextSize, ImGuiAlign_Center | ImGuiAlign_VCenter);
|
|
|
|
|
2015-10-01 02:22:51 +03:00
|
|
|
if (ImGui::BeginPopupContextItem("TabMenu"))
|
|
|
|
{
|
|
|
|
if (ImGui::Selectable("Close"))
|
|
|
|
{
|
|
|
|
(*it)->Destroy();
|
|
|
|
}
|
|
|
|
if (ImGui::BeginMenu("Dock to"))
|
|
|
|
{
|
|
|
|
int iIndex1 = 0;
|
|
|
|
|
|
|
|
if (pWindowManager->GetMainPlatformWindow()->GetContainer()->IsEmpty())
|
|
|
|
{
|
|
|
|
ImGui::PushID(0);
|
|
|
|
if (ImGui::Selectable("Main")) pWindowManager->Dock((*it));
|
|
|
|
ImGui::PopID();
|
|
|
|
++iIndex1;
|
|
|
|
}
|
2015-10-01 08:36:56 +03:00
|
|
|
const WindowList& lWindows = pWindowManager->GetWindowList();
|
|
|
|
for (WindowList::const_iterator itWindow = lWindows.begin(); itWindow != lWindows.end(); ++itWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if ((*it) != (*itWindow))
|
|
|
|
{
|
|
|
|
ImGui::PushID(iIndex1);
|
|
|
|
if (ImGui::BeginMenu((*itWindow)->GetTitle()))
|
|
|
|
{
|
|
|
|
bool bHovered = false;
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* pPlatformWindow = pWindowManager->GetWindowParent((*itWindow));
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
ImVec2 oLastWinPos = (*itWindow)->GetLastPosition();
|
|
|
|
ImVec2 oLastWinSize = (*itWindow)->GetLastSize();
|
|
|
|
|
|
|
|
ImGui::PushID(0);
|
|
|
|
if (ImGui::Selectable("Tab")) pWindowManager->DockWith((*it), (*itWindow), E_DOCK_ORIENTATION_CENTER);
|
|
|
|
if (ImGui::IsItemHovered() && NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
bHovered = true;
|
|
|
|
pWindowManager->DrawWindowArea(pPlatformWindow, oLastWinPos, oLastWinSize, ImColor(0.f, 0.5f, 1.f, 0.5f));
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
ImGui::PushID(1);
|
|
|
|
if (ImGui::Selectable("Top")) pWindowManager->DockWith((*it), (*itWindow), E_DOCK_ORIENTATION_TOP);
|
|
|
|
if (ImGui::IsItemHovered() && NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
bHovered = true;
|
|
|
|
pWindowManager->DrawWindowArea(pPlatformWindow, oLastWinPos, ImVec2(oLastWinSize.x, oLastWinSize.y / 2.f), ImColor(0.f, 0.5f, 1.f, 0.5f));
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
ImGui::PushID(2);
|
|
|
|
if (ImGui::Selectable("Left")) pWindowManager->DockWith((*it), (*itWindow), E_DOCK_ORIENTATION_LEFT);
|
|
|
|
if (ImGui::IsItemHovered() && NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
bHovered = true;
|
|
|
|
pWindowManager->DrawWindowArea(pPlatformWindow, oLastWinPos, ImVec2(oLastWinSize.x / 2.f, oLastWinSize.y), ImColor(0.f, 0.5f, 1.f, 0.5f));
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
ImGui::PushID(3);
|
|
|
|
if (ImGui::Selectable("Right")) pWindowManager->DockWith((*it), (*itWindow), E_DOCK_ORIENTATION_RIGHT);
|
|
|
|
if (ImGui::IsItemHovered() && NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
bHovered = true;
|
|
|
|
pWindowManager->DrawWindowArea(pPlatformWindow, ImVec2(oLastWinPos.x + oLastWinSize.x / 2.f, oLastWinPos.y), ImVec2(oLastWinSize.x / 2.f, oLastWinSize.y), ImColor(0.f, 0.5f, 1.f, 0.5f));
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
ImGui::PushID(4);
|
|
|
|
if (ImGui::Selectable("Bottom")) pWindowManager->DockWith((*it), (*itWindow), E_DOCK_ORIENTATION_BOTTOM);
|
|
|
|
if (ImGui::IsItemHovered() && NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
bHovered = true;
|
|
|
|
pWindowManager->DrawWindowArea(pPlatformWindow, ImVec2(oLastWinPos.x, oLastWinPos.y + oLastWinSize.y / 2.f), ImVec2(oLastWinSize.x, oLastWinSize.y / 2.f), ImColor(0.f, 0.5f, 1.f, 0.5f));
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
if (!bHovered)
|
|
|
|
{
|
|
|
|
if (NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
pWindowManager->DrawWindowArea(pPlatformWindow, oLastWinPos, oLastWinSize, ImColor(0.f, 0.5f, 1.f, 0.5f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
++iIndex1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
if (ImGui::Selectable("Float"))
|
|
|
|
{
|
|
|
|
pWindowManager->Float((*it));
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
++iIndex;
|
|
|
|
}
|
|
|
|
m_iActiveWindow = iNewActive;
|
2015-10-03 08:10:41 +03:00
|
|
|
pDrawList->ChannelsMerge();
|
2015-10-01 02:22:51 +03:00
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowList::iterator itActiveWindow = m_lWindows.begin();
|
2015-10-01 02:22:51 +03:00
|
|
|
std::advance(itActiveWindow, m_iActiveWindow);
|
|
|
|
|
|
|
|
//Draw active
|
|
|
|
IM_ASSERT(itActiveWindow != m_lWindows.end());
|
|
|
|
if (itActiveWindow != m_lWindows.end())
|
|
|
|
{
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, oStyle.WindowPadding);
|
|
|
|
//ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, ImColor(59, 59, 59, 255));
|
|
|
|
ImGui::BeginChild((*itActiveWindow)->GetId(), ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
|
|
|
|
|
|
|
|
|
|
|
ImVec2 oWinPos = ImGui::GetWindowPos();
|
|
|
|
ImVec2 oWinSize = ImGui::GetWindowSize();
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
for (WindowList::iterator it = m_lWindows.begin(); it != m_lWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
(*it)->m_oLastPosition = oWinPos;
|
|
|
|
(*it)->m_oLastSize = oWinSize;
|
|
|
|
}
|
|
|
|
(*itActiveWindow)->OnGui();
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
//ImGui::PopStyleColor(1);
|
|
|
|
ImGui::PopStyleVar(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This case can happened only where it's main container
|
|
|
|
IM_ASSERT(m_pParent == NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* Container::GetBestDocking(const ImVec2 oCursorPos, EDockOrientation& oOutOrientation, ImVec2& oOutAreaPos, ImVec2& oOutAreaSize)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (m_pParent == NULL ||
|
|
|
|
(oCursorPos.x >= m_oLastPosition.x && oCursorPos.x <= (m_oLastPosition.x + m_oLastSize.x) &&
|
|
|
|
oCursorPos.y >= m_oLastPosition.y && oCursorPos.y <= (m_oLastPosition.y + m_oLastSize.y)))
|
|
|
|
{
|
|
|
|
if (IsSplit())
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pBestContainer = NULL;
|
2015-10-01 02:22:51 +03:00
|
|
|
pBestContainer = m_pSplits[0]->GetBestDocking(oCursorPos, oOutOrientation, oOutAreaPos, oOutAreaSize);
|
|
|
|
if (NULL != pBestContainer)
|
|
|
|
{
|
|
|
|
return pBestContainer;
|
|
|
|
}
|
|
|
|
pBestContainer = m_pSplits[1]->GetBestDocking(oCursorPos, oOutOrientation, oOutAreaPos, oOutAreaSize);
|
|
|
|
if (NULL != pBestContainer)
|
|
|
|
{
|
|
|
|
return pBestContainer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const float c_fBoxHalfSize = 20.f;
|
|
|
|
const float c_fBoxSize = c_fBoxHalfSize * 2.f;
|
|
|
|
const float c_fMinSize = c_fBoxSize * 4.f;
|
|
|
|
const float c_fSplitRatio = 0.5f;
|
|
|
|
//const float c_fSplitRatio = oConfig.m_fDragMarginSizeRatio;
|
|
|
|
const ImColor oBoxColor(200, 200, 255, 255);
|
|
|
|
const ImColor oBoxHightlightColor(100, 100, 255, 255);
|
|
|
|
|
|
|
|
if (m_oLastSize.x < c_fMinSize && m_oLastSize.y < c_fMinSize)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_CENTER;
|
|
|
|
oOutAreaPos = m_oLastPosition;
|
|
|
|
oOutAreaSize = m_oLastSize;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImVec2 oCenter = ImVec2(m_oLastPosition.x + m_oLastSize.x / 2.f, m_oLastPosition.y + m_oLastSize.y / 2.f);
|
|
|
|
|
|
|
|
bool bIsInCenter = false;
|
|
|
|
bool bIsInTop = false;
|
|
|
|
bool bIsInLeft = false;
|
|
|
|
bool bIsInRight = false;
|
|
|
|
bool bIsInBottom = false;
|
|
|
|
|
|
|
|
//Center
|
|
|
|
ImRect oRectCenter(ImVec2(oCenter.x - c_fBoxHalfSize, oCenter.y - c_fBoxHalfSize), ImVec2(oCenter.x + c_fBoxHalfSize, oCenter.y + c_fBoxHalfSize));
|
|
|
|
bIsInCenter = oRectCenter.Contains(oCursorPos);
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->DrawWindowArea(m_pParentWindow, oRectCenter.Min, oRectCenter.GetSize(), bIsInCenter ? oBoxHightlightColor : oBoxColor);
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
if (m_oLastSize.y >= c_fMinSize)
|
|
|
|
{
|
|
|
|
//Top
|
|
|
|
ImRect oRectTop(ImVec2(oCenter.x - c_fBoxHalfSize, oCenter.y - c_fBoxHalfSize * 4.f), ImVec2(oCenter.x + c_fBoxHalfSize, oCenter.y - c_fBoxHalfSize * 2.f));
|
|
|
|
bIsInTop = oRectTop.Contains(oCursorPos);
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->DrawWindowArea(m_pParentWindow, oRectTop.Min, oRectTop.GetSize(), bIsInTop ? oBoxHightlightColor : oBoxColor);
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
//Bottom
|
|
|
|
ImRect oRectBottom(ImVec2(oCenter.x - c_fBoxHalfSize, oCenter.y + c_fBoxHalfSize * 2.f), ImVec2(oCenter.x + c_fBoxHalfSize, oCenter.y + c_fBoxHalfSize * 4.f));
|
|
|
|
bIsInBottom = oRectBottom.Contains(oCursorPos);
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->DrawWindowArea(m_pParentWindow, oRectBottom.Min, oRectBottom.GetSize(), bIsInBottom ? oBoxHightlightColor : oBoxColor);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_oLastSize.x >= c_fMinSize)
|
|
|
|
{
|
|
|
|
//Left
|
|
|
|
ImRect oRectLeft(ImVec2(oCenter.x - c_fBoxHalfSize * 4.f, oCenter.y - c_fBoxHalfSize), ImVec2(oCenter.x - c_fBoxHalfSize * 2.f, oCenter.y + c_fBoxHalfSize));
|
|
|
|
bIsInLeft = oRectLeft.Contains(oCursorPos);
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->DrawWindowArea(m_pParentWindow, oRectLeft.Min, oRectLeft.GetSize(), bIsInLeft ? oBoxHightlightColor : oBoxColor);
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
//Right
|
|
|
|
ImRect oRectRight(ImVec2(oCenter.x + c_fBoxHalfSize * 2.f, oCenter.y - c_fBoxHalfSize), ImVec2(oCenter.x + c_fBoxHalfSize * 4.f, oCenter.y + c_fBoxHalfSize));
|
|
|
|
bIsInRight = oRectRight.Contains(oCursorPos);
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->DrawWindowArea(m_pParentWindow, oRectRight.Min, oRectRight.GetSize(), bIsInRight ? oBoxHightlightColor : oBoxColor);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bIsInCenter)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_CENTER;
|
|
|
|
oOutAreaPos = m_oLastPosition;
|
|
|
|
oOutAreaSize = m_oLastSize;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else if (bIsInTop)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_TOP;
|
|
|
|
oOutAreaPos = m_oLastPosition;
|
|
|
|
oOutAreaSize = ImVec2(m_oLastSize.x, m_oLastSize.y * c_fSplitRatio);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else if (bIsInLeft)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_LEFT;
|
|
|
|
oOutAreaPos = m_oLastPosition;
|
|
|
|
oOutAreaSize = ImVec2(m_oLastSize.x * c_fSplitRatio, m_oLastSize.y);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else if (bIsInRight)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_RIGHT;
|
|
|
|
oOutAreaPos = ImVec2(m_oLastPosition.x + m_oLastSize.x * (1.f - c_fSplitRatio), m_oLastPosition.y);
|
|
|
|
oOutAreaSize = ImVec2(m_oLastSize.x * c_fSplitRatio, m_oLastSize.y);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else if (bIsInBottom)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_BOTTOM;
|
|
|
|
oOutAreaPos = ImVec2(m_oLastPosition.x, m_oLastPosition.y + m_oLastSize.y * (1.f - c_fSplitRatio));
|
|
|
|
oOutAreaSize = ImVec2(m_oLastSize.x, m_oLastSize.y * c_fSplitRatio);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow::PlatformWindow(bool bMain, bool bIsDragWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_bMain = bMain;
|
|
|
|
m_bIsDragWindow = bIsDragWindow;
|
2015-10-03 10:47:52 +03:00
|
|
|
m_pContainer = IMGUI_NEW(Container)(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_pState = NULL;
|
|
|
|
m_pPreviousState = NULL;
|
|
|
|
|
|
|
|
void* pTemp = ImGui::GetInternalState();
|
|
|
|
m_pState = ImGui::MemAlloc(ImGui::GetInternalStateSize());
|
|
|
|
ImGui::SetInternalState(m_pState, true);
|
|
|
|
ImGui::GetIO().IniFilename = NULL;
|
|
|
|
ImGui::SetInternalState(pTemp);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow::~PlatformWindow()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(Container, m_pContainer);
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
SetState();
|
|
|
|
if (!IsMain())
|
|
|
|
{
|
|
|
|
ImGui::GetIO().Fonts = NULL;
|
|
|
|
}
|
|
|
|
ImGui::Shutdown();
|
|
|
|
RestoreState();
|
|
|
|
ImGui::MemFree(m_pState);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::OnClose()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->OnClosePlatformWindow(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool s_bStatePush = false;
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool PlatformWindow::IsStateSet()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return s_bStatePush;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::SetState()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT(s_bStatePush == false);
|
|
|
|
s_bStatePush = true;
|
|
|
|
m_pPreviousState = ImGui::GetInternalState();
|
|
|
|
ImGui::SetInternalState(m_pState);
|
|
|
|
memcpy(&((ImGuiState*)m_pState)->Style, &((ImGuiState*)m_pPreviousState)->Style, sizeof(ImGuiStyle));
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::RestoreState()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT(s_bStatePush == true);
|
|
|
|
s_bStatePush = false;
|
|
|
|
memcpy(&((ImGuiState*)m_pPreviousState)->Style, &((ImGuiState*)m_pState)->Style, sizeof(ImGuiStyle));
|
|
|
|
ImGui::SetInternalState(m_pPreviousState);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::OnLoseFocus()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
ImGuiState& g = *((ImGuiState*)m_pState);
|
|
|
|
g.SetNextWindowPosCond = g.SetNextWindowSizeCond = g.SetNextWindowContentSizeCond = g.SetNextWindowCollapsedCond = g.SetNextWindowFocus = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::Paint()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::GetInstance()->Paint(this);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool PlatformWindow::IsMain()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_bMain;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::Dock(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_pContainer->Dock(pWindow);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool PlatformWindow::UnDock(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pContainer->UnDock(pWindow);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* PlatformWindow::GetContainer()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pContainer;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* PlatformWindow::HasWindow(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pContainer->HasWindow(pWindow);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void PlatformWindow::PaintContainer()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_pContainer->Paint();
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::DrawWindowAreaAction::DrawWindowAreaAction(PlatformWindow* pWindow, const ImVec2& oRectPos, const ImVec2& oRectSize, const ImColor& oColor)
|
2015-10-01 02:22:51 +03:00
|
|
|
: m_oColor(oColor)
|
|
|
|
{
|
|
|
|
m_pWindow = pWindow;
|
|
|
|
m_oRectPos = oRectPos;
|
|
|
|
m_oRectSize = oRectSize;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager* WindowManager::s_pInstance = 0;
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::Config::Config()
|
2015-10-01 02:22:51 +03:00
|
|
|
: m_fDragMarginRatio(0.1f)
|
|
|
|
, m_fDragMarginSizeRatio(0.25f)
|
|
|
|
, m_oHightlightAreaColor(0.f, 0.5f, 1.f, 0.5f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::WindowManager()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
s_pInstance = this;
|
|
|
|
m_pMainPlatformWindow = NULL;
|
|
|
|
m_pDragPlatformWindow = NULL;
|
|
|
|
m_pCurrentPlatformWindow = NULL;
|
|
|
|
m_pDraggedWindow = NULL;
|
|
|
|
m_oDragPreviewOffset = ImVec2(-20, -10);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::~WindowManager()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE_NULL(PlatformWindow, m_pMainPlatformWindow);
|
|
|
|
IMGUI_DELETE_NULL(PlatformWindow, m_pDragPlatformWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
s_pInstance = 0;
|
|
|
|
ImGui::Shutdown();
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool WindowManager::Init()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_pMainPlatformWindow = CreatePlatformWindow(true, NULL, false);
|
|
|
|
if (NULL != m_pMainPlatformWindow)
|
|
|
|
{
|
|
|
|
m_pMainPlatformWindow->Show();
|
|
|
|
|
|
|
|
m_pDragPlatformWindow = CreatePlatformWindow(false, m_pMainPlatformWindow, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
bool WindowManager::Run()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (m_pMainPlatformWindow != NULL)
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
m_pMainPlatformWindow->SetSize(io.DisplaySize);
|
|
|
|
}
|
|
|
|
InternalRun();
|
|
|
|
return m_pMainPlatformWindow != NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::Exit()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
//TODO : Manual exit
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* WindowManager::GetMainPlatformWindow()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pMainPlatformWindow;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager::Config& WindowManager::GetConfig()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_oConfig;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::SetMainTitle(const char* pTitle)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (NULL != m_pMainPlatformWindow)
|
|
|
|
{
|
|
|
|
m_pMainPlatformWindow->SetTitle(pTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::Dock(Window* pWindow, EDockOrientation eOrientation, PlatformWindow* pToPlatformWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
DockAction* pAction = IMGUI_NEW(DockAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_bFloat = false;
|
|
|
|
pAction->m_pWindow = pWindow;
|
|
|
|
pAction->m_pWith = NULL;
|
|
|
|
pAction->m_eOrientation = eOrientation;
|
|
|
|
pAction->m_pToPlatformWindow = (pToPlatformWindow != NULL) ? pToPlatformWindow : m_pMainPlatformWindow;
|
|
|
|
pAction->m_pToContainer = NULL;
|
|
|
|
m_lDockActions.push_back(pAction);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::DockTo(Window* pWindow, EDockOrientation eOrientation, Container* pContainer)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
IM_ASSERT(NULL != pContainer);
|
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
DockAction* pAction = IMGUI_NEW(DockAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_bFloat = false;
|
|
|
|
pAction->m_pWindow = pWindow;
|
|
|
|
pAction->m_pWith = NULL;
|
|
|
|
pAction->m_eOrientation = eOrientation;
|
|
|
|
pAction->m_pToPlatformWindow = NULL;
|
|
|
|
pAction->m_pToContainer = pContainer;
|
|
|
|
m_lDockActions.push_back(pAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::DockWith(Window* pWindow, Window* pWithWindow, EDockOrientation eOrientation)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
DockAction* pAction = IMGUI_NEW(DockAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_bFloat = false;
|
|
|
|
pAction->m_pWindow = pWindow;
|
|
|
|
pAction->m_pWith = pWithWindow;
|
|
|
|
pAction->m_eOrientation = eOrientation;
|
|
|
|
m_lDockActions.push_back(pAction);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::Float(Window* pWindow, const ImVec2& oPosition, const ImVec2& oSize)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
DockAction* pAction = IMGUI_NEW(DockAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_bFloat = true;
|
|
|
|
pAction->m_pWindow = pWindow;
|
|
|
|
pAction->m_oPosition = oPosition;
|
|
|
|
pAction->m_oSize = oSize;
|
|
|
|
m_lDockActions.push_back(pAction);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
const WindowList& WindowManager::GetWindowList() const
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_lWindows;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* WindowManager::GetCurrentPlatformWindow()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return m_pCurrentPlatformWindow;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* WindowManager::GetWindowParent(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pContainer = m_pMainPlatformWindow->HasWindow(pWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
|
|
|
return m_pMainPlatformWindow;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
pContainer = (*it)->HasWindow(pWindow);
|
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IM_ASSERT(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::Log(const char* pFormat, ...)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
char pBuffer[32768];
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, pFormat);
|
|
|
|
ImFormatStringV(pBuffer, sizeof(char) * 32767, pFormat, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
LogFormatted(pBuffer);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::PreUpdate()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (NULL != m_pMainPlatformWindow)
|
|
|
|
{
|
|
|
|
m_pMainPlatformWindow->PreUpdate();
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
(*it)->PreUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::Update()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
UpdatePlatformwWindowActions();
|
|
|
|
UpdateDockActions();
|
|
|
|
UpdateOrphans();
|
|
|
|
|
|
|
|
while (m_lToDestroyWindows.begin() != m_lToDestroyWindows.end())
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Window* pWindow = *m_lToDestroyWindows.begin();
|
2015-10-01 02:22:51 +03:00
|
|
|
|
|
|
|
m_lToDestroyWindows.remove(pWindow);
|
|
|
|
m_lOrphanWindows.remove(pWindow);
|
|
|
|
m_lWindows.remove(pWindow);
|
|
|
|
|
|
|
|
InternalUnDock(pWindow);
|
|
|
|
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(Window, pWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (m_lToDestroyPlatformWindows.begin() != m_lToDestroyPlatformWindows.end())
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* pPlatformWindow = *m_lToDestroyPlatformWindows.begin();
|
2015-10-01 02:22:51 +03:00
|
|
|
m_lToDestroyPlatformWindows.remove(pPlatformWindow);
|
|
|
|
m_lPlatformWindows.remove(pPlatformWindow);
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(PlatformWindow, pPlatformWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateDragWindow();
|
|
|
|
|
|
|
|
m_pCurrentPlatformWindow = m_pMainPlatformWindow;
|
|
|
|
if (NULL != m_pMainPlatformWindow)
|
|
|
|
{
|
|
|
|
m_pMainPlatformWindow->Paint();
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_pCurrentPlatformWindow = (*it);
|
|
|
|
(*it)->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pCurrentPlatformWindow = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::UpdatePlatformwWindowActions()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
while (m_lPlatformWindowActions.begin() != m_lPlatformWindowActions.end())
|
|
|
|
{
|
|
|
|
PlatformWindowAction* pAction = *m_lPlatformWindowActions.begin();
|
|
|
|
|
|
|
|
IM_ASSERT((pAction->m_iFlags & E_PLATFORM_WINDOW_ACTION_SHOW & E_PLATFORM_WINDOW_ACTION_HIDE) == 0); // Can't show and hide
|
|
|
|
|
|
|
|
if (pAction->m_iFlags & E_PLATFORM_WINDOW_ACTION_DESTOY)
|
|
|
|
{
|
|
|
|
//pAction->m_pPlatformWindow->Show();
|
|
|
|
//todo destroy
|
|
|
|
bool bFound = false;
|
|
|
|
if (m_pMainPlatformWindow == pAction->m_pPlatformWindow)
|
|
|
|
{
|
|
|
|
while (m_lPlatformWindows.begin() != m_lPlatformWindows.end())
|
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(PlatformWindow, *m_lPlatformWindows.begin());
|
2015-10-01 02:22:51 +03:00
|
|
|
m_lPlatformWindows.erase(m_lPlatformWindows.begin());
|
|
|
|
}
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(PlatformWindow, m_pMainPlatformWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_pMainPlatformWindow = NULL;
|
|
|
|
bFound = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (*it == pAction->m_pPlatformWindow)
|
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(PlatformWindow, *it);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_lPlatformWindows.erase(it);
|
|
|
|
bFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bFound)
|
|
|
|
{
|
|
|
|
IM_ASSERT(false, "ImwPlatformWindow not found, maybe already closed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pAction->m_iFlags & E_PLATFORM_WINDOW_ACTION_SHOW)
|
|
|
|
{
|
|
|
|
pAction->m_pPlatformWindow->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pAction->m_iFlags & E_PLATFORM_WINDOW_ACTION_HIDE)
|
|
|
|
{
|
|
|
|
pAction->m_pPlatformWindow->Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pAction->m_iFlags & E_PLATFORM_WINDOW_ACTION_SET_POSITION)
|
|
|
|
{
|
|
|
|
pAction->m_pPlatformWindow->SetPosition(pAction->m_oPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pAction->m_iFlags & E_PLATFORM_WINDOW_ACTION_SET_SIZE)
|
|
|
|
{
|
|
|
|
pAction->m_pPlatformWindow->SetSize(pAction->m_oSize);
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(PlatformWindowAction, *m_lPlatformWindowActions.begin());
|
2015-10-01 02:22:51 +03:00
|
|
|
m_lPlatformWindowActions.erase(m_lPlatformWindowActions.begin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::UpdateDockActions()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
while (m_lDockActions.begin() != m_lDockActions.end())
|
|
|
|
{
|
|
|
|
DockAction* pAction = *m_lDockActions.begin();
|
|
|
|
|
|
|
|
InternalUnDock(pAction->m_pWindow);
|
|
|
|
|
|
|
|
if (pAction->m_bFloat)
|
|
|
|
{
|
|
|
|
InternalFloat(pAction->m_pWindow, pAction->m_oPosition, pAction->m_oSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NULL != pAction->m_pWith)
|
|
|
|
{
|
|
|
|
InternalDockWith(pAction->m_pWindow, pAction->m_pWith, pAction->m_eOrientation);
|
|
|
|
}
|
|
|
|
else if (NULL != pAction->m_pToContainer)
|
|
|
|
{
|
|
|
|
InternalDockTo(pAction->m_pWindow, pAction->m_eOrientation, pAction->m_pToContainer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InternalDock(pAction->m_pWindow, pAction->m_eOrientation, pAction->m_pToPlatformWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lOrphanWindows.remove(pAction->m_pWindow);
|
|
|
|
|
2015-10-03 10:47:52 +03:00
|
|
|
IMGUI_DELETE(PlatformWindowAction, pAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
m_lDockActions.erase(m_lDockActions.begin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::UpdateOrphans()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
while (m_lOrphanWindows.begin() != m_lOrphanWindows.end())
|
|
|
|
{
|
|
|
|
if (m_pMainPlatformWindow->m_pContainer->IsEmpty())
|
|
|
|
{
|
|
|
|
InternalDock(*m_lOrphanWindows.begin(), E_DOCK_ORIENTATION_CENTER, m_pMainPlatformWindow);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImVec2 oSize = ImVec2(300, 300);
|
|
|
|
ImVec2 oPos = m_pMainPlatformWindow->GetPosition();
|
|
|
|
ImVec2 oMainSize = m_pMainPlatformWindow->GetSize();
|
|
|
|
oPos.x += (oMainSize.x - oSize.x) / 2;
|
|
|
|
oPos.y += (oMainSize.y - oSize.y) / 2;
|
|
|
|
InternalFloat(*m_lOrphanWindows.begin(), oPos, oSize);
|
|
|
|
}
|
|
|
|
m_lOrphanWindows.erase(m_lOrphanWindows.begin());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::Paint(PlatformWindow* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (!pWindow->GetContainer()->IsEmpty() )
|
|
|
|
{
|
|
|
|
float fY = 0.f;
|
|
|
|
// if (pWindow->IsMain())
|
|
|
|
// {
|
|
|
|
// ImGui::BeginMainMenuBar();
|
|
|
|
// for (ImwWindowList::iterator it = m_lWindows.begin(); it != m_lWindows.end(); ++it)
|
|
|
|
// {
|
|
|
|
// (*it)->OnMenu();
|
|
|
|
// }
|
|
|
|
// fY = ImGui::GetWindowHeight();
|
|
|
|
// ImGui::EndMainMenuBar();
|
|
|
|
// }
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(0, fY), ImGuiSetCond_Always);
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(pWindow->GetSize().x, pWindow->GetSize().y - fY), ImGuiSetCond_Always);
|
|
|
|
int iFlags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
|
|
|
|
|
|
|
|
if (NULL != m_pDraggedWindow)
|
|
|
|
{
|
|
|
|
iFlags += ImGuiWindowFlags_NoInputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5.0f, 5.0f));
|
|
|
|
ImGui::Begin("Main", NULL, iFlags);
|
|
|
|
pWindow->PaintContainer();
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::PopStyleVar(1);
|
|
|
|
|
2015-10-03 08:10:41 +03:00
|
|
|
ImGui::Begin("##Overlay", NULL, ImVec2(0, 0), 0.f, ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
|
2015-10-01 02:22:51 +03:00
|
|
|
ImDrawList* pDrawList = ImGui::GetWindowDrawList();
|
|
|
|
for (ImwList<DrawWindowAreaAction>::iterator it = m_lDrawWindowAreas.begin(); it != m_lDrawWindowAreas.end();)
|
|
|
|
{
|
|
|
|
const DrawWindowAreaAction& oAction = *it;
|
|
|
|
|
|
|
|
if (pWindow == oAction.m_pWindow)
|
|
|
|
{
|
|
|
|
ImVec2 oPosA = oAction.m_oRectPos;
|
|
|
|
ImVec2 oPosB = oAction.m_oRectSize;
|
|
|
|
oPosB.x += oPosA.x;
|
|
|
|
oPosB.y += oPosA.y;
|
|
|
|
|
|
|
|
pDrawList->PushClipRectFullScreen();
|
|
|
|
pDrawList->AddRectFilled(oPosA, oPosB, oAction.m_oColor);
|
|
|
|
pDrawList->PopClipRect();
|
|
|
|
ImwList<DrawWindowAreaAction>::iterator toRemove = it;
|
|
|
|
++it;
|
|
|
|
m_lDrawWindowAreas.erase(toRemove);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 08:10:41 +03:00
|
|
|
ImGui::End();
|
2015-10-01 02:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 07:10:18 +03:00
|
|
|
static ImVec2 GetCursorPos()
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
return io.MousePos;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::StartDragWindow(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (NULL == m_pDraggedWindow)
|
|
|
|
{
|
|
|
|
m_pDraggedWindow = pWindow;
|
|
|
|
|
2015-10-03 10:47:52 +03:00
|
|
|
PlatformWindowAction* pAction = IMGUI_NEW(PlatformWindowAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_pPlatformWindow = m_pDragPlatformWindow;
|
|
|
|
pAction->m_iFlags = E_PLATFORM_WINDOW_ACTION_SHOW | E_PLATFORM_WINDOW_ACTION_SET_POSITION | E_PLATFORM_WINDOW_ACTION_SET_SIZE;
|
|
|
|
ImVec2 oCursorPos = GetCursorPos();
|
|
|
|
pAction->m_oPosition = ImVec2(oCursorPos.x + m_oDragPreviewOffset.x, oCursorPos.y + m_oDragPreviewOffset.y);
|
|
|
|
pAction->m_oSize = ImVec2(pWindow->GetLastSize().x, pWindow->GetLastSize().y);
|
|
|
|
m_lPlatformWindowActions.push_back(pAction);
|
|
|
|
|
|
|
|
Dock(pWindow, E_DOCK_ORIENTATION_CENTER, m_pDragPlatformWindow);
|
|
|
|
((ImGuiState*)m_pDragPlatformWindow->m_pState)->IO.MouseDown[0] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::StopDragWindow()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
PlatformWindowAction* pAction = IMGUI_NEW(PlatformWindowAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_pPlatformWindow = m_pDragPlatformWindow;
|
|
|
|
pAction->m_iFlags = E_PLATFORM_WINDOW_ACTION_HIDE;
|
|
|
|
m_pDragPlatformWindow->Hide();
|
|
|
|
m_lPlatformWindowActions.push_back(pAction);
|
|
|
|
m_pDraggedWindow = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::UpdateDragWindow()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (NULL != m_pDraggedWindow)
|
|
|
|
{
|
|
|
|
m_pCurrentPlatformWindow = m_pDragPlatformWindow;
|
|
|
|
m_pDragPlatformWindow->Paint();
|
|
|
|
m_pCurrentPlatformWindow = NULL;
|
|
|
|
|
|
|
|
ImVec2 oCursorPos = GetCursorPos();
|
|
|
|
m_pDragPlatformWindow->SetPosition(ImVec2(oCursorPos.x + m_oDragPreviewOffset.x, oCursorPos.y + m_oDragPreviewOffset.y));
|
|
|
|
|
|
|
|
//Search best dock area
|
|
|
|
EDockOrientation eBestDockOrientation;
|
|
|
|
ImVec2 oHightlightPos;
|
|
|
|
ImVec2 oHightlightSize;
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pBestContainer = GetBestDocking(m_pMainPlatformWindow, oCursorPos, eBestDockOrientation, oHightlightPos, oHightlightSize);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL == pBestContainer)
|
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end() && NULL == pBestContainer; ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
pBestContainer = GetBestDocking(*it, oCursorPos, eBestDockOrientation, oHightlightPos, oHightlightSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pBestContainer)
|
|
|
|
{
|
|
|
|
DrawWindowArea(pBestContainer->GetPlatformWindowParent(), oHightlightPos, oHightlightSize, m_oConfig.m_oHightlightAreaColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (!((ImGuiState*)m_pDragPlatformWindow->m_pState)->IO.MouseDown[0])
|
2015-10-03 07:10:18 +03:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
if (!io.MouseDown[0])
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (NULL != pBestContainer)
|
|
|
|
{
|
|
|
|
DockTo(m_pDraggedWindow, eBestDockOrientation, pBestContainer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Float(m_pDraggedWindow, m_pDragPlatformWindow->GetPosition(), m_pDragPlatformWindow->GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
StopDragWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* WindowManager::GetBestDocking(PlatformWindow* pPlatformWindow, const ImVec2 oCursorPos, EDockOrientation& oOutOrientation, ImVec2& oOutAreaPos, ImVec2& oOutAreaSize)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
ImVec2 oPos = pPlatformWindow->GetPosition();
|
|
|
|
ImVec2 oSize = pPlatformWindow->GetSize();
|
|
|
|
if (oCursorPos.x >= oPos.x && oCursorPos.x <= (oPos.x + oSize.x) &&
|
|
|
|
oCursorPos.y >= oPos.y && oCursorPos.y <= (oPos.y + oSize.y))
|
|
|
|
{
|
|
|
|
ImVec2 oRectPos(oCursorPos.x - oPos.x, oCursorPos.y - oPos.y);
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pBestContainer = pPlatformWindow->GetContainer()->GetBestDocking(oRectPos, oOutOrientation, oOutAreaPos, oOutAreaSize);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != pBestContainer)
|
|
|
|
{
|
|
|
|
return pBestContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Left
|
|
|
|
if (oRectPos.x <= oSize.x * m_oConfig.m_fDragMarginRatio)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_LEFT;
|
|
|
|
oOutAreaPos = IM_VEC2_0;
|
|
|
|
oOutAreaSize = ImVec2(oSize.x * m_oConfig.m_fDragMarginSizeRatio, oSize.y);
|
|
|
|
}
|
|
|
|
//Right
|
|
|
|
else if (oRectPos.x >= oSize.x * (1.f - m_oConfig.m_fDragMarginRatio))
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_RIGHT;
|
|
|
|
oOutAreaPos = ImVec2(oSize.x * (1.f - m_oConfig.m_fDragMarginSizeRatio), 0.f);
|
|
|
|
oOutAreaSize = ImVec2(oSize.x * m_oConfig.m_fDragMarginSizeRatio, oSize.y);
|
|
|
|
}
|
|
|
|
//Top
|
|
|
|
else if (oRectPos.y <= oSize.y * m_oConfig.m_fDragMarginRatio)
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_TOP;
|
|
|
|
oOutAreaPos = IM_VEC2_0;
|
|
|
|
oOutAreaSize = ImVec2(oSize.x, oSize.y * m_oConfig.m_fDragMarginSizeRatio);
|
|
|
|
}
|
|
|
|
//Bottom
|
|
|
|
else if (oRectPos.y >= oSize.y * (1.f - m_oConfig.m_fDragMarginRatio))
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_BOTTOM;
|
|
|
|
oOutAreaPos = ImVec2(0.f, oSize.y * (1.f - m_oConfig.m_fDragMarginSizeRatio));
|
|
|
|
oOutAreaSize = ImVec2(oSize.x, oSize.y * m_oConfig.m_fDragMarginSizeRatio);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
oOutOrientation = E_DOCK_ORIENTATION_CENTER;
|
|
|
|
oOutAreaPos = IM_VEC2_0;
|
|
|
|
oOutAreaSize = ImVec2(oSize.x, oSize.y);
|
|
|
|
//IM_ASSERT(false); //Best dock orientation not found
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return pPlatformWindow->GetContainer();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::AddWindow(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_lWindows.push_back(pWindow);
|
|
|
|
|
|
|
|
m_lOrphanWindows.push_back(pWindow);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::RemoveWindow(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_lWindows.remove(pWindow);
|
|
|
|
m_lOrphanWindows.remove(pWindow);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::DestroyWindow(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (NULL != pWindow && std::find(m_lToDestroyWindows.begin(), m_lToDestroyWindows.end(), pWindow) == m_lToDestroyWindows.end())
|
|
|
|
{
|
|
|
|
m_lToDestroyWindows.push_back(pWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::InternalDock(Window* pWindow, EDockOrientation eOrientation, PlatformWindow* pToPlatformWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
pToPlatformWindow->m_pContainer->Dock(pWindow, eOrientation);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::InternalDockTo(Window* pWindow, EDockOrientation eOrientation, Container* pToContainer)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
pToContainer->Dock(pWindow, eOrientation);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::InternalDockWith(Window* pWindow, Window* pWithWindow, EDockOrientation eOrientation)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
Container* pContainer = m_pMainPlatformWindow->HasWindow(pWithWindow);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
|
|
|
pContainer->Dock(pWindow, eOrientation);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
pContainer = (*it)->HasWindow(pWithWindow);
|
|
|
|
if (NULL != pContainer)
|
|
|
|
{
|
|
|
|
pContainer->Dock(pWindow, eOrientation);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::InternalFloat(Window* pWindow, ImVec2 oPosition, ImVec2 oSize)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-01 08:36:56 +03:00
|
|
|
PlatformWindow* pPlatformWindow = CreatePlatformWindow(false, m_pMainPlatformWindow, false);
|
2015-10-01 02:22:51 +03:00
|
|
|
if (NULL != pPlatformWindow)
|
|
|
|
{
|
|
|
|
m_lPlatformWindows.push_back(pPlatformWindow);
|
|
|
|
|
|
|
|
if (oSize.x == IM_VEC2_N1.x && oSize.y == IM_VEC2_N1.y)
|
|
|
|
{
|
|
|
|
oSize = pWindow->GetLastSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oPosition.x == IM_VEC2_N1.x && oPosition.y == IM_VEC2_N1.y)
|
|
|
|
{
|
|
|
|
oPosition = GetCursorPos();
|
|
|
|
oPosition.x -= 20;
|
|
|
|
oPosition.x -= 10;
|
|
|
|
}
|
|
|
|
pPlatformWindow->Dock(pWindow);
|
|
|
|
pPlatformWindow->SetSize(oSize);
|
|
|
|
pPlatformWindow->SetPosition(oPosition);
|
|
|
|
pPlatformWindow->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::InternalUnDock(Window* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if (m_pMainPlatformWindow->UnDock(pWindow))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
for (PlatformWindowList::iterator it = m_lPlatformWindows.begin(); it != m_lPlatformWindows.end(); ++it)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
if ((*it)->UnDock(pWindow))
|
|
|
|
{
|
|
|
|
//Destroy empty platform window if not main window
|
|
|
|
if (!(*it)->IsMain() && (*it)->GetContainer()->IsEmpty())
|
|
|
|
{
|
|
|
|
m_lToDestroyPlatformWindows.push_back(*it);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pDragPlatformWindow->UnDock(pWindow);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::OnClosePlatformWindow(PlatformWindow* pWindow)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
2015-10-03 10:47:52 +03:00
|
|
|
PlatformWindowAction* pAction = IMGUI_NEW(PlatformWindowAction);
|
2015-10-01 02:22:51 +03:00
|
|
|
pAction->m_iFlags = E_PLATFORM_WINDOW_ACTION_DESTOY;
|
|
|
|
pAction->m_pPlatformWindow = pWindow;
|
|
|
|
m_lPlatformWindowActions.push_back(pAction);
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:36:56 +03:00
|
|
|
void WindowManager::DrawWindowArea(PlatformWindow* pWindow, const ImVec2& oPos, const ImVec2& oSize, const ImColor& oColor)
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
m_lDrawWindowAreas.push_back(DrawWindowAreaAction(pWindow, oPos, oSize, oColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Static
|
2015-10-01 08:36:56 +03:00
|
|
|
WindowManager* WindowManager::GetInstance()
|
2015-10-01 02:22:51 +03:00
|
|
|
{
|
|
|
|
return s_pInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ImWindow
|