GfxDrawText
- draw a text (clipped to rectangle)

Low-level graphics
(AFL 3.0)


SYNTAX GfxDrawText( ''text'', left, top, right, bottom, format = 0 )
RETURNS NOTHING
FUNCTION Formats and draws text in the given rectangle. It formats text by expanding tabs into appropriate spaces, aligning text to the left, right, or center of the given rectangle, and breaking text into lines that fit within the given rectangle. The type of formatting is specified by format argument. When format is not specified the text is aligned to the top/left corner.

Parameters:

  • "text" - string to be drawn
  • left - x-coordinate of upper left corner of the clipping rectangle
  • top - y-coordinate of upper left corner of the clipping rectangle
  • right - x-coordinate of lower right corner of the clipping rectangle
  • bottom - y-coordinate of lower right corner of the clipping rectangle
  • format - specifies the method of formatting the text. It can be any combination of the following values (combine using the bitwise OR operator):
    • DT_BOTTOM = 8 - Specifies bottom-justified text. This value must be combined with DT_SINGLELINE.
    • DT_CENTER = 1 - Centers text horizontally.
    • DT_END_ELLIPSIS = 32768 or DT_PATH_ELLIPSIS = 16384 - Replaces part of the given string with ellipses, if necessary, so that the result fits in the specified rectangle. You can specify DT_END_ELLIPSIS to replace characters at the end of the string, or DT_PATH_ELLIPSIS to replace characters in the middle of the string. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash.
    • DT_EXPANDTABS = 64 - Expands tab characters. The default number of characters per tab is eight.
    • DT_LEFT = 0 - Aligns text flush-left.
    • DT_NOCLIP = 256 - Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.
    • DT_NOPREFIX = 2048 - Turns off processing of prefix characters. Normally, DrawText interprets the ampersand (&) mnemonic-prefix character as a directive to underscore the character that follows, and the two-ampersand (&&) mnemonic-prefix characters as a directive to print a single ampersand. By specifying DT_NOPREFIX, this processing is turned off.
    • DT_RIGHT = 2 - Aligns text flush-right.
    • DT_SINGLELINE = 32 - Specifies single line only. Carriage returns and linefeeds do not break the line.
    • DT_TOP = 0 - Specifies top-justified text (single line only).
    • DT_VCENTER = 4 - Specifies vertically centered text (single line only).
    • DT_WORDBREAK = 16 - Specifies word-breaking. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by lpRect. A carriage return–linefeed sequence will also break the line.
Note: DT_ constants come from Windows API and are provided here for reference only. They are not defined in AmiBroker therefore you should use numerical values instead.

NOTE: This is LOW-LEVEL graphic function. To learn more about low-level graphic functions please read TUTORIAL: Using low-level graphics.

EXAMPLE // formatted text output sample via low-level gfx functions


CellHeight =
20;
CellWidth =
100;
GfxSelectFont( "Tahoma", CellHeight/2 );

function PrintInCell( string, row, Col )
{
GfxDrawText( string, Col * CellWidth, row * CellHeight, (Col + 1 ) * CellWidth, (row + 1 ) * CellHeight, 0 );
}

PrintInCell(
"Open", 0, 0 );
PrintInCell(
"High", 0, 1 );
PrintInCell(
"Low", 0, 2 );
PrintInCell(
"Close", 0, 3 );
PrintInCell(
"Volume", 0, 4 );

GfxSelectPen( colorBlue );
for( i = 1; i < 10 && i < BarCount; i++ )
{
PrintInCell(
StrFormat("%g", O[ i ] ), i, 0 );
PrintInCell(
StrFormat("%g", H[ i ] ), i, 1 );
PrintInCell(
StrFormat("%g", L[ i ] ), i, 2 );
PrintInCell(
StrFormat("%g", C[ i ] ), i, 3 );
PrintInCell(
StrFormat("%g", V[ i ] ), i, 4 );
GfxMoveTo( 0, i * CellHeight );
GfxLineTo( 5 * CellWidth, i * CellHeight );
}
GfxMoveTo( 0, i * CellHeight );
GfxLineTo( 5 * CellWidth, i * CellHeight );

for( Col = 1; Col < 6; Col++ )
{
GfxMoveTo( Col * CellWidth, 0);
GfxLineTo( Col * CellWidth, 10 * CellHeight );
}
SEE ALSO GfxSetTextColor() function , GfxTextOut() function , GfxSetBkColor() function , GfxSetBkMode() function

References:

The GfxDrawText function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference