overview wiki api reference download
 All Classes Functions Variables Typedefs Enumerations Enumerator
Classes | Public Types | Public Member Functions | Static Public Member Functions
gameplay::Font Class Reference

#include <Font.h>

Inheritance diagram for gameplay::Font:
gameplay::Ref

List of all members.

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)
SpriteBatchgetSpriteBatch (unsigned int size) const

Static Public Member Functions

static Fontcreate (const char *path, const char *id=NULL)
static Justify getJustify (const char *justify)

Detailed Description

Defines a font for text rendering.


Member Enumeration Documentation

Defines the format of the font.

Defines the set of allowable alignments when drawing text.

Defines the set of allowable font styles.


Member Function Documentation

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.

Parameters:
pathThe path to a bundle file containing a font resource.
idAn optional ID of the font resource within the bundle (NULL for the first/only resource).
Returns:
The specified Font or NULL if there was an error.
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.

Parameters:
textThe text to draw.
xThe viewport x position to draw text at.
yThe viewport y position to draw text at.
colorThe color of text.
sizeThe size to draw text (0 for default size).
rightToLeftWhether 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.

Parameters:
textThe text to draw.
xThe viewport x position to draw text at.
yThe viewport y position to draw text at.
redThe red channel of the text color.
greenThe green channel of the text color.
blueThe blue channel of the text color.
alphaThe alpha channel of the text color.
sizeThe size to draw text (0 for default size).
rightToLeftWhether 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.

Parameters:
textThe text to draw.
areaThe viewport area to draw within. Text will be clipped outside this rectangle.
colorThe color of text.
sizeThe size to draw text (0 for default size).
justifyJustification of text within the viewport.
wrapWraps text to fit within the width of the viewport if true.
rightToLeftWhether to draw text from right to left.
clipA region to clip text within after applying justification to the viewport area.

Finishes text batching for this font and renders all drawn text.

Returns current character spacing for this font in percentage of fonts size.

See also:
setCharacterSpacing(float)

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.

Parameters:
justifyThe string such as "ALIGN_HCENTER" or "ALIGN_VCENTER_RIGHT".
Returns:
The Justify value.
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.

Parameters:
indexIndex of the size to returned (default is 0).
See also:
getSizeCount
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.

Parameters:
sizeThe font size to be drawn.
Returns:
The SpriteBatch that most closely matches the requested font size.
bool gameplay::Font::isCharacterSupported ( int  character) const

Determines if this font supports the specified character code.

Parameters:
characterThe character code to check.
Returns:
True if this Font supports (can draw) the specified character, false otherwise.
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.

Parameters:
textThe text to measure.
sizeThe font height to scale to.
widthOutDestination for the text's width.
heightOutDestination 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.

Parameters:
textThe text to measure.
clipThe clip rectangle.
sizeThe font height to scale to.
outDestination rectangle to store the bounds in.
justifyJustification of text within the viewport.
wrapWhether to measure text with wrapping applied.
ignoreClipWhether 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.

Parameters:
spacingNew fixed character spacing, expressed as a percentage of font size.

Starts text drawing for this font.

 All Classes Functions Variables Typedefs Enumerations Enumerator