Finally finished VN textbox
This commit is contained in:
@ -30,15 +30,19 @@ std::vector<struct ShaderPassItem> UILabel::getUIRenderPasses() {
|
||||
auto canvas = this->getCanvas();
|
||||
auto shader = getGame()->renderManager.fontShader;
|
||||
|
||||
glm::mat4 model = transform->getWorldTransform();
|
||||
// Translate
|
||||
model = glm::translate(model, glm::vec3(this->textOffset, 0.0f));
|
||||
|
||||
struct ShaderPassItem item;
|
||||
item.shader = shader;
|
||||
item.mesh = &this->mesh;
|
||||
item.matrixValues[shader->paramModel] = transform->getWorldTransform();
|
||||
item.matrixValues[shader->paramModel] = model;
|
||||
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
|
||||
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
|
||||
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
|
||||
item.start = quadStart * QUAD_VERTICE_COUNT;
|
||||
item.count = quadCount == -1 ? -1 : quadCount * QUAD_VERTICE_COUNT;
|
||||
item.start = quadStart * QUAD_INDICE_COUNT;
|
||||
item.count = quadCount == -1 ? -1 : quadCount * QUAD_INDICE_COUNT;
|
||||
|
||||
// Map texture slots
|
||||
auto it = textureMap.begin();
|
||||
@ -74,10 +78,22 @@ std::vector<struct ShaderPassItem> UILabel::getUIRenderPasses() {
|
||||
}
|
||||
|
||||
float_t UILabel::getContentWidth() {
|
||||
return 1;
|
||||
float_t w = 0;
|
||||
auto it = lines.begin();
|
||||
while(it != lines.end()) {
|
||||
w = mathMax<float_t>(w, it->width);
|
||||
++it;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
float_t UILabel::getContentHeight() {
|
||||
float_t h = 0;
|
||||
auto it = lines.begin();
|
||||
while(it != lines.end()) {
|
||||
h += it->height;
|
||||
++it;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -103,6 +119,8 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
// Prepare values shared across all text parts/styles
|
||||
float_t lineWidth = 0;
|
||||
struct UILabelLine currentLine;
|
||||
currentLine.quadStart = quadCountTotal;
|
||||
currentLine.position = position;
|
||||
|
||||
// Now generate quads
|
||||
itText = newTexts.begin();
|
||||
@ -142,6 +160,8 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
auto len = text.text.length();
|
||||
float_t wordWidth = 0;
|
||||
int32_t lastSpaceCharacter = -1;
|
||||
|
||||
currentLine.height = mathMax<float_t>(currentLine.height, realText.style.size);
|
||||
|
||||
std::function<void(int32_t)> fnInsertNewline = [&](int32_t i){
|
||||
if(i != len) {
|
||||
@ -174,6 +194,12 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
|
||||
currentLine = UILabelLine();
|
||||
currentLine.quadStart = quadCountTotal;
|
||||
currentLine.position = position;
|
||||
currentLine.height = realText.style.size;
|
||||
// Here I subtract line height from the line position because we start
|
||||
// by moving the text down by the initial line height, so we need to
|
||||
// compensate for that.
|
||||
currentLine.position.y -= realText.style.size;
|
||||
};
|
||||
|
||||
// Now, iterate each character
|
||||
@ -303,4 +329,7 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
// Update
|
||||
textsBuffered = realNewTexts;
|
||||
texts = newTexts;
|
||||
|
||||
// Event
|
||||
this->eventTextChanged.invoke();
|
||||
}
|
@ -30,6 +30,8 @@ namespace Dawn {
|
||||
|
||||
struct UILabelLine {
|
||||
float_t width = 0.0f;
|
||||
float_t height = 0.0f;
|
||||
glm::vec2 position;
|
||||
int32_t quadStart = -1;
|
||||
int32_t quadCount = 0;
|
||||
};
|
||||
@ -45,9 +47,13 @@ namespace Dawn {
|
||||
int32_t quadCount = -1;
|
||||
int32_t quadCountTotal = -1;
|
||||
|
||||
glm::vec2 textOffset = glm::vec2(0.0f, 0.0f);
|
||||
|
||||
std::vector<struct UILabelText> texts;
|
||||
std::vector<struct UILabelText> textsBuffered;
|
||||
std::vector<struct UILabelLine> lines;
|
||||
|
||||
StateEvent<> eventTextChanged;
|
||||
|
||||
UILabel(SceneItem *item);
|
||||
|
||||
|
Reference in New Issue
Block a user