diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 18a6cabd..7c08b370 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -17,7 +17,7 @@ #include #include #include - +#include "src/UI/UserInterface.h" int main() { @@ -30,14 +30,28 @@ int main() Ref lightTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Light.png"); Ref camTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Camera.png"); Ref GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader"); - + Ref uinterface = Nuake::UI::UserInterface::New("Editor"); + while (!Nuake::Engine::GetCurrentWindow()->ShouldClose()) { + Nuake::RenderCommand::Clear(); Nuake::Engine::Tick(); - Nuake::Engine::Draw(); + uinterface->Update(0.0f); + Nuake::Engine::Draw(); + // + if (Nuake::Input::IsKeyPressed(GLFW_KEY_F1)) + uinterface->Reload(); if (Nuake::Input::IsKeyPressed(GLFW_KEY_F8)) Nuake::Engine::ExitPlayMode(); + + Nuake::Vector2 WindowSize = Nuake::Engine::GetCurrentWindow()->GetSize(); + glViewport(0, 0, WindowSize.x, WindowSize.y); + Nuake::Renderer2D::BeginDraw(WindowSize); + //Nuake::Renderer2D::DrawRect(Nuake::Vector2(100, 100), Nuake::Vector2(100, 100), Nuake::Color(1.0, 0.0, 0.0, 1.0), 2.0f); + + + uinterface->Draw(WindowSize); Ref sceneFramebuffer = Nuake::Engine::GetCurrentWindow()->GetFrameBuffer(); sceneFramebuffer->Bind(); @@ -52,37 +66,41 @@ int main() auto camView = currentScene->m_Registry.view(); for (auto e : camView) { auto [transformComponent, cam] = camView.get(e); - + GuizmoShader->SetUniformMat4f("model", transformComponent.GetTransform()); GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform()); GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective()); - + camTexture->Bind(2); GuizmoShader->SetUniform1i("gizmo_texture", 2); - + Nuake::Renderer::DrawQuad(transformComponent.GetTransform()); } - + auto view = currentScene->m_Registry.view(); for (auto e : view) { auto [transformComponent, light] = view.get(e); - + GuizmoShader->SetUniformMat4f("model", transformComponent.GetTransform()); GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform()); GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective()); - + lightTexture->Bind(2); GuizmoShader->SetUniform1i("gizmo_texture", 2); Nuake::Renderer::DrawQuad(transformComponent.GetTransform()); } + glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); GuizmoShader->Unbind(); } - sceneFramebuffer->Unbind(); - editor.Draw(); + + + //if (ImGui::Begin("test")) {} + //ImGui::End(); + //editor.Draw(); Nuake::Engine::EndDraw(); } diff --git a/Editor/resources/Interface/Testing.css b/Editor/resources/Interface/Testing.css index f9e2ad81..f90e002b 100644 --- a/Editor/resources/Interface/Testing.css +++ b/Editor/resources/Interface/Testing.css @@ -1,13 +1,51 @@ -.screen{ +.screen { + display: flex; + flex-direction: column; + align-content: center; + justify-content: center; height: 100%; width: 100%; - display: flex; - justify-content: center; - flex-direction: row; - align-content:flex-start; } -.rect{ - height: 200px; - width: 200px; +.logo { + width: 500px; + height: 50%; + margin: 0px 0px 0px 0px; + justify-content: center; + align-content: center; + flex-direction: column; +} +.panel { + display: flex; + height: 33%; + width: 33%; + justify-content: space-around; + align-items: center; + align-content: flex-start; +} + +.panel-top { + width: 100%; + height: 75%; + justify-content: flex-start; + flex-direction:column; +} + +.panel-bottom { + width:100%; + height: 25%; + justify-content: space-around; + align-items: center; + align-content: flex-end; +} + +.rect { + display: flex; + justify-content: space-around; + align-items: center; + align-content: center; +} + +.normal-text { + font-size: 2.0; } diff --git a/Editor/resources/Interface/Testing.interface b/Editor/resources/Interface/Testing.interface index e90073cd..69b1627a 100644 --- a/Editor/resources/Interface/Testing.interface +++ b/Editor/resources/Interface/Testing.interface @@ -1,11 +1,32 @@ -

Hello, world!

- - + +

Nuake Engine

+

You can load a project, or create a new one.

+ + +

New Project

+
+ +

Load Project

+
+
diff --git a/Editor/resources/Shaders/sdf_text.shader b/Editor/resources/Shaders/sdf_text.shader index 909df323..7c929523 100644 --- a/Editor/resources/Shaders/sdf_text.shader +++ b/Editor/resources/Shaders/sdf_text.shader @@ -18,7 +18,7 @@ void main() #version 460 core out vec4 FragColor; -in vec2 a_UV; +in sample vec2 a_UV; uniform vec2 texPos; uniform vec2 texScale; @@ -41,12 +41,13 @@ float median(float r, float g, float b) { void main() { vec2 textSize = textureSize(msdf, 0); - vec2 uv = vec2(mix(texPos.x / textSize.x,texScale.x / textSize.x, a_UV.x), - mix(texScale.y / textSize.y, texPos.y / textSize.y, a_UV.y)); + vec2 uv = vec2(mix(texPos.x / textSize.x, texScale.x / textSize.x, a_UV.x), + mix(texScale.y / textSize.y, texPos.y / textSize.y, a_UV.y)); vec3 msd = texture(msdf, uv).rgb; float sd = median(msd.r, msd.g, msd.b); float screenPxDistance = screenPxRange(uv) * (sd - 0.5); - float alpha = smoothstep(0.5 - 1/16.0, 0.5 + 1 / 16.0, sd); - FragColor = mix(bgColor, fgColor, alpha); + float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + + FragColor = mix(bgColor, fgColor, opacity); } \ No newline at end of file diff --git a/Editor/resources/Shaders/ui.shader b/Editor/resources/Shaders/ui.shader index 2245faaf..c254672b 100644 --- a/Editor/resources/Shaders/ui.shader +++ b/Editor/resources/Shaders/ui.shader @@ -2,10 +2,10 @@ #version 460 core layout(location = 0) in vec3 Position; layout(location = 1) in vec2 UV; + uniform mat4 model; uniform mat4 projection; - out sample vec2 a_UV; void main() @@ -17,9 +17,9 @@ void main() #shader fragment #version 460 core -uniform vec4 background_color; -uniform float u_border_radius; -uniform vec2 u_size; +uniform vec4 u_BackgroundColor; +uniform float u_BorderRadius; +uniform vec2 u_Size; out vec4 FragColor; @@ -53,11 +53,11 @@ bool ShouldDiscard(vec2 coords, vec2 dimensions, float radius) void main() { - vec2 coords = a_UV * u_size; - vec2 center = u_size / 2.0; + vec2 coords = a_UV * u_Size; + vec2 center = u_Size / 2.0; // Border rounding - if (ShouldDiscard(coords, u_size, u_border_radius)) + if (ShouldDiscard(coords, u_Size, u_BorderRadius)) discard; - FragColor = background_color; + FragColor = u_BackgroundColor; } diff --git a/Nuake/src/Rendering/Renderer2D.cpp b/Nuake/src/Rendering/Renderer2D.cpp index 4f1bec7a..e56947b4 100644 --- a/Nuake/src/Rendering/Renderer2D.cpp +++ b/Nuake/src/Rendering/Renderer2D.cpp @@ -2,7 +2,9 @@ #include "GL/glew.h" #include #include "src/UI/Nodes/TextNode.h" +#include "Shaders/ShaderManager.h" +#include "src/Vendors/glm/gtx/matrix_decompose.hpp" namespace Nuake { Ref Renderer2D::UIShader; @@ -15,8 +17,8 @@ namespace Nuake void Renderer2D::Init() { - UIShader = CreateRef("resources/Shaders/ui.shader"); - TextShader = CreateRef("resources/Shaders/sdf_text.shader"); + UIShader = ShaderManager::GetShader("resources/Shaders/ui.shader"); + TextShader = ShaderManager::GetShader("resources/Shaders/sdf_text.shader"); float quad_Vertices[] = { // positions // texture Coords @@ -27,6 +29,7 @@ namespace Nuake 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; + // setup plane VAO glGenVertexArrays(1, &Renderer2D::VAO); glGenBuffers(1, &Renderer2D::VBO); @@ -37,12 +40,14 @@ namespace Nuake glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); + } void Renderer2D::BeginDraw(Vector2 size) { glDisable(GL_DEPTH_TEST); - Projection = glm::ortho(0.f, size.x, size.y, 0.f, -0.5f, 1000.0f); + glDisable(GL_CULL_FACE); + Projection = glm::ortho(0.f, size.x, size.y, 0.f, -1.f, 1000.0f); UIShader->Bind(); UIShader->SetUniformMat4f("projection", Projection); } @@ -53,55 +58,97 @@ namespace Nuake glDrawArrays(GL_TRIANGLES, 0, 6); } - Vector2 Renderer2D::CalculateStringSize(const std::string& str, Ref font, Vector2 position, float fontSize) + void Renderer2D::DrawRect(Matrix4 transform, Vector2 size, Color color, float borderRadius) { - float advance = 0.0f; - float Y = 0.0f; - for (char const& c : str) { - Char& letter = font->GetChar((int)c); - advance += letter.Advance * fontSize; - if (letter.PlaneBounds.top - letter.PlaneBounds.bottom > Y) - Y = letter.PlaneBounds.top - letter.PlaneBounds.bottom; - } - return Vector2(advance, Y); + Vector3 translation; + glm::quat rotation; + Vector3 scale; + Vector3 skew; + Vector4 perspective; + glm::decompose(transform, scale, rotation, translation, skew, perspective); + + BeginDraw({ 1920.0f, 1080.0f }); + UIShader->SetUniformMat4f("model", transform); + UIShader->SetUniform1f("u_border_radius", borderRadius); + UIShader->SetUniform2f("u_size", scale.x, scale.y); + + glBindVertexArray(Renderer2D::VAO); + glDrawArrays(GL_TRIANGLES, 0, 6); } - void Renderer2D::DrawString(const std::string& str, TextStyle style, Matrix4 model) + void Renderer2D::DrawRect(Vector2 position, Vector2 size, Color color, float borderRadius ) { + Matrix4 model = Matrix4(1.f); + model = glm::translate(model, Vector3(position.x, position.y, 0.f)); + model = glm::scale(model, Vector3(size.x, size.y, 1.f)); - TextShader->Bind(); - TextShader->SetUniformMat4f("projection", Projection); - float advance = 0.0f; - style.font->FontAtlas->Bind(5); - TextShader->SetUniform1i("msdf", 5); - + UIShader->SetUniformMat4f("model", model); + UIShader->SetUniform1f("u_BorderRadius", borderRadius); + UIShader->SetUniform2f("u_Size", size.x, size.y); + UIShader->SetUniform4f("u_BackgroundColor", color.r, color.g, color.b, color.a); + + 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) { + 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; } - lineHeight *= style.fontSize; - - for (char const& c : str) { + 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), 0.f)); + 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, scaleY, 0.f)); + + 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->SetUniformMat4f("model", mat); - //TextShader->SetUniform4f("bgColor", 0, 0, 1, 1); - TextShader->SetUniform4f("bgColor", 1.f, 0.f, 0.f, 0.f); + 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; + advance += letter.Advance * style.fontSize; } } @@ -131,7 +178,6 @@ namespace Nuake glDrawArrays(GL_TRIANGLES, 0, 6); } - void Renderer2D::EndDraw() { diff --git a/Nuake/src/Rendering/Renderer2D.h b/Nuake/src/Rendering/Renderer2D.h index 8a221384..c77debcc 100644 --- a/Nuake/src/Rendering/Renderer2D.h +++ b/Nuake/src/Rendering/Renderer2D.h @@ -20,7 +20,10 @@ namespace Nuake static void Init(); static void BeginDraw(Vector2 size); static void DrawRect(); - static Vector2 CalculateStringSize(const std::string& str, Ref font, Vector2 position, float fontSize); + static void DrawRect(Matrix4 transform, Vector2 size, Color color, float borderRadius = 0.0f); + 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/Rendering/Shaders/Shader.cpp b/Nuake/src/Rendering/Shaders/Shader.cpp index ab7669a2..2907e898 100644 --- a/Nuake/src/Rendering/Shaders/Shader.cpp +++ b/Nuake/src/Rendering/Shaders/Shader.cpp @@ -117,7 +117,7 @@ namespace Nuake std::cout << "Failed to compile " << (type == GL_VERTEX_SHADER ? "vertex" : "Fragment") << " shader!" << std::endl; - std::cout << message << std::endl; + std::cout << std::string(message) << std::endl; // Delete invalid shader glDeleteShader(id); diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 13bd9038..efa83ac3 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -212,6 +212,7 @@ namespace Nuake { } Renderer::Flush(shadowShader, true); + light.m_Framebuffers[i]->Unbind(); } } diff --git a/Nuake/src/UI/InterfaceParser.cpp b/Nuake/src/UI/InterfaceParser.cpp index a0b99e56..71c8906f 100644 --- a/Nuake/src/UI/InterfaceParser.cpp +++ b/Nuake/src/UI/InterfaceParser.cpp @@ -5,6 +5,23 @@ 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, 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; @@ -27,23 +44,6 @@ namespace Nuake } } - 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, CRITICAL); - return nullptr; - } - - Root = CreateCanvas(doc.first_child()); - Root->Depth = 0; - Iterate(doc.first_child(), Root, 0); - return Root; - } - Ref InterfaceParser::CreateTextNode(const pugi::xml_node& xml_node) { Ref node = CreateRef(); @@ -51,11 +51,10 @@ namespace Nuake node->Type = NodeType::Text; TextStyle style{ FontManager::GetFont("resources/Fonts/RobotoMono-Regular.ttf"), - 2.0, + 0.5, Color(255, 255, 255, 255) }; - - node->SetTextStyle(style); + for (auto& a : xml_node.attributes()) { std::string name = a.name(); @@ -80,7 +79,22 @@ namespace Nuake node->Position = GetVec4Unit(a.value()); if (name == "color") node->BackgroundColor = GetColor(a.value()); + if (name == "font-size") + style.fontSize = std::stof(a.value()); } + + Vector2 minSize = Renderer2D::CalculateStringSize(node->content, style); + node->Width = { + minSize.x, + Layout::Unit::PIXEL + }; + node->Height = { + minSize.y, + Layout::Unit::PIXEL + }; + + + node->SetTextStyle(style); return node; } diff --git a/Nuake/src/UI/Nodes/Node.h b/Nuake/src/UI/Nodes/Node.h index edcdf957..e6c527f0 100644 --- a/Nuake/src/UI/Nodes/Node.h +++ b/Nuake/src/UI/Nodes/Node.h @@ -369,7 +369,7 @@ namespace Nuake { Renderer2D::UIShader->Bind(); Color color = this->BackgroundColor; - Renderer2D::UIShader->SetUniform4f("background_color", + Renderer2D::UIShader->SetUniform4f("u_BackgroundColor", color.r / 255.f, color.g / 255.f, color.b / 255.f, @@ -384,23 +384,29 @@ namespace Nuake 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); + } if (parent) { - parentLeft = YGNodeLayoutGetLeft(YGNodeGetParent(YogaNode)); - parentTop = YGNodeLayoutGetTop(YGNodeGetParent(YogaNode)); - float parentPaddingTop = YGNodeLayoutGetPadding(parent, YGEdgeTop); - float parentPaddingLeft = YGNodeLayoutGetPadding(parent, YGEdgeTop); + //parentLeft = YGNodeLayoutGetLeft(YGNodeGetParent(YogaNode)); + //parentTop = YGNodeLayoutGetTop(YGNodeGetParent(YogaNode)); + //float parentPaddingTop = YGNodeLayoutGetPadding(parent, YGEdgeTop); + //float parentPaddingLeft = YGNodeLayoutGetPadding(parent, YGEdgeTop); // Overflow hidden. - float parentwidth = YGNodeLayoutGetWidth(parent); - if (parentwidth - YGNodeLayoutGetMargin(YogaNode, YGEdgeLeft) < width) - width = parentwidth - parentPaddingLeft; - float parentHeight = YGNodeLayoutGetHeight(parent); - if (parentHeight < height) - height = parentHeight - YGNodeLayoutGetMargin(YogaNode, YGEdgeTop) - parentPaddingTop; + //float parentwidth = YGNodeLayoutGetWidth(parent); + //if (parentwidth - YGNodeLayoutGetMargin(YogaNode, YGEdgeLeft) < width) + // width = parentwidth - parentPaddingLeft; + //float parentHeight = YGNodeLayoutGetHeight(parent); + //if (parentHeight < height) + // height = parentHeight - YGNodeLayoutGetMargin(YogaNode, YGEdgeTop) - parentPaddingTop; } transform = glm::translate(transform, Vector3(left + parentLeft, top + parentTop, 0.f)); @@ -411,8 +417,8 @@ namespace Nuake //Logger::Log("Left: " + std::to_string(left) + " Top:" + std::to_string(top)); Renderer2D::UIShader->SetUniformMat4f("model", transform); - Renderer2D::UIShader->SetUniform1f("u_border_radius", 8.f); - Renderer2D::UIShader->SetUniform2f("u_size", width, height); + Renderer2D::UIShader->SetUniform1f("u_BorderRadius", Border.Left.Value); + Renderer2D::UIShader->SetUniform2f("u_Size", width, height); Renderer2D::DrawRect(); } diff --git a/Nuake/src/UI/Nodes/TextNode.h b/Nuake/src/UI/Nodes/TextNode.h index 37192eb8..4b2a39de 100644 --- a/Nuake/src/UI/Nodes/TextNode.h +++ b/Nuake/src/UI/Nodes/TextNode.h @@ -39,14 +39,21 @@ namespace Nuake float parentLeft = 0.0f; float parentTop = 0.0f; - auto parent = YGNodeGetParent(this->YogaNode); + auto parent = YGNodeGetParent(YogaNode); + + while (parent) + { + parentLeft += YGNodeLayoutGetLeft(parent); + parentTop += YGNodeLayoutGetTop(parent); + parent = YGNodeGetParent(parent); + } if (parent) { - //parentLeft = YGNodeLayoutGetLeft(YGNodeGetParent(this->YogaNode)); - //parentTop = YGNodeLayoutGetTop(YGNodeGetParent(this->YogaNode)); + //parentLeft = YGNodeLayoutGetLeft(parent); + //parentTop = YGNodeLayoutGetTop(parent); //float parentPaddingTop = YGNodeLayoutGetPadding(parent, YGEdgeTop); //float parentPaddingLeft = YGNodeLayoutGetPadding(parent, YGEdgeTop); - //// Overflow hidden. + // Overflow hidden. //float parentwidth = YGNodeLayoutGetWidth(parent); //if (parentwidth - YGNodeLayoutGetMargin(this->YogaNode, YGEdgeLeft) < width) // width = parentwidth - parentPaddingLeft; @@ -58,7 +65,13 @@ namespace Nuake transform = glm::translate(transform, Vector3(left + parentLeft, top + parentTop, 0.f)); + //transform = glm::scale(transform, Vector3(width, height, 1.0)); + //Renderer2D::UIShader->Bind(); + //Renderer2D::UIShader->SetUniformMat4f("model", transform); + //Renderer2D::UIShader->SetUniform1f("u_BorderRadius", Border.Left.Value); + //Renderer2D::UIShader->SetUniform2f("u_Size", width, height); + //Renderer2D::DrawRect(); //Logger::Log("Left: " + std::to_string(left) + " Top:" + std::to_string(top)); diff --git a/Nuake/src/UI/Styling/NodeStyle.h b/Nuake/src/UI/Styling/NodeStyle.h new file mode 100644 index 00000000..6a63d3f1 --- /dev/null +++ b/Nuake/src/UI/Styling/NodeStyle.h @@ -0,0 +1,12 @@ +#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 index f5eff3d9..09a38026 100644 --- a/Nuake/src/UI/Styling/Style.h +++ b/Nuake/src/UI/Styling/Style.h @@ -6,7 +6,7 @@ namespace Nuake { enum class PropType { - HEIGHT, MAX_HEIGHT, MIN_HEIGHT, WIDTH, MAX_WIDTH, MIN_WIDTH, + 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, @@ -17,7 +17,7 @@ namespace Nuake 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, + BACKGROUND_COLOR, COLOR, FONT_SIZE }; enum class PropValueType diff --git a/Nuake/src/UI/Styling/StyleSheetParser.cpp b/Nuake/src/UI/Styling/StyleSheetParser.cpp index fcada426..33aadb67 100644 --- a/Nuake/src/UI/Styling/StyleSheetParser.cpp +++ b/Nuake/src/UI/Styling/StyleSheetParser.cpp @@ -47,6 +47,16 @@ namespace Nuake } } break; + + case PropType::FONT_SIZE: + { + float fvalue = std::stof(str); + return PropValue{ + PropValueType::PIXEL, + fvalue + }; + break; + } } return PropValue(); diff --git a/Nuake/src/UI/Styling/Stylesheet.h b/Nuake/src/UI/Styling/Stylesheet.h index 404b1113..9ff3f0a6 100644 --- a/Nuake/src/UI/Styling/Stylesheet.h +++ b/Nuake/src/UI/Styling/Stylesheet.h @@ -88,7 +88,7 @@ namespace Nuake KatanaDeclaration* declaration = (KatanaDeclaration*)(stylerule->declarations->data[k]); std::string value = declaration->raw; std::string name = declaration->property; - PropType type; + PropType type = PropType::NONE; if (name == "height") type = PropType::HEIGHT; if (name == "width") type = PropType::WIDTH; @@ -235,7 +235,12 @@ namespace Nuake styleGroup->SetProp(type, PropValue{ PropValueType::ENUM, propValue }); continue; } - styleGroup->SetProp(type, StyleSheetParser::ParsePropType(value, type)); + if (name == "font-size") + { + type = PropType::FONT_SIZE; + } + if(type != PropType::NONE) + styleGroup->SetProp(type, StyleSheetParser::ParsePropType(value, type)); Logger::Log(declaration->property); } Logger::Log(rule->name); @@ -244,7 +249,7 @@ namespace Nuake } bool ParseSheet() { - std::string content = FileSystem::ReadFile(this->Path); + std::string content = FileSystem::ReadFile(this->Path, true); Data = katana_parse(content.c_str(), content.length(), KatanaParserModeStylesheet); for (int i = 0; i < Data->stylesheet->rules.length; i++) { diff --git a/Nuake/src/UI/UserInterface.cpp b/Nuake/src/UI/UserInterface.cpp index 08698ec9..34f844f0 100644 --- a/Nuake/src/UI/UserInterface.cpp +++ b/Nuake/src/UI/UserInterface.cpp @@ -99,12 +99,9 @@ namespace Nuake { float leftOffset = YGNodeLayoutGetLeft(Root->YogaNode); float topOffset = YGNodeLayoutGetTop(Root->YogaNode); - Vector2 charPos = Vector2(100.f, 100.f); Char charr = font->GetChar(89); - - DrawRecursive(Root, 0); //Renderer2D::DrawChar(charr, font, charPos, size); } diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index ba0a85ce..7017125c 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -81,6 +81,13 @@ namespace Nuake { return m_Framebuffer; } + Vector2 Window::GetSize() + { + int w, h = 0; + glfwGetWindowSize(m_Window, &w, &h); + return Vector2(w, h); + } + int Window::Init() { diff --git a/Nuake/src/Window.h b/Nuake/src/Window.h index b58e1e40..2756bc7f 100644 --- a/Nuake/src/Window.h +++ b/Nuake/src/Window.h @@ -40,6 +40,8 @@ namespace Nuake Ref GetFrameBuffer() const; + Vector2 GetSize(); + Ref GetScene(); bool SetScene(Ref scene); };