FifeGUI 0.2.0
A C++ GUI library designed for games.
imagefont.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_IMAGEFONT_HPP_
6#define INCLUDE_FIFECHAN_IMAGEFONT_HPP_
7
8#include <array>
9#include <string>
10
11#include "fifechan/font.hpp"
12#include "fifechan/platform.hpp"
13#include "fifechan/rectangle.hpp"
14
15namespace fcn
16{
17 class Color;
18 class Graphics;
19 class Image;
20
50 class FIFEGUI_API ImageFont : public Font
51 {
52 public:
63 ImageFont(std::string const & filename, std::string const & glyphs);
64
76 ImageFont(Image* image, std::string const & glyphs);
77
92 explicit ImageFont(std::string const & filename, unsigned char glyphsFrom = 32, unsigned char glyphsTo = 126);
93
94 ~ImageFont() override;
95
96 ImageFont(ImageFont const &) = delete;
97 ImageFont& operator=(ImageFont const &) = delete;
98 ImageFont(ImageFont&&) = delete;
99 ImageFont& operator=(ImageFont&&) = delete;
100
114 virtual int drawGlyph(Graphics* graphics, unsigned char glyph, int x, int y);
115
123 virtual void setRowSpacing(int spacing);
124
131 virtual int getRowSpacing();
132
140 virtual void setGlyphSpacing(int spacing);
141
148 virtual int getGlyphSpacing();
149
156 virtual int getWidth(unsigned char glyph) const;
157
158 // Inherited from Font
159
160 int getWidth(std::string const & text) const override;
161
162 void drawString(Graphics* graphics, std::string const & text, int x, int y) override;
163
164 int getHeight() const override;
165
166 int getStringIndexAt(std::string const & text, int x) const override;
167
168 protected:
184 Rectangle scanForGlyph(unsigned char glyph, int x, int y, Color const & separator);
185
189 std::array<Rectangle, 256> mGlyph;
190
194 int mHeight{0};
195
200
205
209 Image* mImage{nullptr};
210
214 std::string mFilename;
215 };
216} // namespace fcn
217
218#endif // INCLUDE_FIFECHAN_IMAGEFONT_HPP_
Color.
Definition color.hpp:56
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
virtual int getRowSpacing()
Gets the space between rows in pixels.
int mHeight
Holds the height of the image font.
virtual int drawGlyph(Graphics *graphics, unsigned char glyph, int x, int y)
Draws a glyph.
int getHeight() const override
Gets the height of the glyphs in the font.
int getStringIndexAt(std::string const &text, int x) const override
Gets a string index in a string providing an x coordinate.
Rectangle scanForGlyph(unsigned char glyph, int x, int y, Color const &separator)
Scans for a certain glyph.
Image * mImage
Holds the image with the font data.
std::array< Rectangle, 256 > mGlyph
Holds the glyphs areas in the image.
std::string mFilename
Holds the filename of the image with the font data.
virtual void setRowSpacing(int spacing)
Sets the space between rows in pixels.
ImageFont(std::string const &filename, std::string const &glyphs)
Constructor.
Definition imagefont.cpp:19
virtual int getWidth(unsigned char glyph) const
Gets a width of a glyph in pixels.
virtual int getGlyphSpacing()
Gets the spacing between letters in pixels.
virtual void setGlyphSpacing(int spacing)
Sets the spacing between glyphs in pixels.
int mGlyphSpacing
Holds the glyph spacing of the image font.
int mRowSpacing
Holds the row spacing of the image font.
void drawString(Graphics *graphics, std::string const &text, int x, int y) override
Draws a string.
Abstract holder for image data.
Definition image.hpp:32
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20