< index
< 2. Console emulator
< 2.2 Drawing on the root console

=====================================
Printing a centered string with autowrap
=====================================

C++ : int TCODConsole::printCenterRect(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, const char *fmt, ...)
C   : int TCOD_console_print_center_rect(TCOD_console_t con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, const char *fmt, ...)
Py  : console_print_center_rect(con,x, y, w, h, flag, fmt)

This function draws a centered string in a rectangle inside the console, using default foreground and background colors. If the string reaches the borders of the rectangle, carriage returns are inserted.
If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console.
The function returns the height (number of console lines) of the printed string.
ParameterDescription
conIn the C version, the offscreen console handler or NULL for the root console.
x,yCoordinates of the rectangle's top middle position in the console.
0 <= x < console width
0 <= y < console height
w,hSize of the rectangle in the console.
0 <= x-w/2 <= x+w/2 < console width
y <= y+h < console height
flagThis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t.
fmtprintf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string.

You can also get the expected height without actually printing the string :

C++ : int TCODConsole::getHeightCenterRect(int x, int y, int w, int h, const char *fmt, ...)
C   : int TCOD_console_height_center_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...)
Py  : console_height_center_rect(con,x, y, w, h, fmt)

ParameterDescription
conIn the C version, the offscreen console handler or NULL for the root console.
x,yCoordinates of the rectangle's top middle position in the console.
0 <= x < console width
0 <= y < console height
w,hSize of the rectangle in the console.
0 <= x-w/2 <= x+w/2 < console width
y <= y+h < console height
fmtprintf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string.
insert a comment