Public Member Functions | Static Public Member Functions

mxgui::Font Class Reference
[Mxgui level 1]

#include <font.h>

List of all members.

Public Member Functions

 Font (unsigned char startChar, unsigned char endChar, unsigned char height, unsigned char width, unsigned char dataSize, bool antialiased, const void *data)
 Font (unsigned char startChar, unsigned char endChar, unsigned char height, unsigned char dataSize, bool antialiased, const unsigned char *widths, const unsigned short *offset, const void *data)
template<typename T >
void draw (T &surface, Color colors[4], Point p, const char *s) const
template<typename T >
void clippedDraw (T &surface, Color colors[4], Point p, Point a, Point b, const char *s) const
short int calculateLength (const char *s) const
bool isFixedWidth () const
bool isAntialiased () const
unsigned char getStartChar () const
unsigned char getEndChar () const
unsigned char getHeight () const
unsigned char getWidth () const
unsigned char getDataSize () const
const unsigned char * getWidths () const
const unsigned short * getOffset () const
const void * getData () const

Static Public Member Functions

static void generatePalette (Color out[4], Color fgcolor, Color bgcolor)

Detailed Description

A Font that can be used to draw text. Fonts are immutable except they can be assigned with operator=. Users are not expected to create instances of the Font class directly. Rather, the default use case is to use the pre-instantiated fonts in misc_inst.h, like droid11()


Constructor & Destructor Documentation

mxgui::Font::Font ( unsigned char  startChar,
unsigned char  endChar,
unsigned char  height,
unsigned char  width,
unsigned char  dataSize,
bool  antialiased,
const void *  data 
)

Creates a fixed width font.

Parameters:
startChar the first character available, example ' ' (ASCII space)
endChar the last character available (including)
height the height of the glyphs
width the width of the glyphs (fixed width font)
dataSize can be 8,16 or 32, it is the size of one element of data
antialiased true if font is antialiased
data pinter to the font data. This must point to a static array so that no memeory leak problems occur
mxgui::Font::Font ( unsigned char  startChar,
unsigned char  endChar,
unsigned char  height,
unsigned char  dataSize,
bool  antialiased,
const unsigned char *  widths,
const unsigned short *  offset,
const void *  data 
)

Creates a variable width font.

Parameters:
startChar the first character available, example ' ' (ASCII space)
endChar the last character available (including)
height the height of the glyphs
dataSize can be 8,16 or 32, it is the size of one element of data
antialiased true if font is antialiased
widths pointer to a table that contains the widths of each glyph. This must point to a static arra so that no memeory leak problems occur
offset pointer to a table that contains where in data each glyph begins ( data[offset[c]]) This must point to a static arra so that no memeory leak problems occur
data pinter to the font data. This must point to a static array so that no memeory leak problems occur

Member Function Documentation

short int mxgui::Font::calculateLength ( const char *  s  )  const

Given a string, determine the length in pixels required to draw it. If the string contains characters not between getStartChar and getEndChar their width is supposed to be the length of the character returned by getStartChar.

Parameters:
s a null terminated string
Returns:
the length in pixels
template<typename T >
void mxgui::Font::clippedDraw ( T &  surface,
Color  colors[4],
Point  p,
Point  a,
Point  b,
const char *  s 
) const

Draw part of a string on a surface

Parameters:
surface an object that provides pixel iterators.
colors colors for drawing antialiased text
p point of the upper left corner where the string will be drawn. Negative coordinates are allowed, as long as the clipped view has positive or zero coordinates
a Upper left corner of clipping rectangle
b Lower right corner of clipping rectangle
s string to draw
template<typename T >
void mxgui::Font::draw ( T &  surface,
Color  colors[4],
Point  p,
const char *  s 
) const

Draw a string on a surface.

Parameters:
surface an object that provides pixel iterators.
colors colors for drawing antialiased text
p point of the upper left corner where the string will be drawn.
s string to write
void mxgui::Font::generatePalette ( Color  out[4],
Color  fgcolor,
Color  bgcolor 
) [static]

Genearte a 4 grayscale levels from foreground and background colors for use with antialiased text drawing

Parameters:
out 
fgcolor 
bgcolor 
const void* mxgui::Font::getData (  )  const [inline]
Returns:
a pointer to the font data, that can be used to draw a font. The real datatype depends on getDataType()
unsigned char mxgui::Font::getDataSize (  )  const [inline]
Returns:
the size in bits of the data's data type. Can be 8,16,32. For example if it is 16, data can be cast from void* to unsigned short*
unsigned char mxgui::Font::getEndChar (  )  const [inline]
Returns:
the Font's last character available in its table
unsigned char mxgui::Font::getHeight (  )  const [inline]
Returns:
the Font's height
const unsigned short* mxgui::Font::getOffset (  )  const [inline]
Returns:
a table with the offset within data where a character starts For example, character c in font f starts at:
 if(c>=f.getStartChar() && f<=f.getEndChar())
 result=f.getOffset()[c-f.getStartChar()] 
unsigned char mxgui::Font::getStartChar (  )  const [inline]
Returns:
the Font's first character available in its table
unsigned char mxgui::Font::getWidth (  )  const [inline]
Returns:
the Font's width. Use this member function only if the Font is fixed width, otherwise see getWidths()
const unsigned char* mxgui::Font::getWidths (  )  const [inline]
Returns:
the widths of the characters, only if it is a variable width Font. If you want to know the with of character c when using font f, use:
 if(c>=f.getStartChar() && f<=f.getEndChar())
 result=f.getWidths()[c-f.getStartChar()] 
bool mxgui::Font::isAntialiased (  )  const [inline]
Returns:
true if the Font is antialiased
bool mxgui::Font::isFixedWidth (  )  const [inline]
Returns:
true if the Font is fixed width

The documentation for this class was generated from the following files: