Pretty much everything Label wise is working

This commit is contained in:
2023-06-12 08:32:12 -07:00
parent da5d3da6df
commit dd1004257e
10 changed files with 306 additions and 93 deletions

View File

@ -1,69 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct ColorU8 {
uint8_t r, g, b, a;
};
#pragma pack(push, 4)
struct Color {
float_t r, g, b, a;
struct Color operator * (const float_t &x) {
return {
r * x,
g * x,
b * x,
a * x
};
}
struct Color operator - (const struct Color &color) {
return {
r - color.r,
g - color.g,
b - color.b,
a - color.a
};
}
struct Color operator + (const struct Color &color) {
return {
r + color.r,
g + color.g,
b + color.b,
a + color.a
};
}
operator struct ColorU8() const {
return {
(uint8_t)(r * 255),
(uint8_t)(g * 255),
(uint8_t)(b * 255),
(uint8_t)(a * 255)
};
}
};
#pragma pack(pop)
#define COLOR_DEF(r,g,b,a) { r, g, b, a }
#define COLOR_WHITE COLOR_DEF(1.0f, 1.0f, 1.0f, 1.0f)
#define COLOR_RED COLOR_DEF(1.0f, 0, 0, 1.0f)
#define COLOR_GREEN COLOR_DEF(0, 1.0f, 0, 1.0f)
#define COLOR_BLUE COLOR_DEF(0, 0, 1.0f, 1.0f)
#define COLOR_BLACK COLOR_DEF(0, 0, 0, 1.0f)
#define COLOR_MAGENTA COLOR_DEF(1.0f, 0, 1.0f, 1.0f)
#define COLOR_DARK_GREY COLOR_DEF(0.2f, 0.2f, 0.2f, 1.0f)
#define COLOR_LIGHT_GREY COLOR_DEF(0.8f, 0.8f, 0.8f, 1.0f)
#define COLOR_CORNFLOWER_BLUE COLOR_DEF(0.4f, 0.6f, 0.9f, 1.0f)
#define COLOR_WHITE_TRANSPARENT COLOR_DEF(1.0f, 1.0f, 1.0f, 0.0f)
#define COLOR_BLACK_TRANSPARENT COLOR_DEF(0.0f, 0.0f, 0.0f, 0.0f)
#define COLOR_TRANSPARENT COLOR_BLACK_TRANSPARENT
}

View File

@ -17,88 +17,66 @@ UILabelNew::UILabelNew(SceneItem *item) :
void UILabelNew::onStart() {
this->shaderBuffer.init();
auto font = this->getGame()->assetManager.get<NewTrueTypeAsset>("font_arial");
std::vector<struct UILabelStyle> styleStack;
struct UILabelStyle current;
styleStack.push_back(current);
std::vector<struct UILabelText> texts;
texts.push_back({
.text = "Hello",
.style = {
.color = COLOR_RED,
.style = 0,
.size = 32,
.font = font
std::function<void(Xml*)> parseChildren = [&](Xml *node) {
if(node->children.empty()) {
struct UILabelText text;
text.style = current;
text.text = node->value;
texts.push_back(text);
} else {
auto itNode = node->children.begin();
while(itNode != node->children.end()) {
auto child = *itNode;
assertTrue(child->node == "font");
struct UILabelStyle style;
if(child->attributes.contains("font")) {
style.font = this->getGame()->assetManager.get<NewTrueTypeAsset>(child->attributes["font"]);
} else {
style.font = current.font;
}
if(child->attributes.contains("size")) {
style.size = std::stoi(child->attributes["size"]);
} else {
style.size = current.size;
}
if(child->attributes.contains("style")) {
std::string s = child->attributes["style"];
style.style = 0;
if(s.find("bold") != std::string::npos) style.style |= NEW_TRUETYPE_VARIANT_BOLD;
if(s.find("italic") != std::string::npos) style.style |= NEW_TRUETYPE_VARIANT_ITALICS;
} else {
style.style = current.style;
}
if(child->attributes.contains("color")) {
style.color = Color::fromString(child->attributes["color"]);
} else {
style.color = current.color;
}
styleStack.push_back(style);
current = style;
parseChildren(child);
styleStack.pop_back();
current = styleStack.back();
++itNode;
}
}
});
texts.push_back({
.text = "World",
.style = {
.color = COLOR_BLUE,
.style = 1,
.size = 64,
.font = font
}
});
};
auto root = Xml::load("<root>" + this->test + "</root>");
parseChildren(&root);
this->rebufferQuads(texts);
// std::vector<struct UILabelStyle> styleStack;
// struct UILabelStyle current;
// styleStack.push_back(current);
// std::vector<struct UILabelText> texts;
// std::function<void(Xml*)> parseChildren = [&](Xml *node) {
// if(node->children.empty()) {
// struct UILabelText text;
// text.style = current;
// text.text = node->value;
// (node->value)
// } else {
// auto itNode = node->children.begin();
// while(itNode != node->children.end()) {
// auto child = *itNode;
// std::cout << "Node: " << child->node << std::endl;
// assertTrue(child->node == "font");
// struct UILabelStyle style;
// if(child->attributes.contains("font")) {
// style.font = this->getGame()->assetManager.get<NewTrueTypeAsset>(child->attributes["font"]);
// } else {
// style.font = current.font;
// }
// if(child->attributes.contains("size")) {
// style.size = std::stoi(child->attributes["size"]);
// } else {
// style.size = current.size;
// }
// if(child->attributes.contains("style")) {
// style.style = std::stoi(child->attributes["style"]);
// } else {
// style.style = current.style;
// }
// if(child->attributes.contains("color")) {
// style.color = std::stoi(child->attributes["color"]);
// } else {
// style.color = current.color;
// }
// styleStack.push_back(style);
// current = style;
// parseChildren(child);
// styleStack.pop_back();
// current = styleStack.back();
// ++itNode;
// }
// }
// };
// auto root = Xml::load("<root>" + this->test + "</root>");
// parseChildren(&root);
// this->rebufferQuads(texts);
}
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
@ -165,11 +143,10 @@ float_t UILabelNew::getContentHeight() {
}
void UILabelNew::rebufferQuads(std::vector<struct UILabelText> texts) {
std::cout << "Rebuffering" << std::endl;
auto oldTexts = this->texts;
textureMap.clear();
glm::vec2 position(32, 32);
glm::vec2 position(0, 0);
struct FontShaderBufferData fontData;
int32_t quadIndex = 0;
int32_t partIndex = 0;

View File

@ -11,7 +11,7 @@
namespace Dawn {
struct UILabelStyle {
struct Color color = COLOR_MAGENTA;
struct Color color = COLOR_WHITE;
flag_t style = 0;
uint32_t size = 16;
NewTrueTypeAsset *font = nullptr;