mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
UI text alignment work
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#include <src/Resource/FGD/FGDFile.h>
|
||||
#include <src/Rendering/Shaders/ShaderManager.h>
|
||||
#include <src/Rendering/Renderer.h>
|
||||
|
||||
#include "src/UI/UserInterface.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -30,14 +30,28 @@ int main()
|
||||
Ref<Nuake::Texture> lightTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Light.png");
|
||||
Ref<Nuake::Texture> camTexture = Nuake::TextureManager::Get()->GetTexture("resources/Icons/Gizmo/Camera.png");
|
||||
Ref<Nuake::Shader> GuizmoShader = Nuake::ShaderManager::GetShader("resources/Shaders/gizmo.shader");
|
||||
|
||||
Ref<Nuake::UI::UserInterface> 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<Nuake::FrameBuffer> sceneFramebuffer = Nuake::Engine::GetCurrentWindow()->GetFrameBuffer();
|
||||
sceneFramebuffer->Bind();
|
||||
@@ -52,37 +66,41 @@ int main()
|
||||
auto camView = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::CameraComponent>();
|
||||
for (auto e : camView) {
|
||||
auto [transformComponent, cam] = camView.get<Nuake::TransformComponent, Nuake::CameraComponent>(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<Nuake::TransformComponent, Nuake::LightComponent>();
|
||||
for (auto e : view) {
|
||||
auto [transformComponent, light] = view.get<Nuake::TransformComponent, Nuake::LightComponent>(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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
<Canvas
|
||||
script="Scripts/test Test"
|
||||
stylesheet="Interface/Testing.css"
|
||||
stylesheet="resources/Interface/Testing.css"
|
||||
groups="screen"
|
||||
color="33 33 33 255"
|
||||
height="100%"
|
||||
width="100%"
|
||||
padding="8px 8px 8px 8px"
|
||||
>
|
||||
<p groups="header">Hello, world!</p>
|
||||
|
||||
<Rect onclick="hello()"
|
||||
groups="rect">
|
||||
<Rect groups="logo"
|
||||
color="25 25 25 0">
|
||||
<p font-size="1.5" margin="0 0 0 12px">Nuake Engine</p>
|
||||
<p groups="normal-text">You can load a project, or create a new one.</p>
|
||||
<Rect groups="panel-bottom">
|
||||
<Rect
|
||||
groups="rect"
|
||||
height="50px"
|
||||
width="49%"
|
||||
border="8px 8px 8px 8px"
|
||||
color="18 18 18 255">
|
||||
<p groups="normal-text">New Project</p>
|
||||
</Rect>
|
||||
<Rect
|
||||
groups="rect"
|
||||
height="50px"
|
||||
width="49%"
|
||||
border="8px 8px 8px 8px"
|
||||
color="18 18 18 255">
|
||||
<p groups="normal-text">Load Project</p>
|
||||
</Rect>
|
||||
</Rect>
|
||||
</Rect>
|
||||
</Canvas>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
#include "GL/glew.h"
|
||||
#include <Engine.h>
|
||||
#include "src/UI/Nodes/TextNode.h"
|
||||
#include "Shaders/ShaderManager.h"
|
||||
|
||||
#include "src/Vendors/glm/gtx/matrix_decompose.hpp"
|
||||
namespace Nuake
|
||||
{
|
||||
Ref<Shader> Renderer2D::UIShader;
|
||||
@@ -15,8 +17,8 @@ namespace Nuake
|
||||
|
||||
void Renderer2D::Init()
|
||||
{
|
||||
UIShader = CreateRef<Shader>("resources/Shaders/ui.shader");
|
||||
TextShader = CreateRef<Shader>("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> 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()
|
||||
{
|
||||
|
||||
|
||||
@@ -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> 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> font, Vector2 position, Vector2 size);
|
||||
static void EndDraw();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -212,6 +212,7 @@ namespace Nuake {
|
||||
}
|
||||
|
||||
Renderer::Flush(shadowShader, true);
|
||||
light.m_Framebuffers[i]->Unbind();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,23 @@ namespace Nuake
|
||||
{
|
||||
Ref<Canvas> InterfaceParser::Root = CreateRef<Canvas>();
|
||||
|
||||
Ref<Canvas> 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> node, int depth)
|
||||
{
|
||||
int currentDepth = depth + 1;
|
||||
@@ -27,23 +44,6 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Canvas> 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<TextNode> InterfaceParser::CreateTextNode(const pugi::xml_node& xml_node)
|
||||
{
|
||||
Ref<TextNode> node = CreateRef<TextNode>();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
12
Nuake/src/UI/Styling/NodeStyle.h
Normal file
12
Nuake/src/UI/Styling/NodeStyle.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
class NodeStyler
|
||||
{
|
||||
//static void StyleNode(Node& node, )
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -47,6 +47,16 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PropType::FONT_SIZE:
|
||||
{
|
||||
float fvalue = std::stof(str);
|
||||
return PropValue{
|
||||
PropValueType::PIXEL,
|
||||
fvalue
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return PropValue();
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace Nuake
|
||||
|
||||
Ref<FrameBuffer> GetFrameBuffer() const;
|
||||
|
||||
Vector2 GetSize();
|
||||
|
||||
Ref<Scene> GetScene();
|
||||
bool SetScene(Ref<Scene> scene);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user