![]() |
![]() |
![]() |
![]() |
Draw multiline text in an area
int PgDrawMultiTextArea( char *text,
int len,
PhRect_t *canvas,
int text_flags,
int canvas_flags,
int linespacing );
int PgDrawMultiTextAreaCx( void *dc,
char *text,
int len,
PhRect_t *canvas,
int text_flags,
int canvas_flags,
int linespacing );
ph
These functions draw multiline text within an area called a canvas, using the font specified by a previous call to PgSetFont().
These functions call PgExtentMultiText() to compute the extent of the text. Text can be aligned within the text-extent rectangle, and the text-extent rectangle itself can be aligned within the canvas.
#include <stdio.h>
#include <stdlib.h>
#include <Pt.h>
void MultiTextDraw( PtWidget_t *widget,
PhTile_t *damage )
{
PhRect_t canvas;
int r;
char Helvetica14b[MAX_FONT_TAG];
char s[100] = " clever \n is \n not he who wins \n \
but he who \n wins \n easily ";
// Find the size of the canvas on which the text
// will be drawn
PtCalcCanvas(widget, &canvas);
// Paint the canvas red
PgSetFillColor( Pg_RED );
PgDrawRect( &canvas, Pg_DRAW_FILL );
// Set the fill color, text color, and font.
PgSetFillColor( Pg_BLUE );
PgSetTextColor( Pg_WHITE );
if(PfGenerateFontName("Helvetica", PF_STYLE_BOLD, 14,
Helvetica14b) == NULL) {
perror("Unable to find font");
} else {
PgSetFont( Helvetica14b );
}
// Draw multiline text. Note the text-extent and
// canvas flags, and the linespacing.
r = PgDrawMultiTextArea( s, 0, &canvas,
Pg_TEXT_RIGHT|Pg_BACK_FILL,
Pg_TEXT_CENTER|Pg_TEXT_MIDDLE, 10 );
if ( r == -1 )
fprintf( stderr, "\n Error." );
}
int main(int argc, char **argv)
{
PtWidget_t *base;
PtArg_t args[2];
PhDim_t dim;
// Initialize Photon and create a base window
if (PtInit(NULL) == -1)
exit(EXIT_FAILURE);
dim.w = 250; dim.h = 250;
PtSetArg( &args[0], Pt_ARG_DIM, &dim, 0 );
if ((base = PtCreateWidget(PtWindow, Pt_NO_PARENT,
1, args)) == NULL)
PtExit(EXIT_FAILURE);
// Create a raw widget parented to the base window
PtSetArg( &args[1], Pt_ARG_RAW_DRAW_F,
(long) MultiTextDraw, 0 );
PtCreateWidget( PtRaw, base, 2, args );
// Realize the base window. This will realize the
// raw widget, which in turn will draw itself with
// the MultiTextDraw() function above.
PtRealizeWidget(base);
PtMainLoop();
return EXIT_SUCCESS;
}
This code produces the following output:

Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
PgDrawString*(), PgDrawText*(), PgDrawTextArea*(), PgExtentMultiText*(), PgSetFillColor*(), PgSetFont*(), PgSetTextColor*(), PgSetTextDither*(), PgSetTextTransPat*(), PgSetTextXORColor*(), PgSetUnderline*(), PhRect_t
“Text” in the Raw Drawing and Animation chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |