{{tag>dragonscript graphic canvas ui text}}
[[:start|Start Page]] >> [[:gamedev|Game Development with the Drag[en]gine]] >> [[gamedev:canvassystem:introduction|Canvas System]] >> **Canvas Text**
====== Canvas Text ======
Text canvas display a single line of text. The text starts in the top left corner and is clipped against the canvas area. This behavior is different from other canvas where the content is stretched to fill the entire canvas area. With text canvas the text is not stretched to the canvas area but clipped against it. A transformation matrix can be used to apply effects like stretching if required. Canvas text can be used with colored and colorizeable fonts. A color font display text with exactly the color provided by the font. This is useful for colorful fonts for example for title screens. Colorizeable fonts on the other hand are grayscale images allowing to display text in different colors. The canvas text color parameter is used in this case to colorize the text. For color fonts the canvas text color is ignored. The canvas text does not provide any layout or alignment support. The user is responsible to provide alignment according to needs.
====== Usage example DragonScript ======
var Font font = Font.new( "/fonts/example_font.defont", 18 ) // font size is in pixels
var String text = "This is an example text line"
var Canvas canvas = Canvas.new( Canvas.TEXT )
canvas.setSize( font.getTextSize( text ) ) // set correct size to avoid stretching
canvas.setPosition( Point.new( 25, 20 ) ) // set position relative to parent canvas
canvas.setFont( font ) // assign font
canvas.setColor( Color.BLUE ) // render text in blue
canvas.setText( text ) // assign text
parentCanvas.addCanvas( canvas ) // add canvas to parent making it visible