#include <Font.h>
Classes | |
class | Glyph |
Public Types | |
enum | Style { PLAIN = 0, BOLD = 1, ITALIC = 2, BOLD_ITALIC = 4 } |
enum | Justify { ALIGN_LEFT = 0x01, ALIGN_HCENTER = 0x02, ALIGN_RIGHT = 0x04, ALIGN_TOP = 0x10, ALIGN_VCENTER = 0x20, ALIGN_BOTTOM = 0x40, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT, ALIGN_VCENTER_LEFT = ALIGN_VCENTER | ALIGN_LEFT, ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT, ALIGN_TOP_HCENTER = ALIGN_TOP | ALIGN_HCENTER, ALIGN_VCENTER_HCENTER = ALIGN_VCENTER | ALIGN_HCENTER, ALIGN_BOTTOM_HCENTER = ALIGN_BOTTOM | ALIGN_HCENTER, ALIGN_TOP_RIGHT = ALIGN_TOP | ALIGN_RIGHT, ALIGN_VCENTER_RIGHT = ALIGN_VCENTER | ALIGN_RIGHT, ALIGN_BOTTOM_RIGHT = ALIGN_BOTTOM | ALIGN_RIGHT } |
enum | Format { BITMAP = 0, DISTANCE_FIELD = 1 } |
Public Member Functions | |
unsigned int | getSize (unsigned int index=0) const |
unsigned int | getSizeCount () const |
Format | getFormat () |
bool | isCharacterSupported (int character) const |
void | start () |
void | drawText (const char *text, int x, int y, const Vector4 &color, unsigned int size=0, bool rightToLeft=false) |
void | drawText (const char *text, int x, int y, float red, float green, float blue, float alpha, unsigned int size=0, bool rightToLeft=false) |
void | drawText (const char *text, const Rectangle &area, const Vector4 &color, unsigned int size=0, Justify justify=ALIGN_TOP_LEFT, bool wrap=true, bool rightToLeft=false, const Rectangle &clip=Rectangle(0, 0, 0, 0)) |
void | finish () |
void | measureText (const char *text, unsigned int size, unsigned int *widthOut, unsigned int *heightOut) |
void | measureText (const char *text, const Rectangle &clip, unsigned int size, Rectangle *out, Justify justify=ALIGN_TOP_LEFT, bool wrap=true, bool ignoreClip=false) |
float | getCharacterSpacing () const |
void | setCharacterSpacing (float spacing) |
int | getIndexAtLocation (const char *text, const Rectangle &clip, unsigned int size, const Vector2 &inLocation, Vector2 *outLocation, Justify justify=ALIGN_TOP_LEFT, bool wrap=true, bool rightToLeft=false) |
void | getLocationAtIndex (const char *text, const Rectangle &clip, unsigned int size, Vector2 *outLocation, const unsigned int destIndex, Justify justify=ALIGN_TOP_LEFT, bool wrap=true, bool rightToLeft=false) |
SpriteBatch * | getSpriteBatch (unsigned int size) const |
Static Public Member Functions | |
static Font * | create (const char *path, const char *id=NULL) |
static Justify | getJustify (const char *justify) |
Defines a font for text rendering.
Defines the format of the font.
Defines the set of allowable alignments when drawing text.
Defines the set of allowable font styles.
static Font* gameplay::Font::create | ( | const char * | path, |
const char * | id = NULL |
||
) | [static] |
Creates a font from the given bundle.
If the 'id' parameter is NULL, it is assumed that the Bundle at 'path' contains exactly one Font resource. If the Bundle does not meet this criteria, NULL is returned.
If a font for the given path has already been loaded, the existing font will be returned with its reference count increased.
path | The path to a bundle file containing a font resource. |
id | An optional ID of the font resource within the bundle (NULL for the first/only resource). |
void gameplay::Font::drawText | ( | const char * | text, |
int | x, | ||
int | y, | ||
const Vector4 & | color, | ||
unsigned int | size = 0 , |
||
bool | rightToLeft = false |
||
) |
Draws the specified text in a solid color, with a scaling factor.
text | The text to draw. |
x | The viewport x position to draw text at. |
y | The viewport y position to draw text at. |
color | The color of text. |
size | The size to draw text (0 for default size). |
rightToLeft | Whether to draw text from right to left. |
void gameplay::Font::drawText | ( | const char * | text, |
int | x, | ||
int | y, | ||
float | red, | ||
float | green, | ||
float | blue, | ||
float | alpha, | ||
unsigned int | size = 0 , |
||
bool | rightToLeft = false |
||
) |
Draws the specified text in a solid color, with a scaling factor.
text | The text to draw. |
x | The viewport x position to draw text at. |
y | The viewport y position to draw text at. |
red | The red channel of the text color. |
green | The green channel of the text color. |
blue | The blue channel of the text color. |
alpha | The alpha channel of the text color. |
size | The size to draw text (0 for default size). |
rightToLeft | Whether to draw text from right to left. |
void gameplay::Font::drawText | ( | const char * | text, |
const Rectangle & | area, | ||
const Vector4 & | color, | ||
unsigned int | size = 0 , |
||
Justify | justify = ALIGN_TOP_LEFT , |
||
bool | wrap = true , |
||
bool | rightToLeft = false , |
||
const Rectangle & | clip = Rectangle(0, 0, 0, 0) |
||
) |
Draws the specified text within a rectangular area, with a specified alignment and scale. Clips text outside the viewport. Optionally wraps text to fit within the width of the viewport.
text | The text to draw. |
area | The viewport area to draw within. Text will be clipped outside this rectangle. |
color | The color of text. |
size | The size to draw text (0 for default size). |
justify | Justification of text within the viewport. |
wrap | Wraps text to fit within the width of the viewport if true. |
rightToLeft | Whether to draw text from right to left. |
clip | A region to clip text within after applying justification to the viewport area. |
void gameplay::Font::finish | ( | ) |
Finishes text batching for this font and renders all drawn text.
float gameplay::Font::getCharacterSpacing | ( | ) | const |
Returns current character spacing for this font in percentage of fonts size.
Gets the font format. BITMAP or DISTANCEMAP.
int gameplay::Font::getIndexAtLocation | ( | const char * | text, |
const Rectangle & | clip, | ||
unsigned int | size, | ||
const Vector2 & | inLocation, | ||
Vector2 * | outLocation, | ||
Justify | justify = ALIGN_TOP_LEFT , |
||
bool | wrap = true , |
||
bool | rightToLeft = false |
||
) |
Get an character index into a string corresponding to the character nearest the given location within the clip region.
static Justify gameplay::Font::getJustify | ( | const char * | justify | ) | [static] |
Gets the Justify value from the given string. Returns ALIGN_TOP_LEFT if the string is unrecognized.
justify | The string such as "ALIGN_HCENTER" or "ALIGN_VCENTER_RIGHT". |
void gameplay::Font::getLocationAtIndex | ( | const char * | text, |
const Rectangle & | clip, | ||
unsigned int | size, | ||
Vector2 * | outLocation, | ||
const unsigned int | destIndex, | ||
Justify | justify = ALIGN_TOP_LEFT , |
||
bool | wrap = true , |
||
bool | rightToLeft = false |
||
) |
Get the location of the character at the given index.
unsigned int gameplay::Font::getSize | ( | unsigned int | index = 0 | ) | const |
Gets the font size (max height of glyphs) in pixels, at the specified index.
The Font class can store multiple sizes of glyphs for a font. The number of font sizes stored can be retrieved via getSizeCount.
index | Index of the size to returned (default is 0). |
unsigned int gameplay::Font::getSizeCount | ( | ) | const |
Returns the number of font sizes supported by this Font.
SpriteBatch* gameplay::Font::getSpriteBatch | ( | unsigned int | size | ) | const |
Gets the sprite batch used to draw this Font.
size | The font size to be drawn. |
bool gameplay::Font::isCharacterSupported | ( | int | character | ) | const |
Determines if this font supports the specified character code.
character | The character code to check. |
void gameplay::Font::measureText | ( | const char * | text, |
unsigned int | size, | ||
unsigned int * | widthOut, | ||
unsigned int * | heightOut | ||
) |
Measures a string's width and height without alignment, wrapping or clipping.
text | The text to measure. |
size | The font height to scale to. |
widthOut | Destination for the text's width. |
heightOut | Destination for the text's height. |
void gameplay::Font::measureText | ( | const char * | text, |
const Rectangle & | clip, | ||
unsigned int | size, | ||
Rectangle * | out, | ||
Justify | justify = ALIGN_TOP_LEFT , |
||
bool | wrap = true , |
||
bool | ignoreClip = false |
||
) |
Measures a string's bounding box after alignment, wrapping and clipping within a viewport.
text | The text to measure. |
clip | The clip rectangle. |
size | The font height to scale to. |
out | Destination rectangle to store the bounds in. |
justify | Justification of text within the viewport. |
wrap | Whether to measure text with wrapping applied. |
ignoreClip | Whether to clip 'out' to the viewport. Set false for the bounds of what would actually be drawn within the given viewport; true for bounds that are guaranteed to fit the entire string of text. |
void gameplay::Font::setCharacterSpacing | ( | float | spacing | ) |
Sets the additional character spacing for this font.
Character spacing is the additional amount of space that is inserted between characters. Character spacing is defined as a floating point value that is interpreted as a percentage of size used to draw the font. For example, a value of 0.1 would cause a spacing of 10% of the font size to be inserted between adjacent characters. For a font size of 20, this would equate to 2 pixels of extra space between characters.
The default additional character spacing for fonts is 0.0.
spacing | New fixed character spacing, expressed as a percentage of font size. |
void gameplay::Font::start | ( | ) |
Starts text drawing for this font.