Debug Draw
This commit is contained in:
@ -58,8 +58,6 @@ namespace ia::iae::game
|
|||||||
scene->AddNode(obstacle);
|
scene->AddNode(obstacle);
|
||||||
|
|
||||||
Engine::ChangeScene(scene.get());
|
Engine::ChangeScene(scene.get());
|
||||||
|
|
||||||
DebugDraw::AddDebugUIWindow("Dsd", {100.0f, 100.0f}, {100.0f, 100.0f}, [](){});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Game::Terminate()
|
VOID Game::Terminate()
|
||||||
|
|||||||
@ -34,7 +34,35 @@ namespace ia::iae
|
|||||||
|
|
||||||
ImGuiIO g_imGUIIO{};
|
ImGuiIO g_imGUIIO{};
|
||||||
|
|
||||||
Vector<DebugDraw::DebugUIWindow> DebugDraw::s_debugUIWindows;
|
struct ShapeLine
|
||||||
|
{
|
||||||
|
ImVec2 To{};
|
||||||
|
ImVec2 From{};
|
||||||
|
ImColor Color{};
|
||||||
|
FLOAT32 Thickness{1.0f};
|
||||||
|
BOOL Visibility{true};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ShapeRect
|
||||||
|
{
|
||||||
|
ImVec2 TopLeft{};
|
||||||
|
ImVec2 BottomRight{};
|
||||||
|
ImColor Color{};
|
||||||
|
BOOL Visibility{true};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIWindow
|
||||||
|
{
|
||||||
|
PCCHAR Title{""};
|
||||||
|
glm::vec2 Position{};
|
||||||
|
glm::vec2 Size{};
|
||||||
|
std::function<VOID()> ContentDrawCallback{};
|
||||||
|
BOOL Visibility{true};
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<UIWindow> g_debugUIWindows;
|
||||||
|
Vector<ShapeLine> g_lineShapes;
|
||||||
|
Vector<ShapeRect> g_rectShapes;
|
||||||
|
|
||||||
VOID DebugDraw::Initailize()
|
VOID DebugDraw::Initailize()
|
||||||
{
|
{
|
||||||
@ -69,27 +97,93 @@ namespace ia::iae
|
|||||||
|
|
||||||
VOID DebugDraw::Draw()
|
VOID DebugDraw::Draw()
|
||||||
{
|
{
|
||||||
for (const auto &w : s_debugUIWindows)
|
for (const auto &w : g_debugUIWindows)
|
||||||
{
|
{
|
||||||
|
if (!w.Visibility)
|
||||||
|
continue;
|
||||||
ImGui::Begin(w.Title);
|
ImGui::Begin(w.Title);
|
||||||
ImGui::SetWindowPos({w.Position.x, w.Position.y});
|
ImGui::SetWindowPos({w.Position.x, w.Position.y});
|
||||||
ImGui::SetWindowSize({w.Size.x, w.Size.y});
|
ImGui::SetWindowSize({w.Size.x, w.Size.y});
|
||||||
w.ContentDrawCallback();
|
w.ContentDrawCallback();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
const auto drawList = ImGui::GetForegroundDrawList();
|
||||||
|
for (const auto &t : g_lineShapes)
|
||||||
VOID DebugDraw::DrawLine(IN CONST glm::vec2 &from, IN CONST glm::vec2 &to, IN CONST glm::vec4 &color)
|
|
||||||
{
|
{
|
||||||
|
if (!t.Visibility)
|
||||||
|
continue;
|
||||||
|
drawList->AddLine(t.From, t.To, t.Color, t.Thickness);
|
||||||
}
|
}
|
||||||
|
for (const auto &t : g_rectShapes)
|
||||||
VOID DebugDraw::DrawRect(IN CONST glm::vec2 &position, IN CONST glm::vec2 &size, IN CONST glm::vec4 &color)
|
|
||||||
{
|
{
|
||||||
|
if (!t.Visibility)
|
||||||
|
continue;
|
||||||
|
drawList->AddRectFilled(t.TopLeft, t.BottomRight, t.Color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID DebugDraw::AddDebugUIWindow(IN PCCHAR title, IN CONST glm::vec2 &position, IN CONST glm::vec2 &size,
|
Handle DebugDraw::AddLine(IN CONST glm::vec2 &from, IN CONST glm::vec2 &to, IN CONST glm::vec4 &color,
|
||||||
|
IN FLOAT32 thickness)
|
||||||
|
{
|
||||||
|
g_lineShapes.pushBack(ShapeLine{.To = ImVec2{to.x, to.y},
|
||||||
|
.From = ImVec2{from.x, from.y},
|
||||||
|
.Color = IM_COL32(color.x * 255, color.y * 255, color.z * 255, color.w * 255),
|
||||||
|
.Thickness = thickness});
|
||||||
|
return g_lineShapes.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle DebugDraw::AddRect(IN CONST glm::vec2 &position, IN CONST glm::vec2 &size, IN CONST glm::vec4 &color)
|
||||||
|
{
|
||||||
|
g_rectShapes.pushBack({
|
||||||
|
.TopLeft =
|
||||||
|
ImVec2{
|
||||||
|
position.x,
|
||||||
|
position.y,
|
||||||
|
},
|
||||||
|
.BottomRight =
|
||||||
|
ImVec2{
|
||||||
|
position.x + size.x,
|
||||||
|
position.y + size.y,
|
||||||
|
},
|
||||||
|
.Color = IM_COL32(color.x * 255, color.y * 255, color.z * 255, color.w * 255),
|
||||||
|
});
|
||||||
|
return g_rectShapes.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle DebugDraw::AddUIWindow(IN PCCHAR title, IN CONST glm::vec2 &position, IN CONST glm::vec2 &size,
|
||||||
IN std::function<VOID()> contentDrawCallback)
|
IN std::function<VOID()> contentDrawCallback)
|
||||||
{
|
{
|
||||||
s_debugUIWindows.pushBack(DebugUIWindow{title, position, size, contentDrawCallback});
|
g_debugUIWindows.pushBack(UIWindow{title, position, size, contentDrawCallback});
|
||||||
|
return g_debugUIWindows.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DebugDraw::SetLineVisibility(IN Handle handle, IN BOOL visible)
|
||||||
|
{
|
||||||
|
g_lineShapes[handle].Visibility = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DebugDraw::SetRectVisibility(IN Handle handle, IN BOOL visible)
|
||||||
|
{
|
||||||
|
g_rectShapes[handle].Visibility = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DebugDraw::SetUIWindowVisibility(IN Handle handle, IN BOOL visible)
|
||||||
|
{
|
||||||
|
g_debugUIWindows[handle].Visibility = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DebugDraw::ToggleLineVisibility(IN Handle handle)
|
||||||
|
{
|
||||||
|
g_lineShapes[handle].Visibility = !g_lineShapes[handle].Visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DebugDraw::ToggleRectVisibility(IN Handle handle)
|
||||||
|
{
|
||||||
|
g_rectShapes[handle].Visibility = !g_rectShapes[handle].Visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID DebugDraw::ToggleUIWindowVisibility(IN Handle handle)
|
||||||
|
{
|
||||||
|
g_debugUIWindows[handle].Visibility = !g_debugUIWindows[handle].Visibility;
|
||||||
}
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
@ -22,29 +22,26 @@ namespace ia::iae
|
|||||||
{
|
{
|
||||||
class DebugDraw
|
class DebugDraw
|
||||||
{
|
{
|
||||||
struct DebugUIWindow
|
|
||||||
{
|
|
||||||
PCCHAR Title{""};
|
|
||||||
glm::vec2 Position{};
|
|
||||||
glm::vec2 Size{};
|
|
||||||
std::function<VOID()> ContentDrawCallback{};
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STATIC VOID DrawLine(IN CONST glm::vec2& from, IN CONST glm::vec2& to, IN CONST glm::vec4& color);
|
STATIC Handle AddLine(IN CONST glm::vec2& from, IN CONST glm::vec2& to, IN CONST glm::vec4& color, IN FLOAT32 thickness = 1.0f);
|
||||||
STATIC VOID DrawRect(IN CONST glm::vec2& position, IN CONST glm::vec2& size, IN CONST glm::vec4& color);
|
STATIC Handle AddRect(IN CONST glm::vec2& position, IN CONST glm::vec2& size, IN CONST glm::vec4& color);
|
||||||
|
STATIC Handle AddUIWindow(IN PCCHAR title, IN CONST glm::vec2 &position, IN CONST glm::vec2 &size,
|
||||||
STATIC VOID AddDebugUIWindow(IN PCCHAR title, IN CONST glm::vec2 &position, IN CONST glm::vec2 &size,
|
|
||||||
IN std::function<VOID()> contentDrawCallback);
|
IN std::function<VOID()> contentDrawCallback);
|
||||||
|
|
||||||
|
STATIC VOID SetLineVisibility(IN Handle handle, IN BOOL visible);
|
||||||
|
STATIC VOID SetRectVisibility(IN Handle handle, IN BOOL visible);
|
||||||
|
STATIC VOID SetUIWindowVisibility(IN Handle handle, IN BOOL visible);
|
||||||
|
|
||||||
|
STATIC VOID ToggleLineVisibility(IN Handle handle);
|
||||||
|
STATIC VOID ToggleRectVisibility(IN Handle handle);
|
||||||
|
STATIC VOID ToggleUIWindowVisibility(IN Handle handle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
STATIC VOID Initailize();
|
STATIC VOID Initailize();
|
||||||
STATIC VOID Terminate();
|
STATIC VOID Terminate();
|
||||||
|
|
||||||
STATIC VOID Draw();
|
STATIC VOID Draw();
|
||||||
|
|
||||||
STATIC Vector<DebugUIWindow> s_debugUIWindows;
|
|
||||||
|
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
};
|
};
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
Reference in New Issue
Block a user