Menge
Modular Pedestrian Simulation Framework for Research and Development
|
A singleton class responsible for writing text to an OpenGL context. More...
#include <TextWriter.h>
Public Types | |
enum | Alignment { NO_ALIGN = 0x0, VCENTER = 0x1, TOP = 0x2, BOTTOM = 0x4, LEFT = 0x8, LEFT_CENTER = 0x9, LEFT_TOP = 0xA, LEFT_BOTTOM = 0xC, RIGHT = 0x10, RIGHT_CENTER = 0x11, RIGHT_TOP = 0x12, RIGHT_BOTTOM = 0x14, HCENTER = 0x20, CENTERED = 0x21, CENTER_TOP = 0x22, CENTER_BOTTOM = 0x24 } |
Enumeration for controlling text alignment. | |
Public Member Functions | |
void | newGLContext () |
Resets the text writer's context-dependent data Called when the OpenGL context is called. | |
void | printText (const std::string &text, Alignment alignment, float anchorX, float anchorY, int fontSize, bool currColor=false, bool transparent=true) |
Print the given text with an alignment relative to the given anchor point. More... | |
void | printText (const std::string &text, float left, float bottom, int fontSize, bool currColor=false, bool transparent=true) |
Print the given text to the screen at the given coordinates. More... | |
void | printAlignText (const std::string &text, Alignment alignment, int fontSize, float hpad, float vpad, bool currColor=false, bool transparent=true) |
Print the given text to the screen with the specified alignment. More... | |
void | printAnchorText (const std::string &text, float anchorX, float anchorY, float xWeight, float yWeight, int fontSize, bool currColor=false, bool transparent=true) |
Prints the text anchored to the position. The relationship to the anchor depends on the anchor weights. It interpolates them from bottom left top top right. More... | |
void | textSize (const std::string &text, int fontSize, float &textWidth, float &textHeight) |
Reports the size, in pixels, the given text will consume on the screen, given current font and indicated font size. More... | |
void | resize (int w, int h) |
Inform the text writer that the viewport has resized. More... | |
int | getViewWidth () const |
Reports TextWriter's belief of the viewport width. More... | |
int | getViewHeight () const |
Reports TextWriter's belief of the viewport width. More... | |
bool | setFont (const std::string &fontName) |
Changes the font family. More... | |
void | setDefaultColor (float r, float g, float b, float alpha=1.f) |
Sets the default font color. More... | |
int | flipY (int y) |
A utility function to map from screen to image coordinates. More... | |
Static Public Member Functions | |
static void | setDefaultFont (const std::string &fontName) |
Sets the default font to use. More... | |
static TextWriter * | Instance () |
Acquire pointer to a singleton text writer instance. | |
Protected Member Functions | |
TTF_Font * | getFont (int size) |
Returns a pointer to a font for the given size. More... | |
void | closeFonts () |
Close out the current set of fonts. | |
TextWriter () | |
Protected constructor. No instantiation allowed. | |
~TextWriter () | |
Protected destructor. | |
void | makeTextDList () |
Generate the display list for the quad upon which text is printed. | |
void | makeGLTexture () |
Generate the OpenGL texture object for the text. | |
void | sdlSurfaceToGLTex (SDL_Surface *surf) |
Set the surface upon which the text has been rendered to a texture. More... | |
void | printLine (TTF_Font *font, const char *text, float left, float bottom, int lineNum) |
The work necessary to print a single line of text. More... | |
Protected Attributes | |
int | _width |
The width of the viewport the TextWriter considers when computing text positions. | |
int | _height |
The height of the viewport the TextWriter considers when computing text positions. | |
FontMap | _fonts |
Map of all font sizes for this font face. | |
std::string | _fontName |
Name of font. | |
GLuint | _textID |
Texture object for texturing the rendered text. | |
GLuint | _textQuadID |
Call list for the text surface. | |
float | _defColor [4] |
The default font color. | |
Static Protected Attributes | |
static TextWriter * | _instance = 0x0 |
The singleton pointer. | |
A singleton class responsible for writing text to an OpenGL context.
It has numerous functions for drawing text. It typically works in screen space, where the upper, left-hand corner is (0, 0).
|
inline |
A utility function to map from screen to image coordinates.
The screen coordiantes have the origin in the top, left corner. Image coordinates have the origin at the bottom, left corner.
y | The vertical position in screen coordinates. |
|
protected |
Returns a pointer to a font for the given size.
size | The desired size of the font. |
|
inline |
Reports TextWriter's belief of the viewport width.
|
inline |
Reports TextWriter's belief of the viewport width.
void Menge::SceneGraph::TextWriter::printAlignText | ( | const std::string & | text, |
Alignment | alignment, | ||
int | fontSize, | ||
float | hpad, | ||
float | vpad, | ||
bool | currColor = false , |
||
bool | transparent = true |
||
) |
Print the given text to the screen with the specified alignment.
text | The string to draw. |
alignment | The alignment, relative to the screen. |
fontSize | The size of the text, in pixels. |
hpad | The amount of horizontal padding to apply in the horizontal alignment direction. For example, if left aligned, it goes on the left, if right aligned, the padding is on the right. |
vpad | The amount of vertical padding to apply in the vertical direction. |
currColor | Indicates if the current opengl color should be used (true) or the text writer's default color should be used (false). |
transparent | Indicates if the text is super-imposed over the screen or given a matte. True –> superimposed, false –> matted. |
void Menge::SceneGraph::TextWriter::printAnchorText | ( | const std::string & | text, |
float | anchorX, | ||
float | anchorY, | ||
float | xWeight, | ||
float | yWeight, | ||
int | fontSize, | ||
bool | currColor = false , |
||
bool | transparent = true |
||
) |
Prints the text anchored to the position. The relationship to the anchor depends on the anchor weights. It interpolates them from bottom left top top right.
text | The string to draw. |
anchorX | The x-position of the anchor point (in screen coords). |
anchorY | The y-position of the anchor point (in screen coords). |
xWeight | The horizontal weight in the range [0, 1]. 0–> left, 1 –> right alignment. |
yWeight | The vertical weight in the range [0, 1]. 0–> bottom, 1 –> top alignment. |
fontSize | The size of the text, in pixels. |
currColor | Indicates if the current opengl color should be used (true) or the text writer's default color should be used (false). |
transparent | Indicates if the text is super-imposed over the screen or given a matte. True –> superimposed, false –> matted. |
|
protected |
The work necessary to print a single line of text.
The text is displayed relative to the anchor point of an entire block of text, (left, bottom), withthe text extending above and to the right of the anchor point.
font | The font to render the text. |
text | The text to draw. |
left | The horizontal value of the anchor point. |
bottom | The vertical value of the anchor point. |
lineNum | The line number of the given text (zero-indexed). Used to offset this line relative to the anchor point. |
scale and translate the quad
void Menge::SceneGraph::TextWriter::printText | ( | const std::string & | text, |
Alignment | alignment, | ||
float | anchorX, | ||
float | anchorY, | ||
int | fontSize, | ||
bool | currColor = false , |
||
bool | transparent = true |
||
) |
Print the given text with an alignment relative to the given anchor point.
text | The string to draw. |
alignment | The alignment, relative to the screen. |
anchorX | The x-position of the anchor point (in screen coords). |
anchorY | The y-position of the anchor point (in screen coords). |
fontSize | The size of the text, in pixels. |
currColor | Indicates if the current opengl color should be used (true) or the text writer's default color should be used (false). |
transparent | Indicates if the text is super-imposed over the screen or given a matte. True –> superimposed, false –> matted. |
void Menge::SceneGraph::TextWriter::printText | ( | const std::string & | text, |
float | left, | ||
float | bottom, | ||
int | fontSize, | ||
bool | currColor = false , |
||
bool | transparent = true |
||
) |
Print the given text to the screen at the given coordinates.
text | The string to draw. |
left | The position of the left extent of the text (in screen coords). |
bottom | The position of the bottom extent of the text (in screen coords). |
fontSize | The size of the text, in pixels. |
currColor | Indicates if the current opengl color should be used (true) or the text writer's default color should be used (false). |
transparent | Indicates if the text is super-imposed over the screen or given a matte. True –> superimposed, false –> matted. |
void Menge::SceneGraph::TextWriter::resize | ( | int | w, |
int | h | ||
) |
Inform the text writer that the viewport has resized.
This must be called by the viewer when the viewport resizes. This information is how the TextWriter correctly interprets alignment.
w | The viewport width (in pixels). |
h | The viewport height (in pixels). |
|
protected |
Set the surface upon which the text has been rendered to a texture.
surf | The surface upon which the text has been rendered. |
void Menge::SceneGraph::TextWriter::setDefaultColor | ( | float | r, |
float | g, | ||
float | b, | ||
float | alpha = 1.f |
||
) |
Sets the default font color.
r | The red component of the color. |
g | The green component of the color. |
b | The blue component of the color. |
alpha | The alpha component of the color. Default value is 1.0. |
|
static |
Sets the default font to use.
fontName | The path to the font to use. |
bool Menge::SceneGraph::TextWriter::setFont | ( | const std::string & | fontName | ) |
Changes the font family.
The first font is loaded at the default size If it is unable to load the font, the old family is left in place
fontName | The name of the font family to use. |
void Menge::SceneGraph::TextWriter::textSize | ( | const std::string & | text, |
int | fontSize, | ||
float & | textWidth, | ||
float & | textHeight | ||
) |
Reports the size, in pixels, the given text will consume on the screen, given current font and indicated font size.
text | The string to draw. |
fontSize | The size of the font (in points). |
textWidth | The width of the text will be stored in this value. |
textHeight | The height of the text will be stored in this value. |