Refact UI and SDF font managment

This commit is contained in:
Antoine Pilote
2021-06-04 14:31:16 -04:00
parent 94ebaedf43
commit 49cfe9e421
26 changed files with 97 additions and 33 deletions

Binary file not shown.

View File

@@ -8,6 +8,7 @@
groups="container"
padding="8px 8px 8px 8px"
>
<p>Hello world!</p>
<Rect groups="items" color="200 0 200 255"></Rect>
<Rect groups="items" color="200 0 200 255"></Rect>
<Rect groups="items" color="200 0 200 255"></Rect>

View File

@@ -6,7 +6,7 @@ layout(location = 1) in vec2 UV;
uniform mat4 model;
uniform mat4 projection;
out vec2 a_UV;
out sample vec2 a_UV;
void main()
{
@@ -42,7 +42,7 @@ 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));
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);

View File

@@ -6,7 +6,7 @@ uniform mat4 model;
uniform mat4 projection;
out vec2 a_UV;
out sample vec2 a_UV;
void main()
{

View File

@@ -1,4 +1,5 @@
#pragma once
#include "src/Core/Core.h"
#include "src/Window.h"
#include "src/Scene/Scene.h"

View File

@@ -66,6 +66,7 @@ Vector2 Renderer2D::CalculateStringSize(const std::string& str, Ref<Font> font,
void Renderer2D::DrawString(const std::string& str, Ref<Font> font, Vector2 position, float fontSize)
{
TextShader->Bind();
TextShader->SetUniformMat4f("projection", Projection);
float advance = 0.0f;

View File

@@ -0,0 +1,10 @@
#include "HelloWorld.h"
int ScriptingAPI::HelloWorld(lua_State* L)
{
return 1; // Successful
}

View File

@@ -0,0 +1,6 @@
#pragma once
struct lua_State;
namespace ScriptingAPI
{
int HelloWorld(lua_State* L);
}

View File

@@ -1,7 +1,9 @@
#pragma once
#include "../Core/Core.h"
#include <src/Vendors/msdfgen/ext/import-font.h>
#include <map>
#include <src/Rendering/Textures/Texture.h>
#include "src/Core/Maths.h"
struct CharPos
{
double left;

View File

@@ -0,0 +1,20 @@
#include "FontManager.h"
std::map <std::string, Ref<Font>> FontManager::m_Fonts = std::map<std::string, Ref<Font>>();
Ref<Font> 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<Font> newFont = FontLoader::LoadFont(font);
if (newFont)
return newFont;
Logger::Log("Error: failed to load font " + font);
return nullptr;
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include <map>
#include "FontLoader.h"
class FontManager
{
private:
static std::map <std::string, Ref<Font>> m_Fonts;
public:
static Ref<Font> GetFont(const std::string& font);
};

View File

@@ -1,12 +1,12 @@
#pragma once
#include <src/Vendors/pugixml/pugixml.hpp>
#include <iostream>
#include <src/UI/Canvas.h>
#include <src/UI/Rect.h>
#include <src/UI/Nodes/Canvas.h>
#include <src/UI/Nodes/Rect.h>
#include <regex>
#include<iostream>
#include <src/Core/Logger.h>
#include "Nodes/TextNode.h"
class InterfaceParser
{
static Ref<Canvas> Root;
@@ -51,6 +51,11 @@ public:
node->Childrens.push_back(newNode);
Iterate(e, newNode);
}
else if (type == "p")
{
//Ref<TextNode> textnode = CreateTextNode(e);
}
}
}

View File

@@ -4,7 +4,8 @@
#include "yoga/Yoga.h"
#include "../Rendering/Renderer2D.h"
#include "../Core/Logger.h"
#include "Style.h"
#include <src/UI/Styling/Style.h>
namespace Layout
{

View File

@@ -0,0 +1,23 @@
#pragma once
#include "Node.h"
struct TextStyle
{
Ref<Font> font;
float fontSize;
Color color;
};
class TextNode : public Node
{
public:
std::string content = "Hello World!";
TextStyle style;
void Draw()
{
//Renderer2D::DrawString(content, style.font, Vector2(Position.Left, Position.Top), 2.0);
}
};

View File

@@ -8,11 +8,10 @@
#include "katana-parser/katana.h"
#include <string>
#include <map>
#include <src/UI/StyleSheetParser.h>
#include <src/UI/Styling/StyleSheetParser.h>
#include <regex>
#include <regex>
#include <src/UI/InterfaceParser.h>
#include <src/UI/InterfaceParser.h>
namespace UI
{

View File

@@ -1,17 +0,0 @@
#pragma once
#include "Node.h"
class Text : public Node
{
public:
std::string content = "Hello World!";
void Draw()
{
}
};

View File

@@ -1,7 +1,7 @@
#include "UserInterface.h"
#include <src/Vendors/pugixml/pugixml.hpp>
#include "Stylesheet.h"
#include "Styling/Stylesheet.h"
#include "yoga/YGConfig.h"
#include "InterfaceParser.h"
#include <src/UI/Font/FontLoader.h>
@@ -11,7 +11,7 @@ namespace UI
{
m_Name = name;
font = FontLoader::LoadFont("resources/Fonts/OpenSans-Regular.ttf");
font = FontLoader::LoadFont("resources/Fonts/RobotoMono-Regular.ttf");
m_Stylesheet = StyleSheet::New("/Interface\\Testing.css");
@@ -111,7 +111,7 @@ namespace UI
DrawRecursive(Root, 0);
Renderer2D::DrawString("Hello SDF World!", font, charPos, 2.0f);
Renderer2D::DrawString("J'appelle ca grainer", font, charPos, 4.0f);
//Renderer2D::DrawChar(charr, font, charPos, size);
}

View File

@@ -1,12 +1,12 @@
#pragma once
#include <src/Core/Timestep.h>
#include <src/Rendering/Framebuffer.h>
#include <src/UI/Rect.h>
#include <src/UI/Nodes/Rect.h>
#include "yoga/Yoga.h"
#include "Node.h"
#include <src/UI/Canvas.h>
#include "Nodes/Node.h"
#include "Nodes/Canvas.h"
#include "../Core/Maths.h"
#include "Stylesheet.h"
#include "Styling/Stylesheet.h"
#include "Font/Font.h"
namespace UI
{