Compare commits

...

3 Commits

Author SHA1 Message Date
OusmBlueNinja
d373951d91 Logs: Made it a table instead of a List 2025-01-04 23:26:13 -06:00
OusmBlueNinja
99d99280cc Added Escape To desellect 2025-01-04 23:21:26 -06:00
OusmBlueNinja
6d356f5597 Revamped Logger Window 2025-01-04 23:06:38 -06:00
7 changed files with 191 additions and 45 deletions

View File

@ -1,6 +1,6 @@
[Window][DockSpace]
Pos=0,0
Size=1920,1177
Size=1280,720
Collapsed=0
[Window][Debug##Default]
@ -80,8 +80,8 @@ Collapsed=0
DockId=0x0000001F,0
[Window][Performance##performance]
Pos=8,581
Size=335,588
Pos=8,360
Size=335,352
Collapsed=0
DockId=0x0000001C,0
@ -105,7 +105,7 @@ DockId=0x0000000F,0
[Window][Scene Window##SceneWindow]
Pos=8,28
Size=335,551
Size=335,330
Collapsed=0
DockId=0x0000001B,0
@ -134,29 +134,35 @@ Collapsed=0
DockId=0x0000001E,0
[Window][ Logger##logger]
Pos=345,739
Size=586,430
Pos=345,282
Size=265,430
Collapsed=0
DockId=0x00000021,0
[Window][ Editor##EditorWindow]
Pos=345,28
Size=1170,709
Size=530,252
Collapsed=0
DockId=0x0000001F,0
[Window][ Inspector##InspectorWindow]
Pos=1517,28
Size=395,1141
Pos=877,28
Size=395,684
Collapsed=0
DockId=0x00000022,0
[Window][ Profiler]
Pos=933,739
Size=582,430
Pos=612,282
Size=263,430
Collapsed=0
DockId=0x00000023,0
[Window][Logger Window]
Pos=345,282
Size=530,430
Collapsed=0
DockId=0x00000023,1
[Table][0xE9E836E4,4]
Column 0 Weight=1.2999
Column 1 Weight=1.0439
@ -169,8 +175,13 @@ Column 1 Weight=0.9086
Column 2 Weight=0.9665
Column 3 Weight=0.6950
[Table][0x801835C4,2]
RefScale=16
Column 0 Width=30
Column 1 Weight=1.0000
[Docking][Data]
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,51 Size=1904,1141 Split=X Selected=0xF7365A5A
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=146,189 Size=1264,684 Split=X Selected=0xF7365A5A
DockNode ID=0x00000020 Parent=0x14621557 SizeRef=884,684 Split=X
DockNode ID=0x00000013 Parent=0x00000020 SizeRef=335,1142 Split=Y Selected=0x818D04BB
DockNode ID=0x0000001B Parent=0x00000013 SizeRef=264,551 HiddenTabBar=1 Selected=0x1D5D92B6

View File

@ -166,8 +166,8 @@ Entities:
ScriptComponent:
ScriptPath: assets/scripts/camera.lua
Transform:
Position: [578.542908, 200, -169.946655]
Rotation: [0, 160.221146, 0]
Position: [881.214233, 200, -162.832016]
Rotation: [0, 170.205078, 0]
Scale: [1, 1, 1]
CameraComponent:
IsPerspective: true
@ -177,13 +177,16 @@ Entities:
NearPlane: 0.100000001
FarPlane: 7000
- ID: 2
Name: New GameObject 2
Name: Grey Cube
Components:
Mesh:
MeshPath: assets/models/DefaultMesh.obj
submeshes_len: 0
submeshes: ~
submeshes_len: 1
submeshes:
- vao: 53
indexCount: 36
textures: ~
Transform:
Position: [0, 0, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
Position: [-3.43110847, 248.891235, 0]
Rotation: [0, -0, 0]
Scale: [25, 25, 25]

View File

@ -140,7 +140,7 @@ void MeshComponent::Deserialize(const YAML::Node &node)
if (submeshes_len != static_cast<int>(model->submeshes.size()))
{
g_LoggerWindow->AddLog("[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
g_LoggerWindow->AddLog(LogLevel::Error, "[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
}
// Assign submeshes
@ -182,7 +182,7 @@ void MeshComponent::Deserialize(const YAML::Node &node)
}
if (submeshes_len != static_cast<int>(submeshes.size()))
{
g_LoggerWindow->AddLog("[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
g_LoggerWindow->AddLog(LogLevel::Error,"[Mesh] Size Mismatch [%d:%d]: Check for Curupted Scene Files", submeshes_len, static_cast<int>(submeshes.size()));
}
}
}

View File

@ -118,6 +118,7 @@ bool MyEngine::Init(int width, int height, const std::string &title)
#ifdef DEBUG
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable;
#endif
// Path to your font files
@ -184,13 +185,17 @@ bool MyEngine::Init(int width, int height, const std::string &title)
// Optionally, call 'onInit' Lua function
// Some initial logs
m_LoggerWindow->AddLog("Engine initialized.");
m_LoggerWindow->AddLog("Welcome to Tesseract Engine!");
m_Running = true;
m_LastTime = glfwGetTime();
DEBUG_PRINT("[OK] Engine Init ");
#ifdef DEBUG
g_LoggerWindow->AddLog(LogLevel::Warning, "Warning: You are in Debug Mode. Switch to Releace for more performance");
#endif
return true;
}

View File

@ -6,8 +6,9 @@
#include <cstdio>
#include "Icons.h"
#include "Engine/ScopedTimer.h"
#include "Icons.h"
// Helper function to format strings
static std::string FormatString(const char *fmt, va_list args)
{
char buffer[1024];
@ -15,6 +16,48 @@ static std::string FormatString(const char *fmt, va_list args)
return std::string(buffer);
}
// Choose a default icon for each LogLevel
static const char* GetIconForLevel(LogLevel level)
{
switch (level)
{
case LogLevel::Warning: return ICON_FA_TRIANGLE_EXCLAMATION;
case LogLevel::Error: return ICON_FA_CIRCLE_EXCLAMATION;
case LogLevel::Info:
default: return ICON_FA_INFO;
}
}
// Choose a default color for each LogLevel if none is specified.
static ImVec4 GetDefaultColorForLevel(LogLevel level)
{
switch (level)
{
case LogLevel::Warning: return ImVec4(1.0f, 0.8f, 0.0f, 1.0f); // Yellow-ish
case LogLevel::Error: return ImVec4(1.0f, 0.2f, 0.2f, 1.0f); // Reddish
case LogLevel::Info:
default: return ImVec4(0.8f, 0.8f, 0.8f, 1.0f); // Light gray
}
}
void LoggerWindow::AddLog(const char *fmt, std::optional<ImVec4> color, ...)
{
va_list args;
va_start(args, fmt);
std::string formatted = FormatString(fmt, args);
va_end(args);
LogEntry entry;
entry.text = formatted;
entry.level = LogLevel::Info;
entry.color = color;
entry.icon = GetIconForLevel(entry.level);
m_Logs.emplace_back(entry);
m_ScrollToBottom = true;
}
// 1) Existing method (no LogLevel) — default to Info
void LoggerWindow::AddLog(const char *fmt, ...)
{
va_list args;
@ -22,27 +65,62 @@ void LoggerWindow::AddLog(const char *fmt, ...)
std::string formatted = FormatString(fmt, args);
va_end(args);
m_Logs.emplace_back(formatted);
LogEntry entry;
entry.text = formatted;
entry.level = LogLevel::Info;
entry.color = std::nullopt; // We'll use the default color
entry.icon = GetIconForLevel(entry.level);
m_Logs.emplace_back(entry);
m_ScrollToBottom = true;
}
void LoggerWindow::AddLog(const char *fmt, std::optional<ImVec4> color, ...)
// 2) New method for specifying LogLevel
void LoggerWindow::AddLog(LogLevel level, const char *fmt, ...)
{
va_list args;
va_start(args, color);
va_start(args, fmt);
std::string formatted = FormatString(fmt, args);
va_end(args);
m_Logs.emplace_back(formatted, color);
LogEntry entry;
entry.text = formatted;
entry.level = level;
entry.color = std::nullopt; // Use default color for this level
entry.icon = GetIconForLevel(level);
m_Logs.emplace_back(entry);
m_ScrollToBottom = true;
}
// 3) New method for specifying LogLevel + an explicit color override
void LoggerWindow::AddLog(LogLevel level, const ImVec4 &color, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
std::string formatted = FormatString(fmt, args);
va_end(args);
LogEntry entry;
entry.text = formatted;
entry.level = level;
entry.color = color; // Explicit color override
entry.icon = GetIconForLevel(level);
m_Logs.emplace_back(entry);
m_ScrollToBottom = true;
}
void LoggerWindow::Show()
{
SCOPE_TIMER("LoggerWindow::Show");
// Window with an icon in the title
ImGui::Begin(ICON_FA_TERMINAL " Logger##logger");
// Clear button
if (ImGui::Button("Clear"))
{
m_Logs.clear();
@ -50,24 +128,54 @@ void LoggerWindow::Show()
ImGui::Separator();
// Begin a child region to enable scrolling
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
// Child region for scrollable area
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false,
ImGuiWindowFlags_HorizontalScrollbar);
// Optional: tweak cell-padding or other style before beginning the table
// ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4.0f, 4.0f));
// Begin the table with 2 columns
// - RowBg flag for striped rows
// - Borders for a neat grid
// - SizingFixedFit or SizingStretch can be chosen per preference
if (ImGui::BeginTable("LogTable", 2,
ImGuiTableFlags_SizingFixedFit |
ImGuiTableFlags_Borders |
ImGuiTableFlags_RowBg |
ImGuiTableFlags_Resizable))
{
// Optionally set up columns (width, name, etc.)
ImGui::TableSetupColumn("Icon", ImGuiTableColumnFlags_WidthFixed, 30.0f);
ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthStretch);
// If you want a header row (not strictly needed for a log)
// ImGui::TableHeadersRow();
// Loop over your log entries
for (const auto &logEntry : m_Logs)
{
if (logEntry.color.has_value())
{
ImGui::PushStyleColor(ImGuiCol_Text, logEntry.color.value());
ImVec4 color = logEntry.color.value_or(GetDefaultColorForLevel(logEntry.level));
// Start a new row
ImGui::TableNextRow();
// Column 0: Icon
ImGui::TableNextColumn();
ImGui::TextColored(color, "%s", logEntry.icon.c_str());
// Column 1: Text
ImGui::TableNextColumn();
ImGui::TextUnformatted(logEntry.text.c_str());
ImGui::PopStyleColor();
}
else
{
ImGui::TextUnformatted(logEntry.text.c_str());
}
}
// Auto-scroll to bottom if new logs are added
ImGui::EndTable();
}
// If you used PushStyleVar above, pop it here:
// ImGui::PopStyleVar();
// Auto-scroll to bottom if needed
if (m_ScrollToBottom)
{
ImGui::SetScrollHereY(1.0f);
@ -75,6 +183,6 @@ void LoggerWindow::Show()
}
ImGui::EndChild();
ImGui::End();
}

View File

@ -6,19 +6,31 @@
#include <string>
#include <optional>
#include <imgui.h>
#include "Icons.h"
struct LogEntry {
std::string text;
// Example: Different severity levels
enum class LogLevel
{
Info,
Warning,
Error
};
struct LogEntry
{
std::string text ;
LogLevel level;
std::optional<ImVec4> color;
LogEntry(const std::string& msg, std::optional<ImVec4> col = std::nullopt)
: text(msg), color(col) {}
std::string icon ;
};
class LoggerWindow {
public:
void AddLog(const char* fmt, ...);
void AddLog(const char* fmt, std::optional<ImVec4> color, ...);
void AddLog(LogLevel level, const char *fmt, ...);
void AddLog(LogLevel level, const ImVec4 &color, const char *fmt, ...);
void Show();
private:

View File

@ -29,6 +29,13 @@ std::shared_ptr<GameObject> CreateDefaultCube()
void SceneWindow::Show()
{
SCOPE_TIMER("SceneWindow::Show");
if (g_SelectedObject) {
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
g_SelectedObject = nullptr;
}
}
if (ImGui::Begin("Scene Window##SceneWindow"))
{
// Add Button