mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-08-06 23:41:54 +03:00
Compare commits
2 Commits
98111f2920
...
a2e1dc98a2
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a2e1dc98a2 | ||
![]() |
665b8862fd |
@ -1 +1 @@
|
||||
Subproject commit a654f25957979c381760916f6382b526ef024491
|
||||
Subproject commit 0401d901376995c7a209125b8cb12f1ceaa46fb7
|
107
src/gx/Font.cpp
107
src/gx/Font.cpp
@ -10,11 +10,13 @@
|
||||
#include "gx/Shader.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <bc/Memory.hpp>
|
||||
#include <storm/Error.hpp>
|
||||
#include <storm/String.hpp>
|
||||
#include <storm/Unicode.hpp>
|
||||
#include <tempest/Math.hpp>
|
||||
#include <common/Unicode.hpp>
|
||||
|
||||
CGxShader* g_fontPixelShader[1];
|
||||
CGxShader* g_fontVertexShader[2];
|
||||
@ -177,7 +179,18 @@ uint32_t GetScreenPixelWidth() {
|
||||
}
|
||||
|
||||
QUOTEDCODE GxuDetermineQuotedCode(const char* text, int32_t& advance, CImVector* color, uint32_t flags, uint32_t& wide) {
|
||||
wide = SUniSGetUTF8(reinterpret_cast<const uint8_t*>(text), &advance);
|
||||
STORM_ASSERT(text);
|
||||
STORM_ASSERT(*text);
|
||||
|
||||
bool ignoreColorCodes = flags & 0x100;
|
||||
bool ignoreNewlines = flags & 0x200;
|
||||
bool ignoreHyperlinks = flags & 0x400;
|
||||
bool ignorePipes = flags & 0x800;
|
||||
bool ignoreTextures = flags & 0x1000;
|
||||
|
||||
auto utext = reinterpret_cast<const uint8_t*>(text);
|
||||
|
||||
wide = sgetu8(utext, &advance);
|
||||
|
||||
switch (wide) {
|
||||
case 0x0:
|
||||
@ -185,7 +198,7 @@ QUOTEDCODE GxuDetermineQuotedCode(const char* text, int32_t& advance, CImVector*
|
||||
return CODE_INVALIDCODE;
|
||||
|
||||
case '\r':
|
||||
advance = 2 - (SUniSGetUTF8(reinterpret_cast<const uint8_t*>(text + 1), &advance) != '\n');
|
||||
advance = 2 - (sgetu8(utext + 1, &advance) != '\n');
|
||||
return CODE_NEWLINE;
|
||||
|
||||
case '\n':
|
||||
@ -193,7 +206,7 @@ QUOTEDCODE GxuDetermineQuotedCode(const char* text, int32_t& advance, CImVector*
|
||||
return CODE_NEWLINE;
|
||||
}
|
||||
|
||||
if (wide != '|' || flags & 0x800) {
|
||||
if (wide != '|' || ignorePipes) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
|
||||
@ -203,18 +216,98 @@ QUOTEDCODE GxuDetermineQuotedCode(const char* text, int32_t& advance, CImVector*
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
|
||||
int32_t firstCharAdvance = advance;
|
||||
|
||||
switch (quotedCode) {
|
||||
case 'N':
|
||||
case 'n': {
|
||||
if (flags & 0x200) {
|
||||
case 'C':
|
||||
case 'c': {
|
||||
if (ignoreColorCodes) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
size_t offset = advance + 1;
|
||||
|
||||
uint8_t comps[4];
|
||||
|
||||
for (size_t j = 0; j < 4; ++j) {
|
||||
if (!text[offset] || !text[offset + 1]) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
|
||||
char hex[3] = { text[offset], text[offset + 1], '\0' };
|
||||
offset += 2;
|
||||
char* error = nullptr;
|
||||
comps[j] = static_cast<uint8_t>(strtol(hex, &error, 16));
|
||||
if (error && *error) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
}
|
||||
|
||||
if (color) {
|
||||
color->value = CImVector::MakeARGB(255, comps[1], comps[2], comps[3]);
|
||||
}
|
||||
|
||||
advance = 10;
|
||||
return CODE_COLORON;
|
||||
}
|
||||
|
||||
case 'H': {
|
||||
if (ignoreHyperlinks) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
case 'N':
|
||||
case 'n': {
|
||||
if (ignoreNewlines) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
advance = 2;
|
||||
return CODE_NEWLINE;
|
||||
}
|
||||
|
||||
// TODO handle other control codes
|
||||
case 'R':
|
||||
case 'r': {
|
||||
if (ignoreColorCodes) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
advance = 2;
|
||||
return CODE_COLORRESTORE;
|
||||
}
|
||||
|
||||
case 'T': {
|
||||
if (ignoreTextures) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h': {
|
||||
if (ignoreHyperlinks) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
advance = 2;
|
||||
return CODE_HYPERLINKSTOP;
|
||||
}
|
||||
|
||||
case 't': {
|
||||
if (ignoreTextures) {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
advance = 2;
|
||||
return CODE_TEXTURESTOP;
|
||||
}
|
||||
|
||||
case '|': {
|
||||
advance = 2;
|
||||
return CODE_PIPE;
|
||||
}
|
||||
|
||||
default: {
|
||||
return CODE_INVALIDCODE;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remainder of function
|
||||
|
@ -348,7 +348,7 @@ int32_t CGxString::Initialize(float fontHeight, const C3Vector& position, float
|
||||
|
||||
face->m_strings.LinkToTail(this);
|
||||
|
||||
float requestedFontHeight = this->m_flags & 0x4 && !(this->m_flags & 0x80)
|
||||
float requestedFontHeight = ((this->m_flags & 0x4) && !(this->m_flags & 0x80))
|
||||
? GxuFontGetOneToOneHeight(face)
|
||||
: fontHeight;
|
||||
this->m_requestedFontHeight = requestedFontHeight;
|
||||
@ -382,7 +382,7 @@ void CGxString::InitializeTextLine(const char* currentText, uint32_t numBytes, C
|
||||
float stepGlyph = 0.0f;
|
||||
float stepScreen = 0.0f;
|
||||
uint32_t prevCode = 0;
|
||||
CImVector color;
|
||||
CImVector color = this->m_fontColor;
|
||||
|
||||
while (numBytes && *currentText) {
|
||||
int32_t advance;
|
||||
|
@ -876,9 +876,17 @@ void CSimpleFontString::UpdateString() {
|
||||
uint32_t styleFlags = this->m_styleFlags;
|
||||
|
||||
if (!(this->m_styleFlags & 0x400)) {
|
||||
// TODO
|
||||
|
||||
styleFlags |= 0x400;
|
||||
// Set FixedColor flag if the text does not contain color tags
|
||||
bool found = false;
|
||||
for (size_t i = 0; displayText && displayText[i]; ++i) {
|
||||
if (displayText[i] == '|' && (displayText[i + 1] == 'C' || displayText[i + 1] == 'c')) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
styleFlags |= 0x400u;
|
||||
}
|
||||
}
|
||||
|
||||
CImVector color = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
Loading…
Reference in New Issue
Block a user