add basic core
This commit is contained in:
23
include/NazaraEditor/Core/Asset/Asset.hpp
Normal file
23
include/NazaraEditor/Core/Asset/Asset.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Asset
|
||||
{
|
||||
public:
|
||||
virtual bool IsExtensionSupported(std::string_view ext) = 0;
|
||||
};
|
||||
|
||||
template<typename TResourceManager>
|
||||
class TAsset
|
||||
{
|
||||
public:
|
||||
virtual bool IsExtensionSupported(std::string_view ext) { return m_resourceManager. }
|
||||
protected:
|
||||
TResourceManager m_resourceManager;
|
||||
};
|
||||
}
|
||||
0
include/NazaraEditor/Core/Asset/AssetManager.hpp
Normal file
0
include/NazaraEditor/Core/Asset/AssetManager.hpp
Normal file
16
include/NazaraEditor/Core/Config.hpp
Normal file
16
include/NazaraEditor/Core/Config.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARAEDITOR_CORE_CONFIG_HPP
|
||||
#define NAZARAEDITOR_CORE_CONFIG_HPP
|
||||
|
||||
#if !defined(NAZARAEDITOR_STATIC)
|
||||
#ifdef NAZARAEDITOR_CORE_BUILD
|
||||
#define NAZARAEDITOR_CORE_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARAEDITOR_CORE_API NAZARA_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define NAZARAEDITOR_CORE_API
|
||||
#endif
|
||||
|
||||
#endif // NAZARAEDITOR_CORE_CONFIG_HPP
|
||||
25
include/NazaraEditor/Core/Core.hpp
Normal file
25
include/NazaraEditor/Core/Core.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Config.hpp>
|
||||
|
||||
#include <Nazara/Core/ModuleBase.hpp>
|
||||
#include <NazaraImgui/NazaraImgui.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARAEDITOR_CORE_API EditorCore : public Nz::ModuleBase<EditorCore>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Imgui>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
EditorCore(Config config);
|
||||
~EditorCore();
|
||||
|
||||
private:
|
||||
static EditorCore* s_instance;
|
||||
};
|
||||
}
|
||||
144
include/NazaraEditor/Core/Reflection/Core.hpp
Normal file
144
include/NazaraEditor/Core/Reflection/Core.hpp
Normal file
@@ -0,0 +1,144 @@
|
||||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Reflection/Reflection.hpp>
|
||||
#include <NazaraEditor/Core/Reflection/Math.hpp>
|
||||
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <>
|
||||
class TypeReflect<Color>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, Color& obj)
|
||||
{
|
||||
p.AddProperty(obj.r, "R", "Red (0-255)");
|
||||
p.AddProperty(obj.g, "G", "Green (0-255)");
|
||||
p.AddProperty(obj.b, "B", "Blue (0-255)");
|
||||
p.AddProperty(obj.a, "A", "Alpha (0-255)");
|
||||
}
|
||||
};
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
inline bool Begin(Color& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
// your IMGUI Code
|
||||
float values[] = { obj.r, obj.g, obj.b, obj.a };
|
||||
if (ImGui::ColorEdit4(name.c_str(), values, ImGuiColorEditFlags_PickerHueWheel))
|
||||
{
|
||||
obj = Color(values[0], values[1], values[2], values[3]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void End(Color&) {}
|
||||
}
|
||||
|
||||
// Wrapper for array values
|
||||
template <typename T>
|
||||
struct ArrayEntry
|
||||
{
|
||||
T& value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class TypeReflect<ArrayEntry<T>>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, ArrayEntry<T>& obj)
|
||||
{
|
||||
p.AddProperty(p.value, "", "");
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, size_t Size>
|
||||
class TypeReflect<std::array<T, Size>>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, std::array<T, Size>& obj)
|
||||
{
|
||||
for (size_t i = 0; i < Size; ++i)
|
||||
{
|
||||
p.AddProperty(ArrayEntry{ obj[i] }, "", "");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
template <typename T, size_t Size>
|
||||
static bool Begin(ArrayEntry<T>& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
ImGui::BeginGroup();
|
||||
}
|
||||
|
||||
template <typename T, size_t Size>
|
||||
static void End(ArrayEntry<T>&) {
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
|
||||
template <typename T, size_t Size>
|
||||
static bool Begin(std::array<T, Size>& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
return ImGui::TreeNode(name.c_str());
|
||||
}
|
||||
|
||||
template <typename T, size_t Size>
|
||||
static void End(std::array<T, Size>&) {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <>
|
||||
class TypeReflect<entt::handle>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, entt::handle& obj)
|
||||
{
|
||||
for (auto&& curr : obj.storage())
|
||||
{
|
||||
if (auto& storage = curr.second; storage.contains(obj))
|
||||
{
|
||||
entt::id_type id = curr.first;
|
||||
if (auto reflect = entt::resolve(id).func(entt::hashed_string("Reflect")); reflect)
|
||||
reflect.invoke({}, p, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
static bool Begin(entt::handle& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
std::string n = "Entity " + name;
|
||||
return ImGui::TreeNode(n.c_str());
|
||||
}
|
||||
|
||||
static void End(entt::handle&) {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TPropertyEnumerator, typename TComponent>
|
||||
inline void ReflectComponent(TPropertyEnumerator& p, entt::handle& obj)
|
||||
{
|
||||
TComponent* component = obj.try_get<TComponent>();
|
||||
if (component != nullptr)
|
||||
p.AddProperty(*component, "", "");
|
||||
}
|
||||
}
|
||||
47
include/NazaraEditor/Core/Reflection/Editor.hpp
Normal file
47
include/NazaraEditor/Core/Reflection/Editor.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename TPropertyDetail>
|
||||
struct EditorPropertyInspector
|
||||
{
|
||||
template <typename T>
|
||||
void AddProperty(T& prop, const std::string& name, const std::string& tooltip);
|
||||
|
||||
/*template <typename T, typename U, typename V>
|
||||
void AddProperty(T& parent, V(U::* Getter)() const, void(U::*Setter(const V&))(), const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
U val = parent->Getter();
|
||||
AddProperty(val, name, tooltip);
|
||||
parent->Setter(val);
|
||||
}*/
|
||||
|
||||
template <typename TGetter, typename TSetter>
|
||||
void AddProperty(TGetter Getter, TSetter Setter, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
auto val = Getter();
|
||||
AddProperty(val, name, tooltip);
|
||||
Setter(val);
|
||||
}
|
||||
};
|
||||
|
||||
struct EditorRenderer
|
||||
{
|
||||
template <typename T>
|
||||
static bool Begin(T& prop, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
return EditorImgui::Begin(prop, name, tooltip);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void End(T& prop)
|
||||
{
|
||||
EditorImgui::End(prop);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <NazaraEditor/Core/Reflection/Editor.inl>
|
||||
15
include/NazaraEditor/Core/Reflection/Editor.inl
Normal file
15
include/NazaraEditor/Core/Reflection/Editor.inl
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
template <typename TPropertyDetail>
|
||||
template <typename T> void EditorPropertyInspector<TPropertyDetail>::AddProperty(T& prop, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
if (TPropertyDetail::Begin(prop, name, tooltip))
|
||||
{
|
||||
TypeReflect<T>::Reflect(*this, prop);
|
||||
TPropertyDetail::End(prop);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
52
include/NazaraEditor/Core/Reflection/Graphics.hpp
Normal file
52
include/NazaraEditor/Core/Reflection/Graphics.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Reflection/Reflection.hpp>
|
||||
|
||||
#include <Nazara/Graphics.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <>
|
||||
class TypeReflect<LightComponent::LightEntry>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, LightComponent::LightEntry& obj)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class TypeReflect<LightComponent>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, LightComponent& obj)
|
||||
{
|
||||
p.AddProperty([&obj]() { return obj.IsVisible(); }, [&obj](bool v) { obj.Show(v); }, "Is Visible", "Toggles lights visibility");
|
||||
//p.AddProperty(obj.GetLights(), "Lights", "");
|
||||
}
|
||||
};
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
inline bool Begin(Nz::LightComponent::LightEntry& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void End(Nz::LightComponent::LightEntry&) {
|
||||
}
|
||||
|
||||
inline bool Begin(Nz::LightComponent& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
return ImGui::TreeNode("LightComponent");
|
||||
}
|
||||
|
||||
inline void End(Nz::LightComponent&) {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
78
include/NazaraEditor/Core/Reflection/Math.hpp
Normal file
78
include/NazaraEditor/Core/Reflection/Math.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Reflection/Reflection.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace EditorImgui
|
||||
{
|
||||
inline bool Begin(bool& obj, const std::string& name, const std::string& /*tooltip*/)
|
||||
{
|
||||
ImGui::Checkbox(name.c_str(), &obj);
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void End(bool&) {}
|
||||
|
||||
#define IMGUI_BASIC_INTEGER(Type) \
|
||||
inline bool Begin(Type& obj, const std::string& name, const std::string& /*tooltip*/) \
|
||||
{ \
|
||||
int value = static_cast<int>(obj); \
|
||||
if (ImGui::DragInt(name.c_str(), &value, 1.f, std::numeric_limits<Type>::min(), std::numeric_limits<Type>::max())) \
|
||||
obj = static_cast<Type>(value); \
|
||||
return false; \
|
||||
} \
|
||||
inline void End(Type&) {}
|
||||
|
||||
IMGUI_BASIC_INTEGER(Nz::Int8);
|
||||
IMGUI_BASIC_INTEGER(Nz::Int16)
|
||||
IMGUI_BASIC_INTEGER(Nz::Int32);
|
||||
IMGUI_BASIC_INTEGER(Nz::Int64);
|
||||
IMGUI_BASIC_INTEGER(Nz::UInt8);
|
||||
IMGUI_BASIC_INTEGER(Nz::UInt16);
|
||||
IMGUI_BASIC_INTEGER(Nz::UInt32);
|
||||
IMGUI_BASIC_INTEGER(Nz::UInt64);
|
||||
|
||||
#define IMGUI_BASIC_FLOAT(Type) \
|
||||
inline bool Begin(Type& obj, const std::string& name, const std::string& /*tooltip*/) \
|
||||
{ \
|
||||
float value = (float)obj; \
|
||||
if (ImGui::DragFloat(name.c_str(), &value, 1.f, std::numeric_limits<Type>::min(), std::numeric_limits<Type>::max())) \
|
||||
obj = (Type)value; \
|
||||
return false; \
|
||||
} \
|
||||
inline void End(Type&) {}
|
||||
|
||||
IMGUI_BASIC_FLOAT(float);
|
||||
IMGUI_BASIC_FLOAT(double);
|
||||
|
||||
|
||||
inline bool Begin(Nz::Vector3f& obj, const std::string& name, const std::string& /*tooltip*/)
|
||||
{
|
||||
float value[] = { obj.x, obj.y, obj.z };
|
||||
if (ImGui::DragFloat3(name.c_str(), value, 1.f, std::numeric_limits<float>::min(), std::numeric_limits<float>::max()))
|
||||
obj = Nz::Vector3f(value[0], value[1], value[2]);
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void End(Nz::Vector3f&) {}
|
||||
|
||||
|
||||
inline bool Begin(Nz::Quaternionf& obj, const std::string& name, const std::string& /*tooltip*/)
|
||||
{
|
||||
auto euler = obj.ToEulerAngles();
|
||||
float value[] = { euler.pitch.ToDegrees(), euler.yaw.ToDegrees(), euler.roll.ToDegrees() };
|
||||
if (ImGui::DragFloat3(name.c_str(), value, 1.f, std::numeric_limits<float>::min(), std::numeric_limits<float>::max()))
|
||||
{
|
||||
obj = EulerAnglesf(value[0], value[1], value[2]).ToQuaternion();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void End(Nz::Quaternionf&) {}
|
||||
}
|
||||
|
||||
}
|
||||
12
include/NazaraEditor/Core/Reflection/Reflection.hpp
Normal file
12
include/NazaraEditor/Core/Reflection/Reflection.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename T>
|
||||
class TypeReflect
|
||||
{
|
||||
public:
|
||||
template <typename TEnumerator>
|
||||
static void Reflect(TEnumerator&, T&) { } // default specialization
|
||||
};
|
||||
}
|
||||
36
include/NazaraEditor/Core/Reflection/Utility.hpp
Normal file
36
include/NazaraEditor/Core/Reflection/Utility.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Reflection/Reflection.hpp>
|
||||
|
||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
template <>
|
||||
class TypeReflect<NodeComponent>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, NodeComponent& obj)
|
||||
{
|
||||
p.AddProperty([&obj]() { return obj.GetPosition(); }, [&obj](const Nz::Vector3f& v) { return obj.SetPosition(v); }, "Position", "Position of the node");
|
||||
p.AddProperty([&obj]() { return obj.GetRotation(); }, [&obj](const Nz::Quaternionf& v) { return obj.SetRotation(v); }, "Rotation", "Rotation of the node");
|
||||
p.AddProperty([&obj]() { return obj.GetScale(); }, [&obj](const Nz::Vector3f& v) { return obj.SetScale(v); }, "Scale", "Scale of the node");
|
||||
}
|
||||
};
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
inline bool Begin(Nz::NodeComponent& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
return ImGui::TreeNode("NodeComponent");
|
||||
}
|
||||
|
||||
inline void End(Nz::NodeComponent&) {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
}
|
||||
0
include/NazaraEditor/Core/UI/Panel.hpp
Normal file
0
include/NazaraEditor/Core/UI/Panel.hpp
Normal file
0
include/NazaraEditor/Core/UI/Widget.hpp
Normal file
0
include/NazaraEditor/Core/UI/Widget.hpp
Normal file
54
include/NazaraEditor/Core/UI/Window.hpp
Normal file
54
include/NazaraEditor/Core/UI/Window.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <NazaraEditor/Core/Config.hpp>
|
||||
#include <NazaraImgui/NazaraImgui.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
using ActionCallback = std::function<void(void)>;
|
||||
|
||||
class NAZARAEDITOR_CORE_API EditorWindow
|
||||
: private Nz::ImguiHandler
|
||||
{
|
||||
public:
|
||||
EditorWindow(const std::string& name = "");
|
||||
~EditorWindow();
|
||||
|
||||
EditorWindow(const EditorWindow&) = delete;
|
||||
EditorWindow& operator=(const EditorWindow&) = delete;
|
||||
|
||||
virtual void OnRenderImgui() override;
|
||||
|
||||
void AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback);
|
||||
void AddMenuSeparator(const std::string& path);
|
||||
|
||||
protected:
|
||||
virtual void OnEditorGUI() {};
|
||||
|
||||
private:
|
||||
void DrawMenus();
|
||||
|
||||
std::string m_windowName;
|
||||
|
||||
struct MenuAction
|
||||
{
|
||||
std::string label;
|
||||
std::string shortcut;
|
||||
ActionCallback callback;
|
||||
};
|
||||
|
||||
struct MenuSeparator
|
||||
{};
|
||||
|
||||
struct MenuList
|
||||
{
|
||||
std::string label;
|
||||
std::vector<std::variant<MenuAction, MenuSeparator, MenuList>> entries;
|
||||
};
|
||||
|
||||
MenuList m_root;
|
||||
|
||||
MenuList& GetOrCreateMenuHierarchy(const std::vector<std::string_view>& hierarchy);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user