Home  Contents

gcx:text

Graphics Core4 Lua Commands

SYNOPSIS

#include <lua/gfx.lh>
  1. gcx:text(x, y, text [, mode])
  2. gcx:text(x, y, w, h, text [, mode])
  3. gcx:text(rect, text [, mode])

DESCRIPTION

First form, no rectangle size specified

The first form draws text at position x, y using the stored font and colors. It supports three alignment modes:

Mode Symbolic x specifies
"left" ALIGN_LEFT Left edge of text
"right" ALIGN_RIGHT Right edge of text
"center" ALIGN_CENTER Horizontal center of text

The y coordinate specifies the position of the baseline of the font. The baseline is at the lower edge of the upper case letter A. If there are newlines in the text string, the y coordinate is advanced by the font's height and the alignment is calculated anew for the next line.

Forms 2 and 3: With box size given

Draws text into the specified rectangle using the stored font and colors.

mode specifies the alignment within the specified rectangle, default is top/left.

Mode Symbolic
"tl" or "topleft" ALIGN_TOP | ALIGN_LEFT
"tr" or "topright" ALIGN_TOP | ALIGN_RIGHT
"bl" or "bottomleft" ALIGN_BOTTOM | ALIGN_LEFT
"br" or "bottomright" ALIGN_BOTTOM | ALIGN_RIGHT
"tc" or "topcenter" ALIGN_TOP | ALIGN_CENTER
"bc" or "bottomcenter" ALIGN_BOTTOM | ALIGN_CENTER
"cl" or "centerleft" ALIGN_VCENTER | ALIGN_LEFT
"cr" or "centerright" ALIGN_VCENTER | ALIGN_RIGHT
"cc" or "middle" ALIGN_VCENTER | ALIGN_CENTER

ERRORS

Raises an error if gcx is not a graphics context.

EXAMPLE

gcx:text(gcx:width()/2, gcx:height()/2, "Hello World", "center")

SEE ALSO