GUI cleanup

This commit is contained in:
2025-01-30 10:19:06 -05:00
parent 28b1938f01
commit 06e2c30a71
28 changed files with 264 additions and 1491 deletions

View File

@@ -11,13 +11,10 @@
namespace fgl::engine
{
#ifdef TITOR_EDITOR
void ModelComponent::drawImGui()
{
drawComponentTransform( m_transform );
//ImGui::Text( "MODEL COMPONENT WOOOOOO" );
// TODO: If the model is not set then we should be able to set it to one from the file selection
if ( this->m_model == nullptr )
{
@@ -30,13 +27,17 @@ namespace fgl::engine
ImGui::Text( "%i primitives", model.m_primitives.size() );
}
std::string_view ModelComponent::name() const
std::string_view ModelComponent::humanName() const
{
if ( !m_model ) return "Empty";
return m_model->getName();
}
#endif
std::string_view ModelComponent::className() const
{
return "ModelComponent";
}
Model* ModelComponent::operator->()
{

View File

@@ -98,10 +98,12 @@ namespace fgl::editor
{
ZoneScoped;
auto timer = debug::timing::push( "Draw ImGui" );
ImGui::ShowDemoWindow();
// ImGui::ShowDemoWindow();
gui::drawDock();
gui::drawMenubar( info );
gui::drawCameraOutputs( info );
gui::drawEntityGUI( info );
gui::drawEntityInfo( info );

View File

@@ -222,7 +222,7 @@ namespace fgl::engine::filesystem
ImGui::PopID();
}
FileBrowser::FileBrowser()
FileBrowser::FileBrowser() : m_current_dir( std::make_unique< DirInfo >( TEST_PATH ) )
{
m_folder_texture = getTextureStore().load( "./assets/folder.png", vk::Format::eR8G8B8A8Unorm );
m_file_texture = getTextureStore().load( "./assets/file.png", vk::Format::eR8G8B8A8Unorm );

View File

@@ -20,6 +20,8 @@ namespace fgl::engine::gui
void drawDock();
void drawMenubar( FrameInfo& info );
void drawImGui( FrameInfo& );
void drawEntityGUI( FrameInfo& );

View File

@@ -26,14 +26,27 @@ namespace fgl::engine::gui
void drawComponentsList( GameObject& game_object )
{
ImGui::PushStyleVar( ImGuiStyleVar_ChildRounding, 5.0f );
ImGui::BeginChild(
"ComponentsList",
ImVec2( 0, 0 ),
ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_Border | ImGuiChildFlags_ResizeY );
ImGui::SeparatorText( "Components" );
for ( const GameObjectComponentPtr component : game_object.getComponents() )
const auto& components { game_object.getComponents() };
for ( const GameObjectComponentPtr component : components )
{
component->drawNode( SELECTED_COMPONENT );
}
if ( SELECTED_COMPONENT != nullptr )
ImGui::EndChild();
ImGui::PopStyleVar();
ImGui::BeginChild( "Selected", ImVec2( 0, 0 ), ImGuiChildFlags_Border );
if ( SELECTED_COMPONENT != nullptr && std::ranges::find( components, SELECTED_COMPONENT ) != components.end() )
{
ImGui::SeparatorText( "Selected Component" );
@@ -41,6 +54,12 @@ namespace fgl::engine::gui
SELECTED_COMPONENT->drawImGui();
ImGui::PopID();
}
else
{
ImGui::SeparatorText( "No component selected" );
}
ImGui::EndChild();
}
} // namespace fgl::engine::gui

View File

@@ -0,0 +1,67 @@
//
// Created by kj16609 on 1/30/25.
//
#include "helpers.hpp"
#include "primitives/Rotation.hpp"
namespace fgl::engine::gui
{
float clampEuler( const float value )
{
if ( value >= 180.0f )
{
// Wrap around.
return value - 360.0f;
}
else if ( value <= -180.0f )
{
return value + 360.0f;
}
return value;
}
void dragFloat3Rot( const char* const label, Rotation& rot )
{
enum Axis
{
Pitch = 0,
Yaw = 1,
Roll = 2
};
const glm::vec3 c_dat { rot.euler() };
glm::vec3 dat { glm::degrees( c_dat ) };
ImGui::DragFloat3( label, &dat.x, 1.0f );
dat = glm::radians( dat );
const glm::vec3 diff { c_dat - dat };
constexpr float epsilon { std::numeric_limits< float >::epsilon() };
const glm::vec< 3, bool > changed_high { glm::greaterThanEqual( diff, glm::vec3( epsilon ) ) };
const glm::vec< 3, bool > changed_low { glm::lessThanEqual( diff, glm::vec3( -epsilon ) ) };
const glm::vec< 3, bool > changed { changed_high || changed_low };
if ( changed[ Pitch ] )
{
dat[ Pitch ] = clampEuler( dat[ Pitch ] );
rot.setX( dat[ Pitch ] );
}
if ( changed[ Roll ] )
{
dat[ Roll ] = clampEuler( dat[ Roll ] );
rot.setZ( dat[ Roll ] );
}
if ( changed[ Yaw ] )
{
dat[ Yaw ] = clampEuler( dat[ Yaw ] );
rot.setY( dat[ Yaw ] );
}
}
} // namespace fgl::engine::gui

View File

@@ -4,8 +4,14 @@
#pragma once
#include "glm/vec3.hpp"
#include "safe_include.hpp"
namespace fgl::engine
{
struct Rotation;
}
namespace fgl::engine::gui
{
inline void dragFloat3( const char* const label, glm::vec3& vec )
@@ -13,49 +19,6 @@ namespace fgl::engine::gui
ImGui::DragFloat3( label, &vec.x );
}
inline void dragFloat3Rot( const char* const label, Rotation& rot )
{
enum Axis
{
Pitch = 0,
Yaw = 1,
Roll = 2
};
glm::vec3 dat { glm::degrees( rot.euler() ) };
const glm::vec3 c_dat { dat };
constexpr float speed { 1.0f };
assert( &dat.x + 1 == &dat.y );
assert( &dat.y + 1 == &dat.z );
ImGui::DragFloat3( label, &dat.x, speed );
const glm::vec3 diff { c_dat - dat };
constexpr float epsilon { std::numeric_limits< float >::epsilon() };
const glm::vec< 3, bool > changed_high { glm::greaterThanEqual( diff, glm::vec3( epsilon ) ) };
const glm::vec< 3, bool > changed_low { glm::lessThanEqual( diff, glm::vec3( -epsilon ) ) };
const glm::vec< 3, bool > changed { changed_high || changed_low };
// Convert back to radians
dat = glm::radians( dat );
if ( changed[ Pitch ] )
{
//TODO: rot.xAngle() = dat[ Pitch ];
}
if ( changed[ Roll ] )
{
//TODO: rot.zAngle() = dat[ Roll ];
}
if ( changed[ Yaw ] )
{
//TODO: rot.yAngle() = dat[ Yaw ];
}
}
void dragFloat3Rot( const char* label, Rotation& rot );
} // namespace fgl::engine::gui

View File

@@ -0,0 +1,31 @@
//
// Created by kj16609 on 1/29/25.
//
#include <imgui.h>
#include "FrameInfo.hpp"
namespace fgl::engine::gui
{
void drawMenubar( FrameInfo& info )
{
ImGui::BeginMainMenuBar();
if ( ImGui::BeginMenu( "File" ) )
{
if ( ImGui::MenuItem( "Save..." ) )
{
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
} // namespace fgl::engine::gui