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

summaryrefslogtreecommitdiff
path: root/source/rendering/StarFontTextureGroup.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/rendering/StarFontTextureGroup.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/rendering/StarFontTextureGroup.cpp')
-rw-r--r--source/rendering/StarFontTextureGroup.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/rendering/StarFontTextureGroup.cpp b/source/rendering/StarFontTextureGroup.cpp
new file mode 100644
index 0000000..038b535
--- /dev/null
+++ b/source/rendering/StarFontTextureGroup.cpp
@@ -0,0 +1,40 @@
+#include "StarFontTextureGroup.hpp"
+#include "StarTime.hpp"
+#include "StarImageProcessing.hpp"
+
+namespace Star {
+
+FontTextureGroup::FontTextureGroup(FontPtr font, TextureGroupPtr textureGroup)
+ : m_font(move(font)), m_textureGroup(move(textureGroup)) {}
+
+void FontTextureGroup::cleanup(int64_t timeout) {
+ int64_t currentTime = Time::monotonicMilliseconds();
+ 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) {
+ 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())
+ image = processImageOperations(parseImageOperations(processingDirectives), image);
+
+ res.first->second.texture = m_textureGroup->create(image);
+ }
+
+ res.first->second.time = Time::monotonicMilliseconds();
+ return res.first->second.texture;
+}
+
+unsigned FontTextureGroup::glyphWidth(String::Char c, unsigned fontSize) {
+ m_font->setPixelSize(fontSize);
+ return m_font->width(c);
+}
+
+}