Replaced ImGui docking with simpler code.

This commit is contained in:
Branimir Karadžić 2016-10-20 22:04:01 -07:00
Родитель c5f2c5b373
Коммит 5f84d95fed
8 изменённых файлов: 1130 добавлений и 2352 удалений

1
3rdparty/ocornut-imgui/imgui_user.h поставляемый
Просмотреть файл

@ -45,3 +45,4 @@ namespace ImGui
#include "widgets/file_list.h"
#include "widgets/memory_editor.h"
#include "widgets/gizmo.h"
#include "widgets/dock.h"

1
3rdparty/ocornut-imgui/imgui_user.inl поставляемый
Просмотреть файл

@ -75,3 +75,4 @@ namespace ImGui
#include "widgets/file_list.inl"
#include "widgets/memory_editor.inl"
#include "widgets/gizmo.inl"
#include "widgets/dock.inl"

1688
3rdparty/ocornut-imgui/imgui_wm.cpp поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

310
3rdparty/ocornut-imgui/imgui_wm.h поставляемый
Просмотреть файл

@ -1,310 +0,0 @@
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
/*
* Based on ImWindow code from:
* https://github.com/thennequin/ImWindow
*
* MIT license:
* https://github.com/thennequin/ImWindow/blob/master/LICENSE
*/
#ifndef IMGUI_WM_H_HEADER_GUARD
#define IMGUI_WM_H_HEADER_GUARD
#include "imgui.h"
typedef unsigned int ImU32;
#ifndef ImwList
# include <list>
# define ImwList std::list
#endif // ImList
#ifndef ImwMap
# include <unordered_map>
# define ImwMap std::unordered_map
#endif // ImMap
namespace ImGuiWM
{
enum EDockOrientation
{
E_DOCK_ORIENTATION_CENTER,
E_DOCK_ORIENTATION_TOP,
E_DOCK_ORIENTATION_LEFT,
E_DOCK_ORIENTATION_RIGHT,
E_DOCK_ORIENTATION_BOTTOM,
};
class Id
{
public:
Id();
ImU32 GetId() const;
const char* GetStr() const;
private:
ImU32 m_iId;
char m_pId[11];
static int s_iNextId;
};
class Window
{
friend class WindowManager;
friend class Container;
public:
virtual void OnGui() = 0;
virtual void OnMenu() {};
const char* GetId() const { return m_oId.GetStr(); }
void Destroy();
void SetTitle(const char* pTitle);
const char* GetTitle() const;
const ImVec2& GetLastPosition() const;
const ImVec2& GetLastSize() const;
protected:
Window();
virtual ~Window();
char* m_pTitle;
Id m_oId;
ImVec2 m_oLastPosition;
ImVec2 m_oLastSize;
};
typedef ImwList<Window*> WindowList;
class PlatformWindow;
class Container
{
friend class PlatformWindow;
public:
void Dock(Window* pWindow,EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER);
bool UnDock(Window* pWindow);
bool IsEmpty();
bool IsSplit();
bool HasWindowTabbed();
Container* HasWindow(const Window* pWindow);
PlatformWindow* GetPlatformWindowParent() const;
Container* GetBestDocking(const ImVec2 oCursorPosInContainer,EDockOrientation& oOutOrientation,ImVec2& oOutAreaPos,ImVec2& oOutAreaSize);
protected:
Container(Container* pParent);
Container(PlatformWindow* pParent);
~Container();
void CreateSplits();
void Paint();
Container* m_pParent;
PlatformWindow* m_pParentWindow;
WindowList m_lWindows;
Container* m_pSplits[2];
float m_fSplitRatio;
bool m_bVerticalSplit;
int m_iActiveWindow;
bool m_bIsDrag;
ImVec2 m_oLastPosition;
ImVec2 m_oLastSize;
};
class PlatformWindow
{
friend class WindowManager;
public:
PlatformWindow(bool bMainWindow,bool bIsDragWindow);
virtual ~PlatformWindow();
virtual bool Init(PlatformWindow* pParent) = 0;
virtual const ImVec2& GetPosition() const = 0;
virtual const ImVec2& GetSize() const = 0;
virtual void Show() = 0;
virtual void Hide() = 0;
virtual void SetSize(const ImVec2& size) = 0;
virtual void SetPosition(const ImVec2& pos) = 0;
virtual void SetTitle(const char* pTitle) = 0;
bool IsMain();
void Dock(Window* pWindow);
bool UnDock(Window* pWindow);
Container* GetContainer();
Container* HasWindow(Window* pWindow);
bool IsStateSet();
protected:
void SetState();
void RestoreState();
void OnLoseFocus();
virtual void PreUpdate() = 0;
virtual void PaintBegin() = 0;
virtual void Paint();
virtual void PaintEnd() = 0;
virtual void Destroy() = 0;
virtual void StartDrag() = 0;
virtual void StopDrag() = 0;
virtual bool IsDraging() = 0;
void PaintContainer();
void OnClose();
Id m_oId;
bool m_bMain;
bool m_bIsDragWindow;
Container* m_pContainer;
ImGuiContext* m_pState;
ImGuiContext* m_pPreviousState;
};
typedef ImwList<PlatformWindow*> PlatformWindowList;
class WindowManager
{
friend class Window;
friend class PlatformWindow;
friend class Container;
struct PlatformWindowAction
{
PlatformWindow* m_pPlatformWindow;
unsigned int m_iFlags;
ImVec2 m_oPosition;
ImVec2 m_oSize;
};
struct DockAction
{
Window* m_pWindow;
// Is Dock or Float
bool m_bFloat;
//For Docking
Window* m_pWith;
EDockOrientation m_eOrientation;
PlatformWindow* m_pToPlatformWindow;
Container* m_pToContainer;
//For Floating
ImVec2 m_oPosition;
ImVec2 m_oSize;
};
struct DrawWindowAreaAction
{
DrawWindowAreaAction(PlatformWindow* pWindow,const ImVec2& oRectPos,const ImVec2& oRectSize,const ImColor& oColor);
PlatformWindow* m_pWindow;
ImVec2 m_oRectPos;
ImVec2 m_oRectSize;
ImColor m_oColor;
};
public:
struct Config
{
Config();
float m_fDragMarginRatio;
float m_fDragMarginSizeRatio;
ImColor m_oHightlightAreaColor;
};
WindowManager();
virtual ~WindowManager();
bool Init();
bool Run();
void Exit();
PlatformWindow* GetMainPlatformWindow();
Config& GetConfig();
void SetMainTitle(const char* pTitle);
void Dock(Window* pWindow, EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER, PlatformWindow* pToPlatformWindow = NULL);
void DockTo(Window* pWindow, EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER, Container* pContainer = NULL);
void DockWith(Window* pWindow, Window* pWithWindow,EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER);
void Float(Window* pWindow, const ImVec2& oPosition = ImVec2(-1,-1), const ImVec2& oSize = ImVec2(-1,-1));
const WindowList& GetWindowList() const;
PlatformWindow* GetCurrentPlatformWindow();
PlatformWindow* GetWindowParent(Window* pWindow);
void Log(const char* pFormat, ...);
virtual void LogFormatted(const char* pStr) = 0;;
static WindowManager* GetInstance();
protected:
virtual PlatformWindow* CreatePlatformWindow(bool bMain,PlatformWindow* pParent,bool bDragWindow) = 0;
virtual void InternalRun() = 0;
void AddWindow(Window* pWindow);
void RemoveWindow(Window* pWindow);
void DestroyWindow(Window* pWindow);
void InternalDock(Window* pWindow,EDockOrientation eOrientation,PlatformWindow* pToPlatformWindow);
void InternalDockTo(Window* pWindow,EDockOrientation eOrientation,Container* pToContainer);
void InternalDockWith(Window* pWindow,Window* pWithWindow,EDockOrientation eOrientation);
bool InternalFloat(Window* pWindow,ImVec2 oPosition,ImVec2 oSize);
void InternalUnDock(Window* pWindow);
void InternalDrag(Window* pWindow);
void OnClosePlatformWindow(PlatformWindow* pWindow);
void DrawWindowArea(PlatformWindow* pWindow,const ImVec2& oPos,const ImVec2& oSize,const ImColor& oColor);
void PreUpdate();
void Update();
void UpdatePlatformwWindowActions();
void UpdateDockActions();
void UpdateOrphans();
void Paint(PlatformWindow* pWindow);
void StartDragWindow(Window* pWindow);
void StopDragWindow();
void UpdateDragWindow();
Container* GetBestDocking(PlatformWindow* pPlatformWindow,const ImVec2 oCursorPos,EDockOrientation& oOutOrientation,ImVec2& oOutAreaPos,ImVec2& oOutAreaSize);
Config m_oConfig;
PlatformWindow* m_pMainPlatformWindow;
PlatformWindowList m_lPlatformWindows;
PlatformWindow* m_pDragPlatformWindow;
WindowList m_lWindows;
WindowList m_lOrphanWindows;
WindowList m_lToDestroyWindows;
PlatformWindowList m_lToDestroyPlatformWindows;
ImwList<PlatformWindowAction*> m_lPlatformWindowActions;
ImwList<DockAction*> m_lDockActions;
ImwList<DrawWindowAreaAction> m_lDrawWindowAreas;
PlatformWindow* m_pCurrentPlatformWindow;
Window* m_pDraggedWindow;
ImVec2 m_oDragPreviewOffset;
static WindowManager* s_pInstance;
};
}
#endif // IMGUI_WM_H_HEADER_GUARD

21
3rdparty/ocornut-imgui/widgets/dock.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,21 @@
namespace ImGui
{
///
IMGUI_API void InitDockContext();
///
IMGUI_API void ShutdownDockContext();
///
IMGUI_API void RootDock(const ImVec2& pos, const ImVec2& size);
///
IMGUI_API bool BeginDock(const char* label, bool* opened = NULL, ImGuiWindowFlags extra_flags = 0);
///
IMGUI_API void EndDock();
///
IMGUI_API void SetDockActive();
} // namespace ImGui

1105
3rdparty/ocornut-imgui/widgets/dock.inl поставляемый Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -28,7 +28,6 @@
#include <bgfx/bgfx.h>
#include <ocornut-imgui/imgui.h>
#include <ocornut-imgui/imgui_wm.h>
#include <iconfontheaders/icons_kenney.h>
#include <iconfontheaders/icons_font_awesome.h>

Просмотреть файл

@ -8,7 +8,6 @@
#include <bx/fpumath.h>
#include <bx/timer.h>
#include <ocornut-imgui/imgui.h>
#include <ocornut-imgui/imgui_wm.h>
#include "imgui.h"
#include "ocornut_imgui.h"
@ -50,181 +49,6 @@ static FontRangeMerge s_fontRangeMerge[] =
{ s_iconsFontAwesomeTtf, sizeof(s_iconsFontAwesomeTtf), { ICON_MIN_FA, ICON_MAX_FA, 0 } },
};
class PlatformWindow : public ImGuiWM::PlatformWindow
{
typedef ImGuiWM::PlatformWindow Super;
public:
PlatformWindow(bool _mainWindow, bool _isDragWindow)
: ImGuiWM::PlatformWindow(_mainWindow, _isDragWindow)
, m_pos(0.0f, 0.0f)
, m_size(0.0f, 0.0f)
, m_drag(false)
{
#if USE_ENTRY
if (!_mainWindow
&& !_isDragWindow)
{
m_window = entry::createWindow(0, 0, 640, 380);
extern void pwToWindow(entry::WindowHandle _handle, class PlatformWindow* _pw);
pwToWindow(m_window, this);
}
else
{
m_window.idx = 0;
}
#endif // USE_ENTRY
}
virtual ~PlatformWindow()
{
#if USE_ENTRY
if (0 != m_window.idx)
{
entry::destroyWindow(m_window);
}
#endif // USE_ENTRY
}
virtual bool Init(ImGuiWM::PlatformWindow* /*_parent*/) BX_OVERRIDE
{
return true;
}
virtual const ImVec2& GetPosition() const BX_OVERRIDE
{
return m_pos;
}
virtual const ImVec2& GetSize() const BX_OVERRIDE
{
return m_size;
}
virtual void Show() BX_OVERRIDE
{
}
virtual void Hide() BX_OVERRIDE
{
}
virtual void SetSize(const ImVec2& _size) BX_OVERRIDE
{
#if USE_ENTRY
if (0 != m_window.idx
&& m_size.x != _size.x
&& m_size.y != _size.y)
{
entry::setWindowSize(m_window, int32_t(_size.x), int32_t(_size.y) );
}
#endif // USE_ENTRY
m_size = _size;
}
virtual void SetPosition(const ImVec2& _pos) BX_OVERRIDE
{
#if USE_ENTRY
if (0 != m_window.idx
&& m_pos.x != _pos.x
&& m_pos.y != _pos.y)
{
entry::setWindowPos(m_window, int32_t(_pos.x), int32_t(_pos.y) );
}
#endif // USE_ENTRY
m_pos = _pos;
}
virtual void SetTitle(const char* _title) BX_OVERRIDE
{
#if USE_ENTRY
entry::setWindowTitle(m_window, _title);
#else
BX_UNUSED(_title);
#endif // USE_ENTRY
}
virtual void PreUpdate() BX_OVERRIDE
{
}
virtual void PaintBegin() BX_OVERRIDE;
virtual void Paint() BX_OVERRIDE;
virtual void PaintEnd() BX_OVERRIDE;
virtual void Destroy() BX_OVERRIDE
{
}
virtual void StartDrag() BX_OVERRIDE
{
m_drag = true;
}
virtual void StopDrag() BX_OVERRIDE
{
m_drag = false;
}
virtual bool IsDraging() BX_OVERRIDE
{
return m_drag;
}
private:
ImVec2 m_pos;
ImVec2 m_size;
bool m_drag;
#if USE_ENTRY
entry::WindowHandle m_window;
#endif // USE_ENTRY
};
class WindowManager : public ImGuiWM::WindowManager
{
typedef ImGuiWM::WindowManager Super;
public:
WindowManager()
{
}
virtual ~WindowManager()
{
}
protected:
virtual ImGuiWM::PlatformWindow* CreatePlatformWindow(bool _main, ImGuiWM::PlatformWindow* _parent, bool _isDragWindow) BX_OVERRIDE
{
#if USE_ENTRY
#else
if (!_main
&& !_isDragWindow)
{
return NULL;
}
#endif // USE_ENTRY
PlatformWindow* window = new (ImGui::MemAlloc(sizeof(PlatformWindow) ) ) PlatformWindow(_main, _isDragWindow);
window->Init(_parent);
return static_cast<ImGuiWM::PlatformWindow*>(window);
}
virtual void LogFormatted(const char* _str) BX_OVERRIDE
{
BX_TRACE("%s", _str); BX_UNUSED(_str);
}
virtual void InternalRun() BX_OVERRIDE
{
PreUpdate();
Update();
}
};
struct OcornutImguiContext
{
static void* memAlloc(size_t _size);
@ -483,60 +307,12 @@ struct OcornutImguiContext
, bgfx::copy(data, width*height*4)
);
m_wm = BX_NEW(m_allocator, WindowManager);
m_wm->Init();
#if 0
{
class Window : public ImGuiWM::Window
{
public:
Window(const char* _title)
: ImGuiWM::Window()
{
SetTitle(_title);
}
virtual void OnGui() BX_OVERRIDE
{
}
};
class WindowX : public ImGuiWM::Window
{
public:
WindowX(const char* _title)
: ImGuiWM::Window()
{
SetTitle(_title);
}
virtual void OnGui() BX_OVERRIDE
{
#if defined(SCI_NAMESPACE) && 0
bool opened = true;
ImGuiScintilla("Scintilla Editor", &opened, ImVec2(640.0f, 480.0f) );
#endif // 0
}
};
Window* w0 = new Window("test");
WindowX* w1 = new WindowX("Scintilla");
Window* w2 = new Window("xyzw");
Window* w3 = new Window("0123");
m_wm->Dock(w0);
m_wm->DockWith(w1, w0, ImGuiWM::E_DOCK_ORIENTATION_RIGHT);
m_wm->DockWith(w2, w1, ImGuiWM::E_DOCK_ORIENTATION_BOTTOM);
m_wm->DockWith(w3, w0, ImGuiWM::E_DOCK_ORIENTATION_BOTTOM);
}
#endif // 0
ImGui::InitDockContext();
}
void destroy()
{
m_wm->Exit();
BX_DELETE(m_allocator, m_wm);
ImGui::ShutdownDockContext();
ImGui::Shutdown();
bgfx::destroyUniform(s_tex);
@ -656,36 +432,10 @@ struct OcornutImguiContext
ImGui::NewFrame();
ImGuizmo::BeginFrame();
ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
#if 0
ImGui::ShowTestWindow(); //Debug only.
#endif // 0
#if 0
{
static ImGui::MemoryEditor me;
bool open = true;
if (ImGui::Begin("HexII", &open))
{
me.Draw(s_iconsKenneyTtf, sizeof(s_iconsKenneyTtf) );
ImGui::End();
}
}
#endif // 0
#if 0
{
extern void ShowExampleAppCustomNodeGraph(bool* opened);
bool opened = true;
ShowExampleAppCustomNodeGraph(&opened);
}
#endif // 0
}
void endFrame()
{
m_wm->Run();
ImGui::PopStyleVar(1);
ImGui::Render();
}
@ -696,114 +446,13 @@ struct OcornutImguiContext
bgfx::TextureHandle m_texture;
bgfx::UniformHandle s_tex;
ImFont* m_font[ImGui::Font::Count];
WindowManager* m_wm;
int64_t m_last;
int32_t m_lastScroll;
uint8_t m_viewId;
#if USE_ENTRY
struct Window
{
Window()
{
m_fbh.idx = bgfx::invalidHandle;
}
entry::WindowState m_state;
PlatformWindow* m_pw;
bgfx::FrameBufferHandle m_fbh;
uint8_t m_viewId;
};
Window m_window[16];
#endif // USE_ENTRY
};
static OcornutImguiContext s_ctx;
void PlatformWindow::PaintBegin()
{
#if USE_ENTRY
if (!m_bIsDragWindow)
{
OcornutImguiContext::Window& win = s_ctx.m_window[m_window.idx];
entry::WindowState& state = win.m_state;
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2((float)state.m_mouse.m_mx, (float)state.m_mouse.m_my);
io.MouseDown[0] = !!state.m_mouse.m_buttons[entry::MouseButton::Left];
io.MouseDown[1] = !!state.m_mouse.m_buttons[entry::MouseButton::Right];
io.MouseDown[2] = !!state.m_mouse.m_buttons[entry::MouseButton::Middle];
io.MouseWheel = float(state.m_mouse.m_mz);
ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)win.m_viewId);
}
#endif // USE_ENTRY
}
void PlatformWindow::Paint()
{
if (!m_bIsDragWindow)
{
Super::Paint();
}
}
void PlatformWindow::PaintEnd()
{
#if USE_ENTRY
if (!m_bIsDragWindow)
{
ImGui::PopStyleVar(1);
entry::WindowState& state = s_ctx.m_window[0].m_state;
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2((float)state.m_mouse.m_mx, (float)state.m_mouse.m_my);
io.MouseDown[0] = !!state.m_mouse.m_buttons[entry::MouseButton::Left];
io.MouseDown[1] = !!state.m_mouse.m_buttons[entry::MouseButton::Right];
io.MouseDown[2] = !!state.m_mouse.m_buttons[entry::MouseButton::Middle];
io.MouseWheel = float(state.m_mouse.m_mz);
}
#endif // USE_ENTRY
}
#if USE_ENTRY
void pwToWindow(entry::WindowHandle _handle, PlatformWindow* _pw)
{
s_ctx.m_window[_handle.idx].m_pw = _pw;
}
void imguiUpdateWindow(const entry::WindowState& _state)
{
OcornutImguiContext::Window& window = s_ctx.m_window[_state.m_handle.idx];
if (window.m_state.m_nwh != _state.m_nwh
|| (window.m_state.m_width != _state.m_width
|| window.m_state.m_height != _state.m_height) )
{
// When window changes size or native window handle changed
// frame buffer must be recreated.
if (bgfx::isValid(window.m_fbh) )
{
bgfx::destroyFrameBuffer(window.m_fbh);
window.m_fbh.idx = bgfx::invalidHandle;
}
if (NULL != _state.m_nwh)
{
window.m_fbh = bgfx::createFrameBuffer(_state.m_nwh, _state.m_width, _state.m_height);
window.m_viewId = 200 + _state.m_handle.idx;
}
else
{
window.m_viewId = s_ctx.m_viewId;
}
}
memcpy(&window.m_state, &_state, sizeof(entry::WindowState) );
}
#endif // USE_ENTRY
void* OcornutImguiContext::memAlloc(size_t _size)
{
return BX_ALLOC(s_ctx.m_allocator, _size);