|
|
|
|
/******************************************************************************
|
|
|
|
|
* File - component_guis.cpp
|
|
|
|
|
* Author - Joey Pollack
|
|
|
|
|
* Date - 2022/06/01 (y/m/d)
|
|
|
|
|
* Mod Date - 2022/06/01 (y/m/d)
|
|
|
|
|
* Description - Functions to render component editing GUIs
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "component_guis.h"
|
|
|
|
|
#include <editor/editor.h>
|
|
|
|
|
#include <utils/logger.h>
|
|
|
|
|
#include <dearimgui/imgui.h>
|
|
|
|
|
#include <dearimgui/imgui_internal.h>
|
|
|
|
|
|
|
|
|
|
namespace lunarium { namespace editor
|
|
|
|
|
{
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
// HELPERS
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/// This function was taken from the Hazel engine written by Cherno!
|
|
|
|
|
/// https://github.com/TheCherno/Hazel/blob/master/Hazelnut/src/Panels/SceneHierarchyPanel.cpp
|
|
|
|
|
static void DrawVec3Control(const std::string& label, glm::vec3& values, float resetValue = 0.0f, float columnWidth = 100.0f)
|
|
|
|
|
{
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
auto boldFont = io.Fonts->Fonts[0];
|
|
|
|
|
|
|
|
|
|
ImGui::PushID(label.c_str());
|
|
|
|
|
|
|
|
|
|
ImGui::Columns(2);
|
|
|
|
|
ImGui::SetColumnWidth(0, columnWidth);
|
|
|
|
|
ImGui::Text(label.c_str());
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
|
|
|
|
|
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
|
|
|
|
|
|
|
|
|
float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
|
|
|
|
ImVec2 buttonSize = { lineHeight + 3.0f, lineHeight };
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 0.2f, 0.2f, 1.0f });
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
|
|
|
|
ImGui::PushFont(boldFont);
|
|
|
|
|
if (ImGui::Button("X", buttonSize))
|
|
|
|
|
values.x = resetValue;
|
|
|
|
|
ImGui::PopFont();
|
|
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::DragFloat("##X", &values.x, 0.1f, 0.0f, 0.0f, "%.2f");
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.3f, 0.8f, 0.3f, 1.0f });
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
|
|
|
|
ImGui::PushFont(boldFont);
|
|
|
|
|
if (ImGui::Button("Y", buttonSize))
|
|
|
|
|
values.y = resetValue;
|
|
|
|
|
ImGui::PopFont();
|
|
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::DragFloat("##Y", &values.y, 0.1f, 0.0f, 0.0f, "%.2f");
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f });
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.2f, 0.35f, 0.9f, 1.0f });
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f });
|
|
|
|
|
ImGui::PushFont(boldFont);
|
|
|
|
|
if (ImGui::Button("Z", buttonSize))
|
|
|
|
|
values.z = resetValue;
|
|
|
|
|
ImGui::PopFont();
|
|
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::DragFloat("##Z", &values.z, 0.1f, 0.0f, 0.0f, "%.2f");
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
|
|
ImGui::Columns(1);
|
|
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompGui::RenderTagComp(TagComponent& comp)
|
|
|
|
|
{
|
|
|
|
|
const int BUFFER_SIZE = 256;
|
|
|
|
|
static char buffer[BUFFER_SIZE] = "";
|
|
|
|
|
ImGui::Text("Tag:");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
strcpy(buffer, comp.Info.c_str());
|
|
|
|
|
ImGui::InputText("##Tag", buffer, BUFFER_SIZE);
|
|
|
|
|
comp.Info = buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// This code also taken from the Hazel engine
|
|
|
|
|
/// https://github.com/TheCherno/Hazel/blob/master/Hazelnut/src/Panels/SceneHierarchyPanel.cpp
|
|
|
|
|
void CompGui::RenderTransformComp(TransformComponent& comp)
|
|
|
|
|
{
|
|
|
|
|
DrawVec3Control("Translation", comp.Position);
|
|
|
|
|
glm::vec3 rotation = glm::degrees(comp.Rotation);
|
|
|
|
|
DrawVec3Control("Rotation", rotation);
|
|
|
|
|
comp.Rotation = glm::radians(rotation);
|
|
|
|
|
DrawVec3Control("Scale", comp.Scale, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}}
|