Made Inspector Look Better

This commit is contained in:
OusmBlueNinja 2024-12-25 17:42:58 -06:00
parent 6be1be5a51
commit ba20674570
2 changed files with 215 additions and 190 deletions

View File

@ -121,10 +121,10 @@ void MyEngine::Run()
double current_time = glfwGetTime(); double current_time = glfwGetTime();
double delta = current_time - m_LastTime; double delta = current_time - m_LastTime;
m_FrameCount++; m_FrameCount++;
if (delta >= 1.0) if (delta >= 0.1)
{ {
m_Fps = (float)(m_FrameCount / delta); m_Fps = (float)(m_FrameCount / delta);
m_Ms = 1000.0f / m_Fps; m_Ms = 100.0f / m_Fps;
m_FrameCount = 0; m_FrameCount = 0;
m_LastTime = current_time; m_LastTime = current_time;
} }

View File

@ -1,42 +1,31 @@
#include "InspectorWindow.h" #include "InspectorWindow.h"
#include <cstdio> // for printf, if needed #include <cstdio> // for debugging or printing if needed
#include <cstring> // for strcpy, if needed #include <cstring> // for strcpy, if needed
void InspectorWindow::Show(Transform &transform, Script &script) void InspectorWindow::Show(Transform& transform, Script& script)
{ {
// We can push additional style for a more Unity/Godot-like inspector // Increase window/item spacing for a cleaner look
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(12, 12)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(12, 12));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 4)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 4));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(8, 8)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 10));
// Optional: a slight color for window background
// (If you want to override the themes default)
// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.12f, 0.12f, 0.12f, 1.f));
if (ImGui::Begin("Inspector")) if (ImGui::Begin("Inspector"))
{ {
// Title or header-like text // Title label (white text)
{
// A mild accent color for the header text
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.9f, 0.85f, 0.2f, 1.f));
ImGui::TextUnformatted("Selected Object Inspector"); ImGui::TextUnformatted("Selected Object Inspector");
ImGui::PopStyleColor();
}
ImGui::Separator(); ImGui::Separator();
ImGui::Spacing(); ImGui::Spacing();
// ---------------- // ===========================
// TRANSFORM // 1) TRANSFORM
// ---------------- // ===========================
{ // Color the Transform header
// A bit of color or bold for the header ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 0.4f, 1.0f));
// Inside your InspectorWindow::Show(...) method, bool transformOpen = ImGui::CollapsingHeader("Transform##Main", ImGuiTreeNodeFlags_DefaultOpen);
// specifically within the Transform section: ImGui::PopStyleColor();
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) if (transformOpen)
{ {
// Provide a quick tooltip/hint on hover
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
{ {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
@ -44,124 +33,169 @@ void InspectorWindow::Show(Transform &transform, Script &script)
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
// ------------------------------------------ // -----------------------------------
// Position // Position
// ------------------------------------------ // -----------------------------------
if (ImGui::TreeNodeEx("Position", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth)) ImGui::TextUnformatted("Position");
{
// We'll do a custom layout with color-coded X, Y, Z labels
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "Position:");
ImGui::Spacing(); ImGui::Spacing();
// Colors for each axis: X=red, Y=green, Z=blue {
ImVec4 colX(1.0f, 0.4f, 0.4f, 1.0f); // We'll assign colors for X, Y, Z buttons
ImVec4 colY(0.4f, 1.0f, 0.4f, 1.0f); // (normal, hovered, active)
ImVec4 colZ(0.4f, 0.4f, 1.0f, 1.0f); static const ImVec4 colX = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
static const ImVec4 colXHover = ImVec4(1.0f, 0.6f, 0.6f, 1.0f);
static const ImVec4 colXActive= ImVec4(1.0f, 0.2f, 0.2f, 1.0f);
// Axis labels for reference static const ImVec4 colY = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
const char *axisLabels[3] = {"X", "Y", "Z"}; static const ImVec4 colYHover = ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
ImVec4 axisColors[3] = {colX, colY, colZ}; static const ImVec4 colYActive= ImVec4(0.2f, 1.0f, 0.2f, 1.0f);
float *pos = transform.position;
// We'll lay them out on one line with spacing static const ImVec4 colZ = ImVec4(0.4f, 0.4f, 1.0f, 1.0f);
ImGui::PushID("PositionFields"); static const ImVec4 colZHover = ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
static const ImVec4 colZActive= ImVec4(0.2f, 0.2f, 1.0f, 1.0f);
const char* axisNames[3] = { "X", "Y", "Z" };
// We'll reference transform.position here
float* pos = transform.position;
ImGui::PushID("PositionRow");
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
// Color-coded label // Determine color set
ImGui::TextColored(axisColors[i], "%s", axisLabels[i]); ImVec4 col, colH, colA;
ImGui::SameLine(); if (i == 0) { col = colX; colH = colXHover; colA = colXActive; }
else if (i == 1) { col = colY; colH = colYHover; colA = colYActive; }
else { col = colZ; colH = colZHover; colA = colZActive; }
// We push another ID so each DragFloat is unique // Push color style for button
ImGui::PushID(i); ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::SetNextItemWidth(60.0f); // or -1 for full stretch ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colH);
ImGui::DragFloat("##Pos", &pos[i], 0.1f); ImGui::PushStyleColor(ImGuiCol_ButtonActive, colA);
ImGui::PopID();
// Small spacing between each axis // Small button with the axis name
if (i < 2) if (ImGui::Button(axisNames[i], ImVec2(20, 0)))
{ {
ImGui::SameLine(0, 15); // No action on click, but we have a box with color
} }
ImGui::PopStyleColor(3);
ImGui::SameLine();
ImGui::SetNextItemWidth(60.0f);
ImGui::DragFloat((std::string("##Pos") + axisNames[i]).c_str(), &pos[i], 0.1f);
if (i < 2) ImGui::SameLine(0, 15);
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TreePop();
} }
ImGui::Spacing();
// ------------------------------------------ ImGui::Spacing();
ImGui::Separator();
// -----------------------------------
// Rotation // Rotation
// ------------------------------------------ // -----------------------------------
if (ImGui::TreeNodeEx("Rotation", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth)) ImGui::TextUnformatted("Rotation");
{
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "Rotation:");
ImGui::Spacing(); ImGui::Spacing();
ImVec4 colX(1.0f, 0.4f, 0.4f, 1.0f); {
ImVec4 colY(0.4f, 1.0f, 0.4f, 1.0f); // Same approach, but referencing transform.rotation
ImVec4 colZ(0.4f, 0.4f, 1.0f, 1.0f); const char* axisNames[3] = { "X", "Y", "Z" };
float* rot = transform.rotation;
const char *axisLabels[3] = {"X", "Y", "Z"}; // We can reuse the same color sets
ImVec4 axisColors[3] = {colX, colY, colZ}; ImGui::PushID("RotationRow");
float *rot = transform.rotation;
ImGui::PushID("RotationFields");
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
ImGui::TextColored(axisColors[i], "%s", axisLabels[i]); // Decide color sets for X, Y, Z
ImGui::SameLine(); ImVec4 col, colH, colA;
if (i == 0) {
col = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
colH= ImVec4(1.0f, 0.6f, 0.6f, 1.0f);
colA= ImVec4(1.0f, 0.2f, 0.2f, 1.0f);
}
else if (i == 1) {
col = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
colH= ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
colA= ImVec4(0.2f, 1.0f, 0.2f, 1.0f);
}
else {
col = ImVec4(0.4f, 0.4f, 1.0f, 1.0f);
colH= ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
colA= ImVec4(0.2f, 0.2f, 1.0f, 1.0f);
}
ImGui::PushID(i); ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::SetNextItemWidth(60.0f); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colH);
ImGui::DragFloat("##Rot", &rot[i], 0.1f); ImGui::PushStyleColor(ImGuiCol_ButtonActive, colA);
ImGui::PopID();
if (i < 2) if (ImGui::Button(axisNames[i], ImVec2(20, 0)))
{ {
ImGui::SameLine(0, 15); // No action
} }
ImGui::PopStyleColor(3);
ImGui::SameLine();
ImGui::SetNextItemWidth(60.0f);
ImGui::DragFloat((std::string("##Rot") + axisNames[i]).c_str(), &rot[i], 0.1f);
if (i < 2) ImGui::SameLine(0, 15);
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TreePop();
} }
ImGui::Spacing();
// ------------------------------------------ ImGui::Spacing();
ImGui::Separator();
// -----------------------------------
// Scale // Scale
// ------------------------------------------ // -----------------------------------
if (ImGui::TreeNodeEx("Scale", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth)) ImGui::TextUnformatted("Scale");
{
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "Scale:");
ImGui::Spacing(); ImGui::Spacing();
ImVec4 colX(1.0f, 0.4f, 0.4f, 1.0f); {
ImVec4 colY(0.4f, 1.0f, 0.4f, 1.0f); const char* axisNames[3] = { "X", "Y", "Z" };
ImVec4 colZ(0.4f, 0.4f, 1.0f, 1.0f); float* scl = transform.scale;
const char *axisLabels[3] = {"X", "Y", "Z"}; ImGui::PushID("ScaleRow");
ImVec4 axisColors[3] = {colX, colY, colZ};
float *scl = transform.scale;
ImGui::PushID("ScaleFields");
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
ImGui::TextColored(axisColors[i], "%s", axisLabels[i]); // same color approach
ImGui::SameLine(); ImVec4 col, colH, colA;
if (i == 0) {
col = ImVec4(1.0f, 0.4f, 0.4f, 1.0f);
colH= ImVec4(1.0f, 0.6f, 0.6f, 1.0f);
colA= ImVec4(1.0f, 0.2f, 0.2f, 1.0f);
}
else if (i == 1) {
col = ImVec4(0.4f, 1.0f, 0.4f, 1.0f);
colH= ImVec4(0.6f, 1.0f, 0.6f, 1.0f);
colA= ImVec4(0.2f, 1.0f, 0.2f, 1.0f);
}
else {
col = ImVec4(0.4f, 0.4f, 1.0f, 1.0f);
colH= ImVec4(0.6f, 0.6f, 1.0f, 1.0f);
colA= ImVec4(0.2f, 0.2f, 1.0f, 1.0f);
}
ImGui::PushID(i); ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::SetNextItemWidth(60.0f); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colH);
ImGui::DragFloat("##Scale", &scl[i], 0.1f); ImGui::PushStyleColor(ImGuiCol_ButtonActive, colA);
ImGui::PopID();
if (i < 2) if (ImGui::Button(axisNames[i], ImVec2(20, 0)))
{ {
ImGui::SameLine(0, 15); // No action
} }
ImGui::PopStyleColor(3);
ImGui::SameLine();
ImGui::SetNextItemWidth(60.0f);
ImGui::DragFloat((std::string("##Scl") + axisNames[i]).c_str(), &scl[i], 0.1f);
if (i < 2) ImGui::SameLine(0, 15);
} }
ImGui::PopID(); ImGui::PopID();
ImGui::TreePop();
} }
ImGui::Spacing(); ImGui::Spacing();
@ -169,31 +203,26 @@ void InspectorWindow::Show(Transform &transform, Script &script)
} }
ImGui::Spacing(); ImGui::Spacing();
}
// ---------------- // ===========================
// SCRIPT // 2) SCRIPT
// ---------------- // ===========================
{ // We keep script text in white
if (ImGui::CollapsingHeader("Script##Inspector", ImGuiTreeNodeFlags_DefaultOpen)) if (ImGui::CollapsingHeader("Script##Main", ImGuiTreeNodeFlags_DefaultOpen))
{ {
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered())
{ {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
ImGui::TextUnformatted("Attach a script (logic) to this object."); ImGui::TextUnformatted("Attach a script or logic component here.");
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
// Script Name ImGui::TextUnformatted("Script Name:");
ImGui::TextColored(ImVec4(0.9f, 0.9f, 0.9f, 1.0f), "Script Name:");
ImGui::SameLine(); ImGui::SameLine();
{
// We'll allocate a buffer to edit the script name
char buffer[128];
// Copy the current name into the buffer
std::snprintf(buffer, sizeof(buffer), "%s", script.scriptName.c_str());
// Provide an input text {
char buffer[128];
std::snprintf(buffer, sizeof(buffer), "%s", script.scriptName.c_str());
ImGui::SetNextItemWidth(-1); ImGui::SetNextItemWidth(-1);
if (ImGui::InputText("##ScriptName", buffer, sizeof(buffer))) if (ImGui::InputText("##ScriptName", buffer, sizeof(buffer)))
{ {
@ -201,22 +230,18 @@ void InspectorWindow::Show(Transform &transform, Script &script)
} }
} }
// Enabled? ImGui::Spacing();
ImGui::Checkbox("Enabled##ScriptEnabled", &script.enabled);
// In a real engine, you might display all public fields of the script here ImGui::TextUnformatted("Script Enabled:");
// e.g., float moveSpeed, int health, etc. ImGui::SameLine();
ImGui::Checkbox("##ScriptEnabled", &script.enabled);
ImGui::Spacing(); ImGui::Spacing();
ImGui::Separator(); ImGui::Separator();
} }
} }
}
ImGui::End(); ImGui::End();
// Pop the potential override color if used
// ImGui::PopStyleColor();
// Restore style // Restore style
ImGui::PopStyleVar(3); ImGui::PopStyleVar(3);
} }