This repository was archived by the owner on Jan 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitan_Debug.hpp
More file actions
214 lines (178 loc) · 4.76 KB
/
Copy pathTitan_Debug.hpp
File metadata and controls
214 lines (178 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* Titan Debug System
*
* Immediate Mode Debug UI
* Follows Unreal Engine naming conventions
*/
#ifndef TITAN_DEBUG_HPP
#define TITAN_DEBUG_HPP
#include "Titan_Core.hpp"
#include <vector>
#include <cstdio>
#include <cstdarg>
// Forward declarations
namespace Titan::Assets { struct Font; }
namespace Titan::Graphics { struct TextureHandle; }
namespace Titan::Debug {
// ============================================================================
// Draw Command Structure
// ============================================================================
struct FDrawCommand
{
uint32 Type; // 0 = Rect, 1 = Text
float X, Y;
float Width, Height;
Math::Vec4 Color;
char Text[64];
};
// ============================================================================
// Debug Context
// ============================================================================
struct FDebugContext
{
float CursorX = 10.0f;
float CursorY = 10.0f;
float StartX = 10.0f;
float StartY = 10.0f;
float Padding = 5.0f;
bool bIsActive = true;
Assets::Font* Font = nullptr;
std::vector<FDrawCommand> Commands;
Math::Vec2 MousePosition;
bool bMouseClicked = false;
};
// ============================================================================
// Global Context Access (defined in .cpp)
// ============================================================================
FDebugContext& GetContext();
// ============================================================================
// Debug API
// ============================================================================
void Initialize();
void Shutdown();
void Begin();
void End();
bool Button(const char* Label);
void Text(const char* Format, ...);
void Rect(float X, float Y, float Width, float Height, const Math::Vec4& Color);
void SetActive(bool bActive);
bool IsActive();
// ============================================================================
// Inline Implementations
// ============================================================================
inline void Begin()
{
auto& Ctx = GetContext();
if (!Ctx.bIsActive)
{
return;
}
Ctx.Commands.clear();
Ctx.CursorX = Ctx.StartX;
Ctx.CursorY = Ctx.StartY;
}
inline void End()
{
// Nothing to do - commands are processed by render system
}
inline bool Button(const char* Label)
{
auto& Ctx = GetContext();
if (!Ctx.bIsActive)
{
return false;
}
float Width = 150.0f;
float Height = 30.0f;
bool bHover = (Ctx.MousePosition.x >= Ctx.CursorX &&
Ctx.MousePosition.x <= Ctx.CursorX + Width &&
Ctx.MousePosition.y >= Ctx.CursorY &&
Ctx.MousePosition.y <= Ctx.CursorY + Height);
bool bPressed = bHover && Ctx.bMouseClicked;
Math::Vec4 Color;
if (bPressed)
{
Color = {0.1f, 0.6f, 0.1f, 1.0f};
}
else if (bHover)
{
Color = {0.4f, 0.4f, 0.4f, 0.9f};
}
else
{
Color = {0.2f, 0.2f, 0.2f, 0.8f};
}
FDrawCommand RectCmd;
RectCmd.Type = 0;
RectCmd.X = Ctx.CursorX;
RectCmd.Y = Ctx.CursorY;
RectCmd.Width = Width;
RectCmd.Height = Height;
RectCmd.Color = Color;
RectCmd.Text[0] = '\0';
Ctx.Commands.push_back(RectCmd);
FDrawCommand TextCmd;
TextCmd.Type = 1;
TextCmd.X = Ctx.CursorX + 10.0f;
TextCmd.Y = Ctx.CursorY + 20.0f;
TextCmd.Width = 0;
TextCmd.Height = 0;
TextCmd.Color = {1.0f, 1.0f, 1.0f, 1.0f};
strncpy(TextCmd.Text, Label, 63);
TextCmd.Text[63] = '\0';
Ctx.Commands.push_back(TextCmd);
Ctx.CursorY += Height + Ctx.Padding;
return bPressed;
}
inline void Text(const char* Format, ...)
{
auto& Ctx = GetContext();
if (!Ctx.bIsActive)
{
return;
}
char Buffer[64];
va_list Args;
va_start(Args, Format);
vsnprintf(Buffer, 63, Format, Args);
va_end(Args);
Buffer[63] = '\0';
FDrawCommand Cmd;
Cmd.Type = 1;
Cmd.X = Ctx.CursorX;
Cmd.Y = Ctx.CursorY + 16.0f;
Cmd.Width = 0;
Cmd.Height = 0;
Cmd.Color = {1.0f, 1.0f, 1.0f, 1.0f};
strncpy(Cmd.Text, Buffer, 63);
Cmd.Text[63] = '\0';
Ctx.Commands.push_back(Cmd);
Ctx.CursorY += 20.0f + Ctx.Padding;
}
inline void Rect(float X, float Y, float Width, float Height, const Math::Vec4& Color)
{
auto& Ctx = GetContext();
if (!Ctx.bIsActive)
{
return;
}
FDrawCommand Cmd;
Cmd.Type = 0;
Cmd.X = X;
Cmd.Y = Y;
Cmd.Width = Width;
Cmd.Height = Height;
Cmd.Color = Color;
Cmd.Text[0] = '\0';
Ctx.Commands.push_back(Cmd);
}
inline void SetActive(bool bActive)
{
GetContext().bIsActive = bActive;
}
inline bool IsActive()
{
return GetContext().bIsActive;
}
} // namespace Titan::Debug
#endif // TITAN_DEBUG_HPP