$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
#include <imagefont.h>
Public Member Functions | |
ImageFont (const std::string &filename, const std::string &glyphs) | |
ImageFont (const std::string &filename, unsigned char glyphsFrom=32, unsigned char glyphsTo=126) | |
virtual | ~ImageFont () |
virtual int | drawGlyph (Graphics *graphics, unsigned char glyph, int x, int y) |
virtual void | setRowSpacing (int spacing) |
virtual int | getRowSpacing () |
virtual void | setGlyphSpacing (int spacing) |
virtual int | getGlyphSpacing () |
virtual int | getWidth (unsigned char glyph) const |
virtual int | getWidth (const std::string &text) const |
virtual void | drawString (Graphics *graphics, const std::string &text, int x, int y) |
virtual int | getHeight () const |
virtual int | getStringIndexAt (const std::string &text, int x) |
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 |
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");
gcn::ImageFont::ImageFont | ( | const std::string & | filename, | |
const std::string & | glyphs | |||
) |
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.
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. |
gcn::ImageFont::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. 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. |
gcn::ImageFont::~ImageFont | ( | ) | [virtual] |
Destructor.
int gcn::ImageFont::drawGlyph | ( | Graphics * | graphics, | |
unsigned char | glyph, | |||
int | x, | |||
int | y | |||
) | [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 | a graphics object to be 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. |
void gcn::ImageFont::setRowSpacing | ( | int | spacing | ) | [virtual] |
Sets the spacing between rows in pixels. Default is 0 pixels. The spacing can be negative.
spacing | the spacing in pixels. |
int gcn::ImageFont::getRowSpacing | ( | ) | [virtual] |
Gets the spacing between rows in pixels.
void gcn::ImageFont::setGlyphSpacing | ( | int | spacing | ) | [virtual] |
Sets the spacing between letters in pixels. Default is 0 pixels. The spacing can be negative.
spacing | the spacing in pixels |
int gcn::ImageFont::getGlyphSpacing | ( | ) | [virtual] |
Gets the spacing between letters in pixels.
int gcn::ImageFont::getWidth | ( | unsigned char | glyph | ) | const [virtual] |
Gets a width of a glyph.
glyph | the glyph which width will be returned |
int gcn::ImageFont::getWidth | ( | const std::string & | text | ) | const [virtual] |
Gets the width of a string. The width of a string is not necesserily the sum of all the widths of it's glyphs.
text | the string to return the width of. |
Implements gcn::Font.
void gcn::ImageFont::drawString | ( | Graphics * | graphics, | |
const std::string & | text, | |||
int | x, | |||
int | y | |||
) | [virtual] |
Draws a string.
NOTE: You normally won't use this function to draw text since Graphics contains better functions for drawing text.
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 gcn::Font.
int gcn::ImageFont::getHeight | ( | ) | const [virtual] |
Gets the height of the glyphs in the font.
Implements gcn::Font.
int gcn::ImageFont::getStringIndexAt | ( | const std::string & | text, | |
int | x | |||
) | [virtual] |
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.
void gcn::ImageFont::addGlyph | ( | unsigned char | c, | |
int & | x, | |||
int & | y, | |||
const Color & | separator | |||
) | [protected] |
Rectangle gcn::ImageFont::mGlyph[256] [protected] |
int gcn::ImageFont::mHeight [protected] |
int gcn::ImageFont::mGlyphSpacing [protected] |
int gcn::ImageFont::mRowSpacing [protected] |
Image* gcn::ImageFont::mImage [protected] |
std::string gcn::ImageFont::mFilename [protected] |