libtcod
Loading...
Searching...
No Matches
console_printing.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2026, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef TCOD_CONSOLE_PRINTING_H_
36#define TCOD_CONSOLE_PRINTING_H_
37
38#include <stdarg.h>
39#include <stdbool.h>
40#ifndef NO_UNICODE
41#include <wchar.h>
42#endif
43
44#include "config.h"
45#include "console_types.h"
46#include "error.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
63
72TCOD_DEPRECATED("Use TCOD_console_printf instead.")
73TCODLIB_API void TCOD_console_print(TCOD_Console* con, int x, int y, const char* fmt, ...);
74
85TCOD_DEPRECATED("Use TCOD_console_printf_ex instead.")
86TCODLIB_API void TCOD_console_print_ex(
87 TCOD_Console* con, int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char* fmt, ...);
88
102TCOD_DEPRECATED("Use TCOD_console_printf_rect instead.")
103TCODLIB_API int TCOD_console_print_rect(TCOD_Console* con, int x, int y, int w, int h, const char* fmt, ...);
104
120TCOD_DEPRECATED("Use TCOD_console_printf_rect_ex instead.")
122 TCOD_Console* con,
123 int x,
124 int y,
125 int w,
126 int h,
128 TCOD_alignment_t alignment,
129 const char* fmt,
130 ...);
131
152TCOD_DEPRECATED("Use TCOD_console_printf_frame instead.")
154 TCOD_console_t con, int x, int y, int w, int h, bool empty, TCOD_bkgnd_flag_t flag, const char* fmt, ...);
155
169TCOD_DEPRECATED("Use TCOD_console_get_height_rect_fmt instead.")
170TCODLIB_API int TCOD_console_get_height_rect(TCOD_Console* con, int x, int y, int w, int h, const char* fmt, ...);
171#ifndef NO_UNICODE
172
178TCOD_DEPRECATED("Use TCOD_console_printf instead.")
179TCODLIB_API void TCOD_console_print_utf(TCOD_Console* con, int x, int y, const wchar_t* fmt, ...);
180
186TCOD_DEPRECATED("Use TCOD_console_printf_ex instead.")
188 TCOD_Console* con, int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t* fmt, ...);
189
195TCOD_DEPRECATED("Use TCOD_console_printf_rect instead.")
196TCODLIB_API int TCOD_console_print_rect_utf(TCOD_Console* con, int x, int y, int w, int h, const wchar_t* fmt, ...);
197
203TCOD_DEPRECATED("Use TCOD_console_printf_rect_ex instead.")
205 TCOD_Console* con,
206 int x,
207 int y,
208 int w,
209 int h,
211 TCOD_alignment_t alignment,
212 const wchar_t* fmt,
213 ...);
214
219TCOD_DEPRECATED("Use TCOD_console_get_height_rect_fmt instead.")
221 TCOD_Console* con, int x, int y, int w, int h, const wchar_t* fmt, ...);
223#endif
224
225typedef enum TCOD_colctrl_t {
226 TCOD_COLCTRL_1 = 1,
227 TCOD_COLCTRL_2,
228 TCOD_COLCTRL_3,
229 TCOD_COLCTRL_4,
230 TCOD_COLCTRL_5,
231 TCOD_COLCTRL_NUMBER = 5,
232 TCOD_COLCTRL_FORE_RGB,
233 TCOD_COLCTRL_BACK_RGB,
234 TCOD_COLCTRL_STOP,
235} TCOD_colctrl_t;
236
237
244TCODLIB_API void TCOD_console_set_color_control(TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back);
245
246#ifndef TCOD_NO_UNICODE
250
259TCOD_DEPRECATED("Use TCOD_printf_rgb instead.")
260TCODLIB_API TCODLIB_FORMAT(4, 5) TCOD_Error
261 TCOD_console_printf(TCOD_Console* __restrict con, int x, int y, const char* __restrict fmt, ...);
271TCOD_DEPRECATED("Use TCOD_printf_rgb instead.")
272TCODLIB_API TCODLIB_FORMAT(6, 7) TCOD_Error TCOD_console_printf_ex(
273 TCOD_Console* __restrict con,
274 int x,
275 int y,
277 TCOD_alignment_t alignment,
278 const char* __restrict fmt,
279 ...);
289TCOD_DEPRECATED("Use TCOD_printf_rgb instead.")
290TCODLIB_API TCODLIB_FORMAT(6, 7) int TCOD_console_printf_rect(
291 TCOD_Console* __restrict con, int x, int y, int w, int h, const char* __restrict fmt, ...);
301TCOD_DEPRECATED("Use TCOD_printf_rgb instead.")
302TCODLIB_API TCODLIB_FORMAT(8, 9) int TCOD_console_printf_rect_ex(
303 TCOD_Console* __restrict con,
304 int x,
305 int y,
306 int w,
307 int h,
309 TCOD_alignment_t alignment,
310 const char* __restrict fmt,
311 ...);
325TCOD_DEPRECATED("Print function TCOD_printf_rgb and TCOD_console_draw_frame_rgb should be called separately.")
326TCODLIB_API TCODLIB_FORMAT(8, 9) TCOD_Error TCOD_console_printf_frame(
327 TCOD_Console* __restrict con,
328 int x,
329 int y,
330 int w,
331 int h,
332 int empty,
334 const char* __restrict fmt,
335 ...);
345TCODLIB_API TCODLIB_FORMAT(6, 7) int TCOD_console_get_height_rect_fmt(
346 TCOD_Console* __restrict con, int x, int y, int w, int h, const char* __restrict fmt, ...);
366 TCOD_Console* __restrict console,
367 int x,
368 int y,
369 size_t n,
370 const char* __restrict str,
371 const TCOD_ColorRGB* __restrict fg,
372 const TCOD_ColorRGB* __restrict bg,
374 TCOD_alignment_t alignment);
396 TCOD_Console* __restrict console,
397 int x,
398 int y,
399 int width,
400 int height,
401 size_t n,
402 const char* __restrict str,
403 const TCOD_ColorRGB* __restrict fg,
404 const TCOD_ColorRGB* __restrict bg,
406 TCOD_alignment_t alignment);
422 TCOD_Console* __restrict console, int x, int y, int width, int height, size_t n, const char* __restrict str);
433TCOD_PUBLIC int TCOD_console_get_height_rect_wn(int width, size_t n, const char* __restrict str);
434TCOD_DEPRECATED("Print function TCOD_printn_rgb and TCOD_console_draw_frame_rgb should be called separately.")
435TCOD_PUBLIC TCOD_Error TCOD_console_printn_frame(
436 TCOD_Console* __restrict console,
437 int x,
438 int y,
439 int width,
440 int height,
441 size_t n,
442 const char* __restrict title,
443 const TCOD_ColorRGB* __restrict fg,
444 const TCOD_ColorRGB* __restrict bg,
446 bool clear);
447
465TCOD_DEPRECATED("Use TCOD_vprintf_rgb instead.")
467 TCOD_Console* __restrict console,
468 int x,
469 int y,
470 const TCOD_color_t* __restrict fg,
471 const TCOD_color_t* __restrict bg,
473 TCOD_alignment_t alignment,
474 const char* __restrict fmt,
475 va_list args);
476
496TCOD_DEPRECATED("Use TCOD_vprintf_rgb instead.")
498 TCOD_Console* __restrict console,
499 int x,
500 int y,
501 int width,
502 int height,
503 const TCOD_color_t* __restrict fg,
504 const TCOD_color_t* __restrict bg,
506 TCOD_alignment_t alignment,
507 const char* fmt,
508 va_list args);
509
512typedef struct TCOD_PrintParamsRGB {
513 int x; // The starting X coordinate, the left-most position being 0.
514 int y; // The starting Y coordinate, the top-most position being 0.
515 int width; // Width of the bounding rectangle. Will be unbound if set to 0
516 int height; // Height of the bounding rectangle. Will be unbound if set to 0
517 const TCOD_ColorRGB* __restrict fg; // An optional foreground color of the string
518 const TCOD_ColorRGB* __restrict bg; // An optional background color of the string
519 TCOD_bkgnd_flag_t flag; // The background blending flag. The default of `TCOD_BKGND_NONE` implies `TCOD_BKGND_SET`.
520 TCOD_alignment_t alignment; // The text justification. Defaults to `TCOD_LEFT`.
522
532TCOD_PUBLIC TCODLIB_FORMAT(3, 4) int TCOD_printf_rgb(
533 TCOD_Console* __restrict console, TCOD_PrintParamsRGB params, const char* __restrict fmt, ...);
534
544TCOD_PUBLIC int TCOD_printn_rgb(
545 TCOD_Console* __restrict console, TCOD_PrintParamsRGB params, int n, const char* __restrict str);
546
556TCOD_PUBLIC int TCOD_vprintf_rgb(
557 TCOD_Console* __restrict console, TCOD_PrintParamsRGB params, const char* __restrict fmt, va_list args);
559#endif // TCOD_NO_UNICODE
560#ifdef __cplusplus
561} // extern "C"
562#endif // __cplusplus
563#endif /* TCOD_CONSOLE_PRINTING_H_ */
Libtcod config header.
void TCOD_console_set_color_control(TCOD_colctrl_t con, TCOD_color_t fore, TCOD_color_t back)
Assign a foreground and background color to a color control index.
C types for console functions.
Error handling module.
TCOD_Error
An enum of libtcod error codes.
Definition error.h:48
TCOD_alignment_t
Print justification options.
Definition console.h:81
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
void TCOD_console_print_frame(TCOD_console_t con, int x, int y, int w, int h, bool empty, TCOD_bkgnd_flag_t flag, const char *fmt,...)
Print an EASCII titled, framed region on a console, using default colors and alignment.
int TCOD_console_print_rect_ex_utf(TCOD_Console *con, int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt,...)
\rst
void TCOD_console_print_utf(TCOD_Console *con, int x, int y, const wchar_t *fmt,...)
\rst
int TCOD_console_print_rect(TCOD_Console *con, int x, int y, int w, int h, const char *fmt,...)
Print an EASCII string on a console constrained to a rectangle, using default colors and alignment.
int TCOD_console_print_rect_utf(TCOD_Console *con, int x, int y, int w, int h, const wchar_t *fmt,...)
\rst
void TCOD_console_print_ex_utf(TCOD_Console *con, int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt,...)
\rst
int TCOD_console_get_height_rect(TCOD_Console *con, int x, int y, int w, int h, const char *fmt,...)
Return the number of lines that would be printed by an EASCII string.
void TCOD_console_print_ex(TCOD_Console *con, int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
Print an EASCII string on a console, using default colors.
int TCOD_console_get_height_rect_utf(TCOD_Console *con, int x, int y, int w, int h, const wchar_t *fmt,...)
\rst
int TCOD_console_print_rect_ex(TCOD_Console *con, int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
Print an EASCII string on a console constrained to a rectangle, using default colors.
TCOD_Error TCOD_console_printn(TCOD_Console *console, int x, int y, size_t n, const char *str, const TCOD_ColorRGB *fg, const TCOD_ColorRGB *bg, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment)
Print a string of a specified length to a console.
int TCOD_printn_rgb(TCOD_Console *console, TCOD_PrintParamsRGB params, int n, const char *str)
Prints n-bytes of a string string to the console.
int TCOD_console_get_height_rect_n(TCOD_Console *console, int x, int y, int width, int height, size_t n, const char *str)
Return the height of the word-wrapped text with the given parameters.
int TCOD_printf_rgb(TCOD_Console *console, TCOD_PrintParamsRGB params, const char *fmt,...)
Prints a formatted string to the console.
int TCOD_console_printf_rect_ex(TCOD_Console *con, int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
Format and print a UTF-8 string to a console.
TCOD_Error TCOD_console_printf_frame(TCOD_Console *con, int x, int y, int w, int h, int empty, TCOD_bkgnd_flag_t flag, const char *fmt,...)
Print a framed and optionally titled region to a console, using default colors and alignment.
TCOD_Error TCOD_console_printf_ex(TCOD_Console *con, int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
Format and print a UTF-8 string to a console.
TCOD_Error TCOD_console_vprintf(TCOD_Console *console, int x, int y, const TCOD_color_t *fg, const TCOD_color_t *bg, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, va_list args)
Print a formatted string using a va_list.
int TCOD_console_printn_rect(TCOD_Console *console, int x, int y, int width, int height, size_t n, const char *str, const TCOD_ColorRGB *fg, const TCOD_ColorRGB *bg, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment)
Print a string of a specified length in a bounding box to a console.
int TCOD_console_printf_rect(TCOD_Console *con, int x, int y, int w, int h, const char *fmt,...)
Format and print a UTF-8 string to a console.
int TCOD_console_vprintf_rect(TCOD_Console *console, int x, int y, int width, int height, const TCOD_color_t *fg, const TCOD_color_t *bg, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt, va_list args)
Print a formatted string using a va_list within a bounding box.
int TCOD_console_get_height_rect_fmt(TCOD_Console *con, int x, int y, int w, int h, const char *fmt,...)
Return the number of lines that would be printed by this formatted string.
TCOD_Error TCOD_console_printf(TCOD_Console *con, int x, int y, const char *fmt,...)
Format and print a UTF-8 string to a console.
int TCOD_console_get_height_rect_wn(int width, size_t n, const char *str)
Return the height of the word-wrapped text with the given width.
int TCOD_vprintf_rgb(TCOD_Console *console, TCOD_PrintParamsRGB params, const char *fmt, va_list args)
Prints a formatted string using va_list.
A 3-channel RGB color struct.
Definition color.h:48
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:121
Information about a string to be printed.
Definition console_printing.h:512