diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index a9bbe718..6f376786 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -21,8 +21,6 @@ #include #include #include -#include "src/UI/UserInterface.h" -#include "src/NewEditor.h" #include #include "src/Actions/EditorSelection.h" diff --git a/Editor/src/Commands/Commands/Commands.cpp b/Editor/src/Commands/Commands/Commands.cpp index 14609dd8..9a7143a6 100644 --- a/Editor/src/Commands/Commands/Commands.cpp +++ b/Editor/src/Commands/Commands/Commands.cpp @@ -1,6 +1,7 @@ #include "Commands.h" #include +#include "src/Core/FileSystem.h" namespace NuakeEditor { diff --git a/Editor/src/NewEditor.cpp b/Editor/src/NewEditor.cpp deleted file mode 100644 index 35d8bb0f..00000000 --- a/Editor/src/NewEditor.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "NewEditor.h" -#include "Engine.h" -#include "src/Core/Input.h" -#include - -namespace Nuake -{ - NewEditor::NewEditor() - { - m_UserInterface = UI::UserInterface::New("Editor", "resources/Interface/Editor.interface"); - FetchNodes(); - } - - void NewEditor::FetchNodes() - { - m_SceneFramebuffer = Engine::GetCurrentWindow()->GetFrameBuffer(); - m_ViewportNode = m_UserInterface->GetNodeByID("viewport-texture"); - m_ViewportNode->BackgroundTexture = m_SceneFramebuffer->GetTexture(); - - m_FileMenu = m_UserInterface->GetNodeByID("action-menu-file"); - - m_Splitter = m_UserInterface->GetNodeByID("splitter"); - m_Splitter2 = m_UserInterface->GetNodeByID("splitter2"); - - m_Right = m_UserInterface->GetNodeByID("right"); - m_Left = m_UserInterface->GetNodeByID("left"); - m_Inspector = m_UserInterface->GetNodeByID("inspector"); - } - - bool dragging = false; - bool dragging2 = false; - void NewEditor::Update(Timestep ts) - { - if (Input::IsKeyPressed(Key::F1)) - { - m_UserInterface->Reload(); - FetchNodes(); - } - - if (m_FileMenu->IsClicked) - { - // Parse the project and load it. - std::string projectPath = FileDialog::OpenFile(".project"); - FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - Ref project = Project::New(); - if (!project->Deserialize(FileSystem::ReadFile(projectPath, true))) - { - Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); - return; - } - - project->FullPath = projectPath; - Engine::LoadProject(project); - } - float mouseX = Input::GetMouseX(); - if (m_Splitter->IsHover && Input::IsMouseButtonDown(0)) - { - dragging = true; - } - - if (m_Splitter2->IsHover && Input::IsMouseButtonDown(0)) - dragging2 = true; - - if (dragging) - { - if (!Input::IsMouseButtonDown(0)) - dragging = false; - - float totalWidth = m_UserInterface->Size.x; - - float mouseX = Input::GetMouseX(); - float ratio = mouseX / totalWidth; - - m_Inspector->NormalStyle.Width.mUnit = Layout::PIXEL; - m_Inspector->NormalStyle.Width.Value = (1.0f - ratio) * totalWidth - 3.0f; - - m_ViewportNode->NormalStyle.Width.mUnit = Layout::PIXEL; - m_ViewportNode->NormalStyle.Width.Value = ratio * totalWidth; - - m_Inspector->HoverStyle.Width.mUnit = Layout::PIXEL; - m_Inspector->HoverStyle.Width.Value = (1.0f - ratio) * totalWidth - 3.0f; - - m_ViewportNode->HoverStyle.Width.mUnit = Layout::PIXEL; - m_ViewportNode->HoverStyle.Width.Value = ratio * totalWidth; - - Logger::Log("mouseX " + std::to_string(ratio)); - } - - if (dragging2 == true) - { - if (!Input::IsMouseButtonDown(0)) - dragging2 = false; - - float totalWidth = m_UserInterface->Size.x; - float mouseX = Input::GetMouseX(); - float ratio = mouseX / totalWidth; - - } - - m_UserInterface->Update(ts); - - // Layout logic - } - - void NewEditor::Draw(Vector2 screenSize) - { - m_UserInterface->Draw(screenSize); - } -} \ No newline at end of file diff --git a/Editor/src/NewEditor.h b/Editor/src/NewEditor.h deleted file mode 100644 index 6d4a04f8..00000000 --- a/Editor/src/NewEditor.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "src/Core/Core.h" -#include "src/UI/UserInterface.h" -#include "src/Core/Maths.h" -#include "src/Core/Timestep.h" -namespace Nuake -{ - class NewEditor - { - public: - NewEditor(); - - void Update(Timestep ts); - void Draw(Vector2 screenSize); - - private: - void FetchNodes(); - Ref m_UserInterface; - Ref m_SceneFramebuffer; - Ref m_ViewportNode; - - Ref m_FileMenu; - Ref m_Splitter; - Ref m_Splitter2; - Ref m_Left; - Ref m_Right; - Ref m_Inspector; - - bool fileOpened = false; - }; -} \ No newline at end of file diff --git a/Editor/src/PropretiesWindow.h b/Editor/src/PropretiesWindow.h deleted file mode 100644 index d0dc233c..00000000 --- a/Editor/src/PropretiesWindow.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -class SelectableElement -{ - virtual void Draw(); -}; - -class SceneFile : public SelectableElement -{ - void Draw() override; -}; - -class ProjectFile : public SelectableElement -{ - void Draw() override; -}; - -class MaterialFile : public SelectableElement -{ - void Draw() override; -}; - -class Entity : public SelectableElement -{ - void Draw() override; -}; - -class PropretiesWindow -{ - SelectableElement selected; - - static void Draw(); -}; diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 2caf90fd..07bc3b97 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -32,7 +32,6 @@ #include #include #include "src/Rendering/Renderer.h" -#include #include "src/Core/Input.h" #include "../Actions/EditorSelection.h" @@ -50,7 +49,7 @@ #include #include - +#include "src/Core/FileSystem.h" #include #include #include @@ -59,7 +58,6 @@ namespace Nuake { - Ref userInterface; ImFont* normalFont; ImFont* boldFont; ImFont* EditorInterface::bigIconFont; diff --git a/Editor/src/Windows/ProjectInterface.cpp b/Editor/src/Windows/ProjectInterface.cpp index e936659a..65ef0868 100644 --- a/Editor/src/Windows/ProjectInterface.cpp +++ b/Editor/src/Windows/ProjectInterface.cpp @@ -1,6 +1,7 @@ #include "ProjectInterface.h" #include #include "Engine.h" +#include "src/Core/FileSystem.h" //#include "ImGuiTextHelper.h" namespace Nuake { diff --git a/Nuake/src/Physics/DynamicWorld.cpp b/Nuake/src/Physics/DynamicWorld.cpp index f44919c5..1aefefca 100644 --- a/Nuake/src/Physics/DynamicWorld.cpp +++ b/Nuake/src/Physics/DynamicWorld.cpp @@ -35,6 +35,7 @@ #include #include +#include namespace Nuake { diff --git a/Nuake/src/Rendering/Renderer2D.cpp b/Nuake/src/Rendering/Renderer2D.cpp index c0faa25f..400eab32 100644 --- a/Nuake/src/Rendering/Renderer2D.cpp +++ b/Nuake/src/Rendering/Renderer2D.cpp @@ -1,7 +1,6 @@ #include "Renderer2D.h" #include #include -#include "src/UI/Nodes/TextNode.h" #include "Shaders/ShaderManager.h" #include "src/Vendors/glm/gtx/matrix_decompose.hpp" @@ -92,98 +91,5 @@ namespace Nuake glBindVertexArray(Renderer2D::VAO); glDrawArrays(GL_TRIANGLES, 0, 6); } - - Vector2 Renderer2D::CalculateStringSize(const std::string& str, const TextStyle& style) - { - float lineHeight = 0.0f; - for (char const& c : str) - { - Char letter = style.font->GetChar((int)c); - - if (letter.PlaneBounds.top - letter.PlaneBounds.bottom > lineHeight) - lineHeight = letter.PlaneBounds.top - letter.PlaneBounds.bottom; - } - - float advance = 0.0f; - for (char const& c : str) - { - Char letter = style.font->GetChar((int)c); - advance += letter.Advance * style.fontSize; - } - return Vector2(advance, lineHeight * style.fontSize); - } - - void Renderer2D::DrawString(const std::string& str, TextStyle style, Matrix4 model) - { - TextShader->Bind(); - TextShader->SetUniformMat4f("projection", Projection); - - style.font->FontAtlas->Bind(5); - TextShader->SetUniform1i("msdf", 5); - - float lineHeight = 0.0f; - for (char const& c : str) - { - Char letter = style.font->GetChar((int)c); - - if (letter.PlaneBounds.top - letter.PlaneBounds.bottom > lineHeight) - lineHeight = letter.PlaneBounds.top - letter.PlaneBounds.bottom; - } - - float advance = 0.0f; - for (char const& c : str) - { - Char letter = style.font->GetChar((int)c); - - Matrix4 mat = glm::translate(model, Vector3(advance, (-(letter.PlaneBounds.top ) + (lineHeight)) * style.fontSize, 0.f)); - float scaleX = letter.PlaneBounds.right - letter.PlaneBounds.left; - float scaleY = letter.PlaneBounds.top - letter.PlaneBounds.bottom; - - mat = glm::scale(mat, Vector3(scaleX * style.fontSize, scaleY * style.fontSize, 0.f)); - TextShader->SetUniformMat4f("model", mat); - - TextShader->SetUniform2f("texPos", letter.AtlasBounds.Pos.x, letter.AtlasBounds.Pos.y); - TextShader->SetUniform2f("texScale", letter.AtlasBounds.Size.x, letter.AtlasBounds.Size.y); - TextShader->SetUniform4f("bgColor", 1.f, 1.f, 1.f, 0.f); - TextShader->SetUniform4f("fgColor", 1.f, 1.f, 1.f, 1.f); - TextShader->SetUniform1f("pxRange", style.fontSize); - //TextShader->SetUniform1f("pxRange", 32); - glBindVertexArray(VAO); - glDrawArrays(GL_TRIANGLES, 0, 6); - advance += letter.Advance * style.fontSize; - } - } - - void Renderer2D::DrawChar(Char& letter, Ref font, Vector2 position, Vector2 size) - { - TextShader->Bind(); - TextShader->SetUniformMat4f("projection", Projection); - - Matrix4 mat = Matrix4(1.0f); - mat = glm::translate(mat, Vector3(position.x, position.y, 0.f)); - mat = glm::scale(mat, Vector3(letter.AtlasBounds.Size.x, letter.AtlasBounds.Size.y, 0.f)); - - //TextShader->SetUniform1f("u_border_radius", 8.1f); - //TextShader->SetUniform2f("u_size", 100.f, 100.f); - - font->FontAtlas->Bind(5); - // - TextShader->SetUniform1i("msdf", 5); - TextShader->SetUniform2f("texPos", letter.AtlasBounds.Pos.x, letter.AtlasBounds.Pos.y); - TextShader->SetUniform2f("texScale", letter.AtlasBounds.Size.x, letter.AtlasBounds.Size.y); - TextShader->SetUniformMat4f("model", mat); - //TextShader->SetUniform4f("bgColor", 0, 0, 1, 1); - TextShader->SetUniform4f("bgColor", 0.f, 0.f, 0.f, 0.f); - TextShader->SetUniform4f("fgColor", 1.f, 1.f, 1.f, 1.f); - //TextShader->SetUniform1f("pxRange", 32); - glBindVertexArray(VAO); - glDrawArrays(GL_TRIANGLES, 0, 6); - } - - void Renderer2D::EndDraw() - { - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - } } diff --git a/Nuake/src/Rendering/Renderer2D.h b/Nuake/src/Rendering/Renderer2D.h index ac7065a4..daf796a2 100644 --- a/Nuake/src/Rendering/Renderer2D.h +++ b/Nuake/src/Rendering/Renderer2D.h @@ -2,7 +2,6 @@ #include "src/Rendering/Shaders/Shader.h" #include "src/Core/Core.h" #include "src/Core/Maths.h" -#include "src/UI/Font/Font.h" namespace Nuake { @@ -24,8 +23,6 @@ namespace Nuake static void DrawRect(Vector2 position, Vector2 size, Color color, float borderRadius = 0.0f); static Vector2 CalculateStringSize(const std::string& str, const TextStyle& style); - static void DrawString(const std::string& str, TextStyle style, Matrix4 model); - static void DrawChar(Char& letter, Ref font, Vector2 position, Vector2 size); static void EndDraw(); }; } diff --git a/Nuake/src/Scene/Components/InterfaceComponent.h b/Nuake/src/Scene/Components/InterfaceComponent.h deleted file mode 100644 index b0e93c25..00000000 --- a/Nuake/src/Scene/Components/InterfaceComponent.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include "src/Core/Core.h" -#include "src/UI/UserInterface.h" -#include "src/Resource/Serializable.h" - -namespace Nuake { - class InterfaceComponent - { - public: - std::string Path; - Ref Interface; - - json Serialize() - { - BEGIN_SERIALIZE(); - SERIALIZE_VAL_LBL("Interface", Interface->GetPath()) - END_SERIALIZE(); - } - - bool Deserialize(const json& j) - { - if (j.contains("Interface")) - SetInterface(j["Interface"]); - - return true; - } - - void SetInterface(const std::string& path) - { - Path = path; - Interface = UI::UserInterface::New("No name", path); - } - }; -} diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 2006844a..30d73297 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -27,7 +27,6 @@ #include "src/Scene/Components/BoxCollider.h" #include "src/Scene/Components/WrenScriptComponent.h" #include "src/Scene/Components/BSPBrushComponent.h" -#include "src/Scene/Components/InterfaceComponent.h" #include "src/Scene/Components/SkinnedModelComponent.h" #include "src/Scene/Components/BoneComponent.h" diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index 06fbaefd..5955f27e 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -9,10 +9,7 @@ #include "EditorCamera.h" #include "src/Resource/Serializable.h" -#include "src/UI/UserInterface.h" - #include "src/Scene/Systems/System.h" - #include "src/Resource/UUID.h" namespace Nuake diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index 39f23743..868ae71d 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -413,7 +413,7 @@ namespace Nuake void ScriptingEngineNet::CopyNuakeNETAssemblies(const std::string& path) { // Create .Net directory in projects folder. - const auto netDirectionPath = '/' + m_NetDirectory + '/'; + const auto netDirectionPath = "/"; const auto netDir = path + netDirectionPath; if (!FileSystem::DirectoryExists(netDirectionPath)) { diff --git a/Nuake/src/UI/Font/AtlasGenerator.h b/Nuake/src/UI/Font/AtlasGenerator.h deleted file mode 100644 index a2fa38f1..00000000 --- a/Nuake/src/UI/Font/AtlasGenerator.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "msdf-atlas-gen/AtlasGenerator.h" -#include -#include - - - -class FontGenerator -{ - template GEN_FN> - static bool makeAtlas(const std::vector& glyphs, const std::vector& fonts, const msdf_atlas::GeneratorAttributes& attr) { - ImmediateAtlasGenerator > generator(config.width, config.height); - generator.setAttributes(attr); - generator.setThreadCount(1); - generator.generate(glyphs.data(), glyphs.size()); - msdfgen::BitmapConstRef bitmap = (msdfgen::BitmapConstRef) generator.atlasStorage(); - - bool success = true; - - //if (config.imageFilename) { - // if (saveImage(bitmap, config.imageFormat, config.imageFilename, config.yDirection)) - // puts("Atlas image file saved."); - // else { - // success = false; - // puts("Failed to save the atlas as an image file."); - // } - //} - - return success; - } -}; \ No newline at end of file diff --git a/Nuake/src/UI/Font/Font.h b/Nuake/src/UI/Font/Font.h deleted file mode 100644 index c14816f4..00000000 --- a/Nuake/src/UI/Font/Font.h +++ /dev/null @@ -1,114 +0,0 @@ -#pragma once -#include "src/Core/Core.h" -#include -#include -#include -#include "src/Core/Maths.h" - -namespace Nuake -{ - struct CharPos - { - float left; - float right; - float top; - float bottom; - }; - - struct CharUV - { - Vector2 Pos; - Vector2 Size; - }; - - class Char - { - public: - uint32_t Unicode; - float Advance = 0.f; - CharPos PlaneBounds; - CharUV AtlasBounds = {}; - - Char() {}; - Char(const unsigned int unicode, float advance, CharPos plane, CharUV atlas) - { - Unicode = unicode; - Advance = advance; - PlaneBounds = plane; - AtlasBounds = atlas; - } - - CharUV GetAtlasUV(const Vector2& atlasSize) - { - return AtlasBounds; - } - }; - - class Font - { - private: - msdfgen::FreetypeHandle* ft; - msdfgen::FontHandle* font; - const char* fontFilename; - - std::map Chars; - - public: - Ref FontAtlas; - - Font() : ft(msdfgen::initializeFreetype()), font(nullptr), fontFilename(nullptr) - { - this->Chars = std::map(); - } - - ~Font() - { - if (!ft) - return; - - if (font) - msdfgen::destroyFont(font); - - msdfgen::deinitializeFreetype(ft); - } - - bool load(const char* fontFilename) - { - if (ft && fontFilename) - { - if (this->fontFilename && !strcmp(this->fontFilename, fontFilename)) - return true; - if (font) - msdfgen::destroyFont(font); - if ((font = msdfgen::loadFont(ft, fontFilename))) - { - this->fontFilename = fontFilename; - return true; - } - - this->fontFilename = nullptr; - } - return false; - } - - operator msdfgen::FontHandle* () const - { - return font; - } - - msdfgen::FontHandle* GetFontHandle() { return font; } - msdfgen::FreetypeHandle* GetFreetypeHandle() { return ft; } - - void AddChar(const unsigned int unicode, float advance, CharPos plane, CharUV atlas) - { - this->Chars[unicode] = Char(unicode, advance, plane, atlas); - } - - Char GetChar(unsigned int unicode) - { - if (Chars.find(unicode) != Chars.end()) - return Chars[unicode]; - return Char(); - } - }; -} diff --git a/Nuake/src/UI/Font/FontLoader.h b/Nuake/src/UI/Font/FontLoader.h deleted file mode 100644 index 94066d88..00000000 --- a/Nuake/src/UI/Font/FontLoader.h +++ /dev/null @@ -1,187 +0,0 @@ -#pragma once -#include -#include -#include "../Core/Core.h" -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "src/Vendors/msdf-atlas-gen/AtlasStorage.h" -#include "src/Vendors/msdf-atlas-gen/glyph-generators.h" -#include -#include - -#include "../Rendering/Textures/Texture.h" -#include "msdf-atlas-gen/json-export.h" -typedef unsigned char byte; - -namespace Nuake -{ - struct Config - { - msdf_atlas::ImageType imageType; - msdf_atlas::ImageFormat imageFormat; - msdf_atlas::YDirection yDirection; - int width, height; - double emSize; - double pxRange; - double angleThreshold; - double miterLimit; - void (*edgeColoring)(msdfgen::Shape&, double, unsigned long long); - bool expensiveColoring; - unsigned long long coloringSeed; - msdf_atlas::GeneratorAttributes generatorAttributes; - bool preprocessGeometry; - bool kerning; - int threadCount = 1; - }; - - class FontLoader - { - public: - - template GEN_FN> - static bool makeAtlas(const std::vector& glyphs, - const std::vector& fonts, - Config& config, Ref font) { - // Create generator - msdf_atlas::ImmediateAtlasGenerator > generator(config.width, config.height); - - // Setup generator settings - generator.setAttributes(config.generatorAttributes); - generator.setThreadCount(config.threadCount); - generator.generate(glyphs.data(), static_cast(glyphs.size())); - - // Create bitmap - msdfgen::BitmapConstRef bitmap = (msdfgen::BitmapConstRef) generator.atlasStorage(); - - // Create Texture from bitmap - //msdf_atlas::exportJSON(fonts.data(), fonts.size(), config.emSize, config.pxRange, config.width, config.height, config.imageType, config.yDirection, "yayayayya.json", config.kerning); - font->FontAtlas = CreateRef(Vector2(config.width, config.height), bitmap, true); - - // Create Char structure - return true; - } - static Ref LoadFont(const std::string path) - { - // create font - Ref font = CreateRef(); - - // Create atlas settings - Config config{}; - config.pxRange = 2; - config.emSize = 0.0; - config.coloringSeed = 125155; - config.imageType = msdf_atlas::ImageType::MTSDF; - config.imageFormat = msdf_atlas::ImageFormat::UNSPECIFIED; - config.yDirection = msdf_atlas::YDirection::BOTTOM_UP; - config.edgeColoring = msdfgen::edgeColoringInkTrap; - config.kerning = true; - config.preprocessGeometry = false; - config.angleThreshold = 3.0; - config.miterLimit = 1.0; - config.generatorAttributes.scanlinePass = true; - config.generatorAttributes.config.overlapSupport = true; - - // Load file - if (!font->load(path.c_str())) - Logger::Log("Failed to load font", "font", CRITICAL); - - // Load charset ASCII - std::vector glyphs; - std::vector fonts; - msdf_atlas::FontGeometry fontGeometry(&glyphs); - msdf_atlas::Charset charset = msdf_atlas::Charset::ASCII; - - // Load Create charset - float fontScale = 32; - bool preprocess = false; - int loaded = fontGeometry.loadCharset(font->GetFontHandle(), fontScale, charset, config.preprocessGeometry, config.kerning); - - fonts.push_back(fontGeometry); - - if (glyphs.empty()) - Logger::Log("No glyphs loaded.", "font", CRITICAL); - - // Create atlas params - msdf_atlas::TightAtlasPacker::DimensionsConstraint atlasSizeConstraint = msdf_atlas::TightAtlasPacker::DimensionsConstraint::MULTIPLE_OF_FOUR_SQUARE; - msdf_atlas::TightAtlasPacker atlasPacker; - atlasPacker.setDimensionsConstraint(atlasSizeConstraint); - msdf_atlas::ImageType imageType = msdf_atlas::ImageType::MTSDF; - atlasPacker.setPadding(imageType == msdf_atlas::ImageType::MSDF || imageType == msdf_atlas::ImageType::MTSDF ? 0 : -1); - atlasPacker.setPixelRange(config.pxRange); - atlasPacker.setUnitRange(config.emSize); - atlasPacker.setMiterLimit(config.miterLimit); - - // Pack atlas - if (int remaining = atlasPacker.pack(glyphs.data(), static_cast(glyphs.size()))) - { - if (remaining < 0) - { - Logger::Log("Failed to pack atlas.", "font", CRITICAL); - } - else - { - printf("Error: Could not fit %d out of %d glyphs into the atlas.\n", remaining, (int)glyphs.size()); - - } - } - - // update atlast size - atlasPacker.getDimensions(config.width, config.height); - if (!(config.width > 0 && config.height > 0)) - printf("Unable to determine atlas size."); - - config.emSize = atlasPacker.getScale(); - config.pxRange = atlasPacker.getPixelRange(); - - // Color the glyph - //unsigned long long glyphSeed = config.coloringSeed; - //for (msdf_atlas::GlyphGeometry& glyph : glyphs) { - // glyphSeed *= 6364136223846793005ull; - // glyph.edgeColoring(config.edgeColoring, config.angleThreshold, glyphSeed); - //} - - msdf_atlas::Workload([&glyphs, &config](int i, int threadNo) -> bool - { - unsigned long long glyphSeed = (6364136223846793005ull * (config.coloringSeed ^ i) + 1442695040888963407ull) * !!config.coloringSeed; - glyphs[i].edgeColoring(config.edgeColoring, config.angleThreshold, glyphSeed); - return true; - }, (int)glyphs.size()).finish(config.threadCount); - - // Create bitmap and char structure - auto bitmap = makeAtlas(glyphs, fonts, config, font); - - for (auto& g : glyphs) - { - double planeLeft, planeBottom, planeRight, planeTop; - g.getQuadPlaneBounds(planeLeft, planeBottom, planeRight, planeTop); - - CharPos plane { - static_cast(planeLeft), - static_cast(planeRight), - static_cast(planeTop), - static_cast(planeBottom) - }; - - double x2, y2, z2, w2; - g.getQuadAtlasBounds(x2, y2, z2, w2); - - CharUV box { - Vector2{x2, y2}, - Vector2{z2, w2} - }; - - font->AddChar(g.getCodepoint(), static_cast(g.getAdvance()), plane, box); - } - - return font; - } - }; -} diff --git a/Nuake/src/UI/Font/FontManager.cpp b/Nuake/src/UI/Font/FontManager.cpp deleted file mode 100644 index 8a33e732..00000000 --- a/Nuake/src/UI/Font/FontManager.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "FontManager.h" - -namespace Nuake { - std::map > FontManager::m_Fonts = std::map>(); - - Ref FontManager::GetFont(const std::string& font) - { - // Fonts exists in memory - if (m_Fonts.find(font) != m_Fonts.end()) - { - return m_Fonts[font]; - } - - // Load font - Ref newFont = FontLoader::LoadFont(font); - if (newFont) - return newFont; - - Logger::Log("Error: failed to load font " + font, "font", CRITICAL); - return nullptr; - } -} diff --git a/Nuake/src/UI/Font/FontManager.h b/Nuake/src/UI/Font/FontManager.h deleted file mode 100644 index 580fe81e..00000000 --- a/Nuake/src/UI/Font/FontManager.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include - -#include "FontLoader.h" - -namespace Nuake { - class FontManager - { - private: - static std::map > m_Fonts; - - public: - static Ref GetFont(const std::string& font); - }; -} diff --git a/Nuake/src/UI/InterfaceParser.cpp b/Nuake/src/UI/InterfaceParser.cpp deleted file mode 100644 index 3e2985c5..00000000 --- a/Nuake/src/UI/InterfaceParser.cpp +++ /dev/null @@ -1,262 +0,0 @@ -#include "InterfaceParser.h" -#include "Styling/Stylesheet.h" -#include "src/Core/String.h" -namespace Nuake -{ - Ref InterfaceParser::Root = CreateRef(); - - Ref InterfaceParser::Parse(const std::string path) - { - pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_file(path.c_str()); - std::string name = doc.first_child().name(); - if (name != "Canvas") - { - Logger::Log("InterfaceParser error: First child should be a canvas - " + path, "ui", CRITICAL); - return nullptr; - } - - Root = CreateCanvas(doc.first_child()); - Root->Depth = 0; - Iterate(doc.first_child(), Root, 0); - return Root; - } - - void InterfaceParser::Iterate(const pugi::xml_node& xml_node, Ref node, int depth) - { - int currentDepth = depth + 1; - for (auto& e : xml_node.children()) - { - std::string type = e.name(); - Ref newNode; - - if (type == "Canvas") - newNode = CreateCanvas(e); - else if (type == "Rect") - newNode = CreateNode(e); - else if (type == "p") - newNode = CreateTextNode(e); - else - continue; - newNode->Depth = currentDepth; - node->Childrens.push_back(newNode); - Iterate(e, newNode, currentDepth); - } - } - - Ref InterfaceParser::CreateTextNode(const pugi::xml_node& xml_node) - { - Ref node = CreateRef(); - node->content = xml_node.text().as_string(); - node->Type = NodeType::Text; - TextStyle style { - FontManager::GetFont("resources/Fonts/RobotoMono-Regular.ttf"), - 0.5, - Color(255, 255, 255, 255) - }; - - for (auto& a : xml_node.attributes()) - { - std::string name = a.name(); - if (name == "groups") - for (auto& g : String::Split(a.value(), ' ')) - node->AddGroup(g); - - if (name == "id") - node->ID = a.value(); - if (name == "height") - node->NormalStyle.Height = GetUnit(a.value()); - if (name == "width") - node->NormalStyle.Width = GetUnit(a.value()); - if (name == "margin") - node->NormalStyle.Margin = GetVec4Unit(a.value()); - if (name == "padding") - node->NormalStyle.Padding = GetVec4Unit(a.value()); - if (name == "border") - node->NormalStyle.Border = GetVec4Unit(a.value()); - if (name == "position") - node->NormalStyle.Position = GetVec4Unit(a.value()); - if (name == "color") - node->NormalStyle.BackgroundColor = GetColor(a.value()); - if (name == "font-size") - style.fontSize = std::stof(a.value()); - } - - Vector2 minSize = Renderer2D::CalculateStringSize(node->content, style); - node->NormalStyle.Width = { - minSize.x, - Layout::Unit::PIXEL - }; - node->NormalStyle.Height = { - minSize.y, - Layout::Unit::PIXEL - }; - - - node->SetTextStyle(style); - return node; - } - - Ref InterfaceParser::CreateNode(const pugi::xml_node& xml_node) - { - Ref node = CreateRef(); - - node->Root = Root; - for (auto& a : xml_node.attributes()) - { - std::string name = a.name(); - if (name == "groups") - for (auto& g : String::Split(a.value(), ' ')) - node->AddGroup(g); - - if (name == "id") - node->ID = a.value(); - if (name == "height") - node->NormalStyle.Height = GetUnit(a.value()); - if (name == "width") - node->NormalStyle.Width = GetUnit(a.value()); - if (name == "margin") - node->NormalStyle.Margin = GetVec4Unit(a.value()); - if (name == "padding") - node->NormalStyle.Padding = GetVec4Unit(a.value()); - if (name == "border") - node->NormalStyle.Border = GetVec4Unit(a.value()); - if (name == "position") - node->NormalStyle.Position = GetVec4Unit(a.value()); - if (name == "color") - node->NormalStyle.BackgroundColor = GetColor(a.value()); - if (name == "onclick") - { - //std::string signature = a.value(); - //Root->Script->RegisterMethod(a.value()); - //node->OnClickSignature = a.value(); - } - } - - return node; - } - - Layout::LayoutUnit InterfaceParser::GetUnit(const std::string& value) - { - std::regex only_number("[0-9]+"); - std::regex not_number("[^0-9]+"); - - // is percentage - std::smatch match_value; - if (std::regex_search(value.begin(), value.end(), match_value, only_number)) - { - std::smatch match_type; - if (std::regex_search(value.begin(), value.end(), match_type, not_number)) - { - float value = std::stof(match_value[0]); - - if (match_type[0] == "%") - { - return Layout::LayoutUnit{ - value, - Layout::Unit::PERCENT - }; - } - else if (match_type[0] == "px") - { - return Layout::LayoutUnit{ - value, - Layout::Unit::PIXEL - }; - } - } - } - - return Layout::LayoutUnit{ 1.0f, Layout::Unit::AUTO }; - } - - Layout::LayoutVec4 InterfaceParser::GetVec4Unit(const std::string& value) - { - Layout::LayoutVec4 result; - - std::regex regex("[0-9]+[^ ]+"); - std::smatch match_value; - - std::vector splits = String::Split(value, ' '); - for (int i = 0; i < splits.size(); i++) - { - if (!std::regex_search(value.begin(), value.end(), match_value, regex)) - continue; - - if (i == 0) - result.Left = GetUnit(splits[i]); - else if (i == 1) - result.Right = GetUnit(splits[i]); - else if (i == 2) - result.Top = GetUnit(splits[i]); - else - result.Bottom = GetUnit(splits[i]); - } - - return result; - } - - Color InterfaceParser::GetColor(const std::string& value) - { - Color result; - - std::regex regex("[0-9]+[^ ]+"); - std::smatch match_value; - - std::vector splits = String::Split(value, ' '); - for (int i = 0; i < splits.size(); i++) - { - if (!std::regex_search(value.begin(), value.end(), match_value, regex)) - continue; - - if (i == 0) result.r = std::stof(splits[i]); - else if (i == 1) result.g = std::stof(splits[i]); - else if (i == 2) result.b = std::stof(splits[i]); - else result.a = std::stof(splits[i]); - } - - return result; - } - - Ref InterfaceParser::CreateCanvas(const pugi::xml_node& xml_node) - { - Ref node = CreateRef(); - node->Root = Root; - for (auto& a : xml_node.attributes()) - { - std::string name = a.name(); - if (name == "groups") - for (auto& g : String::Split(a.value(), ' ')) - node->AddGroup(g); - if (name == "id") - node->ID = a.value(); - else if (name == "height") - node->NormalStyle.Height = GetUnit(a.value()); - else if (name == "width") - node->NormalStyle.Width = GetUnit(a.value()); - else if (name == "margin") - node->NormalStyle.Margin = GetVec4Unit(a.value()); - else if (name == "padding") - node->NormalStyle.Padding = GetVec4Unit(a.value()); - else if (name == "border") - node->NormalStyle.Border = GetVec4Unit(a.value()); - else if (name == "position") - node->NormalStyle.Position = GetVec4Unit(a.value()); - else if (name == "color") - node->NormalStyle.BackgroundColor = GetColor(a.value()); - else if (name == "script") - { - auto scriptModule = String::Split(a.value(), ' '); - node->ScriptsToLoad.push_back({ scriptModule[0], scriptModule[1] }); - //node->Script = ScriptingEngine::RegisterScript(FileSystem::Root + path, module); - } - else if (name == "stylesheet") - { - std::string path = a.value(); - node->StyleSheet = UI::StyleSheet::New(FileSystem::Root + path); - } - } - - return node; - } -} diff --git a/Nuake/src/UI/InterfaceParser.h b/Nuake/src/UI/InterfaceParser.h deleted file mode 100644 index dc073964..00000000 --- a/Nuake/src/UI/InterfaceParser.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include "Nodes/TextNode.h" -#include "Font/FontManager.h" -#include "../Scripting/ScriptingEngine.h" - -namespace Nuake -{ - class InterfaceParser - { - private: - static Ref Root; - public: - static Ref Parse(const std::string path); - - static void Iterate(const pugi::xml_node& xml_node, Ref node, int depth); - - static Ref CreateNode(const pugi::xml_node& xml_node); - static Ref CreateCanvas(const pugi::xml_node& xml_node); - static Ref CreateTextNode(const pugi::xml_node& xml_node); - - static Layout::LayoutUnit GetUnit(const std::string& value); - static Layout::LayoutVec4 GetVec4Unit(const std::string& value); - static Color GetColor(const std::string& value); - }; -} diff --git a/Nuake/src/UI/Nodes/Canvas.cpp b/Nuake/src/UI/Nodes/Canvas.cpp deleted file mode 100644 index a2b9425e..00000000 --- a/Nuake/src/UI/Nodes/Canvas.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Canvas.h" - -namespace Nuake { - Canvas::Canvas() - { - - } -} - diff --git a/Nuake/src/UI/Nodes/Canvas.h b/Nuake/src/UI/Nodes/Canvas.h deleted file mode 100644 index a29354e1..00000000 --- a/Nuake/src/UI/Nodes/Canvas.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "Node.h" -#include "src/Core/Core.h" -#include "src/Scripting/WrenScript.h" -#include "src/UI/Styling/Stylesheet.h" - -#include -#include - -namespace Nuake { - class Canvas : public Node - { - private: - - public: - std::vector> ScriptsToLoad; - - Ref Script; - Ref StyleSheet; - - Canvas(); - }; -} diff --git a/Nuake/src/UI/Nodes/Node.cpp b/Nuake/src/UI/Nodes/Node.cpp deleted file mode 100644 index aed4bec0..00000000 --- a/Nuake/src/UI/Nodes/Node.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "Node.h" - -namespace Nuake -{ - Node::Node() - { - Childrens = std::vector>(); - Groups = std::vector(); - - NormalStyle = { - Layout::PositionType::RELATIVE, - Layout::LayoutVec4(), - Layout::LayoutUnit(), Layout::LayoutUnit(), Layout::LayoutUnit(), - Layout::LayoutUnit(), Layout::LayoutUnit(), Layout::LayoutUnit(), - Layout::LayoutVec4(), - Layout::LayoutVec4(), - Layout::LayoutVec4(), - Color(), - Layout::LayoutDirection::LTR, - Layout::FlexDirection::ROW, - Layout::FlexWrap::WRAP, - 0.f, - 1.f, - 10.f, - 1.f, - Layout::JustifyContent(), - Layout::AlignItems::AUTO, - Layout::AlignItems::AUTO, - }; - } - - void Node::ApplyStyle(Ref stylegroup, StyleGroupSelector selector) - { - Style style = NormalStyle; - for (auto& s : stylegroup->GetProps()) - { - switch (s.first) - { - case PropType::HEIGHT: - { - style.Height.mUnit = (Layout::Unit)(s.second.type); - float value = s.second.value.Number; - style.Height.Value = value; - } - break; - case PropType::MIN_HEIGHT: - style.MinHeight.mUnit = (Layout::Unit)s.second.type; - style.MinHeight.Value = s.second.value.Number; - break; - case PropType::MAX_HEIGHT: - style.MaxHeight.mUnit = (Layout::Unit)s.second.type; - style.MaxHeight.Value = s.second.value.Number; - break; - case PropType::WIDTH: - style.Width.mUnit = (Layout::Unit)s.second.type; - style.Width.Value = s.second.value.Number; - break; - case PropType::MIN_WIDTH: - style.MinWidth.mUnit = (Layout::Unit)s.second.type; - style.MinWidth.Value = s.second.value.Number; - break; - case PropType::MAX_WIDTH: - style.MaxWidth.mUnit = (Layout::Unit)s.second.type; - style.MaxWidth.Value = s.second.value.Number; - break; - case PropType::MARGIN_RIGHT: - style.Margin.Right.mUnit = (Layout::Unit)s.second.type; - style.Margin.Right.Value = s.second.value.Number; - break; - case PropType::MARGIN_LEFT: - style.Margin.Left.mUnit = (Layout::Unit)s.second.type; - style.Margin.Left.Value = s.second.value.Number; - break; - case PropType::MARGIN_TOP: - style.Margin.Top.mUnit = (Layout::Unit)s.second.type; - style.Margin.Top.Value = s.second.value.Number; - break; - case PropType::MARGIN_BOTTOM: - style.Margin.Bottom.mUnit = (Layout::Unit)s.second.type; - style.Margin.Bottom.Value = s.second.value.Number; - break; - case PropType::JUSTIFY_CONTENT: - style.JustifyContent = (Layout::JustifyContent)s.second.value.Enum; - break; - case PropType::FLEX_WRAP: - style.FlexWrap = (Layout::FlexWrap)s.second.value.Enum; - break; - case PropType::FLEX_DIRECTION: - style.FlexDirection = (Layout::FlexDirection)s.second.value.Enum; - break; - case PropType::ALIGN_ITEMS: - style.AlignItems = (Layout::AlignItems)s.second.value.Enum; - break; - case PropType::SELF_ALIGN: - style.AlignSelf = (Layout::AlignItems)s.second.value.Enum; - break; - case PropType::ALIGN_CONTENT: - style.AlignContent = (Layout::AlignContent)s.second.value.Enum; - break; - case PropType::POSITION: - style.PositionType = (Layout::PositionType)s.second.value.Enum; - break; - case PropType::LEFT: - style.Position.Left.mUnit = (Layout::Unit)s.second.type; - style.Position.Left.Value = s.second.value.Number; - break; - case PropType::RIGHT: - style.Position.Right.mUnit = (Layout::Unit)s.second.type; - style.Position.Right.Value = s.second.value.Number; - break; - case PropType::TOP: - style.Position.Top.mUnit = (Layout::Unit)s.second.type; - style.Position.Top.Value = s.second.value.Number; - break; - case PropType::BOTTOM: - style.Position.Bottom.mUnit = (Layout::Unit)s.second.type; - style.Position.Bottom.Value = s.second.value.Number; - break; - } - } - - if (selector == StyleGroupSelector::Hover) - HoverStyle = style; - else - NormalStyle = style; - } - - bool Node::IsPositionInside(Vector2 position) - { - float width = YGNodeLayoutGetWidth(YogaNode); - float height = YGNodeLayoutGetHeight(YogaNode); - float padding = YGNodeLayoutGetPadding(YogaNode, YGEdgeLeft); - float left = YGNodeLayoutGetLeft(YogaNode); //+ offset.x; - float top = YGNodeLayoutGetTop(YogaNode);// +offset.y; - - float parentLeft = 0.0f; - float parentTop = 0.0f; - auto parent = YGNodeGetParent(YogaNode); - while (parent) - { - parentLeft += YGNodeLayoutGetLeft(parent); - parentTop += YGNodeLayoutGetTop(parent); - parent = YGNodeGetParent(parent); - } - - left += parentLeft; - top += parentTop; - return position.x > left && position.x < left + width && position.y > top && position.y < top + height; - } -} diff --git a/Nuake/src/UI/Nodes/Node.h b/Nuake/src/UI/Nodes/Node.h deleted file mode 100644 index ce7f8866..00000000 --- a/Nuake/src/UI/Nodes/Node.h +++ /dev/null @@ -1,378 +0,0 @@ -#pragma once -#include -#include "../Core/Core.h" -#include "yoga/Yoga.h" -#include "../Rendering/Renderer2D.h" -#include "../Core/Logger.h" -#include - -namespace Nuake -{ - enum class NodeType - { - Normal, - Text - }; - - class Node - { - public: - float ScrollAmount = 0.0f; - - int Depth; - Ref Root; - Ref Parent; - std::string ID; - - std::vector Groups; - std::vector> Childrens = std::vector>(); - - std::string OnClickSignature = ""; - - NodeType Type = NodeType::Normal; - - YGNodeRef YogaNode; - - bool IsHover = false; - bool IsClicked = false; - - Style NormalStyle; - Style HoverStyle; - - Ref BackgroundTexture; - - Node(); - - void ApplyStyle(Ref stylegroup, StyleGroupSelector selector = StyleGroupSelector::Normal); - - bool IsPositionInside(Vector2 position); - - void AddGroup(const std::string& group) - { - Groups.push_back(group); - } - - float GetWidth() - { - return YGNodeLayoutGetWidth(YogaNode); - } - - bool IsInGroup(const std::string& group) - { - for (auto& g : Groups) - if (g == group) return true; - - return false; - } - - std::vector GetGroups() const { return Groups; } - - void SetMargin() - { - - } - - void SetPadding() - { - - } - - void SetBorder() - { - - } - - void SetYogaLayout() - { - Style style = this->NormalStyle; - if (IsHover) - style = this->HoverStyle; - - switch (style.Width.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetWidth(YogaNode, style.Width.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetWidthPercent(YogaNode, style.Width.Value); - break; - case Layout::Unit::AUTO: - YGNodeStyleSetWidthAuto(YogaNode); - break; - } - switch (style.Height.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetHeight(YogaNode, style.Height.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetHeightPercent(YogaNode, style.Height.Value); - break; - case Layout::Unit::AUTO: - YGNodeStyleSetHeightAuto(YogaNode); - break; - } - - switch (style.Margin.Left.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetMargin(YogaNode, YGEdgeLeft, style.Margin.Left.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetMarginPercent(YogaNode, YGEdgeLeft, style.Margin.Left.Value); - break; - case Layout::Unit::AUTO: - YGNodeStyleSetMarginAuto(YogaNode, YGEdgeLeft); - break; - } - - switch (style.Margin.Right.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetMargin(YogaNode, YGEdgeRight, style.Margin.Right.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetMarginPercent(YogaNode, YGEdgeRight, style.Margin.Right.Value); - break; - case Layout::Unit::AUTO: - YGNodeStyleSetMarginAuto(YogaNode, YGEdgeRight); - break; - } - - switch (style.Margin.Top.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetMargin(YogaNode, YGEdgeTop, style.Margin.Top.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetMarginPercent(YogaNode, YGEdgeTop, style.Margin.Top.Value); - break; - case Layout::Unit::AUTO: - YGNodeStyleSetMarginAuto(YogaNode, YGEdgeTop); - break; - } - - switch (style.Margin.Bottom.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetMargin(YogaNode, YGEdgeBottom, style.Margin.Bottom.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetMarginPercent(YogaNode, YGEdgeBottom, style.Margin.Bottom.Value); - break; - case Layout::Unit::AUTO: - YGNodeStyleSetMarginAuto(YogaNode, YGEdgeTop); - break; - } - switch (style.Padding.Left.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetPadding(YogaNode, YGEdgeLeft, style.Padding.Left.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetPaddingPercent(YogaNode, YGEdgeLeft, style.Padding.Left.Value); - break; - } - - switch (style.Padding.Right.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetPadding(YogaNode, YGEdgeRight, style.Padding.Right.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetPaddingPercent(YogaNode, YGEdgeRight, style.Padding.Right.Value); - break; - } - - switch (style.Padding.Top.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetPadding(YogaNode, YGEdgeTop, style.Padding.Top.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetPaddingPercent(YogaNode, YGEdgeTop, style.Padding.Top.Value); - break; - } - - switch (style.Padding.Bottom.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetPadding(YogaNode, YGEdgeBottom, style.Padding.Bottom.Value); - break; - case Layout::Unit::PERCENT: - YGNodeStyleSetPaddingPercent(YogaNode, YGEdgeBottom, style.Padding.Bottom.Value); - break; - } - switch (style.Border.Left.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetBorder(YogaNode, YGEdgeLeft, style.Border.Left.Value); - break; - } - - switch (style.Border.Right.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetBorder(YogaNode, YGEdgeRight, style.Border.Right.Value); - break; - } - - switch (style.Border.Top.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetBorder(YogaNode, YGEdgeTop, style.Border.Top.Value); - break; - } - - switch (style.Border.Bottom.mUnit) - { - case Layout::Unit::PIXEL: - YGNodeStyleSetBorder(YogaNode, YGEdgeBottom, style.Border.Bottom.Value); - break; - } - - if (style.FlexWrap == Layout::FlexWrap::WRAP) - YGNodeStyleSetFlexWrap(YogaNode, YGWrapWrap); - else if (style.FlexWrap == Layout::FlexWrap::NO_WRAP) - YGNodeStyleSetFlexWrap(YogaNode, YGWrapNoWrap); - else if (style.FlexWrap == Layout::FlexWrap::WRAP_REVERSED) - YGNodeStyleSetFlexWrap(YogaNode, YGWrapWrapReverse); - - if (style.FlexDirection == Layout::FlexDirection::ROW) - YGNodeStyleSetFlexDirection(YogaNode, YGFlexDirectionRow); - else if (style.FlexDirection == Layout::FlexDirection::ROW_REVERSED) - YGNodeStyleSetFlexDirection(YogaNode, YGFlexDirectionRowReverse); - else if (style.FlexDirection == Layout::FlexDirection::COLUMN) - YGNodeStyleSetFlexDirection(YogaNode, YGFlexDirectionColumn); - else if (style.FlexDirection == Layout::FlexDirection::COLUMN_REVERSED) - YGNodeStyleSetFlexDirection(YogaNode, YGFlexDirectionColumnReverse); - - if (style.JustifyContent == Layout::JustifyContent::FLEX_START) - YGNodeStyleSetJustifyContent(YogaNode, YGJustifyFlexStart); - else if (style.JustifyContent == Layout::JustifyContent::FLEX_END) - YGNodeStyleSetJustifyContent(YogaNode, YGJustifyFlexEnd); - else if (style.JustifyContent == Layout::JustifyContent::CENTER) - YGNodeStyleSetJustifyContent(YogaNode, YGJustifyCenter); - else if (style.JustifyContent == Layout::JustifyContent::SPACE_BETWEEN) - YGNodeStyleSetJustifyContent(YogaNode, YGJustifySpaceBetween); - else if (style.JustifyContent == Layout::JustifyContent::SPACE_AROUND) - YGNodeStyleSetJustifyContent(YogaNode, YGJustifySpaceAround); - else if (style.JustifyContent == Layout::JustifyContent::SPACE_EVENLY) - YGNodeStyleSetJustifyContent(YogaNode, YGJustifySpaceEvenly); - - if (style.AlignItems == Layout::AlignItems::FLEX_START) - YGNodeStyleSetAlignItems(YogaNode, YGAlignFlexStart); - else if (style.AlignItems == Layout::AlignItems::FLEX_END) - YGNodeStyleSetAlignItems(YogaNode, YGAlignFlexEnd); - else if (style.AlignItems == Layout::AlignItems::CENTER) - YGNodeStyleSetAlignItems(YogaNode, YGAlignCenter); - else if (style.AlignItems == Layout::AlignItems::BASELINE) - YGNodeStyleSetAlignItems(YogaNode, YGAlignBaseline); - else if (style.AlignItems == Layout::AlignItems::STRETCH) - YGNodeStyleSetAlignItems(YogaNode, YGAlignStretch); - //else if (AlignItems == Layout::AlignItems::AUTO) - // YGNodeStyleSetAlignItems(YogaNode, YGAlignAuto); - - if (style.AlignSelf == Layout::AlignItems::FLEX_START) - YGNodeStyleSetAlignSelf(YogaNode, YGAlignFlexStart); - else if (style.AlignSelf == Layout::AlignItems::FLEX_END) - YGNodeStyleSetAlignSelf(YogaNode, YGAlignFlexEnd); - else if (style.AlignSelf == Layout::AlignItems::CENTER) - YGNodeStyleSetAlignSelf(YogaNode, YGAlignCenter); - else if (style.AlignSelf == Layout::AlignItems::BASELINE) - YGNodeStyleSetAlignSelf(YogaNode, YGAlignBaseline); - else if (style.AlignSelf == Layout::AlignItems::STRETCH) - YGNodeStyleSetAlignSelf(YogaNode, YGAlignStretch); - else if (style.AlignSelf == Layout::AlignItems::AUTO) - YGNodeStyleSetAlignSelf(YogaNode, YGAlignAuto); - - if (style.AlignContent == Layout::AlignContent::FLEX_START) - YGNodeStyleSetAlignContent(YogaNode, YGAlignFlexStart); - else if (style.AlignContent == Layout::AlignContent::FLEX_END) - YGNodeStyleSetAlignContent(YogaNode, YGAlignFlexEnd); - else if (style.AlignContent == Layout::AlignContent::CENTER) - YGNodeStyleSetAlignContent(YogaNode, YGAlignCenter); - else if (style.AlignContent == Layout::AlignContent::STRETCH) - YGNodeStyleSetAlignContent(YogaNode, YGAlignStretch); - else if (style.AlignContent == Layout::AlignContent::SPACE_BETWEEN) - YGNodeStyleSetAlignContent(YogaNode, YGAlignSpaceBetween); - else if (style.AlignContent == Layout::AlignContent::SPACE_AROUND) - YGNodeStyleSetAlignContent(YogaNode, YGAlignSpaceAround); - - if (style.PositionType == Layout::PositionType::RELATIVE) - YGNodeStyleSetPositionType(YogaNode, YGPositionTypeRelative); - else if (style.PositionType == Layout::PositionType::ABSOLUTE) - YGNodeStyleSetPositionType(YogaNode, YGPositionTypeAbsolute); - } - - void Draw(float z) - { - Renderer2D::UIShader->Bind(); - Color color = this->NormalStyle.BackgroundColor; - if(IsHover) - color = this->HoverStyle.BackgroundColor; - - Renderer2D::UIShader->SetUniform4f("u_BackgroundColor", - color.r / 255.f, - color.g / 255.f, - color.b / 255.f, - color.a / 255.f - ); - - Matrix4 transform = Matrix4(1.0f); - - float width = YGNodeLayoutGetWidth(YogaNode); - float height = YGNodeLayoutGetHeight(YogaNode); - - float scrollRange = height; - float padding = YGNodeLayoutGetPadding(YogaNode, YGEdgeLeft); - float left = YGNodeLayoutGetLeft(YogaNode); //+ offset.x; - float top = YGNodeLayoutGetTop(YogaNode);// +offset.y; - - float parentLeft = 0.0f; - float parentTop = 0.0f; - float parentHeight = 0.0f; - float parentWidth = 0.0f; - - auto parent = YGNodeGetParent(YogaNode); - if (parent) - { - parentHeight = YGNodeLayoutGetHeight(parent); - parentWidth = YGNodeLayoutGetWidth(parent); - } - - while (parent) - { - parentLeft += YGNodeLayoutGetLeft(parent); - parentTop += YGNodeLayoutGetTop(parent); - parent = YGNodeGetParent(parent); - } - - transform = glm::translate(transform, Vector3(left + parentLeft, top + parentTop, 0.f)); - - //if (top + height > parentHeight) - //{ - // float heightDifference = parentHeight - (top + height); - // height = height + heightDifference; - //} - - Vector3 scale = Vector3(width, height, 0); - transform = glm::scale(transform, scale); - - Renderer2D::UIShader->SetUniformMat4f("model", transform); - Renderer2D::UIShader->SetUniform1f("u_BorderRadius", NormalStyle.Border.Left.Value); - Renderer2D::UIShader->SetUniform2f("u_Size", width, height); - - if (BackgroundTexture != nullptr) - { - BackgroundTexture->Bind(1); - Renderer2D::UIShader->SetUniform1i("u_BackgroundTexture", 1); - Renderer2D::UIShader->SetUniform1i("u_HasBackgroundTexture", 1); - } - else - Renderer2D::UIShader->SetUniform1i("u_HasBackgroundTexture", 0); - - Renderer2D::DrawRect(); - } - }; -} \ No newline at end of file diff --git a/Nuake/src/UI/Nodes/Rect.h b/Nuake/src/UI/Nodes/Rect.h deleted file mode 100644 index 7bb1b494..00000000 --- a/Nuake/src/UI/Nodes/Rect.h +++ /dev/null @@ -1,111 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include - -namespace Nuake -{ - namespace UI - { - // Styling props - class RectProp - { - public: - float BorderRadius = 0.0f; - float BorderMinXWidth = 0.0f; - float BorderMinYWidth = 0.0f; - float BorderMaxXWidth = 0.0f; - float BorderMaxYWidth = 0.0f; - Color BorderColor = Color(0, 0, 0, 1); - Color BackgroundColor = Color(1, 0, 0, 1); - Ref BackgroundTexture; - }; - - // This is the base component for every UI layout. - class Rect - { - private: - std::string id; // This is similar to html ids - std::vector groups; // this is similar to html classes - - public: - RectProp Props; - - float MinX; - float MinY; - float MaxX; - float MaxY; - - static Ref New(float minx, float miny, float maxx, float maxy) - { - return CreateRef(minx, miny, maxx, maxy); - } - - Rect(float minx, float miny, float maxx, float maxy) - { - this->MinX = minx; - this->MinY = miny; - this->MaxX = maxx; - this->MaxY = maxy; - - this->id = ""; - this->groups = std::vector(); - } - - // Check if a point is inside the rectangle. - bool IsInside(Vector2 point) - { - return point.x > MinX && point.x < MaxX&& point.y > MinY && point.y < MaxY; - } - - bool HasGroup(const std::string& group) - { - for (auto g : groups) - if (g == group) - return true; - return false; - } - - std::vector GetGroups() { return groups; } - void AddGroup(const std::string& group) - { - // Check if already has group. - for (auto g : groups) - if (g == group) - return; - groups.push_back(group); - } - - std::string GetID() { return id; } - void SetID(const std::string& id) { this->id = id; } - - // Cuts a rectangle left and returns a new one. - Ref CutLeft(float a) - { - float minx = this->MinX; - this->MinX = std::min(this->MaxX, this->MinX + a); - return CreateRef(minx, this->MinY, this->MinX, this->MaxY); - } - - void Draw() - { - Renderer2D::UIShader->SetUniform4f("background_color", Props.BackgroundColor.r, - Props.BackgroundColor.g, - Props.BackgroundColor.b, - Props.BackgroundColor.a); - - // Get transform - Matrix4 transform = Matrix4(1.0f); - transform = glm::translate(transform, Vector3(MinX, MinY, 0)); - Vector3 scale = Vector3(MaxX - MinX, MaxY - MinY, 0); - transform = glm::scale(transform, scale); - Renderer2D::UIShader->SetUniformMat4f("model", transform); - - Renderer2D::DrawRect(); - } - }; - } -} diff --git a/Nuake/src/UI/Nodes/TextInput.h b/Nuake/src/UI/Nodes/TextInput.h deleted file mode 100644 index 9d45b485..00000000 --- a/Nuake/src/UI/Nodes/TextInput.h +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "Node.h" - -namespace Nuake -{ - namespace UI - { - class TextInput : public Node - { - private: - std::string content = ""; - bool IsFocus = false; - - Ref Background; - public: - TextInput() - { - Background = CreateRef(); - Background->NormalStyle.MinWidth = {200, Layout::Unit::PIXEL }; - Background->NormalStyle.MinHeight = { 30, Layout::Unit::PIXEL }; - - Childrens.push_back(Background); - } - - void Draw() - { - Renderer2D::DrawRect() - } - }; - } -} \ No newline at end of file diff --git a/Nuake/src/UI/Nodes/TextNode.h b/Nuake/src/UI/Nodes/TextNode.h deleted file mode 100644 index 31c82764..00000000 --- a/Nuake/src/UI/Nodes/TextNode.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once -#include "Node.h" - -namespace Nuake -{ - struct TextStyle - { - Ref font; - float fontSize; - Color color; - }; - - class TextNode : public Node - { - public: - std::string content = "Hello World!"; - TextStyle textStyle; - - - void SetTextStyle(TextStyle textStyle) - { - this->textStyle = textStyle; - } - - void CalculateSize() - { - - } - - void Draw(float z) - { - Renderer2D::TextShader->Bind(); - - Matrix4 transform = Matrix4(1.0f); - float width = YGNodeLayoutGetWidth(this->YogaNode); - float height = YGNodeLayoutGetHeight(this->YogaNode); - float left = YGNodeLayoutGetLeft(this->YogaNode); //+ offset.x; - float top = YGNodeLayoutGetTop(this->YogaNode);// +offset.y; - - float parentLeft = 0.0f; - float parentTop = 0.0f; - auto parent = YGNodeGetParent(YogaNode); - - float maxWidth = 0; - if (parent) - maxWidth = YGNodeLayoutGetWidth(parent); - - while (parent) - { - parentLeft += YGNodeLayoutGetLeft(parent); - parentTop += YGNodeLayoutGetTop(parent); - parent = YGNodeGetParent(parent); - } - transform = glm::translate(transform, Vector3(left + parentLeft, top + parentTop, 0.f)); - Renderer2D::DrawString(content, textStyle, transform); - } - }; -} diff --git a/Nuake/src/UI/Styling/NodeStyle.h b/Nuake/src/UI/Styling/NodeStyle.h deleted file mode 100644 index 6a63d3f1..00000000 --- a/Nuake/src/UI/Styling/NodeStyle.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -namespace Nuake -{ - namespace UI - { - class NodeStyler - { - //static void StyleNode(Node& node, ) - }; - } -} \ No newline at end of file diff --git a/Nuake/src/UI/Styling/Style.h b/Nuake/src/UI/Styling/Style.h deleted file mode 100644 index 5d68c23f..00000000 --- a/Nuake/src/UI/Styling/Style.h +++ /dev/null @@ -1,175 +0,0 @@ -#pragma once -#include "../Core/Maths.h" -#include - -namespace Nuake -{ - namespace Layout - { - enum class LayoutDirection - { - LTR = 2, RTL = 3 - }; - - enum class FlexWrap - { - NO_WRAP, WRAP, WRAP_REVERSED - }; - - enum class FlexDirection - { - ROW, COLUMN, ROW_REVERSED, COLUMN_REVERSED - }; - - enum class JustifyContent - { - FLEX_START, FLEX_END, CENTER, SPACE_BETWEEN, SPACE_AROUND, SPACE_EVENLY - }; - - enum class AlignItems - { - STRETCH, FLEX_START, FLEX_END, CENTER, BASELINE, AUTO, - }; - - enum class AlignContent - { - FLEX_START, FLEX_END, STRETCH, CENTER, SPACE_BETWEEN, SPACE_AROUND - }; - - enum class PositionType - { - STATIC, RELATIVE, ABSOLUTE - }; - - enum Unit - { - PIXEL, PERCENT, AUTO - }; - - struct LayoutUnit - { - float Value = 0.0f; - Unit mUnit = Unit::PIXEL; - }; - - struct LayoutVec4 - { - LayoutUnit Top = LayoutUnit{ 0, PIXEL }; - LayoutUnit Bottom = LayoutUnit{ 0, PIXEL }; - LayoutUnit Left = LayoutUnit{ 0, PIXEL }; - LayoutUnit Right = LayoutUnit{ 0, PIXEL }; - }; - } - - enum class PropType - { - NONE, HEIGHT, MAX_HEIGHT, MIN_HEIGHT, WIDTH, MAX_WIDTH, MIN_WIDTH, - LAYOUT_DIRECTION, JUSTIFY_CONTENT, - FLEX_BASIS, FLEX_GROW, FLEX_SHRINK, FLEX_WRAP, FLEX_DIRECTION, - ASPECT_RATIO, - ALIGN_ITEMS, SELF_ALIGN, ALIGN_CONTENT, - POSITION, - LEFT, RIGHT, TOP, BOTTOM, - MARGIN, MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM, - PADDING, PADDING_LEFT, PADDING_RIGHT, PADDING_TOP, PADDING_BOTTOM, - BORDER, BORDER_LEFT, BORDER_RIGHT, BORDER_TOP, BORDER_BOTTOM, - BORDER_RADIUS, BORDER_RADIUS_LEFT, BORDER_RADIUS_RIGHT, BORDER_RADIUS_TOP, BORDER_RADIUS_BOTTOM, - BACKGROUND_COLOR, COLOR, FONT_SIZE - }; - - enum class PropValueType - { - PIXEL, PERCENT, AUTO, COLOR, ENUM - }; - union Value - { - float Number; - Color Color_; - int Enum; - }; - struct PropValue - { - PropValueType type; - Value value; - }; - - enum class StyleGroupSelector - { - Normal, - Hover, - Active - }; - - class StyleGroup - { - public: - std::map Props; - StyleGroupSelector Selector; - - StyleGroup() - { - this->Props = std::map(); - } - - void SetProp(PropType type, PropValue prop) - { - Props[type] = prop; - } - - PropValue GetProp(PropType type) - { - if (Props.find(type) != Props.end()) - return Props[type]; - - return PropValue(); - } - - bool HasProp(PropType type) - { - return Props.find(type) != Props.end(); - } - - std::map GetProps() - { - return Props; - } - - StyleGroup operator+(StyleGroup other) - { - for (auto p : other.Props) - { - this->Props[p.first] = p.second; - } - - return *this; - } - }; - - - struct Style - { - Layout::PositionType PositionType; - Layout::LayoutVec4 Position; - Layout::LayoutUnit Width; - Layout::LayoutUnit MaxWidth; - Layout::LayoutUnit MinWidth; - Layout::LayoutUnit Height; - Layout::LayoutUnit MaxHeight; - Layout::LayoutUnit MinHeight; - Layout::LayoutVec4 Margin; - Layout::LayoutVec4 Padding; - Layout::LayoutVec4 Border; - Color BackgroundColor; - Layout::LayoutDirection Direction; - Layout::FlexDirection FlexDirection; - Layout::FlexWrap FlexWrap; - float FlexGrow; - float FlexShrink; - float FlexBasis; - float AspectRatio; - Layout::JustifyContent JustifyContent; - Layout::AlignItems AlignItems; - Layout::AlignItems AlignSelf; - Layout::AlignContent AlignContent; - }; -} diff --git a/Nuake/src/UI/Styling/StyleSheetParser.cpp b/Nuake/src/UI/Styling/StyleSheetParser.cpp deleted file mode 100644 index 1f9056a1..00000000 --- a/Nuake/src/UI/Styling/StyleSheetParser.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "StyleSheetParser.h" -#include -#include -#include "src/Core/String.h" - -namespace Nuake -{ - PropValue StyleSheetParser::ParsePropType(const std::string& str, PropType type) - { - switch (type) - { - case PropType::HEIGHT: case PropType::MIN_HEIGHT: case PropType::MAX_HEIGHT: - case PropType::WIDTH: case PropType::MIN_WIDTH: case PropType::MAX_WIDTH: - case PropType::LEFT: case PropType::RIGHT: case PropType::TOP: case PropType::BOTTOM: - case PropType::MARGIN_LEFT: case PropType::MARGIN_RIGHT: case PropType::MARGIN_TOP: case PropType::MARGIN_BOTTOM: - case PropType::PADDING_LEFT: case PropType::PADDING_RIGHT: case PropType::PADDING_TOP: case PropType::PADDING_BOTTOM: - case PropType::BORDER_LEFT: case PropType::BORDER_RIGHT: case PropType::BORDER_TOP: case PropType::BORDER_BOTTOM: - { - std::regex only_number("[0-9]+"); - std::regex not_number("[^0-9]+"); - // is percentage - std::smatch match_value; - if (std::regex_search(str.begin(), str.end(), match_value, only_number)) - { - std::smatch match_type; - if (std::regex_search(str.begin(), str.end(), match_type, not_number)) - { - float value = std::stof(match_value[0]); - if (match_type[0] == "%") - { - PropValue returnValue = PropValue{ - PropValueType::PERCENT, - {0} - }; - returnValue.value.Number = value; - return returnValue; - } - else if (match_type[0] == "px") - { - PropValue returnValue = PropValue { - PropValueType::PIXEL, - {0} - }; - returnValue.value.Number = value; - return returnValue; - } - } - } - } - break; - - case PropType::FONT_SIZE: - { - float fvalue = std::stof(str); - return PropValue{ - PropValueType::PIXEL, - fvalue - }; - break; - } - break; - case PropType::BACKGROUND_COLOR: - std::vector splits = String::Split(str, ' '); - - if (splits.size() == 4) - { - float r = String::ToFloat(splits[0]); - float g = String::ToFloat(splits[1]); - float b = String::ToFloat(splits[2]); - float a = String::ToFloat(splits[3]); - PropValue data = PropValue{ - PropValueType::COLOR, - {0}, - }; - return data; - } - } - - return PropValue(); - } -} diff --git a/Nuake/src/UI/Styling/StyleSheetParser.h b/Nuake/src/UI/Styling/StyleSheetParser.h deleted file mode 100644 index d780f480..00000000 --- a/Nuake/src/UI/Styling/StyleSheetParser.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include "Style.h" - -namespace Nuake -{ - class StyleSheetParser - { - - public: - static PropValue ParsePropType(const std::string& str, PropType type); - }; -} diff --git a/Nuake/src/UI/Styling/Stylesheet.cpp b/Nuake/src/UI/Styling/Stylesheet.cpp deleted file mode 100644 index 967dbe87..00000000 --- a/Nuake/src/UI/Styling/Stylesheet.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Stylesheet.h" - -namespace Nuake { - namespace UI { - Ref StyleSheet::New(const std::string& path) - { - return CreateRef(path); - } - } -} \ No newline at end of file diff --git a/Nuake/src/UI/Styling/Stylesheet.h b/Nuake/src/UI/Styling/Stylesheet.h deleted file mode 100644 index 6ad37517..00000000 --- a/Nuake/src/UI/Styling/Stylesheet.h +++ /dev/null @@ -1,271 +0,0 @@ -#pragma once - -#include "katana-parser/katana.h" -#include "../Core/FileSystem.h" -#include "../Core/Logger.h" -#include "../Core/Core.h" -#include "../Nodes/Node.h" -#include -#include -#include "src/Core/String.h" -#include - -namespace Nuake -{ - namespace UI - { - class StyleSheet - { - private: - KatanaOutput* Data; - - std::map> Styles; - public: - std::string Path; - static Ref New(const std::string& path); - - void AddStyleGroup(std::string selector, Ref group) - { - Styles[selector] = group; - } - - bool HasStyleGroup(const std::string& group) - { - return Styles.find(group) != Styles.end(); - } - - Ref GetStyleGroup(const std::string group) - { - if (!HasStyleGroup(group)) - return nullptr; - - return Styles[group]; - } - - StyleSheet(const std::string& path) - { - this->Path = path; - ParseSheet(); - } - - ~StyleSheet() - { - katana_destroy_output(Data); - } - - bool ParseRule(KatanaRule* rule) - { - if (rule->type == KatanaRuleStyle) - { - Ref styleGroup = CreateRef(); - styleGroup->Selector = StyleGroupSelector::Normal; - - // Selectors - KatanaStyleRule* stylerule = (KatanaStyleRule*)rule; - for (uint32_t j = 0; j < stylerule->selectors->length; j++) - { - KatanaSelector* selector = (KatanaSelector*)stylerule->selectors->data[j]; - std::string name = selector->data->value; - - KatanaPseudoType pseudo = KatanaPseudoUnknown; - if(selector->tagHistory) - pseudo = selector->tagHistory->pseudo; - - // Special selectors - if (pseudo == KatanaPseudoHover) - { - name += ":hover"; - styleGroup->Selector = StyleGroupSelector::Hover; - } - - AddStyleGroup(name, styleGroup); - } - - // Declarations - for (uint32_t k = 0; k < stylerule->declarations->length; k++) - { - KatanaDeclaration* declaration = (KatanaDeclaration*)(stylerule->declarations->data[k]); - std::string value = declaration->raw; - std::string name = declaration->property; - PropType type = PropType::NONE; - - if (name == "height") type = PropType::HEIGHT; - if (name == "width") type = PropType::WIDTH; - if (name == "left") type = PropType::LEFT; - if (name == "right") type = PropType::RIGHT; - if (name == "top") type = PropType::TOP; - if (name == "bottom") type = PropType::BOTTOM; - if (name == "margin") - { - std::regex regex("[0-9]+[^ ]+"); - std::smatch match_value; - Layout::LayoutVec4 result; - - std::vector splits = String::Split(value, ' '); - int idx = 0; - for (auto& s : splits) - { - if (idx == 0) - { - type = PropType::MARGIN_LEFT; - styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type)); - } - else if (idx == 1) - { - type = PropType::MARGIN_RIGHT; - styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type)); - } - else if (idx == 2) - { - type = PropType::MARGIN_TOP; - styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type)); - } - else if (idx == 3) - { - type = PropType::MARGIN_BOTTOM; - styleGroup->SetProp(type, StyleSheetParser::ParsePropType(s, type)); - } - idx++; - } - continue; - } - if (name == "flex-direction") - { - type = PropType::FLEX_DIRECTION; - Value propValue{}; - - if (value == "row") - propValue.Enum = (int)Layout::FlexDirection::ROW; - if (value == "row-reversed") - propValue.Enum = (int)Layout::FlexDirection::ROW_REVERSED; - if (value == "column") - propValue.Enum = (int)Layout::FlexDirection::COLUMN; - if (value == "column-reversed") - propValue.Enum = (int)Layout::FlexDirection::COLUMN_REVERSED; - - styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); - continue; - } - if (name == "justify-content") - { - type = PropType::JUSTIFY_CONTENT; - Value propValue{}; - if (value == "flex-start") - propValue.Enum = (int)Layout::JustifyContent::FLEX_START; - if (value == "flex-end") - propValue.Enum = (int)Layout::JustifyContent::FLEX_END; - if (value == "center") - propValue.Enum = (int)Layout::JustifyContent::CENTER; - if (value == "space-between") - propValue.Enum = (int)Layout::JustifyContent::SPACE_BETWEEN; - if (value == "space-around") - propValue.Enum = (int)Layout::JustifyContent::SPACE_AROUND; - if (value == "space-evenly") - propValue.Enum = (int)Layout::JustifyContent::SPACE_EVENLY; - - styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); - continue; - } - if (name == "flex-wrap") - { - type = PropType::FLEX_WRAP; - Value propValue{}; - if (value == "no-wrap") - propValue.Enum = (int)Layout::FlexWrap::NO_WRAP; - if (value == "wrap") - propValue.Enum = (int)Layout::FlexWrap::WRAP; - if (value == "wrap-reversed") - propValue.Enum = (int)Layout::FlexWrap::WRAP_REVERSED; - - styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); - continue; - } - if (name == "align-self" || name == "align-items") - { - if (name == "align-self") - type = PropType::SELF_ALIGN; - else - type = PropType::ALIGN_ITEMS; - - Value propValue{}; - if (value == "stretch") - propValue.Enum = (int)Layout::AlignItems::STRETCH; - if (value == "flex-start") - propValue.Enum = (int)Layout::AlignItems::FLEX_START; - if (value == "flex-end") - propValue.Enum = (int)Layout::AlignItems::FLEX_END; - if (value == "center") - propValue.Enum = (int)Layout::AlignItems::CENTER; - if (value == "baseline") - propValue.Enum = (int)Layout::AlignItems::BASELINE; - - styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); - continue; - } - if (name == "align-content") - { - type = PropType::ALIGN_CONTENT; - - Value propValue{}; - if (value == "stretch") - propValue.Enum = (int)Layout::AlignContent::STRETCH; - if (value == "flex-start") - propValue.Enum = (int)Layout::AlignContent::FLEX_START; - if (value == "flex-end") - propValue.Enum = (int)Layout::AlignContent::FLEX_END; - if (value == "center") - propValue.Enum = (int)Layout::AlignContent::CENTER; - if (value == "space-between") - propValue.Enum = (int)Layout::AlignContent::SPACE_BETWEEN; - if (value == "space-around") - propValue.Enum = (int)Layout::AlignContent::SPACE_AROUND; - styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); - continue; - } - if (name == "position") - { - type = PropType::POSITION; - Value propValue{}; - if (value == "relative") - propValue.Enum = (int)Layout::PositionType::RELATIVE; - if (value == "absolute") - propValue.Enum = (int)Layout::PositionType::ABSOLUTE; - - styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); - continue; - } - if (name == "font-size") - { - type = PropType::FONT_SIZE; - } - if (name == "background-color") - { - type = PropType::BACKGROUND_COLOR; - } - - if(type != PropType::NONE) - styleGroup->SetProp(type, StyleSheetParser::ParsePropType(value, type)); - } - } - return true; - } - bool ParseSheet() - { - std::string content = FileSystem::ReadFile(this->Path, true); - Data = katana_parse(content.c_str(), content.length(), KatanaParserModeStylesheet); - for (uint32_t i = 0; i < Data->stylesheet->rules.length; i++) - { - KatanaRule* rule = (KatanaRule*)Data->stylesheet->rules.data[i]; - ParseRule(rule); - } - - if (Data->errors.length > 0) - { - KatanaArray errors = Data->errors; - return false; - } - return true; - } - }; - } -} diff --git a/Nuake/src/UI/UserInterface.cpp b/Nuake/src/UI/UserInterface.cpp deleted file mode 100644 index 5262c6d4..00000000 --- a/Nuake/src/UI/UserInterface.cpp +++ /dev/null @@ -1,216 +0,0 @@ -#include "UserInterface.h" - -#include "src/Vendors/pugixml/pugixml.hpp" -#include "Styling/Stylesheet.h" -#include "yoga/YGConfig.h" -#include "InterfaceParser.h" -#include -#include "src/Core/Input.h" - -namespace Nuake { - namespace UI { - UserInterface::UserInterface(const std::string& name, const std::string& path) - { - m_Name = name; - m_Path = path; - - font = FontLoader::LoadFont("resources/Fonts/OpenSans-Regular.ttf"); - Root = InterfaceParser::Parse(FileSystem::Root + path); - - if (!Root) - { - Logger::Log("Failed to generate interface structure", "ui", CRITICAL); - } - - yoga_config = YGConfigNew(); - yoga_config->useWebDefaults = true; - - CreateYogaLayout(); - } - - UserInterface::~UserInterface() - { - YGConfigFree(yoga_config); - if (yoga_root) - YGNodeFreeRecursive(yoga_root); - } - - void UserInterface::Reload() - { - Root = InterfaceParser::Parse(FileSystem::Root + this->m_Path); - if (!Root) - { - Logger::Log("Failed to generate interface structure", "ui", CRITICAL); - } - - yoga_config = YGConfigNew(); - yoga_config->useWebDefaults = true; - CreateYogaLayout(); - } - - Ref UserInterface::New(const std::string& name, const std::string& path) - { - return CreateRef(name, path); - } - - void UserInterface::Calculate(int available_width, int available_height) - { - YGNodeRef root = Root->YogaNode; - YGNodeCalculateLayout(root, static_cast(available_width), static_cast(available_height), YGDirectionLTR); - } - - void UserInterface::CreateYogaLayout() - { - yoga_root = YGNodeNewWithConfig(yoga_config); - Root->YogaNode = yoga_root; - - for (auto& g : Root->GetGroups()) - { - if (!Root->StyleSheet->HasStyleGroup(g)) - continue; - - Ref stylegroup = Root->StyleSheet->GetStyleGroup(g); - if(stylegroup->Selector == StyleGroupSelector::Normal) - Root->ApplyStyle(stylegroup); - } - Root->SetYogaLayout(); - CreateYogaLayoutRecursive(Root, yoga_root); - } - - void UserInterface::CreateYogaLayoutRecursive(Ref node, YGNodeRef yoga_node) - { - if (node->Childrens.size() > 0) - YGNodeCalculateLayout(yoga_node, YGNodeLayoutGetWidth(yoga_node), YGNodeLayoutGetHeight(yoga_node), YGDirectionLTR); - - int index = 0; - for (auto& n : node->Childrens) - { - YGNodeRef newYogaNode = YGNodeNew(); - n->YogaNode = newYogaNode; - - for (auto& g : n->GetGroups()) - { - if (!Root->StyleSheet->HasStyleGroup(g)) - continue; - - Ref stylegroup = Root->StyleSheet->GetStyleGroup(g); - if (stylegroup->Selector == StyleGroupSelector::Normal) - n->ApplyStyle(stylegroup); - } - - n->HoverStyle = n->NormalStyle; - - n->SetYogaLayout(); - YGNodeInsertChild(yoga_node, newYogaNode, index); - CreateYogaLayoutRecursive(n, newYogaNode); - index++; - } - } - - void UserInterface::Draw(Vector2 size) - { - Calculate((int)size.x, (int)size.y); - Renderer2D::BeginDraw(size); - DrawRecursive(Root, 0); - Renderer2D::EndDraw(); - Size = size; - } - - void UserInterface::DrawRecursive(Ref node, float z) - { - if (!node) - return; - - if (node->Type == NodeType::Text) - std::static_pointer_cast(node)->Draw(z); - else - node->Draw(z); - - if (node->Childrens.size() <= 0) - return; - - for (auto& c : node->Childrens) - DrawRecursive(c, z + 1); - } - - void UserInterface::Update(Timestep ts) - { - // Hover - RecursiveHover(Root, Input::GetMousePosition()); - - // Check Input - ConsumeMouseClick(Input::GetMousePosition()); - } - - void UserInterface::RecursiveHover(Ref node, Vector2 pos) - { - for (auto& c : node->Childrens) - { - RecursiveHover(c, pos); - - bool isHover = c->IsPositionInside(pos); - c->IsHover = isHover; - c->IsClicked = false; - if (isHover) - { - for (auto& g : c->GetGroups()) - { - if (!Root->StyleSheet->HasStyleGroup(g + ":hover")) - continue; - - Ref stylegroup = Root->StyleSheet->GetStyleGroup(g + ":hover"); - c->ApplyStyle(stylegroup, StyleGroupSelector::Hover); - } - } - c->SetYogaLayout(); - } - } - - void UserInterface::RecursiveMouseClick(Ref node, Vector2 pos) - { - if (node->IsHover) - { - node->IsClicked = true; - } - - for (auto& c : node->Childrens) - { - RecursiveMouseClick(c, pos); - } - } - - void UserInterface::ConsumeMouseClick(Vector2 pos) - { - if(Input::IsMouseButtonPressed(0)) - RecursiveMouseClick(Root, pos); - } - - - Ref UserInterface::GetNodeByID(const std::string& id) - { - for (auto& n : Root->Childrens) - { - Ref result = GetNodeByIDRecurse(n, id); - if (result) - return result; - } - - return nullptr; - } - - Ref UserInterface::GetNodeByIDRecurse(Ref node, const std::string& id) - { - for (auto& n : node->Childrens) - { - if (n->ID == id) - return n; - - Ref result = GetNodeByIDRecurse(n, id); - if (result != nullptr) - return result; - } - return nullptr; - } - } -} - diff --git a/Nuake/src/UI/UserInterface.h b/Nuake/src/UI/UserInterface.h deleted file mode 100644 index 893454d5..00000000 --- a/Nuake/src/UI/UserInterface.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once -#include -#include -#include -#include "yoga/Yoga.h" -#include "Nodes/Node.h" -#include "Nodes/Canvas.h" -#include "src/Core/Maths.h" -#include "Styling/Stylesheet.h" -#include "Font/Font.h" -#include -#include - -namespace Nuake { - namespace UI { - class UserInterface - { - private: - std::string m_Name; - std::string m_Path; - - Ref m_Framebuffer; // Texture of the interface. - - Ref Root; - - YGConfigRef yoga_config; - YGNodeRef yoga_root; - - std::vector m_Scripts; - - Ref GetNodeByIDRecurse(Ref node, const std::string& id); - void RecursiveHover(Ref node, Vector2 pos); - public: - Ref font; - const int Width = 1920; - const int Height = 1080; - - Vector2 Size = Vector2(); - - UserInterface(const std::string& name, const std::string& path); - ~UserInterface(); - - void Reload(); - - static Ref New(const std::string& name, const std::string& path); - void Calculate(int available_width, int available_height); - - void CreateYogaLayout(); - void CreateYogaLayoutRecursive(Ref node, YGNodeRef yoga_node); - void Draw(Vector2 size); - void DrawRecursive(Ref node, float z); - void Update(Timestep ts); - - void RecursiveStyle(Ref node); - void RecursiveMouseClick(Ref node, Vector2 pos); - - Ref GetNodeByID(const std::string& id); - - void ConsumeMouseClick(Vector2 pos); - - std::string GetPath() const { return m_Path; } - }; - } -} diff --git a/premake5.lua b/premake5.lua index f9605314..8f7c3b1d 100644 --- a/premake5.lua +++ b/premake5.lua @@ -65,10 +65,6 @@ project "Nuake" "%{prj.name}/src/**.cpp", "%{prj.name}/src/Vendors/libmap/h/*.h", "%{prj.name}/src/Vendors/libmap/c/*.c", - "%{prj.name}/src/Vendors/msdfgen/**.h", - "%{prj.name}/src/Vendors/msdfgen/**.cpp", - "%{prj.name}/src/Vendors/msdf-atlas-gen/*.h", - "%{prj.name}/src/Vendors/msdf-atlas-gen/*.cpp", "%{prj.name}/src/Vendors/wren/src/vm/*.h", "%{prj.name}/src/Vendors/wren/src/vm/*.c", "%{prj.name}/src/Vendors/katana-parser/*.h", @@ -85,24 +81,20 @@ project "Nuake" "%{prj.name}/dependencies/glfw/include", "%{prj.name}/dependencies/assimp/include", "%{prj.name}/dependencies/JoltPhysics", - "%{prj.name}/src/Vendors/msdfgen/include", - "%{prj.name}/src/Vendors/msdfgen/freetype/include", - "%{prj.name}/src/Vendors/msdfgen", "%{prj.name}/src/Vendors/wren/src/include", "%{prj.name}/src/Vendors/incbin", "%{prj.name}/dependencies/build", "%{prj.name}/dependencies/soloud/include", "%{prj.name}/dependencies/Coral/Coral.Native/Include", - "%{prj.name}/dependencies/recastnavigation/DebugUtils/Include", - "%{prj.name}/dependencies/recastnavigation/Detour/Include", - "%{prj.name}/dependencies/recastnavigation/DetourCrowd/Include", - "%{prj.name}/dependencies/recastnavigation/DetourTileCache/Include", - "%{prj.name}/dependencies/recastnavigation/Recast/Include" + "%{prj.name}/dependencies/recastnavigation/DebugUtils/Include", + "%{prj.name}/dependencies/recastnavigation/Detour/Include", + "%{prj.name}/dependencies/recastnavigation/DetourCrowd/Include", + "%{prj.name}/dependencies/recastnavigation/DetourTileCache/Include", + "%{prj.name}/dependencies/recastnavigation/Recast/Include" } links { - "Freetype", "soloud" } @@ -185,11 +177,7 @@ project "NuakeRuntime" libdirs { "%{prj.name}/../Nuake/dependencies/assimp/lib/", - "%{prj.name}/../Nuake/dependencies/freetype-windows-binaries/release static/win64", "%{prj.name}/../bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/Nuake/", - "%{prj.name}/../Nuake/dependencies/freetype/include", - "%{prj.name}/../Nuake/src/Vendors/msdfgen/freetype/win64", - "%{prj.name}/../Nuake/src/Vendors/msdfgen", "%{prj.name}/../Nuake/src/Vendors/wren/src/include", "%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/", "%{prj.name}/../Nuake/dependencies/soloud/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}", @@ -202,7 +190,6 @@ project "NuakeRuntime" "GLFW", "glad", "assimp", - "Freetype", "JoltPhysics", "soloud", "Coral.Native", @@ -240,7 +227,7 @@ project "NuakeRuntime" "asound", "glib-2.0", "gtk-3", - "gobject-2.0" + "gobject-2.0" } @@ -311,27 +298,22 @@ project "Editor" "%{prj.name}/../Nuake/dependencies/glfw/include", "%{prj.name}/../Nuake/dependencies/assimp/include", "%{prj.name}/../Nuake/dependencies/build", - "%{prj.name}/../Nuake/src/Vendors/msdfgen", - "%{prj.name}/../Nuake/dependencies/JoltPhysics", + "%{prj.name}/../Nuake/dependencies/JoltPhysics", "%{prj.name}/../Nuake/dependencies/build", "%{prj.name}/../Nuake/dependencies/soloud/include", "/usr/include/gtk-3.0/", - "%{prj.name}/../Nuake/dependencies/recastnavigation/DebugUtils/Include", - "%{prj.name}/../Nuake/dependencies/recastnavigation/Detour/Include", - "%{prj.name}/../Nuake/dependencies/recastnavigation/DetourCrowd/Include", - "%{prj.name}/../Nuake/dependencies/recastnavigation/DetourTileCache/Include", - "%{prj.name}/../Nuake/dependencies/recastnavigation/Recast/Include" + "%{prj.name}/../Nuake/dependencies/recastnavigation/DebugUtils/Include", + "%{prj.name}/../Nuake/dependencies/recastnavigation/Detour/Include", + "%{prj.name}/../Nuake/dependencies/recastnavigation/DetourCrowd/Include", + "%{prj.name}/../Nuake/dependencies/recastnavigation/DetourTileCache/Include", + "%{prj.name}/../Nuake/dependencies/recastnavigation/Recast/Include" } libdirs { "%{prj.name}/../Nuake/dependencies/GLEW/lib/Release/x64", "%{prj.name}/../Nuake/dependencies/assimp/lib/", - "%{prj.name}/../Nuake/dependencies/freetype-windows-binaries/release static/win64", "%{prj.name}/../bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/Nuake/", - "%{prj.name}/../Nuake/dependencies/freetype/include", - "%{prj.name}/../Nuake/src/Vendors/msdfgen/freetype/win64", - "%{prj.name}/../Nuake/src/Vendors/msdfgen", "%{prj.name}/../Nuake/src/Vendors/wren/src/include", "%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/", "%{prj.name}/../Nuake/dependencies/soloud/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}", @@ -344,15 +326,14 @@ project "Editor" "glad", "GLFW", "assimp", - "Freetype", "JoltPhysics", "soloud", "Coral.Native", - "DebugUtils", - "Detour", - "DetourCrowd", - "DetourTileCache", - "Recast" + "DebugUtils", + "Detour", + "DetourCrowd", + "DetourTileCache", + "Recast" } filter "system:Windows"