diff --git a/Deer/Include/DeerCore/Components.h b/Deer/Include/DeerCore/Components.h index 1bb3524..df4f6ac 100755 --- a/Deer/Include/DeerCore/Components.h +++ b/Deer/Include/DeerCore/Components.h @@ -30,18 +30,18 @@ namespace Deer { }; struct RelationshipComponent { - uint16_t parent_id = 0; + u_int32_t parent_id = 0; // Use p-ranav's small_vector for children storage // Inline capacity ENTITY_MAX_CHILDREN, fallback to heap if exceeded - ankerl::svector children; + ankerl::svector children; - inline uint16_t getChildId(size_t i) const { + inline u_int32_t getChildId(size_t i) const { DEER_CORE_ASSERT(i < children.size() && children[i] != 0, "Invalid child request {0}", i); return children[i]; } - inline void addChildId(uint16_t childId) { + inline void addChildId(u_int32_t childId) { // Prevent duplicates for (auto id : children) if (id == childId) @@ -49,7 +49,7 @@ namespace Deer { children.push_back(childId); } - inline bool removeChild(uint16_t childId) { + inline bool removeChild(u_int32_t childId) { for (size_t i = 0; i < children.size(); ++i) { if (children[i] == childId) { // Swap-remove for O(1) @@ -67,7 +67,7 @@ namespace Deer { RelationshipComponent() = default; RelationshipComponent(const RelationshipComponent&) = default; - RelationshipComponent(uint16_t _parent) : parent_id(_parent) {} + RelationshipComponent(u_int32_t _parent) : parent_id(_parent) {} }; struct TransformComponent { diff --git a/Deer/Include/DeerCore/Scripting.h b/Deer/Include/DeerCore/Scripting.h index cb95956..c5845b0 100644 --- a/Deer/Include/DeerCore/Scripting.h +++ b/Deer/Include/DeerCore/Scripting.h @@ -58,6 +58,7 @@ namespace Deer { void executeOnGroup_voidEvent(size_t eventIndex); void executeOnObject_voidEvent(size_t systemIndex, size_t eventIndex); + void executeOnObject_voidEvent(ScriptSystem* system, size_t eventIndex); private: ScriptObjectGroup(ScriptEnvironment* env); @@ -71,12 +72,15 @@ namespace Deer { class ScriptSystem { public: const char* getSystemName(); + bool hasFunction(size_t index); + size_t getSystemIndex(); private: - ScriptSystem(const Scripting::SystemDescription& desc, asITypeInfo* type); + ScriptSystem(const Scripting::SystemDescription& desc, asITypeInfo* type, size_t _systemIndex); asITypeInfo* systemType; Scope environmentFunctions; + size_t systemIndex; friend ScriptEnvironment; friend ScriptObjectGroup; diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp index 56d26e2..329857e 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp +++ b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.cpp @@ -3,6 +3,7 @@ #include "DeerCore/EntityEnviroment.h" #include "angelscript.h" +#include "scriptarray.h" #ifdef DEER_RENDER #include "DeerRender/Mesh.h" @@ -12,6 +13,10 @@ #endif namespace Deer { + namespace Scripting { + extern asIScriptEngine* scriptEngine; + } + Entity& Scripting::getContextEntity(EntityHandle handle) { asIScriptContext* context = asGetActiveContext(); ScriptEnvironmentContextData* environmentData = (ScriptEnvironmentContextData*)context->GetUserData(); @@ -57,6 +62,10 @@ namespace Deer { return getContextEntity(handle).getComponent().tag; } + int Scripting::entity_getId(EntityHandle& handle) { + return handle.entityId; + } + void Scripting::entity_setName(std::string& name, EntityHandle& handle) { getContextEntity(handle).getComponent().tag = name; } @@ -73,11 +82,31 @@ namespace Deer { getContextEntity(handle).destroy(); } - EntityHandle Scripting::entity_createChild(EntityHandle& handle) { + CScriptArray* Scripting::entity_getChildrens(EntityHandle& handle) { + Entity& entity = getContextEntity(handle); + + asITypeInfo* arrayStringType = scriptEngine->GetTypeInfoByDecl("array"); + CScriptArray* array = CScriptArray::Create(arrayStringType); + + RelationshipComponent& relationship = entity.getComponent(); + size_t childCount = relationship.getChildCount(); + + for (size_t i = 0; i < childCount; i++) { + EntityHandle entity(relationship.getChildId(i), handle.environmentId); + + array->Resize(array->GetSize() + 1); + array->SetValue(array->GetSize() - 1, &entity); + } + + return array; + } + + EntityHandle Scripting::entity_createChild(std::string& childName, EntityHandle& handle) { Entity& child = getContextEntityEnvironment(handle).createEntity(); Entity& self = getContextEntity(handle); child.setParent(self); + child.getComponent().tag = childName; return EntityHandle(child.getId(), handle.environmentId); } diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h index 92f1b65..ff5b293 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h +++ b/Deer/src/DeerCore/Scripting/InternalAPI/Entity.h @@ -4,6 +4,7 @@ #include class asIScriptGeneric; +class CScriptArray; namespace Deer { class Entity; @@ -26,12 +27,14 @@ namespace Deer { EntityHandle entity_getSelf(EntityHandle&); std::string entity_getName(EntityHandle&); + int entity_getId(EntityHandle&); void entity_setName(std::string&, EntityHandle&); bool entity_exists(EntityHandle&); bool entity_isRoot(EntityHandle&); void entity_destroy(EntityHandle&); + CScriptArray* entity_getChildrens(EntityHandle&); - EntityHandle entity_createChild(EntityHandle&); + EntityHandle entity_createChild(std::string&, EntityHandle&); void entity_setParent(EntityHandle, EntityHandle&); EntityHandle entity_getParent(EntityHandle&); diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp b/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp new file mode 100644 index 0000000..6b8b124 --- /dev/null +++ b/Deer/src/DeerCore/Scripting/InternalAPI/World.cpp @@ -0,0 +1,7 @@ +#include "DeerCore/Scripting/InternalAPI/World.h" + +namespace Deer { + EntityHandle Scripting::getRoot() { + return EntityHandle(0, 0); + } +} // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/InternalAPI/World.h b/Deer/src/DeerCore/Scripting/InternalAPI/World.h index d88119b..19e20df 100644 --- a/Deer/src/DeerCore/Scripting/InternalAPI/World.h +++ b/Deer/src/DeerCore/Scripting/InternalAPI/World.h @@ -1,8 +1,8 @@ #pragma once -#include "DeerCore/Universe.h" +#include "DeerCore/Scripting/InternalAPI/Entity.h" namespace Deer { namespace Scripting { - Universe::WorldHandle getExecutingWorld(); + EntityHandle getRoot(); } } // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/PredefinedGenerator.cpp b/Deer/src/DeerCore/Scripting/PredefinedGenerator.cpp index 8b97aa0..e8fedbf 100644 --- a/Deer/src/DeerCore/Scripting/PredefinedGenerator.cpp +++ b/Deer/src/DeerCore/Scripting/PredefinedGenerator.cpp @@ -169,8 +169,20 @@ namespace Deer { } else { stream << t->GetEngine()->GetTypeDeclaration(methodReturnId) << " "; } + stream << m->GetName(); - stream << m->GetName() << "("; + if (m->GetSubTypeCount() > 0) { + stream << "<"; + for (int sub = 0; sub < m->GetSubTypeCount(); ++sub) { + if (sub > 0) + stream << ", "; + const auto st = m->GetSubType(sub); + stream << st->GetName(); + } + stream << ">"; + } + + stream << "("; writeParameters(m); stream << ")"; diff --git a/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp b/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp index 5d4f715..8105805 100644 --- a/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp +++ b/Deer/src/DeerCore/Scripting/Registry/EntityRegistry.cpp @@ -18,6 +18,7 @@ namespace Deer { void Scripting::registerEntityFunctions() { REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "string get_name() const property", entity_getName); + REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "int get_id() const property", entity_getId); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "void set_name(string& in) property", entity_setName); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "Entity createChild(const string& in)", entity_createChild); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "bool get_isRoot() const property", entity_isRoot); @@ -27,6 +28,7 @@ namespace Deer { REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "void set_parent(Entity) property", entity_setParent); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "bool isDescendantOf(Entity)", entity_isDescendantOf); REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "bool opEquals(const Entity &in) const", entity_opEquals); + REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Entity", "array@ getChildrens()", entity_getChildrens); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T getComponent()", entity_getGenericComponent); REGISTER_GENERIC_OBJECT_METHOD(scriptEngine, "Entity", "T addComponent()", entity_addGenericComponent); @@ -42,8 +44,8 @@ namespace Deer { } void Scripting::registerEntityStructs() { - AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); - AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); + AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); + AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits() | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Entity", "void f()", constructEntityStruct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "TransformComponent", "void f()", constructEntityStruct); diff --git a/Deer/src/DeerCore/Scripting/Registry/WorldRegistry.cpp b/Deer/src/DeerCore/Scripting/Registry/WorldRegistry.cpp new file mode 100644 index 0000000..ef21aaf --- /dev/null +++ b/Deer/src/DeerCore/Scripting/Registry/WorldRegistry.cpp @@ -0,0 +1,27 @@ +#include "DeerCore/Scripting.h" +#include "DeerCore/Scripting/Helpers.h" +#include "DeerCore/Scripting/InternalAPI/World.h" +#include "angelscript.h" + +namespace Deer { + namespace Scripting { + extern asIScriptEngine* scriptEngine; + + void registerWorld(); + void registerWorldStructs(); + void registerWorldFunctions(); + } // namespace Scripting + + void Scripting::registerWorldStructs() {} + + void Scripting::registerWorldFunctions() { + scriptEngine->SetDefaultNamespace("World"); + REGISTER_GLOBAL_FUNC(scriptEngine, "Entity getRoot()", getRoot); + scriptEngine->SetDefaultNamespace(""); + } + + void Scripting::registerWorld() { + registerWorldStructs(); + registerWorldFunctions(); + } +} // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp b/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp index 97ce9b7..f9bdf56 100644 --- a/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp +++ b/Deer/src/DeerCore/Scripting/ScriptEnvironment.cpp @@ -33,6 +33,10 @@ namespace Deer { baseType = Scripting::scriptEngine->GetTypeInfoByName(systemDescription.baseTypeName.c_str()); context = Scripting::scriptEngine->CreateContext(); + environmentContext = MakeScope(); + environmentContext->environment = this; + context->SetUserData(environmentContext.get()); + if (!baseType) { DEER_CORE_ERROR("Could not find {} on script environment", systemDescription.baseTypeName.c_str()); return; @@ -40,11 +44,11 @@ namespace Deer { size_t typeCount = module->GetObjectTypeCount(); std::vector types; - for (int i = 0; i < typeCount; i++) { + for (size_t i = 0; i < typeCount; i++) { asITypeInfo* type = module->GetObjectTypeByIndex(i); if (Scripting::typeImplementsInterface(type, baseType)) - systems.push_back(Scope(new ScriptSystem(systemDescription, type))); + systems.push_back(Scope(new ScriptSystem(systemDescription, type, systems.size()))); } } @@ -64,8 +68,8 @@ namespace Deer { return false; } - ScriptSystem::ScriptSystem(const Scripting::SystemDescription& desc, asITypeInfo* type) - : systemType(type) { + ScriptSystem::ScriptSystem(const Scripting::SystemDescription& desc, asITypeInfo* type, size_t indx) + : systemType(type), systemIndex(indx) { environmentFunctions = MakeScope(desc.events.size()); @@ -79,6 +83,13 @@ namespace Deer { const char* ScriptSystem::getSystemName() { return systemType->GetName(); } + bool ScriptSystem::hasFunction(size_t index) { + return environmentFunctions[index] != nullptr; + } + + size_t ScriptSystem::getSystemIndex() { + return systemIndex; + } size_t ScriptEnvironment::getSystemCount() { return systems.size(); @@ -99,6 +110,10 @@ namespace Deer { return systemGroup; } + void ScriptEnvironment::tieWorld(World* world) { + environmentContext->world = world; + } + ScriptObjectGroup* ScriptEnvironment::createEmptyGroup() { systemGroups.push_back(Scope(new ScriptObjectGroup(this))); ScriptObjectGroup* systemGroup = systemGroups.back().get(); @@ -147,6 +162,18 @@ namespace Deer { environment->context->Unprepare(); } + void ScriptObjectGroup::executeOnObject_voidEvent(ScriptSystem* system, size_t eventIndex) { + asIScriptFunction* function = system->environmentFunctions[eventIndex]; + + if (!function) + return; + + AS_CHECK(environment->context->Prepare(function)); + AS_CHECK(environment->context->SetObject(systemInstances[system->systemIndex])); + AS_CHECK(environment->context->Execute()); + AS_CHECK(environment->context->Unprepare()); + } + void ScriptObjectGroup::executeOnGroup_voidEvent(size_t eventIndex) { for (size_t i = 0; i < environment->systems.size(); i++) { if (!systemInstances[i]) diff --git a/Deer/src/DeerCore/Scripting/ScriptEnvironmentContextData.h b/Deer/src/DeerCore/Scripting/ScriptEnvironmentContextData.h index 60d21ad..d816336 100644 --- a/Deer/src/DeerCore/Scripting/ScriptEnvironmentContextData.h +++ b/Deer/src/DeerCore/Scripting/ScriptEnvironmentContextData.h @@ -5,9 +5,7 @@ namespace Deer { class World; struct ScriptEnvironmentContextData { - ScriptEnvironmentContextData(); - - ScriptEnvironment* environment; - World* world; + ScriptEnvironment* environment = nullptr; + World* world = nullptr; }; } // namespace Deer \ No newline at end of file diff --git a/Deer/src/DeerCore/Scripting/ScriptSystem.cpp b/Deer/src/DeerCore/Scripting/ScriptSystem.cpp index 86b9845..2638615 100644 --- a/Deer/src/DeerCore/Scripting/ScriptSystem.cpp +++ b/Deer/src/DeerCore/Scripting/ScriptSystem.cpp @@ -20,9 +20,11 @@ namespace Deer { void registerMath(); void registerEngine(); void registerEntity(); + void registerWorld(); #ifdef DEER_RENDER void registerResources(); void registerEntity_Render(); + void registerImGui(); #endif }; // namespace Scripting @@ -45,6 +47,8 @@ namespace Deer { #ifdef DEER_RENDER registerResources(); registerEntity_Render(); + registerWorld(); + registerImGui(); #endif } diff --git a/Deer/src/DeerCore/World/World.cpp b/Deer/src/DeerCore/World/World.cpp index f95a268..efa7e23 100755 --- a/Deer/src/DeerCore/World/World.cpp +++ b/Deer/src/DeerCore/World/World.cpp @@ -16,7 +16,7 @@ namespace Deer { entityEnvironment = MakeScope(); DEER_CORE_ASSERT(worldSettings.updateFrequency <= 120, "Invalid world update frequency"); - executingState = WorldState::Stopped; + executingState = WorldState::Created; } World::~World() { diff --git a/Deer/src/DeerRender/Scripting/EntityRegistry.cpp b/Deer/src/DeerRender/Scripting/EntityRegistry.cpp index d63502e..3473a76 100644 --- a/Deer/src/DeerRender/Scripting/EntityRegistry.cpp +++ b/Deer/src/DeerRender/Scripting/EntityRegistry.cpp @@ -42,9 +42,9 @@ namespace Deer { } void Scripting::registerEntityStructs_Render() { - AS_CHECK(scriptEngine->RegisterObjectType("MeshComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); - AS_CHECK(scriptEngine->RegisterObjectType("ShaderComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); - AS_CHECK(scriptEngine->RegisterObjectType("CameraComponent", sizeof(EntityHandle), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_C)); + AS_CHECK(scriptEngine->RegisterObjectType("MeshComponent", sizeof(EntityHandle), asGetTypeTraits() | asOBJ_VALUE | asOBJ_APP_CLASS_C | asOBJ_POD)); + AS_CHECK(scriptEngine->RegisterObjectType("ShaderComponent", sizeof(EntityHandle), asGetTypeTraits() | asOBJ_VALUE | asOBJ_APP_CLASS_C | asOBJ_POD)); + AS_CHECK(scriptEngine->RegisterObjectType("CameraComponent", sizeof(EntityHandle), asGetTypeTraits() | asOBJ_VALUE | asOBJ_APP_CLASS_C | asOBJ_POD)); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "MeshComponent", "void f()", constructEntityStruct); REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "ShaderComponent", "void f()", constructEntityStruct); diff --git a/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp b/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp new file mode 100644 index 0000000..ab317d4 --- /dev/null +++ b/Deer/src/DeerRender/Scripting/ImGuiRegistry.cpp @@ -0,0 +1,196 @@ +#include "DeerCore/Scripting/Helpers.h" +#include "DeerRender/Scripting/InternalAPI/ImGUI.h" +#include "imgui.h" + +namespace Deer { + namespace Scripting { + extern asIScriptEngine* scriptEngine; + + void registerImGui(); + + void registerImGuiFunctions(); + void registerImGuiStructs(); + } // namespace Scripting + + void Scripting::registerImGui() { + registerImGuiStructs(); + registerImGuiFunctions(); + } + + void Scripting::registerImGuiFunctions() { + scriptEngine->SetDefaultNamespace("ImGui"); + + // Buttons + REGISTER_GLOBAL_FUNC(scriptEngine, "bool button(const string& in text)", Scripting::button); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool buttonCenter(const string& in text)", Scripting::buttonCenter); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool buttonEnd(const string& in text)", Scripting::buttonEnd); + + REGISTER_GLOBAL_FUNC(scriptEngine, "bool cartIconButton(const string& in label, const string& in icon, int iconSize, int width)", Scripting::cartIconButton); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool cartIconButton(const string& in label, FrameBuffer frameBuffer, int iconSize, int width)", Scripting::cartIconButton_frameBuffer); + + // Checkboxes + REGISTER_GLOBAL_FUNC(scriptEngine, "bool checkbox(const string& in text, bool value)", Scripting::checkbox); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool checkboxDisabled(const string& in text, bool value)", Scripting::checkboxDisabled); + + // Sliders & Inputs + REGISTER_GLOBAL_FUNC(scriptEngine, "float magicSlider(const string& in text, float value, float speed)", Scripting::magicSlider); + REGISTER_GLOBAL_FUNC(scriptEngine, "vec3 magicSlider3(const string& in text, vec3 value, float speed)", Scripting::magicSlider3); + REGISTER_GLOBAL_FUNC(scriptEngine, "int sliderInt(string& in text, int value, int min, int max)", Scripting::sliderInt); + REGISTER_GLOBAL_FUNC(scriptEngine, "float slider(string& in text, float value, float min, float max)", Scripting::slider); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool inputText(const string& in text, const string& in value, string& out valueOutput)", Scripting::inputText); + + // Menus + REGISTER_GLOBAL_FUNC(scriptEngine, "bool menuItem(const string& in text)", Scripting::menuItem); + REGISTER_GLOBAL_FUNC(scriptEngine, "void menuItemDisabled(const string& in text)", Scripting::menuItemDisabled); + REGISTER_GLOBAL_FUNC(scriptEngine, "void subMenu(const string& in text, SimpleFunction@+ func)", Scripting::subMenu); + + // Text + REGISTER_GLOBAL_FUNC(scriptEngine, "void text(const string& in text)", Scripting::text); + REGISTER_GLOBAL_FUNC(scriptEngine, "void textCenter(const string& in text)", Scripting::textCenter); + REGISTER_GLOBAL_FUNC(scriptEngine, "void textEnd(const string& in text)", Scripting::textEnd); + REGISTER_GLOBAL_FUNC(scriptEngine, "void textColor(float r, float g, float b, const string& in text)", Scripting::textColor); + + // Titles + REGISTER_GLOBAL_FUNC(scriptEngine, "void title(const string& in text)", Scripting::title); + REGISTER_GLOBAL_FUNC(scriptEngine, "void titleCenter(const string& in text)", Scripting::titleCenter); + REGISTER_GLOBAL_FUNC(scriptEngine, "void titleCenterY(const string& in text, int height)", Scripting::titleCenterY); + REGISTER_GLOBAL_FUNC(scriptEngine, "void titleEnd(const string& in text)", Scripting::titleEnd); + + // Layout helpers + REGISTER_GLOBAL_FUNC(scriptEngine, "void sameline()", Scripting::sameline); + REGISTER_GLOBAL_FUNC(scriptEngine, "void separator()", Scripting::separator); + REGISTER_GLOBAL_FUNC(scriptEngine, "void space()", Scripting::space); + REGISTER_GLOBAL_FUNC(scriptEngine, "void space(int x, int y = 10)", Scripting::space_params); + + // Drawing + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBuffer(FrameBuffer, int, int)", Scripting::drawFrameBuffer); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawFrameBufferCentered(FrameBuffer, int, int)", Scripting::drawFrameBufferCentered); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(const string& in, int)", Scripting::drawIcon); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(const string& in, int)", Scripting::drawIconCentered); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(const string& in, int)", Scripting::drawIconHighlight); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(const string& in, int)", Scripting::drawIconCenteredHighlight); + + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIcon(Texture texture, int)", Scripting::drawIcon_resource); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCentered(Texture texture, int)", Scripting::drawIconCentered_resource); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconHighlight(Texture texture, int)", Scripting::drawIconHighlight_resource); + REGISTER_GLOBAL_FUNC(scriptEngine, "void drawIconCenteredHighlight(Texture texture, int)", Scripting::drawIconCenteredHighlight_resource); + + // Input state + REGISTER_GLOBAL_FUNC(scriptEngine, "bool isKeyDown(key)", Scripting::isKeyDown); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool isKeyPressed(key)", Scripting::isKeyPressed); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool isMouseDragging(key)", Scripting::isMouseDragging); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool isItemClicked(int)", Scripting::isItemClicked); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool isMouseDoubleClicked(int)", Scripting::isMouseDoubleClicked); + + // Mouse info + REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDragDeltaX()", Scripting::getMouseDragDeltaX); + REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDragDeltaY()", Scripting::getMouseDragDeltaY); + REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaX()", Scripting::getMouseDeltaX); + REGISTER_GLOBAL_FUNC(scriptEngine, "float getMouseDeltaY()", Scripting::getMouseDeltaY); + + // Panel & layout co(scriptEngine, trol + REGISTER_GLOBAL_FUNC(scriptEngine, "bool isPanelActive()", Scripting::isPanelActive); + REGISTER_GLOBAL_FUNC(scriptEngine, "void disablePanelPadding(bool)", Scripting::disablePanelPadding); + REGISTER_GLOBAL_FUNC(scriptEngine, "int getAvailableSizeX()", Scripting::getAvailableSizeX); + REGISTER_GLOBAL_FUNC(scriptEngine, "int getAvailableSizeY()", Scripting::getAvailableSizeY); + + // Columns + REGISTER_GLOBAL_FUNC(scriptEngine, "void automaticColumns(int)", Scripting::automaticColumns); + REGISTER_GLOBAL_FUNC(scriptEngine, "void columns(int)", Scripting::columns); + REGISTER_GLOBAL_FUNC(scriptEngine, "void nextColumn()", Scripting::nextColumn); + REGISTER_GLOBAL_FUNC(scriptEngine, "void endColumns()", Scripting::endColumns); + + // Tree & Components(scriptEngine, + REGISTER_GLOBAL_FUNC(scriptEngine, "void treeNodeLeaf(const string& in, bool)", Scripting::treeNodeLeaf); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool treeNode(const string& in, bool, SimpleFunction@+)", Scripting::treeNode); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool componentNode(const string& in, SimpleFunction@+)", Scripting::componentNode); + REGISTER_GLOBAL_FUNC(scriptEngine, "bool componentNodeContextMenu(const string& in, SimpleFunction@+, SimpleFunction@+)", Scripting::componentNodeContextMenu); + + // Popups & Modals + REGISTER_GLOBAL_FUNC(scriptEngine, "void contextItemPopup(const string& in, SimpleFunction@+)", Scripting::contextItemPopup); + REGISTER_GLOBAL_FUNC(scriptEngine, "void contextMenuPopup(const string& in, SimpleFunction@+)", Scripting::contextMenuPopup); + REGISTER_GLOBAL_FUNC(scriptEngine, "void modalPopup(const string& in, SimpleFunction@+)", Scripting::modalPopup); + REGISTER_GLOBAL_FUNC(scriptEngine, "void simplePopup(const string& in, SimpleFunction@+)", Scripting::simplePopup); + REGISTER_GLOBAL_FUNC(scriptEngine, "void openPopup(const string& in, any@)", Scripting::openPopup); + REGISTER_GLOBAL_FUNC(scriptEngine, "void closePopup()", Scripting::closePopup); + + // Drag & Drop + REGISTER_GLOBAL_FUNC(scriptEngine, "void dragDropSource(const string& in, any@+, const string& in)", Scripting::dragDropSource); + REGISTER_GLOBAL_FUNC(scriptEngine, "void dragDropTarget(const string& in, ReciverFunction@+)", Scripting::dragDropTarget); + scriptEngine->SetDefaultNamespace(""); + } + + void Scripting::registerImGuiStructs() { + + AS_CHECK(scriptEngine->RegisterEnum("key")); + + AS_CHECK(scriptEngine->RegisterEnumValue("key", "A", ImGuiKey_A)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "B", ImGuiKey_B)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "C", ImGuiKey_C)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "D", ImGuiKey_D)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "E", ImGuiKey_E)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "F", ImGuiKey_F)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "G", ImGuiKey_G)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "H", ImGuiKey_H)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "I", ImGuiKey_I)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "J", ImGuiKey_J)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K", ImGuiKey_K)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "L", ImGuiKey_L)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "M", ImGuiKey_M)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "N", ImGuiKey_N)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "O", ImGuiKey_O)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "P", ImGuiKey_P)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Q", ImGuiKey_Q)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "R", ImGuiKey_R)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "S", ImGuiKey_S)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "T", ImGuiKey_T)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "U", ImGuiKey_U)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "V", ImGuiKey_V)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "W", ImGuiKey_W)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "X", ImGuiKey_X)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Y", ImGuiKey_Y)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Z", ImGuiKey_Z)); + + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K0", ImGuiKey_0)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K1", ImGuiKey_1)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K2", ImGuiKey_2)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K3", ImGuiKey_3)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K4", ImGuiKey_4)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K5", ImGuiKey_5)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K6", ImGuiKey_6)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K7", ImGuiKey_7)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K8", ImGuiKey_8)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "K9", ImGuiKey_9)); + + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Tab", ImGuiKey_Tab)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Enter", ImGuiKey_Enter)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Escape", ImGuiKey_Escape)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Backspace", ImGuiKey_Backspace)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Space", ImGuiKey_Space)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Delete", ImGuiKey_Delete)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Insert", ImGuiKey_Insert)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Home", ImGuiKey_Home)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "End", ImGuiKey_End)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "PageUp", ImGuiKey_PageUp)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "PageDown", ImGuiKey_PageDown)); + + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Right", ImGuiKey_RightArrow)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Up", ImGuiKey_UpArrow)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Down", ImGuiKey_DownArrow)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "Left", ImGuiKey_LeftArrow)); + + AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightCtrl", ImGuiKey_RightCtrl)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftShift", ImGuiKey_LeftShift)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightShift", ImGuiKey_RightShift)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftAlt", ImGuiKey_LeftAlt)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightAlt", ImGuiKey_RightAlt)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftSuper", ImGuiKey_LeftSuper)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightSuper", ImGuiKey_RightSuper)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftCtrl", ImGuiKey_LeftCtrl)); + + AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseLeft", ImGuiKey_MouseLeft)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseRight", ImGuiKey_MouseRight)); + AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseMiddle", ImGuiKey_MouseMiddle)); + } + +} // namespace Deer diff --git a/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp b/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp index 15bc5c5..a57a68b 100644 --- a/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp +++ b/Deer/src/DeerRender/Scripting/InternalAPI/ImGUI.cpp @@ -192,7 +192,9 @@ namespace Deer { ImGui::TextColored(ImVec4(r, g, b, 1.0f), "%s", msg.c_str()); } - void text(std::string& msg) { ImGui::Text("%s", msg.c_str()); } + void text(std::string& msg) { + ImGui::Text("%s", msg.c_str()); + } bool isPanelActive() { return ImGui::IsWindowFocused( diff --git a/Deer/vendor/GLFW/CMakeLists.txt b/Deer/vendor/GLFW/CMakeLists.txt deleted file mode 100755 index f5e538b..0000000 --- a/Deer/vendor/GLFW/CMakeLists.txt +++ /dev/null @@ -1,179 +0,0 @@ -cmake_minimum_required(VERSION 3.4...3.20 FATAL_ERROR) - -project(GLFW VERSION 3.4.0 LANGUAGES C) - -set(CMAKE_LEGACY_CYGWIN_WIN32 OFF) - -if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif() - -if (POLICY CMP0069) - cmake_policy(SET CMP0069 NEW) -endif() - -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif() - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) - -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(GLFW_STANDALONE TRUE) -endif() - -option(BUILD_SHARED_LIBS "Build shared libraries" OFF) -option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE}) -option(GLFW_BUILD_TESTS "Build the GLFW test programs" ${GLFW_STANDALONE}) -option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON) -option(GLFW_INSTALL "Generate installation target" ON) - -include(GNUInstallDirs) -include(CMakeDependentOption) - -if (GLFW_USE_OSMESA) - message(FATAL_ERROR "GLFW_USE_OSMESA has been removed; set the GLFW_PLATFORM init hint") -endif() - -cmake_dependent_option(GLFW_BUILD_WIN32 "Build support for Win32" ON "WIN32" OFF) -cmake_dependent_option(GLFW_BUILD_COCOA "Build support for Cocoa" ON "APPLE" OFF) -cmake_dependent_option(GLFW_BUILD_X11 "Build support for X11" ON "UNIX;NOT APPLE" OFF) -cmake_dependent_option(GLFW_BUILD_WAYLAND "Build support for Wayland" - "${GLFW_USE_WAYLAND}" "UNIX;NOT APPLE" OFF) - -cmake_dependent_option(GLFW_USE_HYBRID_HPG "Force use of high-performance GPU on hybrid systems" OFF - "WIN32" OFF) -cmake_dependent_option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" ON - "MSVC" OFF) - -set(GLFW_LIBRARY_TYPE "${GLFW_LIBRARY_TYPE}" CACHE STRING - "Library type override for GLFW (SHARED, STATIC, OBJECT, or empty to follow BUILD_SHARED_LIBS)") - -if (GLFW_LIBRARY_TYPE) - if (GLFW_LIBRARY_TYPE STREQUAL "SHARED") - set(GLFW_BUILD_SHARED_LIBRARY TRUE) - else() - set(GLFW_BUILD_SHARED_LIBRARY FALSE) - endif() -else() - set(GLFW_BUILD_SHARED_LIBRARY ${BUILD_SHARED_LIBS}) -endif() - -list(APPEND CMAKE_MODULE_PATH "${GLFW_SOURCE_DIR}/CMake/modules") - -find_package(Threads REQUIRED) - -if (GLFW_BUILD_DOCS) - set(DOXYGEN_SKIP_DOT TRUE) - find_package(Doxygen) -endif() - -#-------------------------------------------------------------------- -# Report backend selection -#-------------------------------------------------------------------- -if (GLFW_BUILD_WIN32) - message(STATUS "Including Win32 support") -endif() -if (GLFW_BUILD_COCOA) - message(STATUS "Including Cocoa support") -endif() -if (GLFW_BUILD_WAYLAND) - message(STATUS "Including Wayland support") -endif() -if (GLFW_BUILD_X11) - message(STATUS "Including X11 support") -endif() - -#-------------------------------------------------------------------- -# Apply Microsoft C runtime library option -# This is here because it also applies to tests and examples -#-------------------------------------------------------------------- -if (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL) - if (CMAKE_VERSION VERSION_LESS 3.15) - foreach (flag CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELWITHDEBINFO) - - if (flag MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") - endif() - if (flag MATCHES "/MDd") - string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") - endif() - - endforeach() - else() - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - endif() -endif() - -#-------------------------------------------------------------------- -# Create generated files -#-------------------------------------------------------------------- -include(CMakePackageConfigHelpers) - -set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3") - -configure_package_config_file(CMake/glfw3Config.cmake.in - src/glfw3Config.cmake - INSTALL_DESTINATION "${GLFW_CONFIG_PATH}" - NO_CHECK_REQUIRED_COMPONENTS_MACRO) - -write_basic_package_version_file(src/glfw3ConfigVersion.cmake - VERSION ${GLFW_VERSION} - COMPATIBILITY SameMajorVersion) - -#-------------------------------------------------------------------- -# Add subdirectories -#-------------------------------------------------------------------- -add_subdirectory(src) - -if (GLFW_BUILD_EXAMPLES) - add_subdirectory(examples) -endif() - -if (GLFW_BUILD_TESTS) - add_subdirectory(tests) -endif() - -if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS) - add_subdirectory(docs) -endif() - -#-------------------------------------------------------------------- -# Install files other than the library -# The library is installed by src/CMakeLists.txt -#-------------------------------------------------------------------- -if (GLFW_INSTALL) - install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) - - install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" - "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" - DESTINATION "${GLFW_CONFIG_PATH}") - - install(EXPORT glfwTargets FILE glfw3Targets.cmake - EXPORT_LINK_INTERFACE_LIBRARIES - DESTINATION "${GLFW_CONFIG_PATH}") - install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - - if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS) - install(DIRECTORY "${GLFW_BINARY_DIR}/docs/html" - DESTINATION "${CMAKE_INSTALL_DOCDIR}") - endif() - - # Only generate this target if no higher-level project already has - if (NOT TARGET uninstall) - configure_file(CMake/cmake_uninstall.cmake.in - cmake_uninstall.cmake IMMEDIATE @ONLY) - - add_custom_target(uninstall - "${CMAKE_COMMAND}" -P - "${GLFW_BINARY_DIR}/cmake_uninstall.cmake") - set_target_properties(uninstall PROPERTIES FOLDER "GLFW3") - endif() -endif() - diff --git a/Deer/vendor/GLFW/src/CMakeLists.txt b/Deer/vendor/GLFW/src/CMakeLists.txt deleted file mode 100755 index a07ca93..0000000 --- a/Deer/vendor/GLFW/src/CMakeLists.txt +++ /dev/null @@ -1,399 +0,0 @@ - -add_library(glfw ${GLFW_LIBRARY_TYPE} - "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" - "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h" - internal.h platform.h mappings.h - context.c init.c input.c monitor.c platform.c vulkan.c window.c - egl_context.c osmesa_context.c null_platform.h null_joystick.h - null_init.c null_monitor.c null_window.c null_joystick.c) - -# The time, thread and module code is shared between all backends on a given OS, -# including the null backend, which still needs those bits to be functional -if (APPLE) - target_sources(glfw PRIVATE cocoa_time.h cocoa_time.c posix_thread.h - posix_module.c posix_thread.c) -elseif (WIN32) - target_sources(glfw PRIVATE win32_time.h win32_thread.h win32_module.c - win32_time.c win32_thread.c) -else() - target_sources(glfw PRIVATE posix_time.h posix_thread.h posix_module.c - posix_time.c posix_thread.c) -endif() - -add_custom_target(update_mappings - COMMAND "${CMAKE_COMMAND}" -P "${GLFW_SOURCE_DIR}/CMake/GenerateMappings.cmake" mappings.h.in mappings.h - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMENT "Updating gamepad mappings from upstream repository" - SOURCES mappings.h.in "${GLFW_SOURCE_DIR}/CMake/GenerateMappings.cmake" - VERBATIM) - -set_target_properties(update_mappings PROPERTIES FOLDER "GLFW3") - -if (GLFW_BUILD_COCOA) - target_compile_definitions(glfw PRIVATE _GLFW_COCOA) - target_sources(glfw PRIVATE cocoa_platform.h cocoa_joystick.h cocoa_init.m - cocoa_joystick.m cocoa_monitor.m cocoa_window.m - nsgl_context.m) -endif() - -if (GLFW_BUILD_WIN32) - target_compile_definitions(glfw PRIVATE _GLFW_WIN32) - target_sources(glfw PRIVATE win32_platform.h win32_joystick.h win32_init.c - win32_joystick.c win32_monitor.c win32_window.c - wgl_context.c) -endif() - -if (GLFW_BUILD_X11) - target_compile_definitions(glfw PRIVATE _GLFW_X11) - target_sources(glfw PRIVATE x11_platform.h xkb_unicode.h x11_init.c - x11_monitor.c x11_window.c xkb_unicode.c - glx_context.c) -endif() - -if (GLFW_BUILD_WAYLAND) - target_compile_definitions(glfw PRIVATE _GLFW_WAYLAND) - target_sources(glfw PRIVATE wl_platform.h xkb_unicode.h wl_init.c - wl_monitor.c wl_window.c xkb_unicode.c) -endif() - -if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND) - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c) - endif() -endif() - -if (GLFW_BUILD_WAYLAND) - include(CheckIncludeFiles) - include(CheckFunctionExists) - check_function_exists(memfd_create HAVE_MEMFD_CREATE) - if (HAVE_MEMFD_CREATE) - target_compile_definitions(glfw PRIVATE HAVE_MEMFD_CREATE) - endif() - - find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner) - - include(FindPkgConfig) - pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.15) - pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir) - pkg_get_variable(WAYLAND_CLIENT_PKGDATADIR wayland-client pkgdatadir) - - macro(wayland_generate protocol_file output_file) - add_custom_command(OUTPUT "${output_file}.h" - COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_file}" "${output_file}.h" - DEPENDS "${protocol_file}" - VERBATIM) - - add_custom_command(OUTPUT "${output_file}-code.h" - COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_file}" "${output_file}-code.h" - DEPENDS "${protocol_file}" - VERBATIM) - - target_sources(glfw PRIVATE "${output_file}.h" "${output_file}-code.h") - endmacro() - - wayland_generate( - "${WAYLAND_CLIENT_PKGDATADIR}/wayland.xml" - "${GLFW_BINARY_DIR}/src/wayland-client-protocol") - wayland_generate( - "${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml" - "${GLFW_BINARY_DIR}/src/wayland-xdg-shell-client-protocol") - wayland_generate( - "${WAYLAND_PROTOCOLS_BASE}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml" - "${GLFW_BINARY_DIR}/src/wayland-xdg-decoration-client-protocol") - wayland_generate( - "${WAYLAND_PROTOCOLS_BASE}/stable/viewporter/viewporter.xml" - "${GLFW_BINARY_DIR}/src/wayland-viewporter-client-protocol") - wayland_generate( - "${WAYLAND_PROTOCOLS_BASE}/unstable/relative-pointer/relative-pointer-unstable-v1.xml" - "${GLFW_BINARY_DIR}/src/wayland-relative-pointer-unstable-v1-client-protocol") - wayland_generate( - "${WAYLAND_PROTOCOLS_BASE}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml" - "${GLFW_BINARY_DIR}/src/wayland-pointer-constraints-unstable-v1-client-protocol") - wayland_generate( - "${WAYLAND_PROTOCOLS_BASE}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml" - "${GLFW_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol") -endif() - -if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY) - configure_file(glfw.rc.in glfw.rc @ONLY) - target_sources(glfw PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/glfw.rc") -endif() - -if (UNIX AND GLFW_BUILD_SHARED_LIBRARY) - # On Unix-like systems, shared libraries can use the soname system. - set(GLFW_LIB_NAME glfw) -else() - set(GLFW_LIB_NAME glfw3) -endif() - -set_target_properties(glfw PROPERTIES - OUTPUT_NAME ${GLFW_LIB_NAME} - VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR} - SOVERSION ${GLFW_VERSION_MAJOR} - POSITION_INDEPENDENT_CODE ON - C_STANDARD 99 - C_EXTENSIONS OFF - DEFINE_SYMBOL _GLFW_BUILD_DLL - FOLDER "GLFW3") - -target_include_directories(glfw PUBLIC - "$" - "$") -target_include_directories(glfw PRIVATE - "${GLFW_SOURCE_DIR}/src" - "${GLFW_BINARY_DIR}/src") -target_link_libraries(glfw PRIVATE Threads::Threads) - -# Workaround for CMake not knowing about .m files before version 3.16 -if (CMAKE_VERSION VERSION_LESS "3.16" AND APPLE) - set_source_files_properties(cocoa_init.m cocoa_joystick.m cocoa_monitor.m - cocoa_window.m nsgl_context.m PROPERTIES - LANGUAGE C) -endif() - -if (GLFW_BUILD_WIN32) - list(APPEND glfw_PKG_LIBS "-lgdi32") -endif() - -if (GLFW_BUILD_COCOA) - target_link_libraries(glfw PRIVATE "-framework Cocoa" - "-framework IOKit" - "-framework CoreFoundation") - - set(glfw_PKG_DEPS "") - set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation") -endif() - -if (GLFW_BUILD_WAYLAND) - pkg_check_modules(Wayland REQUIRED - wayland-client>=0.2.7 - wayland-cursor>=0.2.7 - wayland-egl>=0.2.7 - xkbcommon>=0.5.0) - - target_include_directories(glfw PRIVATE ${Wayland_INCLUDE_DIRS}) - - if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") - find_package(EpollShim) - if (EPOLLSHIM_FOUND) - target_include_directories(glfw PRIVATE ${EPOLLSHIM_INCLUDE_DIRS}) - target_link_libraries(glfw PRIVATE ${EPOLLSHIM_LIBRARIES}) - endif() - endif() -endif() - -if (GLFW_BUILD_X11) - find_package(X11 REQUIRED) - target_include_directories(glfw PRIVATE "${X11_X11_INCLUDE_PATH}") - - # Check for XRandR (modern resolution switching and gamma control) - if (NOT X11_Xrandr_INCLUDE_PATH) - message(FATAL_ERROR "RandR headers not found; install libxrandr development package") - endif() - target_include_directories(glfw PRIVATE "${X11_Xrandr_INCLUDE_PATH}") - - # Check for Xinerama (legacy multi-monitor support) - if (NOT X11_Xinerama_INCLUDE_PATH) - message(FATAL_ERROR "Xinerama headers not found; install libxinerama development package") - endif() - target_include_directories(glfw PRIVATE "${X11_Xinerama_INCLUDE_PATH}") - - # Check for Xkb (X keyboard extension) - if (NOT X11_Xkb_INCLUDE_PATH) - message(FATAL_ERROR "XKB headers not found; install X11 development package") - endif() - target_include_directories(glfw PRIVATE "${X11_Xkb_INCLUDE_PATH}") - - # Check for Xcursor (cursor creation from RGBA images) - if (NOT X11_Xcursor_INCLUDE_PATH) - message(FATAL_ERROR "Xcursor headers not found; install libxcursor development package") - endif() - target_include_directories(glfw PRIVATE "${X11_Xcursor_INCLUDE_PATH}") - - # Check for XInput (modern HID input) - if (NOT X11_Xi_INCLUDE_PATH) - message(FATAL_ERROR "XInput headers not found; install libxi development package") - endif() - target_include_directories(glfw PRIVATE "${X11_Xi_INCLUDE_PATH}") - - # Check for X Shape (custom window input shape) - if (NOT X11_Xshape_INCLUDE_PATH) - message(FATAL_ERROR "X Shape headers not found; install libxext development package") - endif() - target_include_directories(glfw PRIVATE "${X11_Xshape_INCLUDE_PATH}") -endif() - -if (UNIX AND NOT APPLE) - find_library(RT_LIBRARY rt) - mark_as_advanced(RT_LIBRARY) - if (RT_LIBRARY) - target_link_libraries(glfw PRIVATE "${RT_LIBRARY}") - list(APPEND glfw_PKG_LIBS "-lrt") - endif() - - find_library(MATH_LIBRARY m) - mark_as_advanced(MATH_LIBRARY) - if (MATH_LIBRARY) - target_link_libraries(glfw PRIVATE "${MATH_LIBRARY}") - list(APPEND glfw_PKG_LIBS "-lm") - endif() - - if (CMAKE_DL_LIBS) - target_link_libraries(glfw PRIVATE "${CMAKE_DL_LIBS}") - list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}") - endif() -endif() - -# Make GCC warn about declarations that VS 2010 and 2012 won't accept for all -# source files that VS will build (Clang ignores this because we set -std=c99) -if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - set_source_files_properties(context.c init.c input.c monitor.c platform.c vulkan.c - window.c null_init.c null_joystick.c null_monitor.c - null_window.c win32_init.c win32_joystick.c win32_module.c - win32_monitor.c win32_time.c win32_thread.c win32_window.c - wgl_context.c egl_context.c osmesa_context.c PROPERTIES - COMPILE_FLAGS -Wdeclaration-after-statement) -endif() - -if (WIN32) - if (GLFW_USE_HYBRID_HPG) - target_compile_definitions(glfw PRIVATE _GLFW_USE_HYBRID_HPG) - endif() -endif() - -# Enable a reasonable set of warnings -# NOTE: The order matters here, Clang-CL matches both MSVC and Clang -if (MSVC) - target_compile_options(glfw PRIVATE "/W3") -elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR - CMAKE_C_COMPILER_ID STREQUAL "Clang" OR - CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - - target_compile_options(glfw PRIVATE "-Wall") -endif() - -if (GLFW_BUILD_WIN32) - target_compile_definitions(glfw PRIVATE UNICODE _UNICODE) -endif() - -# HACK: When building on MinGW, WINVER and UNICODE need to be defined before -# the inclusion of stddef.h (by glfw3.h), which is itself included before -# win32_platform.h. We define them here until a saner solution can be found -# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. -if (MINGW) - target_compile_definitions(glfw PRIVATE WINVER=0x0501) -endif() - -# Workaround for legacy MinGW not providing XInput and DirectInput -if (MINGW) - include(CheckIncludeFile) - check_include_file(dinput.h DINPUT_H_FOUND) - check_include_file(xinput.h XINPUT_H_FOUND) - if (NOT DINPUT_H_FOUND OR NOT XINPUT_H_FOUND) - target_include_directories(glfw PRIVATE "${GLFW_SOURCE_DIR}/deps/mingw") - endif() -endif() - -# Workaround for the MS CRT deprecating parts of the standard library -if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") - target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) -endif() - -# Workaround for VS 2008 not shipping with stdint.h -if (MSVC90) - target_include_directories(glfw PUBLIC "${GLFW_SOURCE_DIR}/deps/vs2008") -endif() - -# Check for the DirectX 9 SDK as it is not included with VS 2008 -if (MSVC90) - include(CheckIncludeFile) - check_include_file(dinput.h DINPUT_H_FOUND) - if (NOT DINPUT_H_FOUND) - message(FATAL_ERROR "DirectX 9 headers not found; install DirectX 9 SDK") - endif() -endif() - -# Workaround for -std=c99 on Linux disabling _DEFAULT_SOURCE (POSIX 2008 and more) -if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND) - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_definitions(glfw PRIVATE _DEFAULT_SOURCE) - endif() -endif() - -if (GLFW_BUILD_SHARED_LIBRARY) - if (WIN32) - if (MINGW) - # Remove the dependency on the shared version of libgcc - # NOTE: MinGW-w64 has the correct default but MinGW needs this - target_link_libraries(glfw PRIVATE "-static-libgcc") - - # Remove the lib prefix on the DLL (but not the import library) - set_target_properties(glfw PROPERTIES PREFIX "") - - # Add a suffix to the import library to avoid naming conflicts - set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") - else() - # Add a suffix to the import library to avoid naming conflicts - set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") - endif() - - target_compile_definitions(glfw INTERFACE GLFW_DLL) - endif() - - if (MINGW) - # Enable link-time exploit mitigation features enabled by default on MSVC - include(CheckCCompilerFlag) - - # Compatibility with data execution prevention (DEP) - set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") - check_c_compiler_flag("" _GLFW_HAS_DEP) - if (_GLFW_HAS_DEP) - target_link_libraries(glfw PRIVATE "-Wl,--nxcompat") - endif() - - # Compatibility with address space layout randomization (ASLR) - set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") - check_c_compiler_flag("" _GLFW_HAS_ASLR) - if (_GLFW_HAS_ASLR) - target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase") - endif() - - # Compatibility with 64-bit address space layout randomization (ASLR) - set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va") - check_c_compiler_flag("" _GLFW_HAS_64ASLR) - if (_GLFW_HAS_64ASLR) - target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va") - endif() - - # Clear flags again to avoid breaking later tests - set(CMAKE_REQUIRED_FLAGS) - endif() - - if (UNIX) - # Hide symbols not explicitly tagged for export from the shared library - target_compile_options(glfw PRIVATE "-fvisibility=hidden") - endif() -endif() - -foreach(arg ${glfw_PKG_DEPS}) - string(APPEND deps " ${arg}") -endforeach() -foreach(arg ${glfw_PKG_LIBS}) - string(APPEND libs " ${arg}") -endforeach() - -set(GLFW_PKG_CONFIG_REQUIRES_PRIVATE "${deps}" CACHE INTERNAL - "GLFW pkg-config Requires.private") -set(GLFW_PKG_CONFIG_LIBS_PRIVATE "${libs}" CACHE INTERNAL - "GLFW pkg-config Libs.private") - -configure_file("${GLFW_SOURCE_DIR}/CMake/glfw3.pc.in" glfw3.pc @ONLY) - -if (GLFW_INSTALL) - install(TARGETS glfw - EXPORT glfwTargets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() - diff --git a/DeerStudio/headers/DeerStudio/AngelScriptEngine.h b/DeerStudio/headers/DeerStudio/AngelScriptEngine.h deleted file mode 100644 index 0cf9cb6..0000000 --- a/DeerStudio/headers/DeerStudio/AngelScriptEngine.h +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once -#include "DeerRender/Tools/Memory.h" -#include "DeerRender/Tools/Path.h" -#include -#include -#include - -class asIScriptEngine; -class asIScriptModule; -class asIScriptContext; -class asIScriptObject; -class asIScriptFunction; -class asIScriptFunction; -class asITypeInfo; -class CScriptBuilder; -class asIScriptGeneric; - -namespace Deer { - namespace StudioAPI { - void initialize(); - void update(); - void shutdown(); - void render(); - void deinitialize(); - - struct ServiceExposedFunctionData { - asIScriptFunction* exposedFunction = nullptr; - asIScriptObject* exposedObject = nullptr; - std::string exposedFunctionName; - }; - - struct Service { - public: - Service(asITypeInfo*); - ~Service(); - - Service(Service&) = delete; - Service& operator=(Service&) = delete; - Service(Service&&) = default; - Service& operator=(Service&&) = default; - - void init(); - void update(); - void shutdown(); - - void updateTypes(asIScriptModule*); - void registerApiExpose(); - - protected: - asITypeInfo* type = nullptr; - asIScriptObject* object = nullptr; - asIScriptFunction* updateFunction = nullptr; - asIScriptFunction* initFunction = nullptr; - asIScriptFunction* shutdownFunction = nullptr; - std::vector> exposedFunctions; - - std::string typeName; - - private: - void registerExposedFunction(asIScriptFunction*); - }; - - void service_exposed_generic_call(asIScriptGeneric*); - - struct Panel : public Service { - public: - Panel(asITypeInfo*); - ~Panel(); - - Panel(Panel&) = delete; - Panel(Panel&&) = default; - Panel& operator=(Panel&&) = default; - - void render(); - void updateTypes(asIScriptModule*); - - private: - asIScriptFunction* renderFunction; - asIScriptFunction* menuBarFunction; - }; - - struct ModuleDescription { - public: - int patchVersion = -1; - std::string moduleName; - std::string modulePath; - std::vector module_requires; - }; - - enum class ModuleState { - NotBuilt = 0, - Building = 1, - Built = 2, - DependencyFailed = 3, - CompilationFailed = 5, - ExecutionError = 6 - }; - - struct Module { - public: - ModuleDescription moduleInfo; - ModuleState state = ModuleState::NotBuilt; - - Module(const ModuleDescription&); - ~Module(); - - Module(const Module&) = delete; - Module& operator=(Module&) = delete; - Module(Module&&) = default; - Module& operator=(Module&&) = default; - - void init(); - void update(); - void render(); - void shutdown(); - - void extract(asIScriptModule*); - void generatePredefined(); - void updateTypes(); - - inline void invalidate() { state = ModuleState::ExecutionError; } - - private: - asIScriptModule* angelscriptModule; - - std::vector panels; - std::vector services; - }; - - extern asIScriptEngine* scriptEngine; - extern asIScriptContext* scriptContext; - extern CScriptBuilder scriptBuilder; - extern std::vector modules; - extern std::unordered_map module_id; - - extern asITypeInfo* panelBaseType; - extern asITypeInfo* serviceBaseType; - extern asITypeInfo* arrayStringBaseType; - - extern Module* executingModule; - - void loadModules(); - asIScriptFunction* getFactory(asITypeInfo*); - - void raiseError(); - void generateAngelscriptPredefined(); - void saveAngelscriptPredefined(const Path& path); - - void registerStructs(); - void registerFunctions(); - void extractBaseTypes(); - } // namespace StudioAPI -} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/headers/DeerStudio/StudioPanel.h b/DeerStudio/headers/DeerStudio/StudioPanel.h new file mode 100644 index 0000000..3c5fdf6 --- /dev/null +++ b/DeerStudio/headers/DeerStudio/StudioPanel.h @@ -0,0 +1,14 @@ +#pragma once + +namespace Deer { + class World; + + namespace StudioPanel { + void init(World*); + + void update(); + void render(); + + void shutdown(); + } // namespace StudioPanel +} // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/DeerStudio.cpp b/DeerStudio/src/DeerStudio/DeerStudio.cpp index d48ab10..d2d887d 100644 --- a/DeerStudio/src/DeerStudio/DeerStudio.cpp +++ b/DeerStudio/src/DeerStudio/DeerStudio.cpp @@ -1,4 +1,5 @@ #include "DeerStudio/DeerStudio.h" +#include "DeerStudio/StudioPanel.h" // #include "DeerStudio/AngelScriptEngine.h" #include "DeerRender/Engine.h" @@ -17,9 +18,6 @@ namespace Deer { namespace DeerStudio { Universe::WorldHandle mainWorld; - Scope editorScriptModules; - ScriptObjectGroup* editorInstance; - void onUpdate(); void onRender(); void onEvent(Event& e); @@ -28,23 +26,6 @@ namespace Deer { void worldRender(World& world); void worldUpdate(World& world); - void initEditorScriptModules() { - Scripting::registerInterface("Panel"); - Scripting::registerInterfaceFunction("Panel", "onImGui", Scripting::EventType::void_event); - - Scripting::compileFiles("Editor/Scripts", "Editor"); - Scripting::SystemDescription systemDescription("Panel", "Editor"); - systemDescription.events.push_back(Scripting::SystemEvent("onInit", Scripting::EventType::void_event)); - systemDescription.events.push_back(Scripting::SystemEvent("onShutdown", Scripting::EventType::void_event)); - systemDescription.events.push_back(Scripting::SystemEvent("onDrawUI", Scripting::EventType::void_event)); - systemDescription.events.push_back(Scripting::SystemEvent("onUpdate", Scripting::EventType::void_event)); - - editorScriptModules = Scripting::createScriptEnvironment(systemDescription); - editorInstance = editorScriptModules->createGroupWithAllSystems(); - - editorInstance->executeOnGroup_voidEvent(0); - } - void main() { Engine::init(); Engine::setEventCallback(DeerStudio::onEvent); @@ -60,15 +41,16 @@ namespace Deer { .renderFrequency = 144, }; - initEditorScriptModules(); - mainWorld = Universe::createWorld(worldSettings); - // Universe::getWorld(mainWorld).execute(); + StudioPanel::init(&Universe::getWorld(mainWorld)); + + Universe::getWorld(mainWorld).execute(); Engine::shutdown(); } // namespace DeerStudio void worldUpdate(World& world) { + StudioPanel::update(); } void worldRender(World& world) { @@ -118,8 +100,7 @@ namespace Deer { } ImGui::PopStyleVar(); - // TerrainEditor::onImGui(); - // viewport_onImGui(); + StudioPanel::render(); ImGui::End(); diff --git a/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled b/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled index 0170710..4693062 100644 --- a/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled +++ b/DeerStudio/src/DeerStudio/Registers/UI.cpp.disabled @@ -7,178 +7,9 @@ namespace Deer { void AngelScriptEngine::registerUIFunctions() { - scriptEngine->SetDefaultNamespace("UI"); - - // Buttons - REGISTER_GLOBAL_FUNC("bool button(const string& in text)", StudioAPI::button); - REGISTER_GLOBAL_FUNC("bool buttonCenter(const string& in text)", StudioAPI::buttonCenter); - REGISTER_GLOBAL_FUNC("bool buttonEnd(const string& in text)", StudioAPI::buttonEnd); - - REGISTER_GLOBAL_FUNC("bool cartIconButton(const string& in label, const string& in icon, int iconSize, int width)", StudioAPI::cartIconButton); - REGISTER_GLOBAL_FUNC("bool cartIconButton(const string& in label, FrameBuffer frameBuffer, int iconSize, int width)", StudioAPI::cartIconButton_frameBuffer); - - // Checkboxes - REGISTER_GLOBAL_FUNC("bool checkbox(const string& in text, bool value)", StudioAPI::checkbox); - REGISTER_GLOBAL_FUNC("bool checkboxDisabled(const string& in text, bool value)", StudioAPI::checkboxDisabled); - - // Sliders & Inputs - REGISTER_GLOBAL_FUNC("float magicSlider(const string& in text, float value, float speed)", StudioAPI::magicSlider); - REGISTER_GLOBAL_FUNC("vec3 magicSlider3(const string& in text, vec3 value, float speed)", StudioAPI::magicSlider3); - REGISTER_GLOBAL_FUNC("int sliderInt(string& in text, int value, int min, int max)", StudioAPI::sliderInt); - REGISTER_GLOBAL_FUNC("float slider(string& in text, float value, float min, float max)", StudioAPI::slider); - REGISTER_GLOBAL_FUNC("bool inputText(const string& in text, const string& in value, string& out valueOutput)", StudioAPI::inputText); - - // Menus - REGISTER_GLOBAL_FUNC("bool menuItem(const string& in text)", StudioAPI::menuItem); - REGISTER_GLOBAL_FUNC("void menuItemDisabled(const string& in text)", StudioAPI::menuItemDisabled); - REGISTER_GLOBAL_FUNC("void subMenu(const string& in text, SimpleFunction@+ func)", StudioAPI::subMenu); - - // Text - REGISTER_GLOBAL_FUNC("void text(const string& in text)", StudioAPI::text); - REGISTER_GLOBAL_FUNC("void textCenter(const string& in text)", StudioAPI::textCenter); - REGISTER_GLOBAL_FUNC("void textEnd(const string& in text)", StudioAPI::textEnd); - REGISTER_GLOBAL_FUNC("void textColor(float r, float g, float b, const string& in text)", StudioAPI::textColor); - - // Titles - REGISTER_GLOBAL_FUNC("void title(const string& in text)", StudioAPI::title); - REGISTER_GLOBAL_FUNC("void titleCenter(const string& in text)", StudioAPI::titleCenter); - REGISTER_GLOBAL_FUNC("void titleCenterY(const string& in text, int height)", StudioAPI::titleCenterY); - REGISTER_GLOBAL_FUNC("void titleEnd(const string& in text)", StudioAPI::titleEnd); - - // Layout helpers - REGISTER_GLOBAL_FUNC("void sameline()", StudioAPI::sameline); - REGISTER_GLOBAL_FUNC("void separator()", StudioAPI::separator); - REGISTER_GLOBAL_FUNC("void space()", StudioAPI::space); - REGISTER_GLOBAL_FUNC("void space(int x, int y = 10)", StudioAPI::space_params); - - // Drawing - REGISTER_GLOBAL_FUNC("void drawFrameBuffer(FrameBuffer, int, int)", StudioAPI::drawFrameBuffer); - REGISTER_GLOBAL_FUNC("void drawFrameBufferCentered(FrameBuffer, int, int)", StudioAPI::drawFrameBufferCentered); - REGISTER_GLOBAL_FUNC("void drawIcon(const string& in, int)", StudioAPI::drawIcon); - REGISTER_GLOBAL_FUNC("void drawIconCentered(const string& in, int)", StudioAPI::drawIconCentered); - REGISTER_GLOBAL_FUNC("void drawIconHighlight(const string& in, int)", StudioAPI::drawIconHighlight); - REGISTER_GLOBAL_FUNC("void drawIconCenteredHighlight(const string& in, int)", StudioAPI::drawIconCenteredHighlight); - - REGISTER_GLOBAL_FUNC("void drawIcon(Texture texture, int)", StudioAPI::drawIcon_resource); - REGISTER_GLOBAL_FUNC("void drawIconCentered(Texture texture, int)", StudioAPI::drawIconCentered_resource); - REGISTER_GLOBAL_FUNC("void drawIconHighlight(Texture texture, int)", StudioAPI::drawIconHighlight_resource); - REGISTER_GLOBAL_FUNC("void drawIconCenteredHighlight(Texture texture, int)", StudioAPI::drawIconCenteredHighlight_resource); - - // Input state - REGISTER_GLOBAL_FUNC("bool isKeyDown(key)", StudioAPI::isKeyDown); - REGISTER_GLOBAL_FUNC("bool isKeyPressed(key)", StudioAPI::isKeyPressed); - REGISTER_GLOBAL_FUNC("bool isMouseDragging(key)", StudioAPI::isMouseDragging); - REGISTER_GLOBAL_FUNC("bool isItemClicked(int)", StudioAPI::isItemClicked); - REGISTER_GLOBAL_FUNC("bool isMouseDoubleClicked(int)", StudioAPI::isMouseDoubleClicked); - - // Mouse info - REGISTER_GLOBAL_FUNC("float getMouseDragDeltaX()", StudioAPI::getMouseDragDeltaX); - REGISTER_GLOBAL_FUNC("float getMouseDragDeltaY()", StudioAPI::getMouseDragDeltaY); - REGISTER_GLOBAL_FUNC("float getMouseDeltaX()", StudioAPI::getMouseDeltaX); - REGISTER_GLOBAL_FUNC("float getMouseDeltaY()", StudioAPI::getMouseDeltaY); - - // Panel & layout control - REGISTER_GLOBAL_FUNC("bool isPanelActive()", StudioAPI::isPanelActive); - REGISTER_GLOBAL_FUNC("void disablePanelPadding(bool)", StudioAPI::disablePanelPadding); - REGISTER_GLOBAL_FUNC("int getAvailableSizeX()", StudioAPI::getAvailableSizeX); - REGISTER_GLOBAL_FUNC("int getAvailableSizeY()", StudioAPI::getAvailableSizeY); - - // Columns - REGISTER_GLOBAL_FUNC("void automaticColumns(int)", StudioAPI::automaticColumns); - REGISTER_GLOBAL_FUNC("void columns(int)", StudioAPI::columns); - REGISTER_GLOBAL_FUNC("void nextColumn()", StudioAPI::nextColumn); - REGISTER_GLOBAL_FUNC("void endColumns()", StudioAPI::endColumns); - - // Tree & Components - REGISTER_GLOBAL_FUNC("void treeNodeLeaf(const string& in, bool)", StudioAPI::treeNodeLeaf); - REGISTER_GLOBAL_FUNC("bool treeNode(const string& in, bool, SimpleFunction@+)", StudioAPI::treeNode); - REGISTER_GLOBAL_FUNC("bool componentNode(const string& in, SimpleFunction@+)", StudioAPI::componentNode); - REGISTER_GLOBAL_FUNC("bool componentNodeContextMenu(const string& in, SimpleFunction@+, SimpleFunction@+)", StudioAPI::componentNodeContextMenu); - - // Popups & Modals - REGISTER_GLOBAL_FUNC("void contextItemPopup(const string& in, SimpleFunction@+)", StudioAPI::contextItemPopup); - REGISTER_GLOBAL_FUNC("void contextMenuPopup(const string& in, SimpleFunction@+)", StudioAPI::contextMenuPopup); - REGISTER_GLOBAL_FUNC("void modalPopup(const string& in, SimpleFunction@+)", StudioAPI::modalPopup); - REGISTER_GLOBAL_FUNC("void simplePopup(const string& in, SimpleFunction@+)", StudioAPI::simplePopup); - REGISTER_GLOBAL_FUNC("void openPopup(const string& in, any@)", StudioAPI::openPopup); - REGISTER_GLOBAL_FUNC("void closePopup()", StudioAPI::closePopup); - - // Drag & Drop - REGISTER_GLOBAL_FUNC("void dragDropSource(const string& in, any@+, const string& in)", StudioAPI::dragDropSource); - REGISTER_GLOBAL_FUNC("void dragDropTarget(const string& in, ReciverFunction@+)", StudioAPI::dragDropTarget); - scriptEngine->SetDefaultNamespace(""); } void AngelScriptEngine::registerUIStructs() { - AS_CHECK(scriptEngine->RegisterEnum("key")); - - AS_CHECK(scriptEngine->RegisterEnumValue("key", "A", ImGuiKey_A)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "B", ImGuiKey_B)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "C", ImGuiKey_C)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "D", ImGuiKey_D)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "E", ImGuiKey_E)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "F", ImGuiKey_F)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "G", ImGuiKey_G)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "H", ImGuiKey_H)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "I", ImGuiKey_I)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "J", ImGuiKey_J)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K", ImGuiKey_K)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "L", ImGuiKey_L)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "M", ImGuiKey_M)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "N", ImGuiKey_N)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "O", ImGuiKey_O)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "P", ImGuiKey_P)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Q", ImGuiKey_Q)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "R", ImGuiKey_R)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "S", ImGuiKey_S)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "T", ImGuiKey_T)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "U", ImGuiKey_U)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "V", ImGuiKey_V)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "W", ImGuiKey_W)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "X", ImGuiKey_X)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Y", ImGuiKey_Y)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Z", ImGuiKey_Z)); - - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K0", ImGuiKey_0)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K1", ImGuiKey_1)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K2", ImGuiKey_2)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K3", ImGuiKey_3)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K4", ImGuiKey_4)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K5", ImGuiKey_5)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K6", ImGuiKey_6)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K7", ImGuiKey_7)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K8", ImGuiKey_8)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "K9", ImGuiKey_9)); - - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Tab", ImGuiKey_Tab)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Enter", ImGuiKey_Enter)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Escape", ImGuiKey_Escape)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Backspace", ImGuiKey_Backspace)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Space", ImGuiKey_Space)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Delete", ImGuiKey_Delete)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Insert", ImGuiKey_Insert)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Home", ImGuiKey_Home)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "End", ImGuiKey_End)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "PageUp", ImGuiKey_PageUp)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "PageDown", ImGuiKey_PageDown)); - - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Right", ImGuiKey_RightArrow)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Up", ImGuiKey_UpArrow)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Down", ImGuiKey_DownArrow)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "Left", ImGuiKey_LeftArrow)); - - AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightCtrl", ImGuiKey_RightCtrl)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftShift", ImGuiKey_LeftShift)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightShift", ImGuiKey_RightShift)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftAlt", ImGuiKey_LeftAlt)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightAlt", ImGuiKey_RightAlt)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftSuper", ImGuiKey_LeftSuper)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "RightSuper", ImGuiKey_RightSuper)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "LeftCtrl", ImGuiKey_LeftCtrl)); - - AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseLeft", ImGuiKey_MouseLeft)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseRight", ImGuiKey_MouseRight)); - AS_CHECK(scriptEngine->RegisterEnumValue("key", "MouseMiddle", ImGuiKey_MouseMiddle)); } } // namespace Deer \ No newline at end of file diff --git a/DeerStudio/src/DeerStudio/StudioPanel.cpp b/DeerStudio/src/DeerStudio/StudioPanel.cpp new file mode 100644 index 0000000..0dd6cd2 --- /dev/null +++ b/DeerStudio/src/DeerStudio/StudioPanel.cpp @@ -0,0 +1,69 @@ +#include "DeerStudio/StudioPanel.h" +#include "DeerRender/Scripting.h" +#include "DeerRender/Tools/Memory.h" +#include "imgui.h" + +namespace Deer { + class World; + + namespace StudioPanel { + Scope studioPanelEnvironment; + ScriptObjectGroup* editorInstance; + void renderSystem(ScriptSystem* system); + } // namespace StudioPanel + + void StudioPanel::init(World* world) { + Scripting::registerInterface("Panel"); + Scripting::registerInterfaceFunction("Panel", "onImGui", Scripting::EventType::void_event); + + Scripting::compileFiles("Editor/Scripts", "Editor"); + Scripting::SystemDescription systemDescription("Panel", "Editor"); + systemDescription.events.push_back(Scripting::SystemEvent("onInit", Scripting::EventType::void_event)); + systemDescription.events.push_back(Scripting::SystemEvent("onShutdown", Scripting::EventType::void_event)); + systemDescription.events.push_back(Scripting::SystemEvent("onImGui", Scripting::EventType::void_event)); + systemDescription.events.push_back(Scripting::SystemEvent("onUpdate", Scripting::EventType::void_event)); + systemDescription.events.push_back(Scripting::SystemEvent("onMenuBar", Scripting::EventType::void_event)); + + studioPanelEnvironment = Scripting::createScriptEnvironment(systemDescription); + studioPanelEnvironment->tieWorld(world); + + editorInstance = studioPanelEnvironment->createGroupWithAllSystems(); + editorInstance->executeOnGroup_voidEvent(0); + } + + void StudioPanel::update() { + editorInstance->executeOnGroup_voidEvent(3); + } + + void StudioPanel::renderSystem(ScriptSystem* system) { + if (system->hasFunction(4)) { + ImGui::Begin(system->getSystemName(), (bool*)0, ImGuiWindowFlags_MenuBar); + if (ImGui::BeginMenuBar()) { + editorInstance->executeOnObject_voidEvent(system, 4); + + ImGui::EndMenuBar(); + } + } else { + ImGui::Begin(system->getSystemName()); + } + + if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) && + (ImGui::IsMouseClicked(ImGuiMouseButton_Right) || + ImGui::IsMouseClicked(ImGuiMouseButton_Middle))) { + ImGui::SetWindowFocus(); + } + editorInstance->executeOnObject_voidEvent(system, 2); + ImGui::End(); + } + + void StudioPanel::render() { + size_t sistemCount = studioPanelEnvironment->getSystemCount(); + for (size_t i = 0; i < sistemCount; i++) { + renderSystem(studioPanelEnvironment->getSystemByIndex(i)); + } + } + + void StudioPanel::shutdown() { + editorInstance->executeOnGroup_voidEvent(1); + } +} // namespace Deer \ No newline at end of file diff --git a/Editor/Modules/EntityManipulation/AddComponent.as b/Editor/Modules/EntityManipulation/AddComponent.as index 185fd10..2b29ffd 100644 --- a/Editor/Modules/EntityManipulation/AddComponent.as +++ b/Editor/Modules/EntityManipulation/AddComponent.as @@ -5,34 +5,34 @@ class AddComponentRender { } void addComponentPopup() { - UI::titleCenter("\uf055 Add Component"); - UI::separator(); - UI::subMenu("Rendering", SimpleFunction(this.addComponentRendering)); - if (UI::menuItem("Script Component")) { + ImGui::titleCenter("\uf055 Add Component"); + ImGui::separator(); + ImGui::subMenu("Renderin ", SimpleFunction(this.addComponentRendering)); + if (ImGui::menuItem("Script Component )) { } } void addComponentRendering() { if (entity.hasMeshComponent()) { - UI::menuItemDisabled("\uf248 Mesh Render Component"); + ImGui::menuItemDisabled("\uf248 Mesh Render Component"); } else { - if (UI::menuItem("\uf248 Mesh Render Component")) { + if (ImGui::menuItem("\uf248 Mesh Render Component )) { entity.createMeshComponent(); } } if (entity.hasShaderComponent()) { - UI::menuItemDisabled("\uf042 Shader Render Component"); + ImGui::menuItemDisabled("\uf042 Shader Render Component"); } else { - if (UI::menuItem("\uf042 Shader Render Component")) { + if (ImGui::menuItem("\uf042 Shader Render Component )) { entity.createShaderComponent(); } } if (entity.hasCameraComponent()) { - UI::menuItemDisabled("\uf030 Camera Component"); + ImGui::menuItemDisabled("\uf030 Camera Component"); } else { - if (UI::menuItem("\uf030 Camera Component")) { + if (ImGui::menuItem("\uf030 Camera Component )) { entity.createCameraComponent(); } } diff --git a/Editor/Modules/EntityManipulation/CameraProperties.as b/Editor/Modules/EntityManipulation/CameraProperties.as index 67bf3d6..513a63a 100644 --- a/Editor/Modules/EntityManipulation/CameraProperties.as +++ b/Editor/Modules/EntityManipulation/CameraProperties.as @@ -15,19 +15,19 @@ class CameraComponentRender { float nearZ = cameraComponent.nearZ; float farZ = cameraComponent.farZ; - fov = UI::magicSlider("Fov", fov, 0.1); + fov = ImGui::magicSlider("Fo ", f v, 0.1); if (fov > 180) fov = 180; if (fov < 0) fov = 0; - aspect = UI::magicSlider("Aspect Ratio", aspect, 0.1); + aspect = ImGui::magicSlider("Aspect Rati ", aspe t, 0.1); if (aspect < 0.1) aspect = 0.1; - nearZ = UI::magicSlider("Near Z", nearZ, 0.1); + nearZ = ImGui::magicSlider("Near ", nea Z, 0.1); if (nearZ < 0) nearZ = 0; - farZ = UI::magicSlider("Far Z", farZ, 0.1); + farZ = ImGui::magicSlider("Far ", fa Z, 0.1); if (farZ < 0) farZ = 0; @@ -41,7 +41,7 @@ class CameraComponentRender { } void remove() { - if (UI::menuItem("Remove")) { + if (ImGui::menuItem("Remove )) { entity.removeCameraComponent(); } } diff --git a/Editor/Modules/EntityManipulation/MeshProperties.as b/Editor/Modules/EntityManipulation/MeshProperties.as index a84da50..d7a06be 100644 --- a/Editor/Modules/EntityManipulation/MeshProperties.as +++ b/Editor/Modules/EntityManipulation/MeshProperties.as @@ -12,36 +12,36 @@ class MeshComponentRender { return; if (meshComponent.hasMesh) { - UI::drawIcon("object3d.png", 32); + ImGui::drawIcon("object3d.pn ", 32); } else { - UI::drawIcon("empty.png", 32); + ImGui::drawIcon("empty.pn ", 32); } - UI::dragDropTarget("MESH", ReciverFunction(this.setMesh)); + ImGui::dragDropTarget("MES ", ReciverFunction(this.setMesh)); if (meshComponent.hasMesh) { - UI::sameline(); - UI::space(); - UI::sameline(); + ImGui::sameline(); + ImGui::space(); + ImGui::sameline(); - UI::titleCenterY(meshComponent.meshResource.name, 32); - UI::dragDropTarget("MESH", ReciverFunction(this.setMesh)); + ImGui::titleCenterY(meshComponent.meshResource.na e, 32); + ImGui::dragDropTarget("MES ", ReciverFunction(this.setMesh)); } - UI::space(20, 20); + ImGui::space( 0, 20); - if (UI::button("Clear")) { + if (ImGui::button("Clear )) { meshComponent.clear(); } - UI::sameline(); - UI::space(10, 20); - UI::sameline(); + ImGui::sameline(); + ImGui::space( 0, 20); + ImGui::sameline(); if (meshComponent.hasMesh) { - meshComponent.isActive = UI::checkbox("Active", meshComponent.isActive); + meshComponent.isActive = ImGui::checkbox("Activ ", meshComponent.isActive); } else { - UI::checkboxDisabled("Active", meshComponent.isActive); + ImGui::checkboxDisabled("Activ ", meshComponent.isActive); } } @@ -53,7 +53,7 @@ class MeshComponentRender { } void remove() { - if (UI::menuItem("Remove")) { + if (ImGui::menuItem("Remove )) { entity.removeMeshComponent(); } } diff --git a/Editor/Modules/EntityManipulation/PropertiesPannel.as b/Editor/Modules/EntityManipulation/PropertiesPannel.as index 174a550..9f38279 100644 --- a/Editor/Modules/EntityManipulation/PropertiesPannel.as +++ b/Editor/Modules/EntityManipulation/PropertiesPannel.as @@ -8,60 +8,60 @@ class PropertiesPanel : Panel { // NAME // Id:0 [+ add component] - UI::title("\uf1b2 " + entity.name); + ImGui::title("\uf1b + entity.name); if (!entity.isRoot) - UI::contextItemPopup("##MenuOptions", SimpleFunction(this.renameEntityMenu)); - UI::separator(); - UI::textColor(0.5, 0.5, 0.5f, "Id : " + entity.id); + ImGui::contextItemPopup("##MenuOption ", SimpleFunction(this.renameEntityMenu)); + ImGui::separator(); + ImGui::textColor(0 5, 0 5, 0. f, "Id + entity.id); // We don't want to change root options if (entity.isRoot) return; - UI::sameline(); - if (UI::buttonEnd("\uf055 Add Component")) { - UI::openPopup("ADD_COMPONENT", any(entity)); + ImGui::sameline(); + if (ImGui::buttonEnd("\uf055 Add Component )) { + ImGui::openPopup("ADD_COMPONEN ", any(entity)); } - UI::space(); + ImGui::space(); TransformPropertiesRender transformComponentRender(entity); - UI::componentNode("\uf0b2 Transform Component", SimpleFunction(transformComponentRender.renderTransformComponent)); + ImGui::componentNode("\uf0b2 Transform Componen ", SimpleFunction(transformComponentRender.renderTransformComponent)); if (entity.hasMeshComponent()) { MeshComponentRender meshComponentRender(entity); - UI::componentNodeContextMenu("\uf248 Mesh Component", SimpleFunction(meshComponentRender.render), SimpleFunction(meshComponentRender.remove)); + ImGui::componentNodeContextMenu("\uf248 Mesh Componen ", SimpleFunction(meshComponentRender.rende ), SimpleFunction(meshComponentRender.remove)); } if (entity.hasShaderComponent()) { ShaderComponentRender shaderComponentRender(entity); - UI::componentNodeContextMenu("\uf248 Shader Component", SimpleFunction(shaderComponentRender.render), SimpleFunction(shaderComponentRender.remove)); + ImGui::componentNodeContextMenu("\uf248 Shader Componen ", SimpleFunction(shaderComponentRender.rende ), SimpleFunction(shaderComponentRender.remove)); } if (entity.hasCameraComponent()) { CameraComponentRender cameraComponentRender(entity); - UI::componentNodeContextMenu("\uf030 Camera Component", SimpleFunction(cameraComponentRender.render), SimpleFunction(cameraComponentRender.remove)); + ImGui::componentNodeContextMenu("\uf030 Camera Componen ", SimpleFunction(cameraComponentRender.rende ), SimpleFunction(cameraComponentRender.remove)); } - UI::space(); + ImGui::space(); - UI::separator(); + ImGui::separator(); - if (UI::buttonCenter("\uf055 Add Component##2")) { - UI::openPopup("ADD_COMPONENT", any(entity)); + if (ImGui::buttonCenter("\uf055 Add Component##2 )) { + ImGui::openPopup("ADD_COMPONEN ", any(entity)); } AddComponentRender addComponentRender(entity); - UI::simplePopup("ADD_COMPONENT", SimpleFunction(addComponentRender.addComponentPopup)); - UI::modalPopup("Rename entity", SimpleFunction(this.renameEntityMenu)); + ImGui::simplePopup("ADD_COMPONEN ", SimpleFunction(addComponentRender.addComponentPopup)); + ImGui::modalPopup("Rename entit ", SimpleFunction(this.renameEntityMenu)); } void renameEntityMenu() { Entity entity = ActiveEntity::getActiveEntity(); if (!entity.isRoot) { - if (UI::menuItem("Rename")) { - UI::openPopup("Rename entity", any(entity)); + if (ImGui::menuItem("Rename )) { + ImGui::openPopup("Rename entit ", any(entity)); } } } diff --git a/Editor/Modules/EntityManipulation/ShaderProperties.as b/Editor/Modules/EntityManipulation/ShaderProperties.as index 294140a..d626f8d 100644 --- a/Editor/Modules/EntityManipulation/ShaderProperties.as +++ b/Editor/Modules/EntityManipulation/ShaderProperties.as @@ -27,47 +27,47 @@ class ShaderComponentRender { return; if (shaderComponent.hasShader) { - UI::drawIcon("shader.png", 32); + ImGui::drawIcon("shader.pn ", 32); } else { - UI::drawIcon("empty.png", 32); + ImGui::drawIcon("empty.pn ", 32); } - UI::dragDropTarget("SHADER", ReciverFunction(this.setShader)); + ImGui::dragDropTarget("SHADE ", ReciverFunction(this.setShader)); if (shaderComponent.hasShader) { - UI::sameline(); - UI::space(); - UI::sameline(); + ImGui::sameline(); + ImGui::space(); + ImGui::sameline(); - UI::titleCenterY(shaderComponent.shader.name, 32); - UI::dragDropTarget("SHADER", ReciverFunction(this.setShader)); + ImGui::titleCenterY(shaderComponent.shader.na e, 32); + ImGui::dragDropTarget("SHADE ", ReciverFunction(this.setShader)); } - UI::space(); + ImGui::space(); if (shaderComponent.texture.isValid()) { - UI::drawIcon(shaderComponent.texture, 32); + ImGui::drawIcon(shaderComponent.textu e, 32); } else { - UI::drawIcon("empty.png", 32); + ImGui::drawIcon("empty.pn ", 32); } - UI::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture)); + ImGui::dragDropTarget("TEXTUR ", ReciverFunction(this.setTexture)); if (shaderComponent.texture.isValid()) { - UI::sameline(); - UI::space(); - UI::sameline(); + ImGui::sameline(); + ImGui::space(); + ImGui::sameline(); - UI::titleCenterY(shaderComponent.texture.name, 32); - UI::dragDropTarget("TEXTURE", ReciverFunction(this.setTexture)); + ImGui::titleCenterY(shaderComponent.texture.na e, 32); + ImGui::dragDropTarget("TEXTUR ", ReciverFunction(this.setTexture)); } - UI::space(20, 20); + ImGui::space( 0, 20); - if (UI::button("Clear")) { + if (ImGui::button("Clear )) { shaderComponent.clear(); } } void remove() { - if (UI::menuItem("Remove")) { + if (ImGui::menuItem("Remove )) { entity.removeShaderComponent(); } } diff --git a/Editor/Modules/EntityManipulation/TransformProperties.as b/Editor/Modules/EntityManipulation/TransformProperties.as index 071d879..96bff7d 100644 --- a/Editor/Modules/EntityManipulation/TransformProperties.as +++ b/Editor/Modules/EntityManipulation/TransformProperties.as @@ -12,8 +12,8 @@ class TransformPropertiesRender { vec3 scale = transform.scale; vec3 rotation = transform.rotation; - transform.position = UI::magicSlider3("Positon", position, 0.1); - transform.scale = UI::magicSlider3("Scale", scale, 0.1); - transform.rotation = UI::magicSlider3("Rotation", rotation, 0.1); + transform.position = ImGui::magicSlider3("Posito ", positi n, 0.1); + transform.scale = ImGui::magicSlider3("Scal ", sca e, 0.1); + transform.rotation = ImGui::magicSlider3("Rotatio ", rotati n, 0.1); } } diff --git a/Editor/Modules/ResourceExplorer/ResourceExplorer.as b/Editor/Modules/ResourceExplorer/ResourceExplorer.as index 73d1eed..8d161aa 100644 --- a/Editor/Modules/ResourceExplorer/ResourceExplorer.as +++ b/Editor/Modules/ResourceExplorer/ResourceExplorer.as @@ -24,18 +24,18 @@ class ResourceExplorer : Panel { void render() { alreadyRendered = false; renderMenuBar(); - UI::space(); + ImGui::space(); fase += 0.3; - UI::automaticColumns(182); + ImGui::automaticColumns(182); string temp_path = currentPath; // Render navigation folders for (uint i = 0; i < subFolders.length(); i++) { - if (UI::cartIconButton(Path::getName(subFolders[i]), "folder.png", 128, UI::getAvailableSizeX())) { + if (ImGui::cartIconButton(Path::getName(subFolders[i ), "folder.pn ", 1 8, ImGui::getAvailableSiz X())) { setPath(subFolders[i]); } - UI::nextColumn(); + ImGui::nextColumn(); } for (uint i = 0; i < subFiles.length(); i++) { @@ -64,50 +64,50 @@ class ResourceExplorer : Panel { meshFrameBuffer[filename] = frameBuffer; alreadyRendered = true; - if (UI::cartIconButton(Path::getName(filename), frameBuffer, 128, UI::getAvailableSizeX())) { + if (ImGui::cartIconButton(Path::getName(filenam ), frameBuff r, 1 8, ImGui::getAvailableSiz X())) { selectedResource = filename; } - UI::dragDropSource("MESH", any(filename), filename); - UI::nextColumn(); + ImGui::dragDropSource("MES ", any(filenam ), filename); + ImGui::nextColumn(); return; } if (resType == ResourceType::Shader) { - if (UI::cartIconButton(Path::getName(filename), "shader.png", 128, UI::getAvailableSizeX())) { + if (ImGui::cartIconButton(Path::getName(filenam ), "shader.pn ", 1 8, ImGui::getAvailableSiz X())) { selectedResource = filename; } - UI::dragDropSource("SHADER", any(filename), filename); - UI::nextColumn(); + ImGui::dragDropSource("SHADE ", any(filenam ), filename); + ImGui::nextColumn(); return; } if (resType == ResourceType::Texture) { Texture texture = Resource::loadTexture(filename); - if (UI::cartIconButton(Path::getName(filename), "texture.png", 128, UI::getAvailableSizeX())) { + if (ImGui::cartIconButton(Path::getName(filenam ), "texture.pn ", 1 8, ImGui::getAvailableSiz X())) { selectedResource = filename; } - UI::dragDropSource("TEXTURE", any(filename), filename); - UI::nextColumn(); + ImGui::dragDropSource("TEXTUR ", any(filenam ), filename); + ImGui::nextColumn(); return; } - UI::cartIconButton(Path::getName(filename), "file.png", 128, UI::getAvailableSizeX()); - UI::nextColumn(); + ImGui::cartIconButton(Path::getName(filenam ), "file.pn ", 1 8, ImGui::getAvailableSizeX()); + ImGui::nextColumn(); } void renderMenuBar() { // If we select that path - if (UI::button("Resources")) { + if (ImGui::button("Resources )) { setPath(""); } array@ paths = Path::divide(currentPath); for (uint i = 0; i < paths.length(); i++) { - UI::sameline(); - UI::text("/"); - UI::sameline(); + ImGui::sameline(); + ImGui::text("/"); + ImGui::sameline(); // If we select that path - if (UI::button(paths[i])) { + if (ImGui::button(paths[i )) { // We obtain that pat string changePath = ""; diff --git a/Editor/Modules/TreeExplorer/Tree.as b/Editor/Modules/TreeExplorer/Tree.as index f1fd1d0..292a281 100644 --- a/Editor/Modules/TreeExplorer/Tree.as +++ b/Editor/Modules/TreeExplorer/Tree.as @@ -19,11 +19,11 @@ class EntityTreeRender { displayName += "##" + entity.id; if (entity.childs.count == 0) { // END OF THE TREE - UI::treeNodeLeaf(displayName, isActiveEntity()); + ImGui::treeNodeLeaf(displayNa e, isActiveEntity()); interaction(); } else { // ADD ANOTHER NODE - bool opened = UI::treeNode(displayName, isActiveEntity(), SimpleFunction(this.renderChilds)); + bool opened = ImGui::treeNode(displayNa e, isActiveEntity ), SimpleFunction(this.renderChilds)); if (!opened) { interaction(); } @@ -39,11 +39,11 @@ class EntityTreeRender { } void interaction() { - UI::dragDropSource("ENTITY", any(entity), entity.name); - UI::dragDropTarget("ENTITY", ReciverFunction(this.entityDrop)); - UI::contextItemPopup("POP_ENTITY_" + entity.id, SimpleFunction(this.renderContextMenu)); + ImGui::dragDropSource("ENTIT ", any(entit ), entity.name); + ImGui::dragDropTarget("ENTIT ", ReciverFunction(this.entityDrop)); + ImGui::contextItemPopup("POP_ENTIT _ + entity. d, SimpleFunction(this.renderContextMenu)); - if (UI::isItemClicked(0)) { + if (ImGui::isItemClicked( )) { ActiveEntity::setActiveEntity(entity); } } @@ -62,19 +62,19 @@ class EntityTreeRender { void renderContextMenu() { if (entity.isRoot) { - if (UI::menuItem("New Entity")) { + if (ImGui::menuItem("New Entity )) { entity.createChild("node"); } } else { - if (UI::menuItem("Add child")) { + if (ImGui::menuItem("Add child )) { entity.createChild("node"); } - if (UI::menuItem("Rename")) { - UI::openPopup("Rename entity", any(entity)); + if (ImGui::menuItem("Rename )) { + ImGui::openPopup("Rename entit ", any(entity)); } - if (UI::menuItem("Destroy")) { + if (ImGui::menuItem("Destroy )) { entity.destroy(); } } @@ -86,7 +86,7 @@ class TreePanel : Panel { Entity root = Engine::getRoot(); EntityTreeRender rootTree(root); - UI::contextMenuPopup("Window popup", SimpleFunction(rootTree.renderContextMenu)); + ImGui::contextMenuPopup("Window popu ", SimpleFunction(rootTree.renderContextMenu)); rootTree.renderEntity(); } } diff --git a/Editor/Modules/Viewport/Viewport.as b/Editor/Modules/Viewport/Viewport.as index 45e6ce6..3c33366 100644 --- a/Editor/Modules/Viewport/Viewport.as +++ b/Editor/Modules/Viewport/Viewport.as @@ -11,8 +11,8 @@ class ViewportPanel : Panel { if (!frameBuffer.isValid()) return; - int x = UI::getAvailableSizeX(); - int y = UI::getAvailableSizeY(); + int x = ImGui::getAvailableSizeX(); + int y = ImGui::getAvailableSizeY(); if (x < 10 || y < 10) return; @@ -23,22 +23,22 @@ class ViewportPanel : Panel { sceneCamera.camera.aspect = float(x) / y; env.render(frameBuffer, sceneCamera); - UI::drawFrameBufferCentered(frameBuffer, x, y); - if (!UI::isPanelActive()) + ImGui::drawFrameBufferCentered(frameBuffer, x, y); + if (!ImGui::isPanelActive()) return; - if (UI::isMouseDragging(key::MouseRight) && !UI::isKeyDown(key::MouseMiddle)) { - pitch += UI::getMouseDeltaY() * 0.1f; - yaw += UI::getMouseDeltaX() * 0.1f; + if (ImGui::isMouseDragging(key::MouseRight) && !ImGui::isKeyDown(key::MouseMiddle)) { + pitch += ImGui::getMouseDeltaY() * 0.1f; + yaw += ImGui::getMouseDeltaX() * 0.1f; sceneCamera.transform.rotation.setEuler(vec3(pitch, yaw, 0)); } - if (UI::isMouseDragging(key::MouseMiddle) && !UI::isKeyDown(key::MouseRight)) { + if (ImGui::isMouseDragging(key::MouseMiddle) && !ImGui::isKeyDown(key::MouseRight)) { vec3 panDir = vec3(); - panDir.x -= UI::getMouseDeltaX(); - panDir.y += UI::getMouseDeltaY(); + panDir.x -= ImGui::getMouseDeltaX(); + panDir.y += ImGui::getMouseDeltaY(); panDir = panDir * vel * 0.4f; sceneCamera.transform.position = sceneCamera.transform.relative(panDir); @@ -46,23 +46,23 @@ class ViewportPanel : Panel { vec3 relDir = vec3(); - if (UI::isKeyDown(key::W)) + if (ImGui::isKeyDown(key::W)) relDir.z++; - if (UI::isKeyDown(key::S)) + if (ImGui::isKeyDown(key::S)) relDir.z--; - if (UI::isKeyDown(key::D)) + if (ImGui::isKeyDown(key::D)) relDir.x++; - if (UI::isKeyDown(key::A)) + if (ImGui::isKeyDown(key::A)) relDir.x--; relDir = relDir * vel; sceneCamera.transform.position = sceneCamera.transform.relative(relDir); float vertically = 0; - if (UI::isKeyDown(key::Space)) + if (ImGui::isKeyDown(key::Space)) vertically++; - if (UI::isKeyDown(key::LeftCtrl)) + if (ImGui::isKeyDown(key::LeftCtrl)) vertically--; sceneCamera.transform.position = sceneCamera.transform.position + vec3(0, vertically * vel, 0); @@ -75,22 +75,22 @@ class ViewportPanel : Panel { sceneCamera.transform.position = vec3(0, 1, -2); sceneCamera.camera.nearZ = 0.1; sceneCamera.camera.farZ = 100; - UI::disablePanelPadding(true); + ImGui::disablePanelPadding(true); } void menuBar() { - if (UI::menuItem("Start")) { + if (ImGui::menuItem("Start")) { } - if (UI::menuItem("Camera Props")) { - UI::openPopup("ViewportCameraProps", any()); + if (ImGui::menuItem("Camera Props")) { + ImGui::openPopup("ViewportCameraProps", any()); } - UI::simplePopup("ViewportCameraProps", SimpleFunction(this.viewportCameraProps)); + ImGui::simplePopup("ViewportCameraProps", SimpleFunction(this.viewportCameraProps)); } void viewportCameraProps() { - sceneCamera.camera.fov = UI::slider("Fov", sceneCamera.camera.fov / 3.14f * 180, 10, 160) / 180 * 3.14f; + sceneCamera.camera.fov = ImGui::slider("Fov", sceneCamera.camera.fov / 3.14f * 180, 10, 160) / 180 * 3.14f; } } diff --git a/Editor/Scripts/ActiveEntity/ActiveEntity.as b/Editor/Scripts/ActiveEntity/ActiveEntity.as new file mode 100644 index 0000000..78bfa8c --- /dev/null +++ b/Editor/Scripts/ActiveEntity/ActiveEntity.as @@ -0,0 +1,11 @@ +namespace ActiveEntity { + Entity entity; + + Entity getActiveEntity() { + return entity; + } + + void setActiveEntity(Entity ent) { + entity = ent; + } +} diff --git a/Editor/Scripts/TreeExplorer/Tree.as b/Editor/Scripts/TreeExplorer/Tree.as new file mode 100644 index 0000000..85c0562 --- /dev/null +++ b/Editor/Scripts/TreeExplorer/Tree.as @@ -0,0 +1,101 @@ +class EntityTreeRender { + EntityTreeRender(Entity _entity) { + entity = _entity; + } + + Entity entity; + bool isActiveEntity() { + return entity == ActiveEntity::getActiveEntity(); + } + + void renderEntity() { + string displayName = entity.name; + if (displayName == "") { + displayName = "-"; + } else { + displayName = "\uf1b2 " + displayName; + } + + displayName += "##" + entity.id; + array@ childs = entity.getChildrens(); + if (childs.length() == 0) { + // END OF THE TREE + ImGui::treeNodeLeaf(displayName, isActiveEntity()); + interaction(); + } else { + // ADD ANOTHER NODE + bool opened = ImGui::treeNode(displayName, isActiveEntity(), SimpleFunction(this.renderChilds)); + if (!opened) { + interaction(); + } + } + } + + void renderChilds() { + interaction(); + array@ childs = entity.getChildrens(); + for (uint i = 0; i < childs.length(); i++) { + EntityTreeRender child(childs[i]); + child.renderEntity(); + } + } + + void interaction() { + ImGui::dragDropSource("ENTITY", any(entity), entity.name); + ImGui::dragDropTarget("ENTITY", ReciverFunction(this.entityDrop)); + ImGui::contextItemPopup("POP_ENTITY_" + entity.id, SimpleFunction(this.renderContextMenu)); + + if (ImGui::isItemClicked(0)) { + ActiveEntity::setActiveEntity(entity); + } + } + + void entityDrop(any@ data) { + Entity data_entity; + data.retrieve(data_entity); + + // You cant be the father of your father + if (data_entity.isRoot || data_entity.isDescendantOf(entity)) { + return; + } + + data_entity.parent = entity; + } + + void renderContextMenu() { + if (entity.isRoot) { + if (ImGui::menuItem("New Entity")) { + print("Child id : " + entity.id); + entity.createChild("node"); + print("Child id : " + entity.id); + } + } else { + if (ImGui::menuItem("Add child")) { + print("Child id : " + entity.id); + entity.createChild("node"); + } + + if (ImGui::menuItem("Rename")) { + ImGui::openPopup("Rename entity", any(entity)); + } + + if (ImGui::menuItem("Destroy")) { + entity.destroy(); + } + } + } +} + +class TreePanel : Panel { + void onInit() { + print("Wtf2"); + } + + void onImGui() { + Entity root; + EntityTreeRender rootTree(root); + + ImGui::contextMenuPopup("Window popup", SimpleFunction(rootTree.renderContextMenu)); + rootTree.renderEntity(); + } +} diff --git a/imgui.ini b/imgui.ini index 1df5648..2d3fd47 100644 --- a/imgui.ini +++ b/imgui.ini @@ -3,12 +3,6 @@ Pos=0,0 Size=2560,1371 Collapsed=0 -[Window][ViewportPanel] -Pos=488,34 -Size=1512,804 -Collapsed=0 -DockId=0x00000004,0 - [Window][Debug##Default] Pos=60,60 Size=400,400 @@ -16,62 +10,10 @@ Collapsed=0 [Window][TreePanel] Pos=0,34 -Size=486,804 +Size=2560,1336 Collapsed=0 -DockId=0x00000001,0 - -[Window][ResourceExplorer] -Pos=0,840 -Size=2560,530 -Collapsed=0 -DockId=0x00000006,0 - -[Window][ResourceMetadata] -Pos=0,758 -Size=1920,253 -Collapsed=0 -DockId=0xA1672E74,1 - -[Window][PropertiesPanel] -Pos=2002,34 -Size=558,804 -Collapsed=0 -DockId=0x00000003,0 - -[Window][Test] -Pos=60,60 -Size=778,411 -Collapsed=0 - -[Window][Dear ImGui Demo] -Pos=650,20 -Size=550,680 -Collapsed=0 - -[Window][Dear ImGui Debug Log] -Pos=358,34 -Size=1192,645 -Collapsed=0 -DockId=0xA1672E74,0 - -[Window][Tst] -Pos=60,60 -Size=127,184 -Collapsed=0 - -[Window][Dear ImGui Metrics/Debugger] -Pos=433,34 -Size=1567,704 -Collapsed=0 -DockId=0x00000004,0 +DockId=0x0AC2E849,0 [Docking][Data] -DockSpace ID=0x0AC2E849 Window=0xD0388BC8 Pos=0,34 Size=2560,1336 Split=Y - DockNode ID=0x00000005 Parent=0x0AC2E849 SizeRef=1920,804 Split=X - DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1360,645 Split=X Selected=0xD9E076F4 - DockNode ID=0x00000001 Parent=0x00000002 SizeRef=486,976 Selected=0x16E3C1E7 - DockNode ID=0x00000004 Parent=0x00000002 SizeRef=1512,976 CentralNode=1 Selected=0x0F5FFC8C - DockNode ID=0x00000003 Parent=0x00000005 SizeRef=558,645 Selected=0x9876A79B - DockNode ID=0x00000006 Parent=0x0AC2E849 SizeRef=1920,530 Selected=0x018A0F9B -DockSpace ID=0xA1672E74 Pos=0,34 Size=1920,976 CentralNode=1 Selected=0x9ED090AF +DockSpace ID=0x0AC2E849 Window=0xD0388BC8 Pos=0,34 Size=2560,1336 CentralNode=1 Selected=0x16E3C1E7