pretty property panel components
This commit is contained in:
@@ -4,8 +4,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
project(OpenEngineProject)
|
||||
|
||||
add_definitions(-DOE_DEBUG_TOOLS=1)
|
||||
add_subdirectory(open_engine)
|
||||
|
||||
add_subdirectory(application
|
||||
./bin
|
||||
add_subdirectory(editor
|
||||
./editor
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[requires]
|
||||
imgui/1.92.5-docking
|
||||
spdlog/1.16.0
|
||||
entt/3.16.0
|
||||
|
||||
[generators]
|
||||
CMakeDeps
|
||||
|
||||
@@ -27,16 +27,16 @@ namespace OpenEngine {
|
||||
{
|
||||
auto delta = Time::DeltaTime();
|
||||
|
||||
auto& transform = GetComponent<TransformComponent>();
|
||||
auto& position = GetComponent<TransformComponent>().translation;
|
||||
|
||||
if (Input::IsKeyPressed(KeyCode::Up))
|
||||
transform.transform[3][1] += 5.0 * delta;
|
||||
position.y += 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Down))
|
||||
transform.transform[3][1] -= 5.0 * delta;
|
||||
position.y -= 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Right))
|
||||
transform.transform[3][0] += 5.0 * delta;
|
||||
position.x += 5.0 * delta;
|
||||
if (Input::IsKeyPressed(KeyCode::Left))
|
||||
transform.transform[3][0] -= 5.0 * delta;
|
||||
position.x -= 5.0 * delta;
|
||||
};
|
||||
|
||||
void OnDestroy()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SCENE_HIERARCHY_HPP
|
||||
|
||||
#include "imgui.h"
|
||||
#include <array>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <panels/scene_hierarchy.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace OpenEngine {
|
||||
@@ -137,14 +136,3 @@ namespace OpenEngine {
|
||||
DrawComponentDrawer<CameraComponent>(entity, "Camera");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight | ImGuiPopupFlags_NoOpenOverItems))
|
||||
{
|
||||
if (ImGui::MenuItem("Create Empty Entity"))
|
||||
{
|
||||
// m_Context->CreateEntity("Empty Entity");
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
*/
|
||||
|
||||
46
imgui.ini
46
imgui.ini
@@ -22,38 +22,38 @@ DockId=0x00000008,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=406,0
|
||||
Size=629,1386
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][Dear ImGui Demo]
|
||||
Pos=1037,0
|
||||
Size=235,1386
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][Scene]
|
||||
Pos=0,151
|
||||
Size=404,264
|
||||
Size=391,1059
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=0,417
|
||||
Size=404,969
|
||||
[Window][Dear ImGui Demo]
|
||||
Pos=406,1061
|
||||
Size=391,325
|
||||
Collapsed=0
|
||||
DockId=0x0000000A,0
|
||||
|
||||
[Window][Scene]
|
||||
Pos=0,151
|
||||
Size=404,1235
|
||||
Collapsed=0
|
||||
DockId=0x00000002,0
|
||||
|
||||
[Window][Properties]
|
||||
Pos=799,0
|
||||
Size=473,1386
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,0 Size=1272,1386 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=1035,1386 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=2085,1386 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=404,1386 Split=Y Selected=0x553E127E
|
||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=274,149 Selected=0x553E127E
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=274,1235 Split=Y Selected=0xE601B12F
|
||||
DockNode ID=0x00000009 Parent=0x00000002 SizeRef=498,264 Selected=0xE601B12F
|
||||
DockNode ID=0x0000000A Parent=0x00000002 SizeRef=498,969 Selected=0x8C72BEA8
|
||||
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=629,1386 CentralNode=1 Selected=0xC450F867
|
||||
DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=235,1386 Split=Y Selected=0x5E5F7166
|
||||
DockNode ID=0x00000007 Parent=0x00000004 SizeRef=235,305 Selected=0x5E5F7166
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=274,1235 Selected=0xE601B12F
|
||||
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=1679,1386 Split=Y Selected=0xC450F867
|
||||
DockNode ID=0x00000009 Parent=0x00000006 SizeRef=629,1067 CentralNode=1 Selected=0xC450F867
|
||||
DockNode ID=0x0000000A Parent=0x00000006 SizeRef=629,325 Selected=0x5E5F7166
|
||||
DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=473,1386 Split=Y Selected=0x5E5F7166
|
||||
DockNode ID=0x00000007 Parent=0x00000004 SizeRef=235,305 Selected=0x8C72BEA8
|
||||
DockNode ID=0x00000008 Parent=0x00000004 SizeRef=235,1079 Selected=0xA5FF3A7A
|
||||
|
||||
|
||||
@@ -5,13 +5,20 @@
|
||||
#include "open_engine/scene/scene_camera.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/fwd.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui.h>
|
||||
#include <string>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value = 0.0f, float column_width = 100.0f,
|
||||
const std::array<const char*, 3> labels = {"x", "y", "z"});
|
||||
|
||||
struct TagComponent
|
||||
{
|
||||
std::string tag;
|
||||
@@ -36,19 +43,33 @@ namespace OpenEngine {
|
||||
|
||||
struct TransformComponent
|
||||
{
|
||||
glm::mat4 transform{ 1.0f };
|
||||
glm::vec3 translation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 scale = { 1.0f, 1.0f, 1.0f };
|
||||
|
||||
TransformComponent() = default;
|
||||
TransformComponent(const TransformComponent&) = default;
|
||||
TransformComponent(const glm::mat4& transform_mat)
|
||||
: transform(transform_mat) {}
|
||||
TransformComponent(const glm::vec3& position)
|
||||
: translation(position) {}
|
||||
|
||||
operator glm::mat4() { return transform; };
|
||||
operator const glm::mat4() const { return transform; };
|
||||
glm::mat4 GetTransform() const
|
||||
{
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation);
|
||||
|
||||
transform *= glm::rotate(glm::mat4(1.0f), rotation.x, { 1, 0, 0 })
|
||||
* glm::rotate(glm::mat4(1.0f), rotation.y, { 0, 1, 0 })
|
||||
* glm::rotate(glm::mat4(1.0f), rotation.z, { 0, 0, 1 });
|
||||
|
||||
transform *= glm::scale(glm::mat4(1.0f), scale);
|
||||
|
||||
return transform;
|
||||
};
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
ImGui::DragFloat3("Position", glm::value_ptr(transform[3]), 0.1f);
|
||||
DrawVec3Control("Position", translation);
|
||||
DrawVec3Control("Rotation", rotation);
|
||||
DrawVec3Control("Scale", scale);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenEngine {
|
||||
float fov = 45.0f;
|
||||
float perspective_near = 0.01f, perspective_far = 1000.0f;
|
||||
|
||||
float aspect_ratio = 0.0f;
|
||||
float aspect_ratio = 16.0f/9.0f;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -160,10 +160,11 @@ namespace OpenEngine {
|
||||
const ImVec4 mauve = ImVec4(0.796f, 0.698f, 0.972f, 1.0f); // #cba6f7
|
||||
const ImVec4 peach = ImVec4(0.980f, 0.709f, 0.572f, 1.0f); // #fab387
|
||||
const ImVec4 yellow = ImVec4(0.980f, 0.913f, 0.596f, 1.0f); // #f9e2af
|
||||
const ImVec4 red = ImVec4(0.953f, 0.545f, 0.659f, 1.0f); // #f38ba8
|
||||
const ImVec4 green = ImVec4(0.650f, 0.890f, 0.631f, 1.0f); // #a6e3a1
|
||||
const ImVec4 blue = ImVec4(0.533f, 0.698f, 0.976f, 1.0f); // #89b4fa
|
||||
const ImVec4 teal = ImVec4(0.580f, 0.886f, 0.819f, 1.0f); // #94e2d5
|
||||
const ImVec4 sapphire = ImVec4(0.458f, 0.784f, 0.878f, 1.0f); // #74c7ec
|
||||
const ImVec4 blue = ImVec4(0.533f, 0.698f, 0.976f, 1.0f); // #89b4fa
|
||||
const ImVec4 lavender = ImVec4(0.709f, 0.764f, 0.980f, 1.0f); // #b4befe
|
||||
|
||||
// Main window and backgrounds
|
||||
|
||||
74
open_engine/src/open_engine/scene/components.cpp
Normal file
74
open_engine/src/open_engine/scene/components.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "imgui.h"
|
||||
#include <pch.hpp>
|
||||
|
||||
#include <scene/components.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value, float column_width,
|
||||
const std::array<const char*, 3> labels)
|
||||
{
|
||||
ImGui::PushID(label);
|
||||
ImVec2 item_spacing = { 15.0f, 0.0f };
|
||||
ImGui::Columns(2);
|
||||
ImGui::SetColumnWidth(0, column_width);
|
||||
ImGui::Text("%s", label);
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered())
|
||||
values = glm::vec3(reset_value);
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
ImVec2 button_size = { line_height + 3.0f, line_height };
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0f, 0.8f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
if (ImGui::Button(labels[0], button_size))
|
||||
values.x = reset_value;
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##X", &values.x, 0.1f);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 1.0f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
if (ImGui::Button(labels[1], button_size))
|
||||
values.y = reset_value;
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Y", &values.y, 0.1f);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.7f, 0.9f, 1.0f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
if (ImGui::Button(labels[2], button_size))
|
||||
values.z = reset_value;
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar(1);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Z", &values.z, 0.1f);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Columns(1);
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ namespace OpenEngine {
|
||||
});
|
||||
}
|
||||
|
||||
Camera* main_camera = nullptr;
|
||||
glm::mat4* main_transform = nullptr;
|
||||
SceneCamera* main_camera = nullptr;
|
||||
glm::mat4 main_transform{ 1.0f };
|
||||
{
|
||||
auto camera_view = registry.view<CameraComponent, TransformComponent>();
|
||||
for (auto entity : camera_view) {
|
||||
@@ -43,19 +43,19 @@ namespace OpenEngine {
|
||||
|
||||
if (camera_component.primary) {
|
||||
main_camera = &camera_component.camera;
|
||||
main_transform = &transform.transform;
|
||||
main_transform = transform.GetTransform();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (main_camera) {
|
||||
Renderer2D::BeginScene(main_camera->GetProjection(), *main_transform);
|
||||
Renderer2D::BeginScene(main_camera->GetProjection(), main_transform);
|
||||
|
||||
auto view = registry.view<TransformComponent, SpriteRendererComponent>();
|
||||
|
||||
for (const auto& entity : view) {
|
||||
auto [transform, sprite] = view.get<TransformComponent, SpriteRendererComponent>(entity);
|
||||
Renderer2D::DrawQuad(transform.transform, sprite.color);
|
||||
Renderer2D::DrawQuad(transform.GetTransform(), sprite.color);
|
||||
}
|
||||
|
||||
Renderer2D::EndScene();
|
||||
|
||||
Reference in New Issue
Block a user