|
FifeGUI 0.3.0
A C++ GUI library designed for games.
|
#include <imagefont.hpp>
Public Member Functions | |
| virtual int | drawGlyph (Graphics *graphics, unsigned char glyph, int x, int y) |
| void | drawString (Graphics *graphics, std::string const &text, int x, int y) override |
| virtual int | getGlyphSpacing () |
| int | getHeight () const override |
| virtual int | getRowSpacing () |
| int | getStringIndexAt (std::string const &text, int x) const override |
| int | getWidth (std::string const &text) const override |
| virtual int | getWidth (unsigned char glyph) const |
| ImageFont (Image *image, std::string const &glyphs) | |
| ImageFont (Image *image, std::string const &glyphs, ImageFontConfig const &config) | |
| ImageFont (ImageFont &&)=delete | |
| ImageFont (ImageFont const &)=delete | |
| ImageFont (std::string const &filename, std::string const &glyphs) | |
| ImageFont (std::string const &filename, std::string const &glyphs, ImageFontConfig const &config) | |
| ImageFont (std::string const &filename, unsigned char glyphsFrom, unsigned char glyphsTo, ImageFontConfig const &config) | |
| ImageFont (std::string const &filename, unsigned char glyphsFrom=32, unsigned char glyphsTo=126) | |
| ImageFont & | operator= (ImageFont &&)=delete |
| ImageFont & | operator= (ImageFont const &)=delete |
| virtual void | setGlyphSpacing (int spacing) |
| virtual void | setRowSpacing (int spacing) |
| Public Member Functions inherited from fcn::Font | |
| Font (Font &&)=default | |
| Font (Font const &)=default | |
| Font & | operator= (Font &&)=default |
| Font & | operator= (Font const &)=default |
| virtual | ~Font ()=default |
Protected Member Functions | |
| Rectangle | scanForGlyph (unsigned char glyph, int x, int y, Color const &separator) |
Protected Attributes | |
| std::string | mFilename |
| std::array< Rectangle, 256 > | mGlyph |
| int | mGlyphSpacing {0} |
| int | mHeight {0} |
| Image * | mImage {nullptr} |
| int | mRowSpacing {0} |
A font implementation using an image atlas containing glyph data.
ImageFont can be used with any image supported by the currently used ImageLoader.
These are two examples of an image containing a font.
The first pixel at coordinate (0,0) tells which color the image font looks for when separating glyphs. The glyphs in the image is provided to the image font's constructor in the order they appear in the image.
To create an ImageFont from the first image example above the following constructor call should be made:
The first glyph defines the width of a space.
Glyphs can span multiple lines using horizontal separators, but these must be exactly 1 pixel high.
Space glyph: If included (e.g. as the first glyph), its width defines the logical space width. Otherwise, ImageFont uses a default.
Vertical separators: Glyphs are divided by columns of a single color. These may span multiple adjacent columns; any column where all pixels match the separator color is treated as part of a separator. This allows flexible spacing (e.g. wider gaps before punctuation).
Horizontal separators: Used to split glyph rows and must be exactly 1 pixel high. Multi-pixel rows are not recognized and may break row detection. If your atlas uses thicker dividers, convert them to 1-pixel rows or use an explicit separator strategy. Support for multi-pixel separators can be added if needed.
Definition at line 126 of file imagefont.hpp.
| fcn::ImageFont::ImageFont | ( | std::string const & | filename, |
| std::string const & | glyphs ) |
Constructor.
Takes an image file containing the font and a string containing the glyphs. The glyphs in the string should be in the same order as they appear in the font image.
| filename | The filename of the image. |
| glyphs | The glyphs found in the image. |
| Exception | when glyph list is incorrect or the font file is corrupt or if no ImageLoader exists. |
Definition at line 232 of file imagefont.cpp.
References mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, and scanForGlyph().
| fcn::ImageFont::ImageFont | ( | std::string const & | filename, |
| std::string const & | glyphs, | ||
| ImageFontConfig const & | config ) |
Constructor with configuration.
| filename | The filename of the image. |
| glyphs | The glyphs found in the image. |
| config | Configuration for parsing the image font. |
Definition at line 180 of file imagefont.cpp.
References fcn::Color::b, fcn::Color::g, fcn::ImageFontConfig::glyphPadding, fcn::Rectangle::height, mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, fcn::Color::r, fcn::ImageFontConfig::strategy, fcn::throwException(), fcn::ImageFontConfig::verbose, fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.
| fcn::ImageFont::ImageFont | ( | Image * | image, |
| std::string const & | glyphs ) |
Constructor.
Takes an image containing the font and a string containing the glyphs. The glyphs in the string should be in the same order as they appear in the font image. The image will be deleted in the destructor.
| image | The image with font glyphs. |
| glyphs | The glyphs found in the image. |
| Exception | when glyph list is incorrect or the font image is is missing. |
Definition at line 280 of file imagefont.cpp.
References mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, scanForGlyph(), and fcn::throwException().
| fcn::ImageFont::ImageFont | ( | Image * | image, |
| std::string const & | glyphs, | ||
| ImageFontConfig const & | config ) |
Constructor from an image with configuration.
The image will be owned by the ImageFont instance.
| image | The image with font glyphs. |
| glyphs | The glyphs found in the image. |
| config | Configuration for parsing the image font. |
Definition at line 324 of file imagefont.cpp.
References fcn::Color::b, fcn::Color::g, fcn::ImageFontConfig::glyphPadding, mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, fcn::Color::r, fcn::ImageFontConfig::strategy, fcn::throwException(), and fcn::ImageFontConfig::verbose.
|
explicit |
Constructor.
Takes an image file containing the font and two boundaries of ASCII values. The font image should include all glyphs specified with the boundaries in increasing ASCII order. The boundaries are inclusive.
| filename | The filename of the image. |
| glyphsFrom | The ASCII value of the first glyph found in the image. |
| glyphsTo | The ASCII value of the last glyph found in the image. |
| Exception | when glyph bondaries are incorrect or the font file is corrupt or if no ImageLoader exists. |
Definition at line 364 of file imagefont.cpp.
References getWidth(), mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, and scanForGlyph().
| fcn::ImageFont::ImageFont | ( | std::string const & | filename, |
| unsigned char | glyphsFrom, | ||
| unsigned char | glyphsTo, | ||
| ImageFontConfig const & | config ) |
Constructor defining glyph range with configuration.
| filename | The filename of the image. |
| glyphsFrom | ASCII of the first glyph (inclusive). |
| glyphsTo | ASCII of the last glyph (inclusive). |
| config | Configuration for parsing the image font. |
Definition at line 402 of file imagefont.cpp.
References fcn::Color::b, fcn::Color::g, fcn::ImageFontConfig::glyphPadding, mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, fcn::Color::r, fcn::ImageFontConfig::strategy, fcn::throwException(), and fcn::ImageFontConfig::verbose.
|
override |
Definition at line 447 of file imagefont.cpp.
|
virtual |
Draws a glyph.
| graphics | A graphics object used for drawing. |
| glyph | A glyph to draw. |
| x | The x coordinate where to draw the glyph. |
| y | The y coordinate where to draw the glyph. |
Definition at line 466 of file imagefont.cpp.
References fcn::Graphics::drawImage(), fcn::Graphics::drawRectangle(), getRowSpacing(), mGlyph, mGlyphSpacing, and mImage.
Referenced by drawString().
|
overridevirtual |
Draws a string.
| graphics | A Graphics object to use for drawing. |
| text | The string to draw. |
| x | The x coordinate where to draw the string. |
| y | The y coordinate where to draw the string. |
Implements fcn::Font.
Definition at line 494 of file imagefont.cpp.
References drawGlyph(), and getWidth().
|
virtual |
Gets the spacing between letters in pixels.
Definition at line 517 of file imagefont.cpp.
References mGlyphSpacing.
|
overridevirtual |
Gets the height of the glyphs in the font.
Implements fcn::Font.
Definition at line 461 of file imagefont.cpp.
References mHeight, and mRowSpacing.
|
virtual |
Gets the space between rows in pixels.
Definition at line 507 of file imagefont.cpp.
References mRowSpacing.
Referenced by drawGlyph().
|
overridevirtual |
Gets a string index in a string providing an x coordinate.
Used to retrieve a string index (for a character in a string) at a certain x position. It is especially useful when a mouse clicks in a TextField and you want to know which character was clicked.
Reimplemented from fcn::Font.
Definition at line 586 of file imagefont.cpp.
References getWidth().
|
overridevirtual |
Gets the width of a string.
The width of a string is not necessarily the sum of all the widths of its glyphs.
| text | The string to return the width of. |
Implements fcn::Font.
Definition at line 574 of file imagefont.cpp.
References getWidth(), and mGlyphSpacing.
|
virtual |
Gets a width of a glyph in pixels.
| glyph | The glyph which width will be returned. |
Definition at line 452 of file imagefont.cpp.
References mGlyph, and mGlyphSpacing.
Referenced by drawString(), getStringIndexAt(), getWidth(), and ImageFont().
|
protected |
Scans for a certain glyph.
| glyph | The glyph to scan for. Used for exception messages. |
| x | The x coordinate where to begin the scan. The coordinate will be updated with the end x coordinate of the glyph when the scan is complete. |
| y | The y coordinate where to begin the scan. The coordinate will be updated with the end y coordinate of the glyph when the scan is complete. |
| separator | The color separator to look for where the glyph ends. |
| Exception | when no glyph is found. |
Definition at line 522 of file imagefont.cpp.
References mFilename, mHeight, mImage, and fcn::throwException().
Referenced by ImageFont(), ImageFont(), and ImageFont().
|
virtual |
Sets the spacing between glyphs in pixels.
Default is 0 pixels. The space can be negative.
| spacing | The glyph space in pixels. |
Definition at line 512 of file imagefont.cpp.
References mGlyphSpacing.
|
virtual |
Sets the space between rows in pixels.
Default is 0 pixels. The space can be negative.
| spacing | The space between rows in pixels. |
Definition at line 502 of file imagefont.cpp.
References mRowSpacing.
|
protected |
Holds the filename of the image with the font data.
Definition at line 324 of file imagefont.hpp.
Referenced by ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), and scanForGlyph().
|
protected |
Holds the glyphs areas in the image.
Definition at line 299 of file imagefont.hpp.
Referenced by drawGlyph(), getWidth(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), and ImageFont().
|
protected |
Holds the glyph spacing of the image font.
Definition at line 309 of file imagefont.hpp.
Referenced by drawGlyph(), getGlyphSpacing(), getWidth(), getWidth(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), and setGlyphSpacing().
|
protected |
Holds the height of the image font.
Definition at line 304 of file imagefont.hpp.
Referenced by getHeight(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), and scanForGlyph().
|
protected |
Holds the image with the font data.
Definition at line 319 of file imagefont.hpp.
Referenced by drawGlyph(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), and scanForGlyph().
|
protected |
Holds the row spacing of the image font.
Definition at line 314 of file imagefont.hpp.
Referenced by getHeight(), getRowSpacing(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), ImageFont(), and setRowSpacing().