OpenLayer Offline Manual

OpenLayer | TextRenderer | Print Print
void Print( | const std::string &text, int x, int baselineY ) const;
Prints the given (multi-lined) text to the screen at the given coordinates.
void Print( | const std::string &text, int x, int baselineY, int maxLineWidth, TextAlignment alignment = LEFT ) const;
Prints the text with automatic line wrapping and alignment. The maxLineWidth tells the maxium width of a text line in pixels. Lines wider than maxLineWidth will be cut to several lines. Possible text alignments are: * LEFT - Align the text lines to the left * CENTER - Center the text lines * RIGHT - Align the text lines to the right * JUSTIFY - Stretch the full text lines to fill the entire maxLineWidth Note that the y-coordinate is the y-coordinate of the baseline of the first text line, not the top position of the text (changed from the previous version)! All coordinates are in pixels. Note that you can print multi-lined text such that the end of a line is marked with an endline character (\n). Also notice that for performance reasons the function takes a reference to the printed text. This means that you have to construct a text variable first and then pass it to this function. OpenLayer contains a function ToString that converts a variable (number, for example) to a string so that it can be passed to the Print -function. See the examples of how to do this. Examples TextRenderer myTextRenderer(...); // Print the text Hello World! to the screen such that the // // top-left corner of the text is positioned at // // x = 200 and y-coodinate of the baseline = 110 // String message = "Hello World!"; myTextRenderer.Print( message, 200, 110 ); // Print a multi-lined message at the same position in the screen // String message = "First line\nSecond line\nThird line"; myTextRenderer.Print( message, 200, 110 ); // Print a number in the screen // int number = 500; String message = ToString( number ); myTextRenderer.Print( message, 200, 110 ); // Print a long text in the screen with automatic line wrappings so that // // the maxium width of a text line is 300 pixels and justify the text // String longText = "This is a very, very long text which will be automatically " + "wrapped to several lines thanks to the overloaded version of the " + "text rendering function!" myTextRenderer.Print( longText , 200, 110, 300, JUSTIFY ); // Print a some text and two numbers in the screen // int number1 = 500; float number2 = 750.5; String message = "The first number is " + ToString( number1 ) + " and the second number is " + ToString( number2 ); // message is: The first number is 500 and the second number is 750.5 // myTextRenderer.Print( message, 200, 110 ); Other functions of the class TextRenderer
Load | Load the font
Print | Prints the given text to the screen
SetColor | Sets the color of the font
GetColor | Returns the text color of the font
SetItalics | Sets the italics angle of the text
GetItalics | Returns the italics angle of the text
Width | Returns the width of the given text
Height | Returns the height of the given text
FirstLineWidth | Returns the width of the first text line of the given text
FirstLineHeight | Returns the height of the first text line of the given text
IsValid | Checks if the TextRenderer was loaded correctly
Advanced functions
GetFace |
SendToGPU |
UnloadFromGPU |
UseAutoDelete |
Back to the main page of the manual Questions about Print? Click here.