libtcod
Loading...
Searching...
No Matches
console_printing.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, 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, ...);
368 TCOD_Console* __restrict console,
369 int x,
370 int y,
371 size_t n,
372 const char* __restrict str,
373 const TCOD_ColorRGB* __restrict fg,
374 const TCOD_ColorRGB* __restrict bg,
376 TCOD_alignment_t alignment);
400 TCOD_Console* __restrict console,
401 int x,
402 int y,
403 int width,
404 int height,
405 size_t n,
406 const char* __restrict str,
407 const TCOD_ColorRGB* __restrict fg,
408 const TCOD_ColorRGB* __restrict bg,
410 TCOD_alignment_t alignment);
428 TCOD_Console* __restrict console, int x, int y, int width, int height, size_t n, const char* __restrict str);
441TCOD_PUBLIC int TCOD_console_get_height_rect_wn(int width, size_t n, const char* __restrict str);
442TCOD_DEPRECATED("Print function TCOD_printn_rgb and TCOD_console_draw_frame_rgb should be called separately.")
443TCOD_PUBLIC TCOD_Error TCOD_console_printn_frame(
444 TCOD_Console* __restrict console,
445 int x,
446 int y,
447 int width,
448 int height,
449 size_t n,
450 const char* __restrict title,
451 const TCOD_ColorRGB* __restrict fg,
452 const TCOD_ColorRGB* __restrict bg,
454 bool clear);
455
475TCOD_DEPRECATED("Use TCOD_vprintf_rgb instead.")
477 TCOD_Console* __restrict console,
478 int x,
479 int y,
480 const TCOD_color_t* __restrict fg,
481 const TCOD_color_t* __restrict bg,
483 TCOD_alignment_t alignment,
484 const char* __restrict fmt,
485 va_list args);
486
508TCOD_DEPRECATED("Use TCOD_vprintf_rgb instead.")
510 TCOD_Console* __restrict console,
511 int x,
512 int y,
513 int width,
514 int height,
515 const TCOD_color_t* __restrict fg,
516 const TCOD_color_t* __restrict bg,
518 TCOD_alignment_t alignment,
519 const char* fmt,
520 va_list args);
521
524typedef struct TCOD_PrintParamsRGB {
525 int x; // The starting X coordinate, the left-most position being 0.
526 int y; // The starting Y coordinate, the top-most position being 0.
527 int width; // Width of the bounding rectangle. Will be unbound if set to 0
528 int height; // Height of the bounding rectangle. Will be unbound if set to 0
529 const TCOD_ColorRGB* __restrict fg; // An optional foreground color of the string
530 const TCOD_ColorRGB* __restrict bg; // An optional background color of the string
531 TCOD_bkgnd_flag_t flag; // The background blending flag. The default of `TCOD_BKGND_NONE` implies `TCOD_BKGND_SET`.
532 TCOD_alignment_t alignment; // The text justification. Defaults to `TCOD_LEFT`.
534
546TCOD_PUBLIC TCODLIB_FORMAT(3, 4) int TCOD_printf_rgb(
547 TCOD_Console* __restrict console, TCOD_PrintParamsRGB params, const char* __restrict fmt, ...);
548
560TCOD_PUBLIC int TCOD_printn_rgb(
561 TCOD_Console* __restrict console, TCOD_PrintParamsRGB params, int n, const char* __restrict str);
562
574TCOD_PUBLIC int TCOD_vprintf_rgb(
575 TCOD_Console* __restrict console, TCOD_PrintParamsRGB params, const char* __restrict fmt, va_list args);
577#endif // TCOD_NO_UNICODE
578#ifdef __cplusplus
579} // extern "C"
580#endif // __cplusplus
581#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.
void TCOD_console_print(TCOD_Console *con, int x, int y, const char *fmt,...)
Print an EASCII string 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,...)
void TCOD_console_print_utf(TCOD_Console *con, int x, int y, const wchar_t *fmt,...)
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,...)
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,...)
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,...)
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:50
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:125
Information about a string to be printed.
Definition console_printing.h:524