|
FifeGUI 0.2.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 (ImageFont &&)=delete | |
| ImageFont (ImageFont const &)=delete | |
| ImageFont (std::string const &filename, std::string const &glyphs) | |
| 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 |
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:
Noteworthy is that the first glyph actually gives the width of space. Glyphs can, as seen in the second image example above, be separated with horizontal lines making it possible to draw glyphs on more then one line in the image. However, these horizontal lines must have a height of one pixel!
Definition at line 50 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 19 of file imagefont.cpp.
References mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, and scanForGlyph().
| 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 67 of file imagefont.cpp.
References mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, and scanForGlyph().
|
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 111 of file imagefont.cpp.
References getWidth(), mFilename, mGlyph, mGlyphSpacing, mHeight, mImage, mRowSpacing, and scanForGlyph().
|
override |
Definition at line 148 of file imagefont.cpp.
|
virtual |
Draws a glyph.
NOTE: You normally won't use this function to draw text since the Graphics class contains better functions for drawing text.
| Graphics & Rendering | 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 167 of file imagefont.cpp.
References fcn::Graphics::drawImage(), fcn::Graphics::drawRectangle(), getRowSpacing(), mGlyph, mGlyphSpacing, and mImage.
Referenced by drawString().
|
overridevirtual |
Draws a string.
NOTE: You normally won't use this function to draw text since Graphics contains better functions for drawing text.
| Graphics & Rendering | 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 189 of file imagefont.cpp.
References drawGlyph(), and getWidth().
|
virtual |
Gets the spacing between letters in pixels.
Definition at line 212 of file imagefont.cpp.
References mGlyphSpacing.
|
overridevirtual |
Gets the height of the glyphs in the font.
Implements fcn::Font.
Definition at line 162 of file imagefont.cpp.
References mHeight, and mRowSpacing.
|
virtual |
Gets the space between rows in pixels.
Definition at line 202 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 272 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 it's glyphs.
| text | The string to return the width of. |
Implements fcn::Font.
Definition at line 260 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 153 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 217 of file imagefont.cpp.
References mFilename, mHeight, and mImage.
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 207 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 197 of file imagefont.cpp.
References mRowSpacing.
|
protected |
Holds the filename of the image with the font data.
Definition at line 214 of file imagefont.hpp.
Referenced by ImageFont(), ImageFont(), ImageFont(), and scanForGlyph().
|
protected |
Holds the glyphs areas in the image.
Definition at line 189 of file imagefont.hpp.
Referenced by drawGlyph(), getWidth(), ImageFont(), ImageFont(), and ImageFont().
|
protected |
Holds the glyph spacing of the image font.
Definition at line 199 of file imagefont.hpp.
Referenced by drawGlyph(), getGlyphSpacing(), getWidth(), getWidth(), ImageFont(), ImageFont(), ImageFont(), and setGlyphSpacing().
|
protected |
Holds the height of the image font.
Definition at line 194 of file imagefont.hpp.
Referenced by getHeight(), ImageFont(), ImageFont(), ImageFont(), and scanForGlyph().
|
protected |
Holds the image with the font data.
Definition at line 209 of file imagefont.hpp.
Referenced by drawGlyph(), ImageFont(), ImageFont(), ImageFont(), and scanForGlyph().
|
protected |
Holds the row spacing of the image font.
Definition at line 204 of file imagefont.hpp.
Referenced by getHeight(), getRowSpacing(), ImageFont(), ImageFont(), ImageFont(), and setRowSpacing().