The Fontpocalypse
I hate it
This commit is contained in:
parent
865f9a328a
commit
f0fec34dc9
@ -1,5 +1,10 @@
|
|||||||
{
|
{
|
||||||
"font" : {
|
"font" : {
|
||||||
"defaultDirectives" : ""
|
"defaultDirectives" : "",
|
||||||
}
|
"defaultFont" : ""
|
||||||
|
},
|
||||||
|
"cursorTooltip" : {
|
||||||
|
"font" : ""
|
||||||
|
},
|
||||||
|
"debugFont" : ""
|
||||||
}
|
}
|
@ -78,7 +78,7 @@ unsigned Font::width(String::Char c) {
|
|||||||
if (auto width = m_widthCache.maybe({c, m_pixelSize})) {
|
if (auto width = m_widthCache.maybe({c, m_pixelSize})) {
|
||||||
return *width;
|
return *width;
|
||||||
} else {
|
} 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;
|
unsigned newWidth = (m_fontImpl->face->glyph->advance.x + 32) / 64;
|
||||||
m_widthCache.insert({c, m_pixelSize}, newWidth);
|
m_widthCache.insert({c, m_pixelSize}, newWidth);
|
||||||
return newWidth;
|
return newWidth;
|
||||||
|
@ -495,21 +495,23 @@ Image processImageOperations(List<ImageOperation> const& operations, Image image
|
|||||||
|
|
||||||
if (dist < std::numeric_limits<int>::max()) {
|
if (dist < std::numeric_limits<int>::max()) {
|
||||||
float percent = (dist - 1) / (2.0f * pixels - 1);
|
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 color = Color::rgbaf((Vec4F(op->startColor) * ((1.0f - percent) / 255.0f)) + (Vec4F(op->endColor) * (percent / 255.0f)));
|
||||||
color.clamp(0.0f, 1.0f);
|
|
||||||
if (pixel[3] != 0) {
|
if (pixel[3] != 0) {
|
||||||
float pixelA = byteToFloat(pixel[3]);
|
|
||||||
if (op->outlineOnly)
|
if (op->outlineOnly)
|
||||||
color[3] *= (1.0f - pixelA);
|
color.setAlphaF(1.0f - byteToFloat(pixel[3]));
|
||||||
else {
|
else {
|
||||||
float colorA = pixelA * (1.0f - color[3]);
|
Color pixelCol = Color::rgba(pixel);
|
||||||
color[0] = Color::fromLinear((Color::toLinear(color[0]) * colorA) + (Color::toLinear(byteToFloat(pixel[0])) * pixelA));
|
float pixelA = pixelCol.alphaF();
|
||||||
color[1] = Color::fromLinear((Color::toLinear(color[1]) * colorA) + (Color::toLinear(byteToFloat(pixel[1])) * pixelA));
|
float colorA = color.alphaF();
|
||||||
color[2] = Color::fromLinear((Color::toLinear(color[2]) * colorA) + (Color::toLinear(byteToFloat(pixel[2])) * pixelA));
|
colorA += pixelA * (1.0f - colorA);
|
||||||
color[3] += 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) {
|
} else if (op->outlineOnly) {
|
||||||
pixel = Vec4B(0, 0, 0, 0);
|
pixel = Vec4B(0, 0, 0, 0);
|
||||||
|
@ -24,6 +24,7 @@ Chat::Chat(UniverseClientPtr client) : m_client(client) {
|
|||||||
auto fontConfig = assets->json("/interface/chat/chat.config:config.font");
|
auto fontConfig = assets->json("/interface/chat/chat.config:config.font");
|
||||||
m_fontSize = fontConfig.getInt("baseSize");
|
m_fontSize = fontConfig.getInt("baseSize");
|
||||||
m_fontDirectives = fontConfig.queryString("directives", "");
|
m_fontDirectives = fontConfig.queryString("directives", "");
|
||||||
|
m_font = fontConfig.queryString("type", "");
|
||||||
m_chatLineHeight = assets->json("/interface/chat/chat.config:config.lineHeight").toFloat();
|
m_chatLineHeight = assets->json("/interface/chat/chat.config:config.lineHeight").toFloat();
|
||||||
m_chatVisTime = assets->json("/interface/chat/chat.config:config.visTime").toFloat();
|
m_chatVisTime = assets->json("/interface/chat/chat.config:config.visTime").toFloat();
|
||||||
m_fadeRate = assets->json("/interface/chat/chat.config:config.fadeRate").toDouble();
|
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())
|
if (message.portrait.empty())
|
||||||
wrapWidth = m_chatLog->size()[0];
|
wrapWidth = m_chatLog->size()[0];
|
||||||
|
|
||||||
|
guiContext.setFont(m_font);
|
||||||
guiContext.setFontSize(m_fontSize);
|
guiContext.setFontSize(m_fontSize);
|
||||||
StringList lines;
|
StringList lines;
|
||||||
if (message.fromNick != "" && message.portrait == "")
|
if (message.fromNick != "" && message.portrait == "")
|
||||||
@ -237,6 +239,7 @@ void Chat::renderImpl() {
|
|||||||
int messageIndex = -m_historyOffset;
|
int messageIndex = -m_historyOffset;
|
||||||
|
|
||||||
GuiContext& guiContext = GuiContext::singleton();
|
GuiContext& guiContext = GuiContext::singleton();
|
||||||
|
guiContext.setFont(m_font);
|
||||||
guiContext.setFontSize(m_fontSize);
|
guiContext.setFontSize(m_fontSize);
|
||||||
guiContext.setLineSpacing(m_chatLineHeight);
|
guiContext.setLineSpacing(m_chatLineHeight);
|
||||||
for (auto message : m_receivedMessages) {
|
for (auto message : m_receivedMessages) {
|
||||||
@ -284,6 +287,7 @@ void Chat::renderImpl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
guiContext.setDefaultLineSpacing();
|
guiContext.setDefaultLineSpacing();
|
||||||
|
guiContext.setDefaultFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chat::hide() {
|
void Chat::hide() {
|
||||||
|
@ -69,6 +69,7 @@ private:
|
|||||||
float m_fadeRate;
|
float m_fadeRate;
|
||||||
unsigned m_fontSize;
|
unsigned m_fontSize;
|
||||||
String m_fontDirectives;
|
String m_fontDirectives;
|
||||||
|
String m_font;
|
||||||
float m_chatLineHeight;
|
float m_chatLineHeight;
|
||||||
unsigned m_chatHistoryLimit;
|
unsigned m_chatHistoryLimit;
|
||||||
int m_historyOffset;
|
int m_historyOffset;
|
||||||
|
@ -194,7 +194,10 @@ void ChatBubbleManager::addChatActions(List<ChatAction> chatActions, bool silent
|
|||||||
// TODO: Get rid of this stupid fucking bullshit, this is the ugliest
|
// TODO: Get rid of this stupid fucking bullshit, this is the ugliest
|
||||||
// fragilest pointlessest horseshit code in the codebase. It wouldn't
|
// fragilest pointlessest horseshit code in the codebase. It wouldn't
|
||||||
// bother me so bad if it weren't so fucking easy to do right.
|
// 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->setFontSize(m_fontSize, m_zoom);
|
||||||
|
m_guiContext->setDefaultFont();
|
||||||
auto result = m_guiContext->determineTextSize(sayAction.text, m_textTemplate);
|
auto result = m_guiContext->determineTextSize(sayAction.text, m_textTemplate);
|
||||||
float textWidth = result.width() / m_zoom + m_textPadding[0];
|
float textWidth = result.width() / m_zoom + m_textPadding[0];
|
||||||
float textHeight = result.height() / m_zoom + m_textPadding[1];
|
float textHeight = result.height() / m_zoom + m_textPadding[1];
|
||||||
|
@ -997,6 +997,7 @@ void MainInterface::renderMessages() {
|
|||||||
m_guiContext->drawQuad(m_config->messageTextContainer,
|
m_guiContext->drawQuad(m_config->messageTextContainer,
|
||||||
RectF::withCenter(backgroundTextCenterPos, Vec2F(imgMetadata->imageSize(m_config->messageTextContainer) * interfaceScale())));
|
RectF::withCenter(backgroundTextCenterPos, Vec2F(imgMetadata->imageSize(m_config->messageTextContainer) * interfaceScale())));
|
||||||
|
|
||||||
|
m_guiContext->setFont(m_config->font);
|
||||||
m_guiContext->setFontSize(m_config->fontSize);
|
m_guiContext->setFontSize(m_config->fontSize);
|
||||||
m_guiContext->setFontColor(Color::White.toRgba());
|
m_guiContext->setFontColor(Color::White.toRgba());
|
||||||
m_guiContext->renderText(message->message, {messageTextOffset, HorizontalAnchor::HMidAnchor, VerticalAnchor::VMidAnchor});
|
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())));
|
m_guiContext->drawQuad(container, RectF::withCenter(backgroundCenterPos + offset, Vec2F(imgMetadata->imageSize(container) * interfaceScale())));
|
||||||
|
|
||||||
auto nameTextOffset = jsonToVec2F(assets->json("/interface.config:monsterHealth.nameTextOffset")) * 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->setFontSize(m_config->fontSize);
|
||||||
m_guiContext->setFontColor(Color::White.toRgba());
|
m_guiContext->setFontColor(Color::White.toRgba());
|
||||||
m_guiContext->renderText(showDamageEntity->name(), backgroundCenterPos + nameTextOffset);
|
m_guiContext->renderText(showDamageEntity->name(), backgroundCenterPos + nameTextOffset);
|
||||||
@ -1250,7 +1252,7 @@ void MainInterface::renderDebug() {
|
|||||||
|
|
||||||
auto assets = Root::singleton().assets();
|
auto assets = Root::singleton().assets();
|
||||||
m_guiContext->setFontSize(m_config->debugFontSize);
|
m_guiContext->setFontSize(m_config->debugFontSize);
|
||||||
int counter = 0;
|
m_guiContext->setFont(m_config->debugFont);
|
||||||
m_guiContext->setFontColor(Color::Green.toRgba());
|
m_guiContext->setFontColor(Color::Green.toRgba());
|
||||||
|
|
||||||
bool clearMap = m_debugMapClearTimer.wrapTick();
|
bool clearMap = m_debugMapClearTimer.wrapTick();
|
||||||
@ -1258,6 +1260,7 @@ void MainInterface::renderDebug() {
|
|||||||
if (clearMap)
|
if (clearMap)
|
||||||
LogMap::clear();
|
LogMap::clear();
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
for (auto const& pair : logMapValues) {
|
for (auto const& pair : logMapValues) {
|
||||||
TextPositioning positioning = {Vec2F(m_config->debugOffset[0], windowHeight() - m_config->debugOffset[1] - m_config->fontSize * interfaceScale() * counter)};
|
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));
|
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->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)) {
|
for (auto const& logText : SpatialLogger::getText("world", clearSpatial)) {
|
||||||
m_guiContext->setFontColor(logText.color);
|
m_guiContext->setFontColor(logText.color);
|
||||||
m_guiContext->renderText(logText.text.utf8Ptr(), camera.worldToScreen(logText.position));
|
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 cursorOffset = (Vec2I{0, -m_cursor.size().y()} + rawCursorOffset) * interfaceScale();
|
||||||
Vec2I tooltipOffset = m_cursorScreenPos + cursorOffset;
|
Vec2I tooltipOffset = m_cursorScreenPos + cursorOffset;
|
||||||
size_t fontSize = assets->json("/interface.config:cursorTooltip.fontSize").toUInt();
|
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();
|
Vec4B fontColor = jsonToColor(assets->json("/interface.config:cursorTooltip.color")).toRgba();
|
||||||
|
|
||||||
m_guiContext->drawQuad(backgroundImage, Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), 0), interfaceScale());
|
m_guiContext->drawQuad(backgroundImage, Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), 0), interfaceScale());
|
||||||
m_guiContext->setFontSize(fontSize);
|
m_guiContext->setFontSize(fontSize);
|
||||||
m_guiContext->setFontColor(fontColor);
|
m_guiContext->setFontColor(fontColor);
|
||||||
|
m_guiContext->setFont(font);
|
||||||
m_guiContext->renderText(*m_cursorTooltip,
|
m_guiContext->renderText(*m_cursorTooltip,
|
||||||
TextPositioning(Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), tooltipSize.y()) / 2,
|
TextPositioning(Vec2F(tooltipOffset) + Vec2F(-tooltipSize.x(), tooltipSize.y()) / 2,
|
||||||
HorizontalAnchor::HMidAnchor,
|
HorizontalAnchor::HMidAnchor,
|
||||||
|
@ -14,7 +14,7 @@ MainInterfaceConfigPtr MainInterfaceConfig::loadFromAssets() {
|
|||||||
auto config = make_shared<MainInterfaceConfig>();
|
auto config = make_shared<MainInterfaceConfig>();
|
||||||
|
|
||||||
config->fontSize = assets->json("/interface.config:font.baseSize").toInt();
|
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->inventoryImage = assets->json("/interface.config:mainBar.inventory.base").toString();
|
||||||
config->inventoryImageHover = assets->json("/interface.config:mainBar.inventory.hover").toString();
|
config->inventoryImageHover = assets->json("/interface.config:mainBar.inventory.hover").toString();
|
||||||
config->inventoryImageGlow = assets->json("/interface.config:mainBar.inventory.glow").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->debugOffset = jsonToVec2I(assets->json("/interface.config:debugOffset"));
|
||||||
config->debugFontSize = assets->json("/interface.config:debugFontSize").toUInt();
|
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->debugSpatialClearTime = assets->json("/interface.config:debugSpatialClearTime").toFloat();
|
||||||
config->debugMapClearTime = assets->json("/interface.config:debugMapClearTime").toFloat();
|
config->debugMapClearTime = assets->json("/interface.config:debugMapClearTime").toFloat();
|
||||||
config->debugBackgroundColor = jsonToColor(assets->json("/interface.config:debugBackgroundColor"));
|
config->debugBackgroundColor = jsonToColor(assets->json("/interface.config:debugBackgroundColor"));
|
||||||
|
@ -43,6 +43,7 @@ struct MainInterfaceConfig {
|
|||||||
static MainInterfaceConfigPtr loadFromAssets();
|
static MainInterfaceConfigPtr loadFromAssets();
|
||||||
|
|
||||||
unsigned fontSize;
|
unsigned fontSize;
|
||||||
|
String font;
|
||||||
|
|
||||||
String inventoryImage;
|
String inventoryImage;
|
||||||
String inventoryImageHover;
|
String inventoryImageHover;
|
||||||
@ -143,6 +144,7 @@ struct MainInterfaceConfig {
|
|||||||
|
|
||||||
Vec2I debugOffset;
|
Vec2I debugOffset;
|
||||||
unsigned debugFontSize;
|
unsigned debugFontSize;
|
||||||
|
String debugFont;
|
||||||
float debugSpatialClearTime;
|
float debugSpatialClearTime;
|
||||||
float debugMapClearTime;
|
float debugMapClearTime;
|
||||||
Color debugBackgroundColor;
|
Color debugBackgroundColor;
|
||||||
|
@ -13,6 +13,8 @@ NameplatePainter::NameplatePainter() {
|
|||||||
Json nametagConfig = assets->json("/interface.config:nametag");
|
Json nametagConfig = assets->json("/interface.config:nametag");
|
||||||
m_opacityRate = nametagConfig.getFloat("opacityRate");
|
m_opacityRate = nametagConfig.getFloat("opacityRate");
|
||||||
m_offset = jsonToVec2F(nametagConfig.get("offset"));
|
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_fontSize = nametagConfig.getFloat("fontSize");
|
||||||
m_statusFontSize = nametagConfig.getFloat("statusFontSize");
|
m_statusFontSize = nametagConfig.getFloat("statusFontSize");
|
||||||
m_statusOffset = jsonToVec2F(nametagConfig.get("statusOffset"));
|
m_statusOffset = jsonToVec2F(nametagConfig.get("statusOffset"));
|
||||||
@ -74,6 +76,7 @@ void NameplatePainter::render() {
|
|||||||
if (nametag.opacity == 0.0f)
|
if (nametag.opacity == 0.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
context.setFont(m_font);
|
||||||
context.setFontSize(m_fontSize);
|
context.setFontSize(m_fontSize);
|
||||||
|
|
||||||
auto color = Color::rgb(nametag.color);
|
auto color = Color::rgb(nametag.color);
|
||||||
@ -87,6 +90,7 @@ void NameplatePainter::render() {
|
|||||||
|
|
||||||
if (nametag.statusText) {
|
if (nametag.statusText) {
|
||||||
context.setFontSize(m_statusFontSize);
|
context.setFontSize(m_statusFontSize);
|
||||||
|
context.setFont(m_statusFont);
|
||||||
context.setFontColor(statusColor.toRgba());
|
context.setFontColor(statusColor.toRgba());
|
||||||
context.renderText(*nametag.statusText, statusPosition(bubble.currentPosition));
|
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 {
|
RectF NameplatePainter::determineBoundBox(Vec2F bubblePosition, Nametag const& nametag) const {
|
||||||
auto& context = GuiContext::singleton();
|
auto& context = GuiContext::singleton();
|
||||||
context.setFontSize(m_fontSize);
|
context.setFontSize(m_fontSize);
|
||||||
|
context.setFont(m_font);
|
||||||
RectF nametagBox = context.determineTextSize(nametag.name, namePosition(bubblePosition));
|
RectF nametagBox = context.determineTextSize(nametag.name, namePosition(bubblePosition));
|
||||||
if (nametag.statusText) {
|
if (nametag.statusText) {
|
||||||
context.setFontSize(m_statusFontSize);
|
context.setFontSize(m_statusFontSize);
|
||||||
|
context.setFont(m_statusFont);
|
||||||
nametagBox.combine(context.determineTextSize(*nametag.statusText, statusPosition(bubblePosition)));
|
nametagBox.combine(context.determineTextSize(*nametag.statusText, statusPosition(bubblePosition)));
|
||||||
}
|
}
|
||||||
return nametagBox;
|
return nametagBox;
|
||||||
|
@ -33,6 +33,8 @@ private:
|
|||||||
|
|
||||||
float m_opacityRate;
|
float m_opacityRate;
|
||||||
Vec2F m_offset;
|
Vec2F m_offset;
|
||||||
|
String m_font;
|
||||||
|
String m_statusFont;
|
||||||
float m_fontSize;
|
float m_fontSize;
|
||||||
float m_statusFontSize;
|
float m_statusFontSize;
|
||||||
Vec2F m_statusOffset;
|
Vec2F m_statusOffset;
|
||||||
|
@ -78,8 +78,8 @@ struct LuaUserDataMethods<CanvasWidgetPtr> {
|
|||||||
canvasWidget->drawTriangles(tris, color.value(Color::White).toRgba());
|
canvasWidget->drawTriangles(tris, color.value(Color::White).toRgba());
|
||||||
});
|
});
|
||||||
methods.registerMethod("drawText",
|
methods.registerMethod("drawText",
|
||||||
[](CanvasWidgetPtr canvasWidget, String text, Json tp, unsigned fontSize, Maybe<Color> color, Maybe<float> lineSpacing, Maybe<String> directives) {
|
[](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), directives.value(""));
|
canvasWidget->drawText(text, TextPositioning(tp), fontSize, color.value(Color::White).toRgba(), FontMode::Normal, lineSpacing.value(DefaultLineSpacing), font.value(""), directives.value(""));
|
||||||
});
|
});
|
||||||
|
|
||||||
return methods;
|
return methods;
|
||||||
|
@ -13,13 +13,21 @@ void FontTextureGroup::cleanup(int64_t timeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FontTextureGroup::switchFont(String const& font) {
|
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;
|
m_fontName = font;
|
||||||
auto find = m_fonts.find(font);
|
auto find = m_fonts.find(font);
|
||||||
m_font = find != m_fonts.end() ? find->second : m_defaultFont;
|
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) {
|
void FontTextureGroup::addFont(FontPtr const& font, String const& name, bool default) {
|
||||||
m_fonts[name] = font;
|
m_fonts[name] = font;
|
||||||
if (default)
|
if (default)
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
void cleanup(int64_t timeout);
|
void cleanup(int64_t timeout);
|
||||||
// Switches the current font
|
// Switches the current font
|
||||||
void switchFont(String const& font);
|
void switchFont(String const& font);
|
||||||
|
String const& activeFont();
|
||||||
void addFont(FontPtr const& font, String const& name, bool default = false);
|
void addFont(FontPtr const& font, String const& name, bool default = false);
|
||||||
private:
|
private:
|
||||||
StringMap<FontPtr> m_fonts;
|
StringMap<FontPtr> m_fonts;
|
||||||
|
@ -144,22 +144,41 @@ int TextPainter::glyphWidth(String::Char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TextPainter::stringWidth(String const& s) {
|
int TextPainter::stringWidth(String const& s) {
|
||||||
|
String font = m_renderSettings.font, setFont = font;
|
||||||
|
m_fontTextureGroup.switchFont(font);
|
||||||
int width = 0;
|
int width = 0;
|
||||||
bool escape = false;
|
bool escape = false;
|
||||||
|
|
||||||
|
String escapeCode;
|
||||||
for (String::Char c : Text::preprocessEscapeCodes(s)) {
|
for (String::Char c : Text::preprocessEscapeCodes(s)) {
|
||||||
if (c == Text::StartEsc)
|
if (c == Text::StartEsc)
|
||||||
escape = true;
|
escape = true;
|
||||||
|
|
||||||
if (!escape)
|
if (!escape)
|
||||||
width += glyphWidth(c);
|
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;
|
escape = false;
|
||||||
|
escapeCode = "";
|
||||||
|
}
|
||||||
|
if (escape && (c != Text::StartEsc))
|
||||||
|
escapeCode.append(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringList TextPainter::wrapText(String const& s, Maybe<unsigned> wrapWidth) {
|
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);
|
String text = Text::preprocessEscapeCodes(s);
|
||||||
|
|
||||||
unsigned lineStart = 0; // Where does this line start ?
|
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
|
unsigned linePixelWidth = 0; // How wide is this line so far
|
||||||
|
|
||||||
bool inEscapeSequence = false;
|
bool inEscapeSequence = false;
|
||||||
|
String escapeCode;
|
||||||
|
|
||||||
unsigned splitPos = 0; // Where did we last see a place to split the string ?
|
unsigned splitPos = 0; // Where did we last see a place to split the string ?
|
||||||
unsigned splitWidth = 0; // How wide was the string there ?
|
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
|
StringList lines; // list of renderable string lines
|
||||||
|
|
||||||
// loop through every character in the string
|
// loop through every character in the string
|
||||||
|
|
||||||
for (auto character : text) {
|
for (auto character : text) {
|
||||||
// this up here to deal with the (common) occurance that the first charcter
|
// this up here to deal with the (common) occurance that the first charcter
|
||||||
// is an escape initiator
|
// is an escape initiator
|
||||||
@ -182,8 +203,21 @@ StringList TextPainter::wrapText(String const& s, Maybe<unsigned> wrapWidth) {
|
|||||||
|
|
||||||
if (inEscapeSequence) {
|
if (inEscapeSequence) {
|
||||||
lineCharSize++; // just jump straight to the next character, we don't care what it is.
|
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;
|
inEscapeSequence = false;
|
||||||
|
escapeCode = "";
|
||||||
|
}
|
||||||
|
if (character != Text::StartEsc)
|
||||||
|
escapeCode.append(character);
|
||||||
} else {
|
} else {
|
||||||
lineCharSize++; // assume at least one character if we get here.
|
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) {
|
void TextPainter::setFont(String const& font) {
|
||||||
m_fontTextureGroup.switchFont(font);
|
m_renderSettings.font = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextPainter::addFont(FontPtr const& font, String const& name) {
|
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;
|
int height = (lines.size() - 1) * m_lineSpacing * m_fontSize + m_fontSize;
|
||||||
|
|
||||||
auto savedRenderSettings = m_renderSettings;
|
RenderSettings savedRenderSettings = m_renderSettings;
|
||||||
m_savedRenderSettings = m_renderSettings;
|
m_savedRenderSettings = m_renderSettings;
|
||||||
|
|
||||||
if (position.vAnchor == VerticalAnchor::BottomAnchor)
|
if (position.vAnchor == VerticalAnchor::BottomAnchor)
|
||||||
@ -306,7 +340,7 @@ RectF TextPainter::doRenderText(String const& s, TextPositioning const& position
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_renderSettings = savedRenderSettings;
|
m_renderSettings = move(savedRenderSettings);
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
@ -315,6 +349,7 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position
|
|||||||
String text = s;
|
String text = s;
|
||||||
TextPositioning pos = position;
|
TextPositioning pos = position;
|
||||||
|
|
||||||
|
|
||||||
if (pos.hAnchor == HorizontalAnchor::RightAnchor) {
|
if (pos.hAnchor == HorizontalAnchor::RightAnchor) {
|
||||||
auto trimmedString = s;
|
auto trimmedString = s;
|
||||||
if (charLimit)
|
if (charLimit)
|
||||||
@ -349,7 +384,7 @@ RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position
|
|||||||
pos.pos[0] += glyphBounds.width();
|
pos.pos[0] += glyphBounds.width();
|
||||||
} else if (c == Text::EndEsc) {
|
} else if (c == Text::EndEsc) {
|
||||||
auto commands = escapeCode.split(',');
|
auto commands = escapeCode.split(',');
|
||||||
for (auto command : commands) {
|
for (auto& command : commands) {
|
||||||
try {
|
try {
|
||||||
if (command == "reset") {
|
if (command == "reset") {
|
||||||
m_renderSettings = m_savedRenderSettings;
|
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) {
|
RectF TextPainter::doRenderGlyph(String::Char c, TextPositioning const& position, bool reallyRender) {
|
||||||
if (m_nonRenderedCharacters.find(String(c)) != NPos)
|
if (m_nonRenderedCharacters.find(String(c)) != NPos)
|
||||||
return RectF();
|
return RectF();
|
||||||
setFont(m_renderSettings.font);
|
m_fontTextureGroup.switchFont(m_renderSettings.font);
|
||||||
int width = glyphWidth(c);
|
int width = glyphWidth(c);
|
||||||
// Offset left by width if right anchored.
|
// Offset left by width if right anchored.
|
||||||
float hOffset = 0;
|
float hOffset = 0;
|
||||||
|
@ -25,6 +25,7 @@ ButtonWidget::ButtonWidget() {
|
|||||||
auto interfaceConfig = assets->json("/interface.config");
|
auto interfaceConfig = assets->json("/interface.config");
|
||||||
m_pressedOffset = jsonToVec2I(interfaceConfig.get("buttonPressedOffset"));
|
m_pressedOffset = jsonToVec2I(interfaceConfig.get("buttonPressedOffset"));
|
||||||
m_fontSize = interfaceConfig.query("font.buttonSize").toInt();
|
m_fontSize = interfaceConfig.query("font.buttonSize").toInt();
|
||||||
|
m_font = interfaceConfig.query("font.defaultFont").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonWidget::ButtonWidget(WidgetCallbackFunc callback,
|
ButtonWidget::ButtonWidget(WidgetCallbackFunc callback,
|
||||||
@ -89,6 +90,7 @@ void ButtonWidget::renderImpl() {
|
|||||||
if (!m_text.empty()) {
|
if (!m_text.empty()) {
|
||||||
auto& guiContext = GuiContext::singleton();
|
auto& guiContext = GuiContext::singleton();
|
||||||
guiContext.setFontSize(m_fontSize);
|
guiContext.setFontSize(m_fontSize);
|
||||||
|
guiContext.setFont(m_font);
|
||||||
if (m_disabled)
|
if (m_disabled)
|
||||||
guiContext.setFontColor(m_fontColorDisabled.toRgba());
|
guiContext.setFontColor(m_fontColorDisabled.toRgba());
|
||||||
else if (m_fontColorChecked && m_checked)
|
else if (m_fontColorChecked && m_checked)
|
||||||
|
@ -121,6 +121,7 @@ protected:
|
|||||||
Vec2U m_buttonBoundSize;
|
Vec2U m_buttonBoundSize;
|
||||||
|
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
|
String m_font;
|
||||||
String m_text;
|
String m_text;
|
||||||
Vec2I m_textOffset;
|
Vec2I m_textOffset;
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ void CanvasWidget::drawTriangles(List<tuple<Vec2F, Vec2F, Vec2F>> const& triangl
|
|||||||
m_renderOps.append(make_tuple(triangles, color));
|
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) {
|
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(processingDirectives)));
|
m_renderOps.append(make_tuple(move(s), move(position), fontSize, color, mode, lineSpacing, move(font), move(processingDirectives)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2I CanvasWidget::mousePosition() const {
|
Vec2I CanvasWidget::mousePosition() const {
|
||||||
@ -137,7 +137,7 @@ void CanvasWidget::renderImpl() {
|
|||||||
if (auto args = op.ptr<TrianglesOp>())
|
if (auto args = op.ptr<TrianglesOp>())
|
||||||
tupleUnpackFunction(bind(&CanvasWidget::renderTriangles, this, renderingOffset, _1, _2), *args);
|
tupleUnpackFunction(bind(&CanvasWidget::renderTriangles, this, renderingOffset, _1, _2), *args);
|
||||||
if (auto args = op.ptr<TextOp>())
|
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);
|
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();
|
auto& context = GuiContext::singleton();
|
||||||
context.setFontProcessingDirectives(directives);
|
context.setFontProcessingDirectives(directives);
|
||||||
context.setFontSize(fontSize);
|
context.setFontSize(fontSize);
|
||||||
context.setFontColor(color);
|
context.setFontColor(color);
|
||||||
context.setFontMode(mode);
|
context.setFontMode(mode);
|
||||||
|
context.setFont(font);
|
||||||
context.setLineSpacing(lineSpacing);
|
context.setLineSpacing(lineSpacing);
|
||||||
|
|
||||||
TextPositioning translatedPosition = position;
|
TextPositioning translatedPosition = position;
|
||||||
translatedPosition.pos += renderingOffset;
|
translatedPosition.pos += renderingOffset;
|
||||||
context.renderInterfaceText(s, translatedPosition);
|
context.renderInterfaceText(s, translatedPosition);
|
||||||
context.setDefaultLineSpacing();
|
context.setDefaultLineSpacing();
|
||||||
|
context.setDefaultFont();
|
||||||
context.setFontProcessingDirectives("");
|
context.setFontProcessingDirectives("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
void drawPoly(PolyF const& poly, Vec4B const& color = Vec4B(255, 255, 255, 255), float lineWidth = 1.0f);
|
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 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:
|
protected:
|
||||||
void renderImpl() override;
|
void renderImpl() override;
|
||||||
@ -78,7 +78,7 @@ protected:
|
|||||||
void renderRect(Vec2F const& renderingOffset, RectF const& coords, Vec4B const& color);
|
void renderRect(Vec2F const& renderingOffset, RectF const& coords, Vec4B const& color);
|
||||||
void renderPoly(Vec2F const& renderingOffset, PolyF poly, Vec4B const& color, float lineWidth);
|
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 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:
|
private:
|
||||||
bool m_captureKeyboard;
|
bool m_captureKeyboard;
|
||||||
@ -95,7 +95,7 @@ private:
|
|||||||
typedef tuple<Vec2F, Vec2F, Vec4B, float> LineOp;
|
typedef tuple<Vec2F, Vec2F, Vec4B, float> LineOp;
|
||||||
typedef tuple<PolyF, Vec4B, float> PolyOp;
|
typedef tuple<PolyF, Vec4B, float> PolyOp;
|
||||||
typedef tuple<List<tuple<Vec2F, Vec2F, Vec2F>>, Vec4B> TrianglesOp;
|
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;
|
typedef MVariant<RectOp, ImageOp, ImageRectOp, DrawableOp, TiledImageOp, LineOp, PolyOp, TrianglesOp, TextOp> RenderOp;
|
||||||
List<RenderOp> m_renderOps;
|
List<RenderOp> m_renderOps;
|
||||||
|
@ -10,6 +10,7 @@ FuelWidget::FuelWidget() {
|
|||||||
auto assets = Root::singleton().assets();
|
auto assets = Root::singleton().assets();
|
||||||
|
|
||||||
m_fontSize = assets->json("/interface.config:font.buttonSize").toInt();
|
m_fontSize = assets->json("/interface.config:font.buttonSize").toInt();
|
||||||
|
m_font = assets->json("/interface.config:font.defaultFont").toString();
|
||||||
|
|
||||||
m_fuelLevel = 0;
|
m_fuelLevel = 0;
|
||||||
m_maxLevel = 0;
|
m_maxLevel = 0;
|
||||||
@ -73,6 +74,7 @@ void FuelWidget::renderImpl() {
|
|||||||
|
|
||||||
auto& guiContext = GuiContext::singleton();
|
auto& guiContext = GuiContext::singleton();
|
||||||
guiContext.setFontSize(m_fontSize);
|
guiContext.setFontSize(m_fontSize);
|
||||||
|
guiContext.setFont(m_font);
|
||||||
if (m_potential != 0) {
|
if (m_potential != 0) {
|
||||||
guiContext.setFontColor(Color::White.toRgba());
|
guiContext.setFontColor(Color::White.toRgba());
|
||||||
} else if (m_fuelLevel == 0) {
|
} else if (m_fuelLevel == 0) {
|
||||||
|
@ -32,6 +32,7 @@ protected:
|
|||||||
float m_pingTimeout;
|
float m_pingTimeout;
|
||||||
|
|
||||||
unsigned m_fontSize;
|
unsigned m_fontSize;
|
||||||
|
String m_font;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
@ -356,6 +356,14 @@ void GuiContext::setFontProcessingDirectives(String const& directives) {
|
|||||||
textPainter()->setProcessingDirectives(directives);
|
textPainter()->setProcessingDirectives(directives);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiContext::setFont(String const& font) {
|
||||||
|
textPainter()->setFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiContext::setDefaultFont() {
|
||||||
|
textPainter()->setFont("");
|
||||||
|
}
|
||||||
|
|
||||||
void GuiContext::setLineSpacing(float lineSpacing) {
|
void GuiContext::setLineSpacing(float lineSpacing) {
|
||||||
textPainter()->setLineSpacing(lineSpacing);
|
textPainter()->setLineSpacing(lineSpacing);
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,8 @@ public:
|
|||||||
void setFontColor(Vec4B const& color);
|
void setFontColor(Vec4B const& color);
|
||||||
void setFontMode(FontMode mode);
|
void setFontMode(FontMode mode);
|
||||||
void setFontProcessingDirectives(String const& directives);
|
void setFontProcessingDirectives(String const& directives);
|
||||||
|
void setFont(String const& font);
|
||||||
|
void setDefaultFont();
|
||||||
|
|
||||||
void setLineSpacing(float lineSpacing);
|
void setLineSpacing(float lineSpacing);
|
||||||
void setDefaultLineSpacing();
|
void setDefaultLineSpacing();
|
||||||
|
@ -22,6 +22,7 @@ ItemSlotWidget::ItemSlotWidget(ItemPtr const& item, String const& backingImage)
|
|||||||
m_countPosition = TextPositioning(jsonToVec2F(interfaceConfig.get("itemCountRightAnchor")), HorizontalAnchor::RightAnchor);
|
m_countPosition = TextPositioning(jsonToVec2F(interfaceConfig.get("itemCountRightAnchor")), HorizontalAnchor::RightAnchor);
|
||||||
m_countFontMode = FontMode::Normal;
|
m_countFontMode = FontMode::Normal;
|
||||||
m_fontSize = interfaceConfig.query("font.itemSize").toInt();
|
m_fontSize = interfaceConfig.query("font.itemSize").toInt();
|
||||||
|
m_font = interfaceConfig.query("font.defaultFont").toString();
|
||||||
m_fontColor = Color::rgb(jsonToVec3B(interfaceConfig.query("font.defaultColor")));
|
m_fontColor = Color::rgb(jsonToVec3B(interfaceConfig.query("font.defaultColor")));
|
||||||
m_itemDraggableArea = jsonToRectI(interfaceConfig.get("itemDraggableArea"));
|
m_itemDraggableArea = jsonToRectI(interfaceConfig.get("itemDraggableArea"));
|
||||||
m_durabilityOffset = jsonToVec2I(interfaceConfig.get("itemIconDurabilityOffset"));
|
m_durabilityOffset = jsonToVec2I(interfaceConfig.get("itemIconDurabilityOffset"));
|
||||||
@ -181,6 +182,7 @@ void ItemSlotWidget::renderImpl() {
|
|||||||
context()->drawInterfaceQuad(strf("/interface/cooldown.png:%d", frame), Vec2F(screenPosition()));
|
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
|
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()->setFontSize(m_fontSize);
|
||||||
context()->setFontColor(m_fontColor.toRgba());
|
context()->setFontColor(m_fontColor.toRgba());
|
||||||
context()->setFontMode(m_countFontMode);
|
context()->setFontMode(m_countFontMode);
|
||||||
|
@ -57,6 +57,7 @@ private:
|
|||||||
RectI m_itemDraggableArea;
|
RectI m_itemDraggableArea;
|
||||||
|
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
|
String m_font;
|
||||||
Color m_fontColor;
|
Color m_fontColor;
|
||||||
|
|
||||||
WidgetCallbackFunc m_callback;
|
WidgetCallbackFunc m_callback;
|
||||||
|
@ -19,6 +19,7 @@ LabelWidget::LabelWidget(String text,
|
|||||||
auto fontConfig = assets->json("/interface.config:font");
|
auto fontConfig = assets->json("/interface.config:font");
|
||||||
m_fontSize = fontConfig.getInt("baseSize");
|
m_fontSize = fontConfig.getInt("baseSize");
|
||||||
m_processingDirectives = fontConfig.getString("defaultDirectives");
|
m_processingDirectives = fontConfig.getString("defaultDirectives");
|
||||||
|
m_font = fontConfig.queryString("defaultFont", "");
|
||||||
setText(move(text));
|
setText(move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +80,7 @@ RectI LabelWidget::getScissorRect() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LabelWidget::renderImpl() {
|
void LabelWidget::renderImpl() {
|
||||||
|
context()->setFont(m_font);
|
||||||
context()->setFontSize(m_fontSize);
|
context()->setFontSize(m_fontSize);
|
||||||
context()->setFontColor(m_color.toRgba());
|
context()->setFontColor(m_color.toRgba());
|
||||||
context()->setFontProcessingDirectives(m_processingDirectives);
|
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()->renderInterfaceText(m_text, {Vec2F(screenPosition()), m_hAnchor, m_vAnchor, m_wrapWidth, m_textCharLimit});
|
||||||
|
|
||||||
|
context()->setDefaultFont();
|
||||||
context()->setFontProcessingDirectives("");
|
context()->setFontProcessingDirectives("");
|
||||||
context()->setDefaultLineSpacing();
|
context()->setDefaultLineSpacing();
|
||||||
}
|
}
|
||||||
@ -98,7 +101,7 @@ void LabelWidget::updateTextRegion() {
|
|||||||
context()->setFontSize(m_fontSize);
|
context()->setFontSize(m_fontSize);
|
||||||
context()->setFontColor(m_color.toRgba());
|
context()->setFontColor(m_color.toRgba());
|
||||||
context()->setFontProcessingDirectives(m_processingDirectives);
|
context()->setFontProcessingDirectives(m_processingDirectives);
|
||||||
|
context()->setFont(m_font);
|
||||||
if (m_lineSpacing)
|
if (m_lineSpacing)
|
||||||
context()->setLineSpacing(*m_lineSpacing);
|
context()->setLineSpacing(*m_lineSpacing);
|
||||||
else
|
else
|
||||||
@ -107,6 +110,7 @@ void LabelWidget::updateTextRegion() {
|
|||||||
m_textRegion = RectI(context()->determineInterfaceTextSize(m_text, {Vec2F(), m_hAnchor, m_vAnchor, m_wrapWidth, m_textCharLimit}));
|
m_textRegion = RectI(context()->determineInterfaceTextSize(m_text, {Vec2F(), m_hAnchor, m_vAnchor, m_wrapWidth, m_textCharLimit}));
|
||||||
setSize(m_textRegion.size());
|
setSize(m_textRegion.size());
|
||||||
|
|
||||||
|
context()->setDefaultFont();
|
||||||
context()->setFontProcessingDirectives("");
|
context()->setFontProcessingDirectives("");
|
||||||
context()->setDefaultLineSpacing();
|
context()->setDefaultLineSpacing();
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ private:
|
|||||||
HorizontalAnchor m_hAnchor;
|
HorizontalAnchor m_hAnchor;
|
||||||
VerticalAnchor m_vAnchor;
|
VerticalAnchor m_vAnchor;
|
||||||
String m_processingDirectives;
|
String m_processingDirectives;
|
||||||
|
String m_font;
|
||||||
Maybe<unsigned> m_wrapWidth;
|
Maybe<unsigned> m_wrapWidth;
|
||||||
Maybe<float> m_lineSpacing;
|
Maybe<float> m_lineSpacing;
|
||||||
Maybe<unsigned> m_textCharLimit;
|
Maybe<unsigned> m_textCharLimit;
|
||||||
|
@ -29,6 +29,7 @@ Pane::Pane() {
|
|||||||
|
|
||||||
auto assets = Root::singleton().assets();
|
auto assets = Root::singleton().assets();
|
||||||
m_fontSize = assets->json("/interface.config:font.baseSize").toInt();
|
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_iconOffset = jsonToVec2I(assets->json("/interface.config:paneIconOffset"));
|
||||||
m_titleOffset = jsonToVec2I(assets->json("/interface.config:paneTitleOffset"));
|
m_titleOffset = jsonToVec2I(assets->json("/interface.config:paneTitleOffset"));
|
||||||
m_subTitleOffset = jsonToVec2I(assets->json("/interface.config:paneSubTitleOffset"));
|
m_subTitleOffset = jsonToVec2I(assets->json("/interface.config:paneSubTitleOffset"));
|
||||||
@ -203,6 +204,7 @@ void Pane::renderImpl() {
|
|||||||
m_context->resetInterfaceScissorRect();
|
m_context->resetInterfaceScissorRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_context->setFont(m_font);
|
||||||
m_context->setFontSize(m_fontSize);
|
m_context->setFontSize(m_fontSize);
|
||||||
m_context->setFontColor(m_titleColor.toRgba());
|
m_context->setFontColor(m_titleColor.toRgba());
|
||||||
m_context->setFontMode(FontMode::Shadow);
|
m_context->setFontMode(FontMode::Shadow);
|
||||||
@ -210,6 +212,7 @@ void Pane::renderImpl() {
|
|||||||
m_context->setFontColor(m_subTitleColor.toRgba());
|
m_context->setFontColor(m_subTitleColor.toRgba());
|
||||||
m_context->renderInterfaceText(m_subTitle, {headerPos + Vec2F(m_subTitleOffset)});
|
m_context->renderInterfaceText(m_subTitle, {headerPos + Vec2F(m_subTitleOffset)});
|
||||||
m_context->setFontMode(FontMode::Normal);
|
m_context->setFontMode(FontMode::Normal);
|
||||||
|
m_context->setDefaultFont();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ protected:
|
|||||||
WidgetPtr m_icon;
|
WidgetPtr m_icon;
|
||||||
String m_title;
|
String m_title;
|
||||||
String m_subTitle;
|
String m_subTitle;
|
||||||
|
String m_font;
|
||||||
unsigned m_fontSize;
|
unsigned m_fontSize;
|
||||||
Vec2I m_iconOffset;
|
Vec2I m_iconOffset;
|
||||||
Vec2I m_titleOffset;
|
Vec2I m_titleOffset;
|
||||||
|
@ -25,6 +25,7 @@ TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, Wid
|
|||||||
auto fontConfig = assets->json("/interface.config:font");
|
auto fontConfig = assets->json("/interface.config:font");
|
||||||
m_fontSize = fontConfig.getInt("baseSize");
|
m_fontSize = fontConfig.getInt("baseSize");
|
||||||
m_processingDirectives = fontConfig.getString("defaultDirectives");
|
m_processingDirectives = fontConfig.getString("defaultDirectives");
|
||||||
|
m_font = fontConfig.queryString("defaultFont", "");
|
||||||
m_color = Color::rgb(jsonToVec3B(fontConfig.getArray("defaultColor")));
|
m_color = Color::rgb(jsonToVec3B(fontConfig.getArray("defaultColor")));
|
||||||
|
|
||||||
// Meh, padding is hard-coded here
|
// Meh, padding is hard-coded here
|
||||||
@ -46,6 +47,7 @@ void TextBoxWidget::renderImpl() {
|
|||||||
else if (m_hAnchor == HorizontalAnchor::RightAnchor)
|
else if (m_hAnchor == HorizontalAnchor::RightAnchor)
|
||||||
pos += Vec2F(size()[0], 0);
|
pos += Vec2F(size()[0], 0);
|
||||||
|
|
||||||
|
context()->setFont(m_font);
|
||||||
if ((m_maxWidth != -1) && m_overfillMode) {
|
if ((m_maxWidth != -1) && m_overfillMode) {
|
||||||
context()->setFontSize(m_fontSize);
|
context()->setFontSize(m_fontSize);
|
||||||
int shift = std::max(0, getCursorOffset() - m_maxWidth);
|
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()->setFontColor(m_color.mix(Color::rgbf(0, 0, 1), blueRate).toRgba());
|
||||||
context()->renderInterfaceText(m_text, {pos, m_hAnchor, m_vAnchor});
|
context()->renderInterfaceText(m_text, {pos, m_hAnchor, m_vAnchor});
|
||||||
}
|
}
|
||||||
|
context()->setDefaultFont();
|
||||||
context()->setFontProcessingDirectives("");
|
context()->setFontProcessingDirectives("");
|
||||||
context()->setFontColor(Vec4B::filled(255));
|
context()->setFontColor(Vec4B::filled(255));
|
||||||
|
|
||||||
@ -85,6 +88,7 @@ void TextBoxWidget::renderImpl() {
|
|||||||
|
|
||||||
int TextBoxWidget::getCursorOffset() { // horizontal only
|
int TextBoxWidget::getCursorOffset() { // horizontal only
|
||||||
float scale;
|
float scale;
|
||||||
|
context()->setFont(m_font);
|
||||||
context()->setFontSize(m_fontSize);
|
context()->setFontSize(m_fontSize);
|
||||||
if (m_hAnchor == HorizontalAnchor::LeftAnchor) {
|
if (m_hAnchor == HorizontalAnchor::LeftAnchor) {
|
||||||
scale = 1.0;
|
scale = 1.0;
|
||||||
@ -391,6 +395,7 @@ bool TextBoxWidget::newTextValid(String const& text) const {
|
|||||||
if (!text.regexMatch(m_regex))
|
if (!text.regexMatch(m_regex))
|
||||||
return false;
|
return false;
|
||||||
if ((m_maxWidth != -1) && !m_overfillMode) {
|
if ((m_maxWidth != -1) && !m_overfillMode) {
|
||||||
|
context()->setFont(m_font);
|
||||||
context()->setFontSize(m_fontSize);
|
context()->setFontSize(m_fontSize);
|
||||||
return context()->stringInterfaceWidth(text) <= m_maxWidth;
|
return context()->stringInterfaceWidth(text) <= m_maxWidth;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ private:
|
|||||||
VerticalAnchor m_vAnchor;
|
VerticalAnchor m_vAnchor;
|
||||||
Color m_color;
|
Color m_color;
|
||||||
String m_processingDirectives;
|
String m_processingDirectives;
|
||||||
|
String m_font;
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
int m_maxWidth;
|
int m_maxWidth;
|
||||||
int m_cursorOffset;
|
int m_cursorOffset;
|
||||||
|
Loading…
Reference in New Issue
Block a user