35#ifndef TCOD_CONSOLE_PRINTING_HPP_
36#define TCOD_CONSOLE_PRINTING_HPP_
50#ifndef TCOD_NO_UNICODE
77 const std::array<int, 2>& xy,
79 std::optional<TCOD_ColorRGB> fg,
80 std::optional<TCOD_ColorRGB> bg,
86 TCOD_console_printn(&console, xy.at(0), xy.at(1), str.size(), str.data(), fg_ptr, bg_ptr, flag, alignment));
116 const std::array<int, 4>& rect,
117 std::string_view str,
118 std::optional<TCOD_ColorRGB> fg,
119 std::optional<TCOD_ColorRGB> bg,
130 fg ? &fg.value() :
nullptr,
131 bg ? &bg.value() :
nullptr,
157TCODLIB_BEGIN_IGNORE_DEPRECATIONS
158[[deprecated(
"It is recommended that you print your own banners for frames.")]]
inline void print_frame(
160 const std::array<int, 4>& rect,
161 std::string_view title,
167 &console, rect.at(0), rect.at(1), rect.at(2), rect.at(3), title.size(), title.data(), fg, bg, flag, clear));
169TCODLIB_END_IGNORE_DEPRECATIONS
197template <
typename... T>
198inline std::string
stringf(
const char* format, T... args) {
199 const int str_length = snprintf(
nullptr, 0, format, args...);
200 if (str_length < 0)
throw std::runtime_error(
"Failed to format string.");
201 std::string out(str_length,
'\0');
202 snprintf(&out[0], str_length + 1, format, args...);
Console string printing module.
TCOD_alignment_t
Print justification options.
Definition console.h:81
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
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 print_rect(TCOD_Console &console, const std::array< int, 4 > &rect, std::string_view str, std::optional< TCOD_ColorRGB > fg, std::optional< TCOD_ColorRGB > bg, TCOD_alignment_t alignment=TCOD_LEFT, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET)
Print a string to a console constrained to a bounding box.
Definition console_printing.hpp:114
void print(TCOD_Console &console, const std::array< int, 2 > &xy, std::string_view str, std::optional< TCOD_ColorRGB > fg, std::optional< TCOD_ColorRGB > bg, TCOD_alignment_t alignment=TCOD_LEFT, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET)
Print a string to a console.
Definition console_printing.hpp:75
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 get_height_rect(int width, std::string_view str)
Return the height of the word-wrapped text with the given width.
Definition console_printing.hpp:154
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.
The libtcod namespace.
Definition bresenham.hpp:157
TCODLIB_END_IGNORE_DEPRECATIONS std::string stringf(const char *format, T... args)
Return a formatted string as a std::string object.
Definition console_printing.hpp:198
int check_throw_error(int error)
Check and throw error messages.
Definition error.hpp:57
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