OpenTTD Source: src/fontcache/spritefontcache.h Source File

OpenTTD Source 14.0-beta1

spritefontcache.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef SPRITEFONTCACHE_H
11 #define SPRITEFONTCACHE_H
12
13 #include "../string_func.h"
14 #include "../fontcache.h"
15
17 class SpriteFontCache : public FontCache {
18 private:
19 SpriteID **glyph_to_spriteid_map;
20 SpriteID GetUnicodeGlyph(char32_t key);
21
22 void ClearGlyphToSpriteMap();
23 public:
24 SpriteFontCache(FontSize fs);
25 ~SpriteFontCache();
26 void SetUnicodeGlyph(char32_t key, SpriteID sprite) override;
27 void InitializeUnicodeGlyphMap() override;
28 void ClearFontCache() override;
29 const Sprite *GetGlyph(GlyphID key) override;
30 uint GetGlyphWidth(GlyphID key) override;
31 bool GetDrawGlyphShadow() override;
32 GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { assert(IsPrintable(key)); return SPRITE_GLYPH | key; }
33 const void *GetFontTable(uint32_t, size_t &length) override { length = 0; return nullptr; }
34 std::string GetFontName() override { return "sprite"; }
35 bool IsBuiltInFont() override { return true; }
36 };
37
38 #endif /* SPRITEFONTCACHE_H */
SpriteFontCache::GetGlyph
const Sprite * GetGlyph(GlyphID key) override
Get the glyph (sprite) of the given key.
Definition: spritefontcache.cpp:122
SpriteFontCache::GetFontTable
const void * GetFontTable(uint32_t, size_t &length) override
Read a font table from the font.
Definition: spritefontcache.h:33
SpriteFontCache::GetGlyphWidth
uint GetGlyphWidth(GlyphID key) override
Get the width of the glyph with the given key.
Definition: spritefontcache.cpp:129
SpriteFontCache::InitializeUnicodeGlyphMap
void InitializeUnicodeGlyphMap() override
Initialize the glyph map.
Definition: spritefontcache.cpp:66
SpriteFontCache
Font cache for fonts that are based on a freetype font.
Definition: spritefontcache.h:17
SpriteFontCache::SetUnicodeGlyph
void SetUnicodeGlyph(char32_t key, SpriteID sprite) override
Map a SpriteID to the key.
Definition: spritefontcache.cpp:59
SpriteFontCache::GetFontName
std::string GetFontName() override
Get the name of this font.
Definition: spritefontcache.h:34
SpriteFontCache::GetDrawGlyphShadow
bool GetDrawGlyphShadow() override
Do we need to draw a glyph shadow?
Definition: spritefontcache.cpp:136
GlyphID
uint32_t GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
SpriteFontCache::glyph_to_spriteid_map
SpriteID ** glyph_to_spriteid_map
Mapping of glyphs to sprite IDs.
Definition: spritefontcache.h:19
FontCache::fs
const FontSize fs
The size of the font.
Definition: fontcache.h:25
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
SpriteFontCache::ClearFontCache
void ClearFontCache() override
Clear the font cache.
Definition: spritefontcache.cpp:115
FontCache
Font cache for basic fonts.
Definition: fontcache.h:21
SpriteFontCache::~SpriteFontCache
~SpriteFontCache()
Free everything we allocated.
Definition: spritefontcache.cpp:48
SpriteFontCache::ClearGlyphToSpriteMap
void ClearGlyphToSpriteMap()
Clear the glyph to sprite mapping.
Definition: spritefontcache.cpp:104
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
SpriteFontCache::IsBuiltInFont
bool IsBuiltInFont() override
Is this a built-in sprite font?
Definition: spritefontcache.h:35
SpriteFontCache::SpriteFontCache
SpriteFontCache(FontSize fs)
Create a new sprite font cache.
Definition: spritefontcache.cpp:38
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17