GrText()

Name

GrText() -- Draw text

Synopsis

void GrText ( GR_DRAW_ID id , GR_GC_ID gc , GR_COORD x , GR_COORD y , void * str , GR_COUNT count , int flags );

Description

This function draws the text str at position (x, y) on the specified drawable. The text will be drawn in the foreground color of the graphics context gc. If the usebackground flag of the GC is set, then the text background will be drawn in the GC's background color. If the usebackground flag is clear, then the text background will not be drawn.

Parameters

TypeNameDescription
GR_DRAW_IDidThe ID of the drawable to draw the text onto.
GR_GC_IDgcThe ID of the graphics context to use when drawing the text.
GR_COORDxThe X coordinate to draw the text at, relative to the drawable.
GR_COORDyThe Y coordinate to draw the text at, relative to the drawable.
void*strThe input string. If the string is NOT zero terminated, then the length of the string must be specified in the count parameter.
GR_COUNTcountThe length of the string. This parameter can be set to -1 if the string is zero terminated and flags contains GR_TFASCII.
intfagsText rendering flags, can be a combination of flags listed below.

The flags parameter is a combination of flags from the following three groups. The combination can include one string encoding flag, one alignment flag and multiple attribute flags.

String encoding flags:

GR_TFASCIIGR_TFUTF8GR_TFUC16GR_TFUC32

Text alignment flags:

GR_TFTOPGR_TFBASELINEGR_TFBOTTOM

Text attribute flags:

GR_TFKERNINGGR_TFANTIALIASGR_TFUNDERLINE

Example

Example 2-1. Using GrText()

 
#include <stdio.h>
#define MWINCLUDECOLORS
#include "microwin/nano-X.h"

GR_WINDOW_ID  wid;
GR_GC_ID      gc;

void event_handler (GR_EVENT *event);

int main (void)
{
    if (GrOpen() < 0)
    {
        fprintf (stderr, "GrOpen failed");
        exit (1);
    }

    gc = GrNewGC();
    GrSetGCUseBackground (gc, GR_FALSE);
    GrSetGCForeground (gc, RED);

    wid = GrNewWindowEx (GR_WM_PROPS_APPFRAME |
                         GR_WM_PROPS_CAPTION  |
                         GR_WM_PROPS_CLOSEBOX,
                         "Hello Window",
                         GR_ROOT_WINDOW_ID, 
                         50, 50, 200, 100, WHITE);

    GrSelectEvents (wid, GR_EVENT_MASK_EXPOSURE | 
                         GR_EVENT_MASK_CLOSE_REQ);

    GrMapWindow (wid);
    GrMainLoop (event_handler);
}

void event_handler (GR_EVENT *event)
{
    switch (event->type)
    {
    case GR_EVENT_TYPE_EXPOSURE:
        GrText (wid, gc, 50, 50, 
                "Hello World",  -1, GR_TFASCII);
        break;

    case GR_EVENT_TYPE_CLOSE_REQ:
        GrClose();
        exit (0);
    }
}

See Also

GrSetGCForeground(), GrSetGCBackground(), GrSetGCUseBackground(), GrGetGCTextSize().