Skip to content

Commit

Permalink
Draw ImGui Types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daethalus committed May 4, 2024
1 parent 2df4029 commit ef66f19
Show file tree
Hide file tree
Showing 18 changed files with 422 additions and 68 deletions.
12 changes: 11 additions & 1 deletion Editor/Source/Fyrion/Editor/Scene/SceneEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,20 @@ namespace Fyrion
ResourceObject write = Repository::Write(object);
write.AddToSubObjectSet(SceneObjectAsset::Components, component);
write.Commit();

Editor::GetAssetTree().MarkDirty();
}

void SceneEditor::UpdateComponent(RID component, VoidPtr value)
void SceneEditor::RemoveComponent(RID object, RID component)
{
Repository::DestroyResource(component);

Editor::GetAssetTree().MarkDirty();
}

void SceneEditor::UpdateComponent(RID component, VoidPtr value)
{
Repository::Commit(component, value);
Editor::GetAssetTree().MarkDirty();
}
}
1 change: 1 addition & 0 deletions Editor/Source/Fyrion/Editor/Scene/SceneEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Fyrion
RID GetLastSelectedObject() const;
void RenameObject(RID rid, const StringView& newName);
void AddComponent(RID object, TypeHandler* typeHandler);
void RemoveComponent(RID object, RID component);
void UpdateComponent(RID component, VoidPtr value);

private:
Expand Down
10 changes: 7 additions & 3 deletions Editor/Source/Fyrion/Editor/Window/PropertiesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ namespace Fyrion
ImGui::PushID(HashValue(component));

ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_AllowItemOverlap;
ImGui::SetNextItemOpen(true, ImGuiCond_Appearing);
bool open = ImGui::CollapsingHeader(typeHandler->GetSimpleName().CStr(), flags);
bool rightClicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
bool hovered = ImGui::IsItemHovered();
Expand All @@ -160,6 +161,7 @@ namespace Fyrion
if (ImGui::Button(ICON_FA_ELLIPSIS_VERTICAL, ImVec2{size.y, size.y - 4 * style.ScaleFactor}) || rightClicked)
{
openComponentSettings = true;
m_selectedComponent = component;
}
if (hovered)
{
Expand All @@ -171,11 +173,13 @@ namespace Fyrion

if (open)
{
ImGui::Indent();
ConstPtr ptr = Repository::ReadData(component);
if (VoidPtr newValue = ImGui::DrawType(HashValue(component) + 10, typeHandler, ptr, ImGuiDrawTypeFlags_ReadOnly))
if (VoidPtr newValue = ImGui::DrawType(HashValue(component), typeHandler, ptr, readOnly ? ImGuiDrawTypeFlags_ReadOnly : 0))
{
m_sceneEditor.UpdateComponent(rid, newValue);
m_sceneEditor.UpdateComponent(component, newValue);
}
ImGui::Unindent();
}
}
}
Expand Down Expand Up @@ -230,7 +234,7 @@ namespace Fyrion

if (ImGui::MenuItem("Remove"))
{
//TODO
m_sceneEditor.RemoveComponent(rid, m_selectedComponent);
ImGui::CloseCurrentPopup();
}
}
Expand Down
1 change: 1 addition & 0 deletions Editor/Source/Fyrion/Editor/Window/PropertiesWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Fyrion
String m_renamingCache{};
RID m_renamingObject{};
String m_searchComponentString{};
RID m_selectedComponent = {};

static void OpenProperties(VoidPtr userData);
void DrawSceneObject(u32 id, RID rid);
Expand Down
71 changes: 71 additions & 0 deletions Engine/Source/Fyrion/Core/CoreTypeRegister.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#include "Math.hpp"
#include "Registry.hpp"
#include "UUID.hpp"

namespace Fyrion
{
struct UUID;

void RegisterBaseTypes()
{
Registry::Type<bool>("bool");
Registry::Type<u8>("u8");
Registry::Type<u16>("u16");
Registry::Type<u32>("u32");
Registry::Type<u64>("u64");
Registry::Type<ul32>("ul32");
Registry::Type<i8>("i8");
Registry::Type<i16>("i16");
Registry::Type<i32>("i32");
Registry::Type<i64>("i64");
Registry::Type<f32>("f32");
Registry::Type<f64>("f64");
Registry::Type<Array<u8>>("Fyrion::ByteArray");
Registry::Type<String>("Fyrion::String");
Registry::Type<StringView>("Fyrion::StringView");

auto uuid = Registry::Type<UUID>();
uuid.Field<&UUID::firstValue>("firstValue");
uuid.Field<&UUID::secondValue>("secondValue");


auto allocator = Registry::Type<Allocator>();
allocator.Function<&Allocator::MemAlloc>("MemAlloc");
allocator.Function<&Allocator::MemFree>("MemFree");
}

void RegisterMathTypes()
{
auto extent = Registry::Type<Extent>();
extent.Field<&Extent::width>("width");
extent.Field<&Extent::height>("height");

auto vec2 = Registry::Type<Vec2>();
vec2.Field<&Vec2::x>("x");
vec2.Field<&Vec2::y>("y");

auto vec3 = Registry::Type<Vec3>();
vec3.Field<&Vec3::x>("x");
vec3.Field<&Vec3::y>("y");
vec3.Field<&Vec3::z>("z");

auto vec4 = Registry::Type<Vec4>();
vec4.Field<&Vec4::x>("x");
vec4.Field<&Vec4::y>("y");
vec4.Field<&Vec4::z>("z");
vec4.Field<&Vec4::w>("w");

auto quat = Registry::Type<Quat>();
quat.Field<&Quat::x>("x");
quat.Field<&Quat::y>("y");
quat.Field<&Quat::z>("z");
quat.Field<&Quat::w>("w");
}

void RegisterCoreTypes()
{
RegisterBaseTypes();
RegisterMathTypes();
}
}
5 changes: 0 additions & 5 deletions Engine/Source/Fyrion/Core/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@ namespace Fyrion
m_fieldHandler.m_fnSetValue = fnSetValue;
}

void FieldBuilder::SetFnGetValue(FieldHandler::FnGetValue fnGetValue)
{
m_fieldHandler.m_fnGetValue = fnGetValue;
}

FunctionBuilder::FunctionBuilder(FunctionHandler& functionHandler) : m_functionHandler(functionHandler)
{
}
Expand Down
26 changes: 15 additions & 11 deletions Engine/Source/Fyrion/Core/Registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ namespace Fyrion
class FY_API AttributeHandler
{
public:
ConstPtr GetAttribute(TypeID attributeId) const;
bool HasAttribute(TypeID attributeId) const;
Span<AttributeInfo*> GetAttributes() const;
virtual ~AttributeHandler() = default;

ConstPtr GetAttribute(TypeID attributeId) const;
bool HasAttribute(TypeID attributeId) const;
Span<AttributeInfo*> GetAttributes() const;

template<typename AttType>
const AttType* GetAttribute() const
Expand Down Expand Up @@ -137,7 +139,6 @@ namespace Fyrion
typedef VoidPtr (*FnGetFieldPointer)(const FieldHandler* fieldHandler, VoidPtr instance);
typedef void (*FnCopyValueTo)(const FieldHandler* fieldHandler, ConstPtr instance, VoidPtr value);
typedef void (*FnSetValue)(const FieldHandler* fieldHandler, VoidPtr instance, ConstPtr value);
typedef void (*FnGetValue)(const FieldHandler* fieldHandler, VoidPtr instance, VoidPtr result);

explicit FieldHandler(const String& name);

Expand All @@ -159,14 +160,19 @@ namespace Fyrion
SetValue(instance, &value);
}

template<typename T>
void CopyValueTo(ConstPtr instance, T& value)
{
CopyValueTo(instance, &value);
}

friend class FieldBuilder;
private:
String m_name;
FnGetFieldInfo m_fnGetFieldInfo;
FnGetFieldPointer m_fnGetFieldPointer;
FnCopyValueTo m_fnCopyValueTo;
FnSetValue m_fnSetValue;
FnGetValue m_fnGetValue;
};

class FY_API FunctionHandler : public AttributeHandler
Expand Down Expand Up @@ -203,7 +209,6 @@ namespace Fyrion

struct DerivedType
{

TypeID typeId{};
FnCast fnCast{};
};
Expand Down Expand Up @@ -345,7 +350,6 @@ namespace Fyrion
void SetFnGetFieldPointer(FieldHandler::FnGetFieldPointer fnGetFieldPointer);
void SetFnCopyValueTo(FieldHandler::FnCopyValueTo fnCopyValueTo);
void SetFnSetValue(FieldHandler::FnSetValue fnSetValue);
void SetFnGetValue(FieldHandler::FnGetValue fnGetValue);
};

class FY_API FunctionBuilder
Expand Down Expand Up @@ -539,13 +543,13 @@ namespace Fyrion
explicit NativeFieldHandler(FieldBuilder fieldBuilder): NativeFieldHandlerBase<mfp, Owner, Field>(fieldBuilder)
{
fieldBuilder.SetFnSetValue(&SetValue);
fieldBuilder.SetFnGetValue(&GetValue);
fieldBuilder.SetFnCopyValueTo(&CopyValueToImpl);
}
private:
static void GetValue(const FieldHandler* fieldHandler, VoidPtr instance, VoidPtr result)
static void CopyValueToImpl(const FieldHandler* fieldHandler, ConstPtr instance, VoidPtr value)
{
using Return = Traits::FunctionReturnType<getFp>;
*static_cast<Traits::RemoveReference<Return>*>(result) = (*static_cast<Owner*>(instance).*getFp)();
*static_cast<Traits::RemoveAll<Return>*>(value) = (*static_cast<const Owner*>(instance).*getFp)();

}

Expand Down Expand Up @@ -671,7 +675,7 @@ namespace Fyrion
template<auto mfp, typename Return, typename Owner>
struct MemberFunctionTemplateDecomposer<mfp, Return(Owner::*)()>
{
using FuncType = MemberFunctionTemplateDecomposer<mfp, Return(Owner::*)()>;
using FuncType = MemberFunctionTemplateDecomposer;

static decltype(auto) CreateHandler(FunctionBuilder functionBuilder)
{
Expand Down
36 changes: 36 additions & 0 deletions Engine/Source/Fyrion/Core/StringUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,40 @@ namespace Fyrion
});
return ret;
}

inline String FormatName(const StringView& property)
{
String name = property;
if (!name.Empty())
{
name[0] = toupper(name[0]);

for (int i = 1; i < name.Size(); ++i)
{
auto p = name.begin() + i;
if (*p == *" ")
{
*p = toupper(*p);
} else if (isupper(*p))
{
bool insertSpace = true;
if (i<name.Size()-1)
{
auto pn = name.begin() + i + 1;
if (isupper(*pn))
{
insertSpace = false;
}
}

if (insertSpace)
{
name.Insert(p, " ");
}
i++;
}
}
}
return name;
}
}
Loading

0 comments on commit ef66f19

Please sign in to comment.