Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/rendering
diff options
context:
space:
mode:
Diffstat (limited to 'source/rendering')
-rw-r--r--source/rendering/StarFontTextureGroup.cpp24
-rw-r--r--source/rendering/StarFontTextureGroup.hpp21
-rw-r--r--source/rendering/StarTextPainter.cpp16
3 files changed, 41 insertions, 20 deletions
diff --git a/source/rendering/StarFontTextureGroup.cpp b/source/rendering/StarFontTextureGroup.cpp
index 038b535..7517c8b 100644
--- a/source/rendering/StarFontTextureGroup.cpp
+++ b/source/rendering/StarFontTextureGroup.cpp
@@ -12,24 +12,34 @@ void FontTextureGroup::cleanup(int64_t timeout) {
eraseWhere(m_glyphs, [&](auto const& p) { return currentTime - p.second.time > timeout; });
}
-TexturePtr FontTextureGroup::glyphTexture(String::Char c, unsigned size) {
- return glyphTexture(c, size, "");
-}
-
-TexturePtr FontTextureGroup::glyphTexture(String::Char c, unsigned size, String const& processingDirectives) {
+const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Char c, unsigned size, String const& processingDirectives)
+{
auto res = m_glyphs.insert(GlyphDescriptor{c, size, processingDirectives}, GlyphTexture());
if (res.second) {
m_font->setPixelSize(size);
Image image = m_font->render(c);
- if (!processingDirectives.empty())
+ if (!processingDirectives.empty()) {
+ Vec2F preSize = Vec2F(image.size());
image = processImageOperations(parseImageOperations(processingDirectives), image);
+ res.first->second.processingOffset = preSize - Vec2F(image.size());
+ }
+ else
+ res.first->second.processingOffset = Vec2F();
res.first->second.texture = m_textureGroup->create(image);
}
res.first->second.time = Time::monotonicMilliseconds();
- return res.first->second.texture;
+ return res.first->second;
+}
+
+TexturePtr FontTextureGroup::glyphTexturePtr(String::Char c, unsigned size) {
+ return glyphTexture(c, size, "").texture;
+}
+
+TexturePtr FontTextureGroup::glyphTexturePtr(String::Char c, unsigned size, String const& processingDirectives) {
+ return glyphTexture(c, size, processingDirectives).texture;
}
unsigned FontTextureGroup::glyphWidth(String::Char c, unsigned fontSize) {
diff --git a/source/rendering/StarFontTextureGroup.hpp b/source/rendering/StarFontTextureGroup.hpp
index d933f1e..17c6467 100644
--- a/source/rendering/StarFontTextureGroup.hpp
+++ b/source/rendering/StarFontTextureGroup.hpp
@@ -11,24 +11,27 @@ STAR_CLASS(FontTextureGroup);
class FontTextureGroup {
public:
+ typedef tuple<String::Char, unsigned, String> GlyphDescriptor;
+
+ struct GlyphTexture {
+ TexturePtr texture;
+ int64_t time;
+ Vec2F processingOffset;
+ };
+
FontTextureGroup(FontPtr font, TextureGroupPtr textureGroup);
- TexturePtr glyphTexture(String::Char, unsigned fontSize);
- TexturePtr glyphTexture(String::Char, unsigned fontSize, String const& processingDirectives);
+ const GlyphTexture& glyphTexture(String::Char, unsigned fontSize, String const& processingDirectives);
+
+ TexturePtr glyphTexturePtr(String::Char, unsigned fontSize);
+ TexturePtr glyphTexturePtr(String::Char, unsigned fontSize, String const& processingDirectives);
unsigned glyphWidth(String::Char c, unsigned fontSize);
// Removes glyphs that haven't been used in more than the given time in
// milliseconds
void cleanup(int64_t timeout);
-
private:
- typedef tuple<String::Char, unsigned, String> GlyphDescriptor;
-
- struct GlyphTexture {
- TexturePtr texture;
- int64_t time;
- };
FontPtr m_font;
TextureGroupPtr m_textureGroup;
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp
index 0ef374d..205aefe 100644
--- a/source/rendering/StarTextPainter.cpp
+++ b/source/rendering/StarTextPainter.cpp
@@ -379,9 +379,16 @@ RectF TextPainter::doRenderGlyph(String::Char c, TextPositioning const& position
if (reallyRender) {
if ((int)m_renderSettings.mode & (int)FontMode::Shadow) {
Color shadow = Color::Black;
- shadow.setAlpha(m_renderSettings.color[3]);
+ uint8_t alphaU = m_renderSettings.color[3];
+ if (alphaU != 255) {
+ float alpha = byteToFloat(alphaU);
+ shadow.setAlpha(floatToByte(alpha * (1.5f - 0.5f * alpha)));
+ }
+ else
+ shadow.setAlpha(alphaU);
+
+ //Kae: Draw only one shadow glyph instead of stacking two, alpha modified to appear perceptually the same as vanilla
renderGlyph(c, position.pos + Vec2F(hOffset, vOffset - 2), m_fontSize, 1, shadow.toRgba(), m_processingDirectives);
- renderGlyph(c, position.pos + Vec2F(hOffset, vOffset - 1), m_fontSize, 1, shadow.toRgba(), m_processingDirectives);
}
renderGlyph(c, position.pos + Vec2F(hOffset, vOffset), m_fontSize, 1, m_renderSettings.color, m_processingDirectives);
@@ -395,8 +402,9 @@ void TextPainter::renderGlyph(String::Char c, Vec2F const& screenPos, unsigned f
if (!fontSize)
return;
- auto texture = m_fontTextureGroup.glyphTexture(c, fontSize, processingDirectives);
- m_renderer->render(renderTexturedRect(move(texture), Vec2F(screenPos), scale, color, 0.0f));
+ const FontTextureGroup::GlyphTexture& glyphTexture = m_fontTextureGroup.glyphTexture(c, fontSize, processingDirectives);
+ Vec2F offset = glyphTexture.processingOffset * (scale * 0.5f); //Kae: Re-center the glyph if the image scale was changed by the directives (it is positioned from the bottom left)
+ m_renderer->render(renderTexturedRect(glyphTexture.texture, Vec2F(screenPos) + offset, scale, color, 0.0f));
}
}