mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-02-17 20:31:57 -05:00
Cleanup.
This commit is contained in:
parent
8a1df57bfb
commit
8ed1052779
2 changed files with 182 additions and 177 deletions
355
3rdparty/ocornut-imgui/imgui_wm.h
vendored
355
3rdparty/ocornut-imgui/imgui_wm.h
vendored
|
@ -19,13 +19,13 @@
|
|||
typedef unsigned int ImU32;
|
||||
|
||||
#ifndef ImwList
|
||||
# include <list>
|
||||
# define ImwList std::list
|
||||
# include <list>
|
||||
# define ImwList std::list
|
||||
#endif // ImList
|
||||
|
||||
#ifndef ImwMap
|
||||
# include <unordered_map>
|
||||
# define ImwMap std::unordered_map
|
||||
# include <unordered_map>
|
||||
# define ImwMap std::unordered_map
|
||||
#endif // ImMap
|
||||
|
||||
namespace ImWindow
|
||||
|
@ -39,14 +39,16 @@ namespace ImWindow
|
|||
E_DOCK_ORIENTATION_BOTTOM,
|
||||
};
|
||||
|
||||
struct ImwId
|
||||
class ImwId
|
||||
{
|
||||
public:
|
||||
ImwId();
|
||||
ImU32 GetId() const;
|
||||
const char* GetStr() const;
|
||||
|
||||
private:
|
||||
ImU32 m_iId;
|
||||
char m_pId[11];
|
||||
ImU32 m_iId;
|
||||
char m_pId[11];
|
||||
static int s_iNextId;
|
||||
};
|
||||
|
||||
|
@ -54,29 +56,30 @@ namespace ImWindow
|
|||
{
|
||||
friend class ImwWindowManager;
|
||||
friend class ImwContainer;
|
||||
|
||||
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:
|
||||
ImwWindow();
|
||||
virtual ~ImwWindow();
|
||||
public:
|
||||
virtual void OnGui() = 0;
|
||||
virtual void OnMenu() {};
|
||||
virtual ~ImwWindow();
|
||||
|
||||
const char* GetId() const { return m_oId.GetStr(); }
|
||||
char* m_pTitle;
|
||||
ImwId m_oId;
|
||||
|
||||
void Destroy();
|
||||
|
||||
void SetTitle(const char* pTitle);
|
||||
const char* GetTitle() const;
|
||||
|
||||
const ImVec2& GetLastPosition() const;
|
||||
const ImVec2& GetLastSize() const;
|
||||
protected:
|
||||
|
||||
char* m_pTitle;
|
||||
ImwId m_oId;
|
||||
|
||||
ImVec2 m_oLastPosition;
|
||||
ImVec2 m_oLastSize;
|
||||
ImVec2 m_oLastPosition;
|
||||
ImVec2 m_oLastSize;
|
||||
};
|
||||
|
||||
typedef ImwList<ImwWindow*> ImwWindowList;
|
||||
|
@ -88,86 +91,87 @@ namespace ImWindow
|
|||
friend class ImwPlatformWindow;
|
||||
|
||||
public:
|
||||
void Dock(ImwWindow* pWindow,EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER);
|
||||
bool UnDock(ImwWindow* pWindow);
|
||||
|
||||
void Dock(ImwWindow* pWindow, EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER);
|
||||
bool UnDock(ImwWindow* pWindow);
|
||||
bool IsEmpty();
|
||||
bool IsSplit();
|
||||
bool HasWindowTabbed();
|
||||
ImwContainer* HasWindow(const ImwWindow* pWindow);
|
||||
ImwPlatformWindow* GetPlatformWindowParent() const;
|
||||
ImwContainer* GetBestDocking(const ImVec2 oCursorPosInContainer,EDockOrientation& oOutOrientation,ImVec2& oOutAreaPos,ImVec2& oOutAreaSize);
|
||||
|
||||
bool IsEmpty();
|
||||
bool IsSplit();
|
||||
bool HasWindowTabbed();
|
||||
ImwContainer* HasWindow(const ImwWindow* pWindow);
|
||||
ImwPlatformWindow* GetPlatformWindowParent() const;
|
||||
ImwContainer* GetBestDocking(const ImVec2 oCursorPosInContainer, EDockOrientation& oOutOrientation, ImVec2& oOutAreaPos, ImVec2& oOutAreaSize);
|
||||
protected:
|
||||
ImwContainer(ImwContainer* pParent);
|
||||
ImwContainer(ImwPlatformWindow* pParent);
|
||||
~ImwContainer();
|
||||
|
||||
void CreateSplits();
|
||||
void CreateSplits();
|
||||
void Paint();
|
||||
|
||||
void Paint();
|
||||
ImwContainer* m_pParent;
|
||||
ImwPlatformWindow* m_pParentWindow;
|
||||
ImwWindowList m_lWindows;
|
||||
ImwContainer* m_pSplits[2];
|
||||
|
||||
ImwContainer* m_pParent;
|
||||
ImwPlatformWindow* m_pParentWindow;
|
||||
ImwWindowList m_lWindows;
|
||||
ImwContainer* m_pSplits[2];
|
||||
float m_fSplitRatio;
|
||||
bool m_bVerticalSplit;
|
||||
int m_iActiveWindow;
|
||||
|
||||
float m_fSplitRatio;
|
||||
bool m_bVerticalSplit;
|
||||
int m_iActiveWindow;
|
||||
bool m_bIsDrag;
|
||||
|
||||
bool m_bIsDrag;
|
||||
|
||||
ImVec2 m_oLastPosition;
|
||||
ImVec2 m_oLastSize;
|
||||
ImVec2 m_oLastPosition;
|
||||
ImVec2 m_oLastSize;
|
||||
};
|
||||
|
||||
class ImwPlatformWindow
|
||||
{
|
||||
friend class ImwWindowManager;
|
||||
|
||||
public:
|
||||
ImwPlatformWindow(bool bMainWindow, bool bIsDragWindow);
|
||||
virtual ~ImwPlatformWindow();
|
||||
ImwPlatformWindow(bool bMainWindow,bool bIsDragWindow);
|
||||
virtual ~ImwPlatformWindow();
|
||||
|
||||
virtual bool Init(ImwPlatformWindow* pParent) = 0;
|
||||
virtual bool Init(ImwPlatformWindow* pParent) = 0;
|
||||
|
||||
virtual const ImVec2& GetPosition() const = 0;
|
||||
virtual const ImVec2& GetSize() const = 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;
|
||||
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();
|
||||
bool IsMain();
|
||||
|
||||
void Dock(ImwWindow* pWindow);
|
||||
bool UnDock(ImwWindow* pWindow);
|
||||
void Dock(ImwWindow* pWindow);
|
||||
bool UnDock(ImwWindow* pWindow);
|
||||
|
||||
ImwContainer* GetContainer();
|
||||
ImwContainer* HasWindow(ImwWindow* pWindow);
|
||||
bool IsStateSet();
|
||||
|
||||
ImwContainer* GetContainer();
|
||||
ImwContainer* HasWindow(ImwWindow* pWindow);
|
||||
bool IsStateSet();
|
||||
protected:
|
||||
void SetState();
|
||||
void RestoreState();
|
||||
void OnLoseFocus();
|
||||
virtual void PreUpdate() = 0;
|
||||
virtual void Paint();
|
||||
virtual void Destroy() = 0;
|
||||
virtual void StartDrag() = 0;
|
||||
virtual void StopDrag() = 0;
|
||||
virtual bool IsDraging() = 0;
|
||||
void SetState();
|
||||
void RestoreState();
|
||||
void OnLoseFocus();
|
||||
virtual void PreUpdate() = 0;
|
||||
virtual void Paint();
|
||||
virtual void Destroy() = 0;
|
||||
virtual void StartDrag() = 0;
|
||||
virtual void StopDrag() = 0;
|
||||
virtual bool IsDraging() = 0;
|
||||
|
||||
void PaintContainer();
|
||||
void OnClose();
|
||||
void PaintContainer();
|
||||
void OnClose();
|
||||
|
||||
ImwId m_oId;
|
||||
bool m_bMain;
|
||||
bool m_bIsDragWindow;
|
||||
ImwContainer* m_pContainer;
|
||||
void* m_pState;
|
||||
void* m_pPreviousState;
|
||||
ImwId m_oId;
|
||||
bool m_bMain;
|
||||
bool m_bIsDragWindow;
|
||||
ImwContainer* m_pContainer;
|
||||
void* m_pState;
|
||||
void* m_pPreviousState;
|
||||
};
|
||||
|
||||
typedef ImwList<ImwPlatformWindow*> ImwPlatformWindowList;
|
||||
|
@ -180,134 +184,135 @@ namespace ImWindow
|
|||
|
||||
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,
|
||||
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,
|
||||
};
|
||||
|
||||
struct PlatformWindowAction
|
||||
{
|
||||
ImwPlatformWindow* m_pPlatformWindow;
|
||||
unsigned int m_iFlags;
|
||||
ImVec2 m_oPosition;
|
||||
ImVec2 m_oSize;
|
||||
ImwPlatformWindow* m_pPlatformWindow;
|
||||
unsigned int m_iFlags;
|
||||
ImVec2 m_oPosition;
|
||||
ImVec2 m_oSize;
|
||||
};
|
||||
|
||||
struct DockAction
|
||||
{
|
||||
ImwWindow* m_pWindow;
|
||||
ImwWindow* m_pWindow;
|
||||
|
||||
// Is Dock or Float
|
||||
bool m_bFloat;
|
||||
bool m_bFloat;
|
||||
|
||||
//For Docking
|
||||
ImwWindow* m_pWith;
|
||||
EDockOrientation m_eOrientation;
|
||||
ImwPlatformWindow* m_pToPlatformWindow;
|
||||
ImwContainer* m_pToContainer;
|
||||
ImwWindow* m_pWith;
|
||||
EDockOrientation m_eOrientation;
|
||||
ImwPlatformWindow* m_pToPlatformWindow;
|
||||
ImwContainer* m_pToContainer;
|
||||
|
||||
//For Floating
|
||||
ImVec2 m_oPosition;
|
||||
ImVec2 m_oSize;
|
||||
ImVec2 m_oPosition;
|
||||
ImVec2 m_oSize;
|
||||
};
|
||||
|
||||
struct DrawWindowAreaAction
|
||||
{
|
||||
DrawWindowAreaAction(ImwPlatformWindow* pWindow, const ImVec2& oRectPos, const ImVec2& oRectSize, const ImColor& oColor);
|
||||
ImwPlatformWindow* m_pWindow;
|
||||
ImVec2 m_oRectPos;
|
||||
ImVec2 m_oRectSize;
|
||||
ImColor m_oColor;
|
||||
DrawWindowAreaAction(ImwPlatformWindow* pWindow,const ImVec2& oRectPos,const ImVec2& oRectSize,const ImColor& oColor);
|
||||
ImwPlatformWindow* m_pWindow;
|
||||
ImVec2 m_oRectPos;
|
||||
ImVec2 m_oRectSize;
|
||||
ImColor m_oColor;
|
||||
};
|
||||
|
||||
public:
|
||||
struct Config
|
||||
{
|
||||
Config();
|
||||
float m_fDragMarginRatio;
|
||||
float m_fDragMarginSizeRatio;
|
||||
ImColor m_oHightlightAreaColor;
|
||||
float m_fDragMarginRatio;
|
||||
float m_fDragMarginSizeRatio;
|
||||
ImColor m_oHightlightAreaColor;
|
||||
};
|
||||
|
||||
ImwWindowManager();
|
||||
virtual ~ImwWindowManager();
|
||||
virtual ~ImwWindowManager();
|
||||
|
||||
bool Init();
|
||||
bool Run();
|
||||
void Exit();
|
||||
bool Init();
|
||||
bool Run();
|
||||
void Exit();
|
||||
|
||||
ImwPlatformWindow* GetMainPlatformWindow();
|
||||
Config& GetConfig();
|
||||
ImwPlatformWindow* GetMainPlatformWindow();
|
||||
Config& GetConfig();
|
||||
|
||||
void SetMainTitle(const char* pTitle);
|
||||
void SetMainTitle(const char* pTitle);
|
||||
|
||||
void Dock(ImwWindow* pWindow, EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER, ImwPlatformWindow* pToPlatformWindow = NULL);
|
||||
void DockTo(ImwWindow* pWindow, EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER, ImwContainer* pContainer = NULL);
|
||||
void DockWith(ImwWindow* pWindow, ImwWindow* pWithWindow, EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER);
|
||||
void Float(ImwWindow* pWindow, const ImVec2& oPosition = ImVec2(-1, -1), const ImVec2& oSize = ImVec2(-1, -1));
|
||||
void Dock(ImwWindow* pWindow,EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER,ImwPlatformWindow* pToPlatformWindow = NULL);
|
||||
void DockTo(ImwWindow* pWindow,EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER,ImwContainer* pContainer = NULL);
|
||||
void DockWith(ImwWindow* pWindow,ImwWindow* pWithWindow,EDockOrientation eOrientation = E_DOCK_ORIENTATION_CENTER);
|
||||
void Float(ImwWindow* pWindow,const ImVec2& oPosition = ImVec2(-1,-1),const ImVec2& oSize = ImVec2(-1,-1));
|
||||
|
||||
const ImwWindowList& GetWindowList() const;
|
||||
ImwPlatformWindow* GetCurrentPlatformWindow();
|
||||
ImwPlatformWindow* GetWindowParent(ImwWindow* pWindow);
|
||||
const ImwWindowList& GetWindowList() const;
|
||||
ImwPlatformWindow* GetCurrentPlatformWindow();
|
||||
ImwPlatformWindow* GetWindowParent(ImwWindow* pWindow);
|
||||
|
||||
void Log(const char* pFormat, ...);
|
||||
virtual void LogFormatted(const char* pStr) = 0;;
|
||||
protected:
|
||||
virtual ImwPlatformWindow* CreatePlatformWindow(bool bMain, ImwPlatformWindow* pParent, bool bDragWindow) = 0;
|
||||
virtual void InternalRun() = 0;
|
||||
virtual ImVec2 GetCursorPos() = 0;
|
||||
virtual bool IsLeftClickDown() = 0;
|
||||
void Log(const char* pFormat, ...);
|
||||
virtual void LogFormatted(const char* pStr) = 0;;
|
||||
|
||||
void AddWindow(ImwWindow* pWindow);
|
||||
void RemoveWindow(ImwWindow* pWindow);
|
||||
void DestroyWindow(ImwWindow* pWindow);
|
||||
|
||||
void InternalDock(ImwWindow* pWindow, EDockOrientation eOrientation, ImwPlatformWindow* pToPlatformWindow);
|
||||
void InternalDockTo(ImwWindow* pWindow, EDockOrientation eOrientation, ImwContainer* pToContainer);
|
||||
void InternalDockWith(ImwWindow* pWindow, ImwWindow* pWithWindow, EDockOrientation eOrientation);
|
||||
void InternalFloat(ImwWindow* pWindow, ImVec2 oPosition, ImVec2 oSize);
|
||||
void InternalUnDock(ImwWindow* pWindow);
|
||||
void InternalDrag(ImwWindow* pWindow);
|
||||
|
||||
void OnClosePlatformWindow(ImwPlatformWindow* pWindow);
|
||||
|
||||
void DrawWindowArea(ImwPlatformWindow* pWindow, const ImVec2& oPos, const ImVec2& oSize, const ImColor& oColor);
|
||||
|
||||
void PreUpdate();
|
||||
void Update();
|
||||
void UpdatePlatformwWindowActions();
|
||||
void UpdateDockActions();
|
||||
void UpdateOrphans();
|
||||
|
||||
void Paint(ImwPlatformWindow* pWindow);
|
||||
|
||||
void StartDragWindow(ImwWindow* pWindow);
|
||||
void StopDragWindow();
|
||||
void UpdateDragWindow();
|
||||
ImwContainer* GetBestDocking(ImwPlatformWindow* pPlatformWindow, const ImVec2 oCursorPos, EDockOrientation& oOutOrientation, ImVec2& oOutAreaPos, ImVec2& oOutAreaSize);
|
||||
|
||||
Config m_oConfig;
|
||||
ImwPlatformWindow* m_pMainPlatformWindow;
|
||||
ImwPlatformWindowList m_lPlatformWindows;
|
||||
ImwPlatformWindow* m_pDragPlatformWindow;
|
||||
ImwWindowList m_lWindows;
|
||||
ImwWindowList m_lOrphanWindows;
|
||||
ImwWindowList m_lToDestroyWindows;
|
||||
ImwPlatformWindowList m_lToDestroyPlatformWindows;
|
||||
ImwList<PlatformWindowAction*> m_lPlatformWindowActions;
|
||||
ImwList<DockAction*> m_lDockActions;
|
||||
ImwList<DrawWindowAreaAction> m_lDrawWindowAreas;
|
||||
|
||||
ImwPlatformWindow* m_pCurrentPlatformWindow;
|
||||
ImwWindow* m_pDraggedWindow;
|
||||
|
||||
ImVec2 m_oDragPreviewOffset;
|
||||
|
||||
// Static
|
||||
public:
|
||||
static ImwWindowManager* GetInstance();
|
||||
static ImwWindowManager* GetInstance();
|
||||
|
||||
protected:
|
||||
static ImwWindowManager* s_pInstance;
|
||||
virtual ImwPlatformWindow* CreatePlatformWindow(bool bMain,ImwPlatformWindow* pParent,bool bDragWindow) = 0;
|
||||
virtual void InternalRun() = 0;
|
||||
virtual ImVec2 GetCursorPos() = 0;
|
||||
virtual bool IsLeftClickDown() = 0;
|
||||
|
||||
void AddWindow(ImwWindow* pWindow);
|
||||
void RemoveWindow(ImwWindow* pWindow);
|
||||
void DestroyWindow(ImwWindow* pWindow);
|
||||
|
||||
void InternalDock(ImwWindow* pWindow,EDockOrientation eOrientation,ImwPlatformWindow* pToPlatformWindow);
|
||||
void InternalDockTo(ImwWindow* pWindow,EDockOrientation eOrientation,ImwContainer* pToContainer);
|
||||
void InternalDockWith(ImwWindow* pWindow,ImwWindow* pWithWindow,EDockOrientation eOrientation);
|
||||
void InternalFloat(ImwWindow* pWindow,ImVec2 oPosition,ImVec2 oSize);
|
||||
void InternalUnDock(ImwWindow* pWindow);
|
||||
void InternalDrag(ImwWindow* pWindow);
|
||||
|
||||
void OnClosePlatformWindow(ImwPlatformWindow* pWindow);
|
||||
|
||||
void DrawWindowArea(ImwPlatformWindow* pWindow,const ImVec2& oPos,const ImVec2& oSize,const ImColor& oColor);
|
||||
|
||||
void PreUpdate();
|
||||
void Update();
|
||||
void UpdatePlatformwWindowActions();
|
||||
void UpdateDockActions();
|
||||
void UpdateOrphans();
|
||||
|
||||
void Paint(ImwPlatformWindow* pWindow);
|
||||
|
||||
void StartDragWindow(ImwWindow* pWindow);
|
||||
void StopDragWindow();
|
||||
void UpdateDragWindow();
|
||||
ImwContainer* GetBestDocking(ImwPlatformWindow* pPlatformWindow,const ImVec2 oCursorPos,EDockOrientation& oOutOrientation,ImVec2& oOutAreaPos,ImVec2& oOutAreaSize);
|
||||
|
||||
Config m_oConfig;
|
||||
ImwPlatformWindow* m_pMainPlatformWindow;
|
||||
ImwPlatformWindowList m_lPlatformWindows;
|
||||
ImwPlatformWindow* m_pDragPlatformWindow;
|
||||
ImwWindowList m_lWindows;
|
||||
ImwWindowList m_lOrphanWindows;
|
||||
ImwWindowList m_lToDestroyWindows;
|
||||
ImwPlatformWindowList m_lToDestroyPlatformWindows;
|
||||
ImwList<PlatformWindowAction*> m_lPlatformWindowActions;
|
||||
ImwList<DockAction*> m_lDockActions;
|
||||
ImwList<DrawWindowAreaAction> m_lDrawWindowAreas;
|
||||
|
||||
ImwPlatformWindow* m_pCurrentPlatformWindow;
|
||||
ImwWindow* m_pDraggedWindow;
|
||||
|
||||
ImVec2 m_oDragPreviewOffset;
|
||||
|
||||
static ImwWindowManager* s_pInstance;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -313,9 +313,9 @@ struct OcornutImguiContext
|
|||
|
||||
m_decl
|
||||
.begin()
|
||||
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
||||
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
||||
.end();
|
||||
|
||||
s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Int1);
|
||||
|
|
Loading…
Reference in a new issue