#include <imagefont.hpp>
Inheritance diagram for gcn::ImageFont:
It implements the font class. You can use any filetype for the font data as long as it can be loaded with your ImageLoader.
This are two examples of an image containing a font.
The Image font format works like this: The first pixel, the pixal at coordinate (0,0), tells which color to look for when seperating glyphs. You create an image with your glyphs and simple separates them with the seperation color. When you create your ImageFont you supply the constructor with the glyphs present in your image. When creating an ImageFont for the image data in the first example above, the following constructor call would be used.
gcn::ImageFont imageFont("fixedfont_big.bmp"," abcdefghijklmno\ pqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
Definition at line 92 of file imagefont.hpp.
Public Member Functions | |
ImageFont (const std::string &filename, const std::string &glyphs) | |
Constructor which takes an image file containing the font and a string containing the glyphs. | |
ImageFont (const std::string &filename, unsigned char glyphsFrom=32, unsigned char glyphsTo=126) | |
Constructor which takes an image file containing the font and two boundaries of ASCII values. | |
virtual | ~ImageFont () |
Destructor. | |
virtual int | drawGlyph (Graphics *graphics, unsigned char glyph, int x, int y) |
Draws a glyph. | |
virtual void | setRowSpacing (int spacing) |
Sets the spacing between rows in pixels. | |
virtual int | getRowSpacing () |
Gets the spacing between rows in pixels. | |
virtual void | setGlyphSpacing (int spacing) |
Sets the spacing between letters in pixels. | |
virtual int | getGlyphSpacing () |
Gets the spacing between letters in pixels. | |
virtual int | getWidth (unsigned char glyph) const |
Gets a width of a glyph. | |
virtual int | getWidth (const std::string &text) const |
Gets the width of a string. | |
virtual void | drawString (Graphics *graphics, const std::string &text, int x, int y) |
Draws a string. | |
virtual int | getHeight () const |
Gets the height of the glyphs in the font. | |
virtual int | getStringIndexAt (const std::string &text, int x) |
Gets a string index in a string providing an x coordinate. | |
Protected Member Functions | |
void | addGlyph (unsigned char c, int &x, int &y, const Color &separator) |
Protected Attributes | |
Rectangle | mGlyph [256] |
int | mHeight |
int | mGlyphSpacing |
int | mRowSpacing |
Image * | mImage |
std::string | mFilename |
|
Constructor which 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.
Definition at line 67 of file imagefont.cpp. References gcn::ImageLoader::finalize(), gcn::ImageLoader::getHeight(), getHeight(), gcn::ImageLoader::getPixel(), and gcn::ImageLoader::getWidth(). |
|
Constructor which 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.
Definition at line 118 of file imagefont.cpp. References gcn::ImageLoader::finalize(), gcn::ImageLoader::getHeight(), getHeight(), gcn::ImageLoader::getPixel(), and gcn::ImageLoader::getWidth(). |
|
Draws a glyph. NOTE: You normally won't use this function to draw text since the Graphics class contains better functions for drawing text.
Definition at line 189 of file imagefont.cpp. References getRowSpacing(), and gcn::Rectangle::width. Referenced by drawString(). |
|
Draws a string. NOTE: You normally won't use this function to draw text since Graphics contains better functions for drawing text.
Implements gcn::Font. Definition at line 208 of file imagefont.cpp. References drawGlyph(), and getWidth(). |
|
Gets the spacing between letters in pixels.
Definition at line 234 of file imagefont.cpp. |
|
Gets the height of the glyphs in the font.
Implements gcn::Font. Definition at line 184 of file imagefont.cpp. Referenced by ImageFont(). |
|
Gets the spacing between rows in pixels.
Definition at line 224 of file imagefont.cpp. Referenced by drawGlyph(). |
|
Gets a string index in a string providing an x coordinate. Used to retrive 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 gcn::Font. Definition at line 311 of file imagefont.cpp. References getWidth(). |
|
Gets the width of a string. The width of a string is not necesserily the sum of all the widths of it's glyphs.
Implements gcn::Font. Definition at line 298 of file imagefont.cpp. References getWidth(). |
|
Gets a width of a glyph.
Definition at line 174 of file imagefont.cpp. References gcn::Rectangle::width. Referenced by drawString(), getStringIndexAt(), and getWidth(). |
|
Sets the spacing between letters in pixels. Default is 0 pixels. The spacing can be negative.
Definition at line 229 of file imagefont.cpp. |
|
Sets the spacing between rows in pixels. Default is 0 pixels. The spacing can be negative.
Definition at line 219 of file imagefont.cpp. |