The Fontpocalypse

I hate it
This commit is contained in:
Kae 2023-06-21 22:29:40 +10:00
parent 865f9a328a
commit f0fec34dc9
31 changed files with 146 additions and 34 deletions

View File

@ -1,5 +1,10 @@
{
"font" : {
"defaultDirectives" : ""
}
"defaultDirectives" : "",
"defaultFont" : ""
},
"cursorTooltip" : {
"font" : ""
},
"debugFont" : ""
}

View File

@ -78,7 +78,7 @@ unsigned Font::width(String::Char c) {
if (auto width = m_widthCache.maybe({c, m_pixelSize})) {
return *width;
} else {
FT_Load_Char(m_fontImpl->face, c, FT_LOAD_DEFAULT);
FT_Load_Char(m_fontImpl->face, c, FT_LOAD_FORCE_AUTOHINT);
unsigned newWidth = (m_fontImpl->face->glyph->advance.x + 32) / 64;
m_widthCache.insert({c, m_pixelSize}, newWidth);
return newWidth;

View File

@ -495,21 +495,23 @@ Image processImageOperations(List<ImageOperation> const& operations, Image image
if (dist < std::numeric_limits<int>::max()) {
float percent = (dist - 1) / (2.0f * pixels - 1);
Vec4F color = (Vec4F(op->startColor) * ((1.0f - percent) / 255.0f)) + (Vec4F(op->endColor) * (percent / 255.0f));
color.clamp(0.0f, 1.0f);
Color color = Color::rgbaf((Vec4F(op->startColor) * ((1.0f - percent) / 255.0f)) + (Vec4F(op->endColor) * (percent / 255.0f)));
if (pixel[3] != 0) {
float pixelA = byteToFloat(pixel[3]);
if (op->outlineOnly)
color[3] *= (1.0f - pixelA);
color.setAlphaF(1.0f - byteToFloat(pixel[3]));
else {
float colorA = pixelA * (1.0f - color[3]);
color[0] = Color::fromLinear((Color::toLinear(color[0]) * colorA) + (Color::toLinear(byteToFloat(pixel[0])) * pixelA));
color[1] = Color::fromLinear((Color::toLinear(color[1]) * colorA) + (Color::toLinear(byteToFloat(pixel[1])) * pixelA));
color[2] = Color::fromLinear((Color::toLinear(color[2]) * colorA) + (Color::toLinear(byteToFloat(pixel[2])) * pixelA));
color[3] += colorA;
Color pixelCol = Color::rgba(pixel);
float pixelA = pixelCol.alphaF();
float colorA = color.alphaF();
colorA += pixelA * (1.0f - colorA);
pixelCol.convertToLinear();
color.convertToLinear();
color.mix(pixelCol, pixelA);
color.convertToSRGB();
color.setAlphaF(colorA);
}
}
pixel = Vec4B(color.piecewiseMultiply(Vec4F::filled(255.0f)));
pixel = color.toRgba();
}
} else if (op->outlineOnly) {
pixel = Vec4B(0, 0, 0, 0);

View File

@ -24,6 +24,7 @@ Chat::Chat(UniverseClientPtr client) : m_client(client) {
auto fontConfig = assets->json("/interface/chat/chat.config:config.font");
m_fontSize = fontConfig.getInt("baseSize");
m_fontDirectives = fontConfig.queryString("directives", "");
m_font = fontConfig.queryString("type", "");
m_chatLineHeight = assets->json("/interface/chat/chat.config:config.lineHeight").toFloat();
m_chatVisTime = assets->json("/interface/chat/chat.config:config.visTime").toFloat();
m_fadeRate = assets->json("/interface/chat/chat.config:config.fadeRate").toDouble();
@ -178,6 +179,7 @@ void Chat::addMessages(List<ChatReceivedMessage> const& messages, bool showPane)
if (message.portrait.empty())
wrapWidth = m_chatLog->size()[0];
guiContext.setFont(m_font);
guiContext.setFontSize(m_fontSize);
StringList lines;
if (message.fromNick != "" && message.portrait == "")
@ -237,6 +239,7 @@ void Chat::renderImpl() {
int messageIndex = -m_historyOffset;
GuiContext& guiContext = GuiContext::singleton();
guiContext.setFont(m_font);
guiContext.setFontSize(m_fontSize);
guiContext.setLineSpacing(m_chatLineHeight);
for (auto message : m_receivedMessages) {
@ -284,6 +287,7 @@ void Chat::renderImpl() {
}
guiContext.setDefaultLineSpacing();
guiContext.setDefaultFont();
}
void Chat::hide() {

View File

@ -69,6 +69,7 @@ private:
float m_fadeRate;
unsigned m_fontSize;
String m_fontDirectives;
String m_font;
float m_chatLineHeight;
unsigned m_chatHistoryLimit;
int m_historyOffset;

View File

@ -194,7 +194,10 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
// TODO: Get rid of this stupid fucking bullshit, this is the ugliest
// fragilest pointlessest horseshit code in the codebase. It wouldn't
// bother me so bad if it weren't so fucking easy to do right.
// yea I agree
m_guiContext->setFontSize(m_fontSize, m_zoom);
m_guiContext->setDefaultFont();
auto result = m_guiContext->determineTextSize(sayAction.text, m_textTemplate);
float textWidth = result.width() / m_zoom + m_textPadding[0];
float textHeight = result.height() / m_zoom + m_textPadding[1];

View File

@ -997,6 +997,7 @@ void MainInterface::renderMessages() {
m_guiContext->drawQuad(m_config->messageTextContainer,
RectF::withCenter(backgroundTextCenterPos, Vec2F(imgMetadata->imageSize(m_config->messageTextContainer) * interfaceScale())));
m_guiContext->setFont(m_config->font);
m_guiContext->setFontSize(m_config->fontSize);
m_guiContext->setFontColor(Color::White.toRgba());
m_guiContext->renderText(message->message, {messageTextOffset, HorizontalAnchor::HMidAnchor, VerticalAnchor::VMidAnchor});
@ -1024,6 +1025,7 @@ void MainInterface::renderMonsterHealthBar() {
m_guiContext->drawQuad(container, RectF::withCenter(backgroundCenterPos + offset, Vec2F(imgMetadata->imageSize(container) * interfaceScale())));
auto nameTextOffset = jsonToVec2F(assets->json("/interface.config:monsterHealth.nameTextOffset")) * interfaceScale();
m_guiContext->setFont(m_config->font);
m_guiContext->setFontSize(m_config->fontSize);
m_guiContext->setFontColor(Color::White.toRgba());
m_guiContext->renderText(showDamageEntity->name(), backgroundCenterPos + nameTextOffset);
@ -1250,7 +1252,7 @@ void MainInterface::renderDebug() {
auto assets = Root::singleton().assets();
m_guiContext->setFontSize(m_config->debugFontSize);
int counter = 0;
m_guiContext->setFont(m_config->debugFont);
m_guiContext->setFontColor(Color::Green.toRgba());
bool clearMap = m_debugMapClearTimer.wrapTick();
@ -1258,6 +1260,7 @@ void MainInterface::renderDebug() {
if (clearMap)
LogMap::clear();
int counter = 0;
for (auto const& pair : logMapValues) {
TextPositioning positioning = {Vec2F(m_config->debugOffset[0], windowHeight() - m_config->debugOffset[1] - m_config->fontSize * interfaceScale() * counter)};
m_debugTextRect.combine(m_guiContext->determineTextSize(strf("%s: %s", pair.first, pair.second), positioning).padded(m_config->debugBackgroundPad));
@ -1307,7 +1310,8 @@ void MainInterface::renderDebug() {
m_guiContext->drawLine(position + Vec2F(2, -2), position + Vec2F(-2, -2), point.color, 1);
}
m_guiContext->setFontSize(assets->json("/interface.config:debugFontSize").toInt());
m_guiContext->setFontSize(m_config->debugFontSize);
for (auto const& logText : SpatialLogger::getText("world", clearSpatial)) {
m_guiContext->setFontColor(logText.color);
m_guiContext->renderText(logText.text.utf8Ptr(), camera.worldToScreen(logText.position));
@ -1381,11 +1385,13 @@ void MainInterface::renderCursor() {
Vec2I cursorOffset = (Vec2I{0, -m_cursor.size().y()} + rawCursorOffset) * interfaceScale();
Vec2I tooltipOffset = m_cursorScreenPos + cursorOffset;
size_t fontSize = assets->json("/interface.config:cursorTooltip.fontSize").toUInt();
String font = assets->json("/interface.config:cursorTooltip.font").toString();
Vec4B fontColor = jsonToColor(assets->json("/interface.config:cursorTooltip.color")).toRgba();
m_guiContext->drawQuad(backgroundImage, Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), 0), interfaceScale());
m_guiContext->setFontSize(fontSize);
m_guiContext->setFontColor(fontColor);
m_guiContext->setFont(font);
m_guiContext->renderText(*m_cursorTooltip,
TextPositioning(Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), tooltipSize.y()) / 2,
HorizontalAnchor::HMidAnchor,

View File

@ -14,7 +14,7 @@ MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() {
auto config = make_shared<MainInterfaceConfig>();
config->fontSize = assets->json("/interface.config:font.baseSize").toInt();
config->font = assets->json("/interface.config:font.defaultFont").toString();
config->inventoryImage = assets->json("/interface.config:mainBar.inventory.base").toString();
config->inventoryImageHover = assets->json("/interface.config:mainBar.inventory.hover").toString();
config->inventoryImageGlow = assets->json("/interface.config:mainBar.inventory.glow").toString();
@ -113,6 +113,7 @@ MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() {
config->debugOffset = jsonToVec2I(assets->json("/interface.config:debugOffset"));
config->debugFontSize = assets->json("/interface.config:debugFontSize").toUInt();
config->debugFont = assets->json("/interface.config:debugFont").toString();
config->debugSpatialClearTime = assets->json("/interface.config:debugSpatialClearTime").toFloat();
config->debugMapClearTime = assets->json("/interface.config:debugMapClearTime").toFloat();
config->debugBackgroundColor = jsonToColor(assets->json("/interface.config:debugBackgroundColor"));

View File

@ -43,6 +43,7 @@ struct MainInterfaceConfig {
static MainInterfaceConfigPtr loadFromAssets();
unsigned fontSize;
String font;
String inventoryImage;
String inventoryImageHover;
@ -143,6 +144,7 @@ struct MainInterfaceConfig {
Vec2I debugOffset;
unsigned debugFontSize;
String debugFont;
float debugSpatialClearTime;
float debugMapClearTime;
Color debugBackgroundColor;

View File

@ -13,6 +13,8 @@ NameplatePainter::NameplatePainter() {
Json nametagConfig = assets->json("/interface.config:nametag");
m_opacityRate = nametagConfig.getFloat("opacityRate");
m_offset = jsonToVec2F(nametagConfig.get("offset"));
m_font = nametagConfig.optString("font").value("");
m_statusFont = nametagConfig.optString("font").value(m_font);
m_fontSize = nametagConfig.getFloat("fontSize");
m_statusFontSize = nametagConfig.getFloat("statusFontSize");
m_statusOffset = jsonToVec2F(nametagConfig.get("statusOffset"));
@ -74,6 +76,7 @@ void NameplatePainter::render() {
if (nametag.opacity == 0.0f)
return;
context.setFont(m_font);
context.setFontSize(m_fontSize);
auto color = Color::rgb(nametag.color);
@ -87,6 +90,7 @@ void NameplatePainter::render() {
if (nametag.statusText) {
context.setFontSize(m_statusFontSize);
context.setFont(m_statusFont);
context.setFontColor(statusColor.toRgba());
context.renderText(*nametag.statusText, statusPosition(bubble.currentPosition));
}
@ -107,9 +111,11 @@ TextPositioning NameplatePainter::statusPosition(Vec2F bubblePosition) const {
RectF NameplatePainter::determineBoundBox(Vec2F bubblePosition, Nametag const& nametag) const {
auto& context = GuiContext::singleton();
context.setFontSize(m_fontSize);
context.setFont(m_font);
RectF nametagBox = context.determineTextSize(nametag.name, namePosition(bubblePosition));
if (nametag.statusText) {
context.setFontSize(m_statusFontSize);
context.setFont(m_statusFont);
nametagBox.combine(context.determineTextSize(*nametag.statusText, statusPosition(bubblePosition)));
}
return nametagBox;

View File

@ -33,6 +33,8 @@ private:
float m_opacityRate;
Vec2F m_offset;
String m_font;
String m_statusFont;
float m_fontSize;
float m_statusFontSize;
Vec2F m_statusOffset;

View File

@ -78,8 +78,8 @@ struct LuaUserDataMethods<CanvasWidgetPtr> {
canvasWidget->drawTriangles(tris, color.value(Color::White).toRgba());
});
methods.registerMethod("drawText",
[](CanvasWidgetPtr canvasWidget, String text, Json tp, unsigned fontSize, Maybe<Color> color, Maybe<float> lineSpacing, Maybe<String> directives) {
canvasWidget->drawText(text, TextPositioning(tp), fontSize, color.value(Color::White).toRgba(), FontMode::Normal, lineSpacing.value(DefaultLineSpacing), directives.value(""));
[](CanvasWidgetPtr canvasWidget, String text, Json tp, unsigned fontSize, Maybe<Color> color, Maybe<float> lineSpacing, Maybe<String> font, Maybe<String> directives) {
canvasWidget->drawText(text, TextPositioning(tp), fontSize, color.value(Color::White).toRgba(), FontMode::Normal, lineSpacing.value(DefaultLineSpacing), font.value(""), directives.value(""));
});
return methods;

View File

@ -13,13 +13,21 @@ void FontTextureGroup::cleanup(int64_t timeout) {
}
void FontTextureGroup::switchFont(String const& font) {
if (m_fontName != font) {
if (font.empty()) {
m_font = m_defaultFont;
m_fontName.clear();
}
else if (m_fontName != font) {
m_fontName = font;
auto find = m_fonts.find(font);
m_font = find != m_fonts.end() ? find->second : m_defaultFont;
}
}
String const& FontTextureGroup::activeFont() {
return m_fontName;
}
void FontTextureGroup::addFont(FontPtr const& font, String const& name, bool default) {
m_fonts[name] = font;
if (default)

View File

@ -34,6 +34,7 @@ public:
void cleanup(int64_t timeout);
// Switches the current font
void switchFont(String const& font);
String const& activeFont();
void addFont(FontPtr const& font, String const& name, bool default = false);
private:
StringMap<FontPtr> m_fonts;

View File

@ -144,22 +144,41 @@ int TextPainter::glyphWidth(String::Char c) {
}
int TextPainter::stringWidth(String const& s) {
String font = m_renderSettings.font, setFont = font;
m_fontTextureGroup.switchFont(font);
int width = 0;
bool escape = false;
String escapeCode;
for (String::Char c : Text::preprocessEscapeCodes(s)) {
if (c == Text::StartEsc)
escape = true;
if (!escape)
width += glyphWidth(c);
if (c == Text::EndEsc)
else if (c == Text::EndEsc) {
auto commands = escapeCode.split(',');
for (auto& command : commands) {
if (command == "reset")
m_fontTextureGroup.switchFont(font = setFont);
else if (command == "set")
setFont = font;
else if (command.beginsWith("font="))
m_fontTextureGroup.switchFont(font = command.substr(5));
}
escape = false;
escapeCode = "";
}
if (escape && (c != Text::StartEsc))
escapeCode.append(c);
}
return width;
}
StringList TextPainter::wrapText(String const& s, Maybe<unsigned> wrapWidth) {
String font = m_renderSettings.font, setFont = font;
m_fontTextureGroup.switchFont(font);
String text = Text::preprocessEscapeCodes(s);
unsigned lineStart = 0; // Where does this line start ?
@ -167,6 +186,7 @@ StringList TextPainter::wrapText(String const& s, Maybe<unsigned> wrapWidth) {
unsigned linePixelWidth = 0; // How wide is this line so far
bool inEscapeSequence = false;
String escapeCode;
unsigned splitPos = 0; // Where did we last see a place to split the string ?
unsigned splitWidth = 0; // How wide was the string there ?
@ -174,6 +194,7 @@ StringList TextPainter::wrapText(String const& s, Maybe<unsigned> wrapWidth) {
StringList lines; // list of renderable string lines
// loop through every character in the string
for (auto character : text) {
// this up here to deal with the (common) occurance that the first charcter
// is an escape initiator
@ -182,8 +203,21 @@ StringList TextPainter::wrapText(String const& s, Maybe<unsigned> wrapWidth) {
if (inEscapeSequence) {
lineCharSize++; // just jump straight to the next character, we don't care what it is.
if (character == Text::EndEsc)
if (character == Text::EndEsc) {
auto commands = escapeCode.split(',');
for (auto& command : commands) {
if (command == "reset")
m_fontTextureGroup.switchFont(font = setFont);
else if (command == "set")
setFont = font;
else if (command.beginsWith("font="))
m_fontTextureGroup.switchFont(font = command.substr(5));
}
inEscapeSequence = false;
escapeCode = "";
}
if (character != Text::StartEsc)
escapeCode.append(character);
} else {
lineCharSize++; // assume at least one character if we get here.
@ -272,7 +306,7 @@ void TextPainter::setProcessingDirectives(String directives) {
}
void TextPainter::setFont(String const& font) {
m_fontTextureGroup.switchFont(font);
m_renderSettings.font = font;
}
void TextPainter::addFont(FontPtr const& font, String const& name) {
@ -289,7 +323,7 @@ RectF TextPainter::doRenderText(String const& s, TextPositioning const& position
int height = (lines.size() - 1) * m_lineSpacing * m_fontSize + m_fontSize;
auto savedRenderSettings = m_renderSettings;
RenderSettings savedRenderSettings = m_renderSettings;
m_savedRenderSettings = m_renderSettings;
if (position.vAnchor == VerticalAnchor::BottomAnchor)
@ -306,7 +340,7 @@ RectF TextPainter::doRenderText(String const& s, TextPositioning const& position
break;
}
m_renderSettings = savedRenderSettings;
m_renderSettings = move(savedRenderSettings);
return bounds;
}
@ -315,6 +349,7 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position
String text = s;
TextPositioning pos = position;
if (pos.hAnchor == HorizontalAnchor::RightAnchor) {
auto trimmedString = s;
if (charLimit)
@ -349,7 +384,7 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position
pos.pos[0] += glyphBounds.width();
} else if (c == Text::EndEsc) {
auto commands = escapeCode.split(',');
for (auto command : commands) {
for (auto& command : commands) {
try {
if (command == "reset") {
m_renderSettings = m_savedRenderSettings;
@ -388,7 +423,7 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position
RectF TextPainter::doRenderGlyph(String::Char c, TextPositioning const& position, bool reallyRender) {
if (m_nonRenderedCharacters.find(String(c)) != NPos)
return RectF();
setFont(m_renderSettings.font);
m_fontTextureGroup.switchFont(m_renderSettings.font);
int width = glyphWidth(c);
// Offset left by width if right anchored.
float hOffset = 0;

View File

@ -25,6 +25,7 @@ ButtonWidget::ButtonWidget() {
auto interfaceConfig = assets->json("/interface.config");
m_pressedOffset = jsonToVec2I(interfaceConfig.get("buttonPressedOffset"));
m_fontSize = interfaceConfig.query("font.buttonSize").toInt();
m_font = interfaceConfig.query("font.defaultFont").toString();
}
ButtonWidget::ButtonWidget(WidgetCallbackFunc callback,
@ -89,6 +90,7 @@ void ButtonWidget::renderImpl() {
if (!m_text.empty()) {
auto& guiContext = GuiContext::singleton();
guiContext.setFontSize(m_fontSize);
guiContext.setFont(m_font);
if (m_disabled)
guiContext.setFontColor(m_fontColorDisabled.toRgba());
else if (m_fontColorChecked && m_checked)

View File

@ -121,6 +121,7 @@ protected:
Vec2U m_buttonBoundSize;
int m_fontSize;
String m_font;
String m_text;
Vec2I m_textOffset;

View File

@ -60,8 +60,8 @@ void CanvasWidget::drawTriangles(List<tuple<Vec2F, Vec2F, Vec2F>> const& triangl
m_renderOps.append(make_tuple(triangles, color));
}
void CanvasWidget::drawText(String s, TextPositioning position, unsigned fontSize, Vec4B const& color, FontMode mode, float lineSpacing, String processingDirectives) {
m_renderOps.append(make_tuple(move(s), move(position), fontSize, color, mode, lineSpacing, move(processingDirectives)));
void CanvasWidget::drawText(String s, TextPositioning position, unsigned fontSize, Vec4B const& color, FontMode mode, float lineSpacing, String font, String processingDirectives) {
m_renderOps.append(make_tuple(move(s), move(position), fontSize, color, mode, lineSpacing, move(font), move(processingDirectives)));
}
Vec2I CanvasWidget::mousePosition() const {
@ -137,7 +137,7 @@ void CanvasWidget::renderImpl() {
if (auto args = op.ptr<TrianglesOp>())
tupleUnpackFunction(bind(&CanvasWidget::renderTriangles, this, renderingOffset, _1, _2), *args);
if (auto args = op.ptr<TextOp>())
tupleUnpackFunction(bind(&CanvasWidget::renderText, this, renderingOffset, _1, _2, _3, _4, _5, _6, _7), *args);
tupleUnpackFunction(bind(&CanvasWidget::renderText, this, renderingOffset, _1, _2, _3, _4, _5, _6, _7, _8), *args);
}
}
@ -222,18 +222,20 @@ void CanvasWidget::renderTriangles(Vec2F const& renderingOffset, List<tuple<Vec2
context.drawInterfaceTriangles(translated, color);
}
void CanvasWidget::renderText(Vec2F const& renderingOffset, String const& s, TextPositioning const& position, unsigned fontSize, Vec4B const& color, FontMode mode, float lineSpacing, String const& directives) {
void CanvasWidget::renderText(Vec2F const& renderingOffset, String const& s, TextPositioning const& position, unsigned fontSize, Vec4B const& color, FontMode mode, float lineSpacing, String const& font, String const& directives) {
auto& context = GuiContext::singleton();
context.setFontProcessingDirectives(directives);
context.setFontSize(fontSize);
context.setFontColor(color);
context.setFontMode(mode);
context.setFont(font);
context.setLineSpacing(lineSpacing);
TextPositioning translatedPosition = position;
translatedPosition.pos += renderingOffset;
context.renderInterfaceText(s, translatedPosition);
context.setDefaultLineSpacing();
context.setDefaultFont();
context.setFontProcessingDirectives("");
}

View File

@ -65,7 +65,7 @@ public:
void drawPoly(PolyF const& poly, Vec4B const& color = Vec4B(255, 255, 255, 255), float lineWidth = 1.0f);
void drawTriangles(List<tuple<Vec2F, Vec2F, Vec2F>> const& poly, Vec4B const& color = Vec4B(255, 255, 255, 255));
void drawText(String s, TextPositioning position, unsigned fontSize, Vec4B const& color = Vec4B(255, 255, 255, 255), FontMode mode = FontMode::Normal, float lineSpacing = Star::DefaultLineSpacing, String processingDirectives = "");
void drawText(String s, TextPositioning position, unsigned fontSize, Vec4B const& color = Vec4B(255, 255, 255, 255), FontMode mode = FontMode::Normal, float lineSpacing = Star::DefaultLineSpacing, String font = "", String processingDirectives = "");
protected:
void renderImpl() override;
@ -78,7 +78,7 @@ protected:
void renderRect(Vec2F const& renderingOffset, RectF const& coords, Vec4B const& color);
void renderPoly(Vec2F const& renderingOffset, PolyF poly, Vec4B const& color, float lineWidth);
void renderTriangles(Vec2F const& renderingOffset, List<tuple<Vec2F, Vec2F, Vec2F>> const& triangles, Vec4B const& color);
void renderText(Vec2F const& renderingOffset, String const& s, TextPositioning const& position, unsigned fontSize, Vec4B const& color, FontMode mode, float lineSpacing, String const& directives);
void renderText(Vec2F const& renderingOffset, String const& s, TextPositioning const& position, unsigned fontSize, Vec4B const& color, FontMode mode, float lineSpacing, String const& font, String const& directives);
private:
bool m_captureKeyboard;
@ -95,7 +95,7 @@ private:
typedef tuple<Vec2F, Vec2F, Vec4B, float> LineOp;
typedef tuple<PolyF, Vec4B, float> PolyOp;
typedef tuple<List<tuple<Vec2F, Vec2F, Vec2F>>, Vec4B> TrianglesOp;
typedef tuple<String, TextPositioning, unsigned, Vec4B, FontMode, float, String> TextOp;
typedef tuple<String, TextPositioning, unsigned, Vec4B, FontMode, float, String, String> TextOp;
typedef MVariant<RectOp, ImageOp, ImageRectOp, DrawableOp, TiledImageOp, LineOp, PolyOp, TrianglesOp, TextOp> RenderOp;
List<RenderOp> m_renderOps;

View File

@ -10,6 +10,7 @@ FuelWidget::FuelWidget() {
auto assets = Root::singleton().assets();
m_fontSize = assets->json("/interface.config:font.buttonSize").toInt();
m_font = assets->json("/interface.config:font.defaultFont").toString();
m_fuelLevel = 0;
m_maxLevel = 0;
@ -73,6 +74,7 @@ void FuelWidget::renderImpl() {
auto& guiContext = GuiContext::singleton();
guiContext.setFontSize(m_fontSize);
guiContext.setFont(m_font);
if (m_potential != 0) {
guiContext.setFontColor(Color::White.toRgba());
} else if (m_fuelLevel == 0) {

View File

@ -32,6 +32,7 @@ protected:
float m_pingTimeout;
unsigned m_fontSize;
String m_font;
private:
};

View File

@ -356,6 +356,14 @@ void GuiContext::setFontProcessingDirectives(String const& directives) {
textPainter()->setProcessingDirectives(directives);
}
void GuiContext::setFont(String const& font) {
textPainter()->setFont(font);
}
void GuiContext::setDefaultFont() {
textPainter()->setFont("");
}
void GuiContext::setLineSpacing(float lineSpacing) {
textPainter()->setLineSpacing(lineSpacing);
}

View File

@ -101,6 +101,8 @@ public:
void setFontColor(Vec4B const& color);
void setFontMode(FontMode mode);
void setFontProcessingDirectives(String const& directives);
void setFont(String const& font);
void setDefaultFont();
void setLineSpacing(float lineSpacing);
void setDefaultLineSpacing();

View File

@ -22,6 +22,7 @@ ItemSlotWidget::ItemSlotWidget(ItemPtr const& item, String const& backingImage)
m_countPosition = TextPositioning(jsonToVec2F(interfaceConfig.get("itemCountRightAnchor")), HorizontalAnchor::RightAnchor);
m_countFontMode = FontMode::Normal;
m_fontSize = interfaceConfig.query("font.itemSize").toInt();
m_font = interfaceConfig.query("font.defaultFont").toString();
m_fontColor = Color::rgb(jsonToVec3B(interfaceConfig.query("font.defaultColor")));
m_itemDraggableArea = jsonToRectI(interfaceConfig.get("itemDraggableArea"));
m_durabilityOffset = jsonToVec2I(interfaceConfig.get("itemIconDurabilityOffset"));
@ -181,6 +182,7 @@ void ItemSlotWidget::renderImpl() {
context()->drawInterfaceQuad(strf("/interface/cooldown.png:%d", frame), Vec2F(screenPosition()));
if (m_item->count() > 1 && m_showCount) { // we don't need to tell people that there's only 1 of something
context()->setFont(m_font);
context()->setFontSize(m_fontSize);
context()->setFontColor(m_fontColor.toRgba());
context()->setFontMode(m_countFontMode);

View File

@ -57,6 +57,7 @@ private:
RectI m_itemDraggableArea;
int m_fontSize;
String m_font;
Color m_fontColor;
WidgetCallbackFunc m_callback;

View File

@ -19,6 +19,7 @@ LabelWidget::LabelWidget(String text,
auto fontConfig = assets->json("/interface.config:font");
m_fontSize = fontConfig.getInt("baseSize");
m_processingDirectives = fontConfig.getString("defaultDirectives");
m_font = fontConfig.queryString("defaultFont", "");
setText(move(text));
}
@ -79,6 +80,7 @@ RectI LabelWidget::getScissorRect() const {
}
void LabelWidget::renderImpl() {
context()->setFont(m_font);
context()->setFontSize(m_fontSize);
context()->setFontColor(m_color.toRgba());
context()->setFontProcessingDirectives(m_processingDirectives);
@ -90,6 +92,7 @@ void LabelWidget::renderImpl() {
context()->renderInterfaceText(m_text, {Vec2F(screenPosition()), m_hAnchor, m_vAnchor, m_wrapWidth, m_textCharLimit});
context()->setDefaultFont();
context()->setFontProcessingDirectives("");
context()->setDefaultLineSpacing();
}
@ -98,7 +101,7 @@ void LabelWidget::updateTextRegion() {
context()->setFontSize(m_fontSize);
context()->setFontColor(m_color.toRgba());
context()->setFontProcessingDirectives(m_processingDirectives);
context()->setFont(m_font);
if (m_lineSpacing)
context()->setLineSpacing(*m_lineSpacing);
else
@ -107,6 +110,7 @@ void LabelWidget::updateTextRegion() {
m_textRegion = RectI(context()->determineInterfaceTextSize(m_text, {Vec2F(), m_hAnchor, m_vAnchor, m_wrapWidth, m_textCharLimit}));
setSize(m_textRegion.size());
context()->setDefaultFont();
context()->setFontProcessingDirectives("");
context()->setDefaultLineSpacing();
}

View File

@ -41,6 +41,7 @@ private:
HorizontalAnchor m_hAnchor;
VerticalAnchor m_vAnchor;
String m_processingDirectives;
String m_font;
Maybe<unsigned> m_wrapWidth;
Maybe<float> m_lineSpacing;
Maybe<unsigned> m_textCharLimit;

View File

@ -29,6 +29,7 @@ Pane::Pane() {
auto assets = Root::singleton().assets();
m_fontSize = assets->json("/interface.config:font.baseSize").toInt();
m_font = assets->json("/interface.config:font.defaultFont").toString();
m_iconOffset = jsonToVec2I(assets->json("/interface.config:paneIconOffset"));
m_titleOffset = jsonToVec2I(assets->json("/interface.config:paneTitleOffset"));
m_subTitleOffset = jsonToVec2I(assets->json("/interface.config:paneSubTitleOffset"));
@ -203,6 +204,7 @@ void Pane::renderImpl() {
m_context->resetInterfaceScissorRect();
}
m_context->setFont(m_font);
m_context->setFontSize(m_fontSize);
m_context->setFontColor(m_titleColor.toRgba());
m_context->setFontMode(FontMode::Shadow);
@ -210,6 +212,7 @@ void Pane::renderImpl() {
m_context->setFontColor(m_subTitleColor.toRgba());
m_context->renderInterfaceText(m_subTitle, {headerPos + Vec2F(m_subTitleOffset)});
m_context->setFontMode(FontMode::Normal);
m_context->setDefaultFont();
}
}

View File

@ -113,6 +113,7 @@ protected:
WidgetPtr m_icon;
String m_title;
String m_subTitle;
String m_font;
unsigned m_fontSize;
Vec2I m_iconOffset;
Vec2I m_titleOffset;

View File

@ -25,6 +25,7 @@ TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, Wid
auto fontConfig = assets->json("/interface.config:font");
m_fontSize = fontConfig.getInt("baseSize");
m_processingDirectives = fontConfig.getString("defaultDirectives");
m_font = fontConfig.queryString("defaultFont", "");
m_color = Color::rgb(jsonToVec3B(fontConfig.getArray("defaultColor")));
// Meh, padding is hard-coded here
@ -46,6 +47,7 @@ void TextBoxWidget::renderImpl() {
else if (m_hAnchor == HorizontalAnchor::RightAnchor)
pos += Vec2F(size()[0], 0);
context()->setFont(m_font);
if ((m_maxWidth != -1) && m_overfillMode) {
context()->setFontSize(m_fontSize);
int shift = std::max(0, getCursorOffset() - m_maxWidth);
@ -61,6 +63,7 @@ void TextBoxWidget::renderImpl() {
context()->setFontColor(m_color.mix(Color::rgbf(0, 0, 1), blueRate).toRgba());
context()->renderInterfaceText(m_text, {pos, m_hAnchor, m_vAnchor});
}
context()->setDefaultFont();
context()->setFontProcessingDirectives("");
context()->setFontColor(Vec4B::filled(255));
@ -85,6 +88,7 @@ void TextBoxWidget::renderImpl() {
int TextBoxWidget::getCursorOffset() { // horizontal only
float scale;
context()->setFont(m_font);
context()->setFontSize(m_fontSize);
if (m_hAnchor == HorizontalAnchor::LeftAnchor) {
scale = 1.0;
@ -391,6 +395,7 @@ bool TextBoxWidget::newTextValid(String const& text) const {
if (!text.regexMatch(m_regex))
return false;
if ((m_maxWidth != -1) && !m_overfillMode) {
context()->setFont(m_font);
context()->setFontSize(m_fontSize);
return context()->stringInterfaceWidth(text) <= m_maxWidth;
}

View File

@ -63,6 +63,7 @@ private:
VerticalAnchor m_vAnchor;
Color m_color;
String m_processingDirectives;
String m_font;
int m_fontSize;
int m_maxWidth;
int m_cursorOffset;