Mana
Loading...
Searching...
No Matches
truetypefont.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 * Copyright (C) 2009 Aethyra Development Team
6 *
7 * This file is part of The Mana Client.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#pragma once
24
25#include <guichan/color.hpp>
26#include <guichan/font.hpp>
27
28#include <SDL_ttf.h>
29
30#include <list>
31#include <optional>
32#include <string>
33
34class Graphics;
35class TextChunk;
36
42class TrueTypeFont : public gcn::Font
43{
44 public:
51 TrueTypeFont(const std::string &filename, int size, int style = 0);
52 ~TrueTypeFont() override;
53
54 const std::string &filename() const { return mFilename; }
55 int pointSize() const { return mPointSize; }
56 int style() const { return mStyle; }
57
58 int getWidth(const std::string &text) const override;
59 int getHeight() const override;
60
66 int getLineHeight() const;
67
71 void drawString(gcn::Graphics *graphics,
72 const std::string &text,
73 int x, int y) override;
74
80 const std::string &text,
81 int x, int y,
82 const std::optional<gcn::Color> &outlineColor,
83 const std::optional<gcn::Color> &shadowColor);
84
85 static void updateFontScale(float scale);
86
87 private:
88 TextChunk &getChunk(const std::string &text) const;
89
90 const std::string mFilename;
91 TTF_Font *mFont = nullptr;
92 TTF_Font *mFontOutline = nullptr;
93
94 const int mPointSize;
95 const int mStyle;
96
97 // Word surfaces cache
98 mutable std::list<TextChunk> mCache;
99
100 static std::list<TrueTypeFont*> mFonts;
101 static float mScale;
102};
A central point of control for graphics.
Definition graphics.h:78
A wrapper around SDL_ttf for allowing the use of TrueType fonts.
~TrueTypeFont() override
const int mPointSize
int getWidth(const std::string &text) const override
static std::list< TrueTypeFont * > mFonts
TTF_Font * mFont
static void updateFontScale(float scale)
TextChunk & getChunk(const std::string &text) const
TTF_Font * mFontOutline
int getLineHeight() const
Returns the height of a line of text.
static float mScale
int pointSize() const
const std::string & filename() const
const int mStyle
int style() const
const std::string mFilename
std::list< TextChunk > mCache
int getHeight() const override
void drawString(gcn::Graphics *graphics, const std::string &text, int x, int y) override
Graphics * graphics
Definition client.cpp:104