35#ifndef TCOD_CONSOLE_HPP_
36#define TCOD_CONSOLE_HPP_
68 const std::array<int, 2>& dest_xy = {0, 0},
69 std::array<int, 4> source_rect = {0, 0, 0, 0},
70 float foreground_alpha = 1.0f,
71 float background_alpha = 1.0f) {
193 [[deprecated(
"This way of initializing libtcod is deprecated. See the documentation for how to use tcod::new_context.")]]
272 "This function is not compatible with contexts."
273 " Consider using tcod::load_tilesheet or TCOD_tileset_load instead."
274 " https://libtcod.readthedocs.io/en/latest/upgrading.html")]]
static void
294 [[deprecated(
"This function is not compatible with contexts.")]]
309 [[deprecated(
"This function is not compatible with contexts.")]]
323 [[deprecated(
"This function is not compatible with contexts.")]]
338 [[deprecated(
"This function is not compatible with contexts. Use SDL_GetWindowFlags to check this.")]]
373 [[deprecated(
"This function is not compatible with contexts. Use SDL_SetWindowFullscreen to set this state.")]]
390 [[deprecated(
"This function is not compatible with contexts. Use SDL_SetWindowTitle to change the window title.")]]
403 [[deprecated(
"This function is not compatible with contexts. Use SDL for events and check for SDL_QUIT.")]]
414 [[deprecated(
"This function is not compatible with contexts. Use SDL_GetWindowFlags to check this.")]]
425 [[deprecated(
"This function is not compatible with contexts. Use SDL_GetWindowFlags to check this.")]]
442 [[deprecated(
"This function is not compatible with contexts. Consider using `TCOD_console_credits_render_ex`.")]]
494 [[deprecated(
"This function is not compatible with contexts. Consider using `TCOD_console_credits_render_ex`.")]]
534 [[deprecated(
"Default console parameters are deprecated.")]]
553 [[deprecated(
"Default console parameters are deprecated.")]]
719 [[deprecated(
"Default console parameters are deprecated.")]]
734 [[deprecated(
"Default console parameters are deprecated.")]]
752 [[deprecated(
"Default console parameters are deprecated.")]]
769 [[deprecated(
"Default console parameters are deprecated.")]]
779 [[deprecated(
"Use TCODConsole::printf or the std::string overload for this function."
780 "\nNote that you'll need to use UTF-8 encoded strings for those functions.")]]
781 void print(
int x,
int y,
const char *fmt, ...);
782#ifndef TCOD_NO_UNICODE
792 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print.")]]
793 void print(
int x,
int y,
const std::string &str);
801 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print.")]]
802 void print(
int x,
int y,
const std::string &str,
813 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print and tcod::stringf.")]]
815 void
printf(
int x,
int y, const
char *fmt, ...);
823 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print and tcod::stringf.")]]
826 const
char *fmt, ...);
837 "Use TCODConsole::print (std::string overload) or TCODConsole::printf"
838 "instead of this function."
839 "\nNote that you'll need to use UTF-8 encoded strings for those functions.")]]
864 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print_rect and tcod::stringf.")]]
866 int
printRect(
int x,
int y,
int w,
int h, const
char *fmt, ...);
892 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print_rect and tcod::stringf.")]]
914 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::get_height_rect.")]]
1000 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print and tcod::stringf.")]]
1001 void print(
int x,
int y,
const wchar_t *fmt, ...);
1007 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print and tcod::stringf.")]]
1014 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print_rect and tcod::stringf.")]]
1015 int printRect(
int x,
int y,
int w,
int h,
const wchar_t *fmt, ...);
1022 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::print_rect and tcod::stringf.")]]
1030 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::get_height_rect.")]]
1031 int getHeightRect(
int x,
int y,
int w,
int h,
const wchar_t *fmt, ...);
1062 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::draw_rect.")]]
1085 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::draw_rect.")]]
1108 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::draw_rect.")]]
1141 [[deprecated(
"TCODConsole methods are deprecated, this call should be replaced with tcod::draw_frame.")]]
1142 TCODLIB_FORMAT(8, 9)
1184 [[deprecated(
"Default console parameters are deprecated.")]]
1198 [[deprecated(
"Default console parameters are deprecated.")]]
1287 [[deprecated(
"This function does not support contexts.")]]
1326 [[deprecated(
"This function does not support contexts.")]]
1447 [[deprecated(
"This API is deprecated, use SDL_WaitEvent instead.")]]
1450 [[deprecated(
"This API is deprecated, use SDL_PollEvent instead.")]]
1451 static
TCOD_key_t checkForKeypress(
int flags=TCOD_KEY_RELEASED);
1600 bool loadXp(
const char *filename) {
1603 bool saveXp(
const char *filename,
int compress_level) {
1699 [[deprecated(
"This function has been replaced by tcod::blit.")]]
1700 static void blit(
const TCODConsole *src,
int xSrc,
int ySrc,
int wSrc,
int hSrc,
TCODConsole *dst,
int xDst,
int yDst,
float foreground_alpha=1.0f,
float background_alpha=1.0f);
1741 [[deprecated(
"This function is a stub and will do nothing.")]]
1743 [[deprecated(
"This function is a stub and will do nothing.")]]
1744 static void disableKeyboardRepeat();
1747 [[deprecated(
"This function does nothing.")]]
void setDirty(
int x,
int y,
int w,
int h);
1760 static const char* getColorControlString(TCOD_colctrl_t ctrl);
1762 static const char* getRGBColorControlString(TCOD_colctrl_t ctrl,
const TCODColor& col);
1773 [[nodiscard]]
auto get_data() const noexcept -> const
TCOD_Console* {
return get(); }
1786 [[nodiscard]]
auto get() const noexcept -> const
TCOD_Console* {
1800 if (!out)
throw std::logic_error(
"Tried to get a reference to nullptr.");
1813 if (!out)
throw std::logic_error(
"Tried to get a reference to nullptr.");
TCOD_alignment_t getAlignment() const
This function returns the default alignment (see TCOD_alignment_t) for the console.
int getHeightRect(int x, int y, int w, int h, const char *fmt,...)
This function returns the expected height of an auto-wrapped string without actually printing the str...
static TCODColor getFadingColor()
This function returns the current fading color, previously defined by setFade.
void printf(int x, int y, const char *fmt,...)
Format and print a UTF-8 string to the console.
TCODConsole(tcod::ConsolePtr console)
Construct a new TCODConsole object from a tcod::ConsolePtr.
Definition console.hpp:1757
void setDefaultBackground(TCODColor back)
This function changes the default background color for a console.
void setAlignment(TCOD_alignment_t alignment)
This function defines the default alignment (see TCOD_alignment_t) for the console.
void putCharEx(int x, int y, int c, const TCODColor &fore, const TCODColor &back)
This function modifies every property of a cell : set the cell's background color to back.
static void mapAsciiCodeToFont(int asciiCode, int fontCharX, int fontCharY)
void putChar(int x, int y, int c, TCOD_bkgnd_flag_t flag=TCOD_BKGND_DEFAULT)
This function modifies every property of a cell : update the cell's background color according to the...
static bool isWindowClosed()
When you start the program, this returns false.
void rect(int x, int y, int w, int h, bool clear, TCOD_bkgnd_flag_t flag=TCOD_BKGND_DEFAULT)
Fill a rectangle inside a console.
void printFrame(int x, int y, int w, int h, bool clear=true, TCOD_bkgnd_flag_t flag=TCOD_BKGND_DEFAULT, const char *fmt=NULL,...)
This function calls the rect function using the supplied background mode flag, then draws a rectangle...
void print(int x, int y, const std::string &str, TCOD_alignment_t alignment, TCOD_bkgnd_flag_t flag)
Print a UTF-8 string to the console with specific alignment and blend mode.
int getHeight() const
This function returns the height of a console (either the root console or an offscreen console).
static void mapStringToFont(const wchar_t *s, int fontCharX, int fontCharY)
those functions are similar to their ASCII equivalent, but work with unicode strings (wchar_t in C/C+...
TCODConsole()=default
Default constructor.
int printRect(int x, int y, int w, int h, const char *fmt,...)
This function draws a string in a rectangle inside the console, using default colors,...
static void setKeyboardRepeat(int initialDelay, int interval)
Use this function to destroy an offscreen console and release any resources allocated.
int getWidth() const
This function returns the width of a console (either the root console or an offscreen console).
static bool isActive()
Returns false if the game window is not the active window or is iconified.
TCODColor getDefaultBackground() const
This function returns the default background color of a console.
void print(int x, int y, const std::string &str)
Print an EASCII encoded string to the console.
static bool isKeyPressed(TCOD_keycode_t key)
The preferred way to check for user input is to use checkForEvent below, but you can also get the sta...
static void initRoot(int w, int h, const char *title, bool fullscreen=false, TCOD_renderer_t renderer=TCOD_RENDERER_SDL)
static void TCODConsole::initRoot(int w, int h, string title) static void TCODConsole::initRoot(int w...
void vline(int x, int y, int l, TCOD_bkgnd_flag_t flag=TCOD_BKGND_DEFAULT)
Draws an vertical line in the console, using ASCII code TCOD_CHAR_VLINE (179), and the console's defa...
static uint8_t getFade()
This function returns the current fade amount, previously defined by setFade.
static void setWindowTitle(const char *title)
This function dynamically changes the title of the game window.
static bool isFullscreen()
This function returns true if the current mode is fullscreen.
static void setColorControl(TCOD_colctrl_t con, const TCODColor &fore, const TCODColor &back)
If you want to draw a string using different colors for each word, the basic solution is to call a st...
void setChar(int x, int y, int c)
This function modifies the ASCII code of a cell, leaving other properties (background and foreground ...
void print(int x, int y, const char *fmt,...)
Print an EASCII formatted string to the console.
static TCOD_key_t waitForKeypress(bool flush)
Some useful graphic characters in the terminal.bmp font.
auto get_data() noexcept -> TCOD_Console *
Return a pointer to the underlying TCOD_Console struct.
Definition console.hpp:1772
void setCharForeground(int x, int y, const TCODColor &col)
This function modifies the foreground color of a cell, leaving other properties (background color and...
static void mapAsciiCodesToFont(int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
bool loadApf(const char *filename)
You can load data from a file created with Ascii Paint with this function.
static bool renderCredits(int x, int y, bool alpha)
You can also print the credits on one of your game screens (your main menu for example) by calling th...
static void setCustomFont(const char *fontFile, int flags=TCOD_FONT_LAYOUT_ASCII_INCOL, int nbCharHoriz=0, int nbCharVertic=0)
This function allows you to use a bitmap font (png or bmp) with custom character size or layout.
bool saveApf(const char *filename) const
You can save data from a console to Ascii Paint format with this function.
int getChar(int x, int y) const
This function returns the ASCII code of a cell.
auto get() noexcept -> TCOD_Console *
Return a pointer to the underlying TCOD_Console struct.
Definition console.hpp:1782
bool loadAsc(const char *filename)
You can load data from a file created with Ascii Paint with this function.
static bool hasMouseFocus()
Returns true if the mouse cursor is inside the game window area and the game window is the active app...
TCOD_bkgnd_flag_t getBackgroundFlag() const
This function returns the background mode (see TCOD_bkgnd_flag_t) for the console.
static void setFade(uint8_t fade, const TCODColor &fadingColor)
This function defines the fading parameters, allowing to easily fade the game screen to/from a color....
void printEx(int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
Print an EASCII formatted string to the console.
static void resetCredits()
When using renderCredits, you can restart the credits animation from the beginning before it's finish...
TCODColor getCharForeground(int x, int y) const
This function returns the foreground color of a cell.
static void setFullscreen(bool fullscreen)
This function switches the root console to fullscreen or windowed mode.
static void mapStringToFont(const char *s, int fontCharX, int fontCharY)
TCODColor getDefaultForeground() const
This function returns the default foreground color of a console.
void setBackgroundFlag(TCOD_bkgnd_flag_t flag)
This function defines the background mode (see TCOD_bkgnd_flag_t) for the console.
static void flush()
Once the root console is initialized, you can use one of the printing functions to change the backgro...
void setDefaultForeground(TCODColor fore)
This function changes the default foreground color for a console.
TCODColor getCharBackground(int x, int y) const
This function returns the background color of a cell.
static void blit(const TCODConsole *src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole *dst, int xDst, int yDst, float foreground_alpha=1.0f, float background_alpha=1.0f)
This function allows you to blit a rectangular area of the source console at a specific position on a...
void setCharBackground(int x, int y, const TCODColor &col, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET)
This function modifies the background color of a cell, leaving other properties (foreground color and...
void setKeyColor(const TCODColor &col)
This function defines a transparent background color for an offscreen console.
static void credits()
You can print a "Powered by libtcod x.y.z" screen during your game startup simply by calling this fun...
void clear()
This function modifies all cells of a console : set the cell's background color to the console defaul...
bool saveAsc(const char *filename) const
You can save data from a console to Ascii Paint format with this function.
void hline(int x, int y, int l, TCOD_bkgnd_flag_t flag=TCOD_BKGND_DEFAULT)
Draws an horizontal line in the console, using ASCII code TCOD_CHAR_HLINE (196), and the console's de...
int printRectEx(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
This function draws a string in a rectangle inside the console, using default colors,...
Various console functions.
Console simple drawing module.
Miscellaneous deprecated functions.
Deprecated root console initialization.
TCOD_Console * TCOD_sys_get_internal_console(void)
Return a pointer to the "root console" used internally by the old API.
Console string printing module.
C types for console functions.
TCOD_keycode_t
Libtcod specific codes representing keys on the keyboard.
Definition console_types.h:126
@ TCOD_FONT_LAYOUT_ASCII_INCOL
Tiles are arranged in column-major order.
Definition console_types.h:467
TCOD_renderer_t
Libtcod rendering modes.
Definition console_types.h:491
@ TCOD_RENDERER_SDL
A software based renderer.
Definition console_types.h:517
void blit(TCOD_Console &dest, const TCOD_Console &source, const std::array< int, 2 > &dest_xy={0, 0}, std::array< int, 4 > source_rect={0, 0, 0, 0}, float foreground_alpha=1.0f, float background_alpha=1.0f)
Blit a region of tiles from one console to another.
Definition console.hpp:65
void TCOD_console_blit(const TCOD_Console *src, int xSrc, int ySrc, int wSrc, int hSrc, TCOD_Console *dst, int xDst, int yDst, float foreground_alpha, float background_alpha)
Blit from one console to another.
TCOD_alignment_t
Print justification options.
Definition console.h:81
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
bool TCOD_console_load_xp(TCOD_Console *con, const char *filename)
Update a console from a REXPaint .xp file.
bool TCOD_console_save_xp(const TCOD_Console *con, const char *filename, int compress_level)
Save a console as a REXPaint .xp file.
The libtcod namespace.
Definition bresenham.hpp:157
std::unique_ptr< struct TCOD_Console, ConsoleDeleter > ConsolePtr
A unique pointer to a TCOD_Console.
Definition console_types.hpp:56
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:125
Libtcod key event data, as a keycode or text character.
Definition console_types.h:207