mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Refact UI and SDF font managment
This commit is contained in:
BIN
Editor/resources/Fonts/OpenSans-Regular.ttf
Normal file
BIN
Editor/resources/Fonts/OpenSans-Regular.ttf
Normal file
Binary file not shown.
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,7 +6,7 @@ uniform mat4 model;
|
||||
uniform mat4 projection;
|
||||
|
||||
|
||||
out vec2 a_UV;
|
||||
out sample vec2 a_UV;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Window.h"
|
||||
#include "src/Scene/Scene.h"
|
||||
|
||||
@@ -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;
|
||||
|
||||
10
Nuake/src/Scripting/ScriptingAPI/HelloWorld.cpp
Normal file
10
Nuake/src/Scripting/ScriptingAPI/HelloWorld.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "HelloWorld.h"
|
||||
|
||||
|
||||
|
||||
int ScriptingAPI::HelloWorld(lua_State* L)
|
||||
{
|
||||
|
||||
|
||||
return 1; // Successful
|
||||
}
|
||||
6
Nuake/src/Scripting/ScriptingAPI/HelloWorld.h
Normal file
6
Nuake/src/Scripting/ScriptingAPI/HelloWorld.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
struct lua_State;
|
||||
namespace ScriptingAPI
|
||||
{
|
||||
int HelloWorld(lua_State* L);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
20
Nuake/src/UI/Font/FontManager.cpp
Normal file
20
Nuake/src/UI/Font/FontManager.cpp
Normal 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;
|
||||
}
|
||||
12
Nuake/src/UI/Font/FontManager.h
Normal file
12
Nuake/src/UI/Font/FontManager.h
Normal 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);
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
23
Nuake/src/UI/Nodes/TextNode.h
Normal file
23
Nuake/src/UI/Nodes/TextNode.h
Normal 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);
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include "Node.h"
|
||||
|
||||
|
||||
class Text : public Node
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
std::string content = "Hello World!";
|
||||
|
||||
|
||||
void Draw()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user