libtcod
Loading...
Searching...
No Matches
TCODConsole Class Reference

Classic turn by turn game loop:TCODConsole::initRoot(80,50,"my game",false); while (!endGame && !TCODConsole::isWindowClosed()) { ... draw on TCODConsole::root TCODConsole::flush(); TCOD_key_t key; TCODConsole::waitForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL,true); ... update world, using key }. More...

#include <console.hpp>

Public Member Functions

 TCODConsole ()=default
 Default constructor.
void setDefaultBackground (TCODColor back)
 This function changes the default background color for a console.
void setDefaultForeground (TCODColor fore)
 This function changes the default foreground color for a console.
void clear ()
 This function modifies all cells of a console : set the cell's background color to the console default background color set the cell's foreground color to the console default foreground color set the cell's ASCII code to 32 (space).
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 ASCII code) unchanged.
void setCharForeground (int x, int y, const TCODColor &col)
 This function modifies the foreground color of a cell, leaving other properties (background color and ASCII code) unchanged.
void setChar (int x, int y, int c)
 This function modifies the ASCII code of a cell, leaving other properties (background and foreground colors) unchanged.
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 console default background color (see TCOD_bkgnd_flag_t).
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.
void setBackgroundFlag (TCOD_bkgnd_flag_t flag)
 This function defines the background mode (see TCOD_bkgnd_flag_t) for the console.
TCOD_bkgnd_flag_t getBackgroundFlag () const
 This function returns the background mode (see TCOD_bkgnd_flag_t) for the console.
void setAlignment (TCOD_alignment_t alignment)
 This function defines the default alignment (see TCOD_alignment_t) for the console.
TCOD_alignment_t getAlignment () const
 This function returns the default alignment (see TCOD_alignment_t) for the console.
void print (int x, int y, const char *fmt,...)
 Print an EASCII formatted string to the console.
void print (int x, int y, const std::string &str)
 Print an EASCII encoded string to the console.
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.
void printf (int x, int y, const char *fmt,...)
 Format and print a UTF-8 string to the console.
void printf (int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const char *fmt,...)
 Format and print a UTF-8 string to the console with specific alignment and blend mode.
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.
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, alignment and background mode.
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, but specific alignment and background mode.
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 string with printRect or printRectEx.
void print (int x, int y, const wchar_t *fmt,...)
void printEx (int x, int y, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt,...)
int printRect (int x, int y, int w, int h, const wchar_t *fmt,...)
int printRectEx (int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, TCOD_alignment_t alignment, const wchar_t *fmt,...)
int getHeightRect (int x, int y, int w, int h, const wchar_t *fmt,...)
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 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 default background/foreground colors.
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 default background/foreground colors.
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 with the console's default foreground color.
int getWidth () const
 This function returns the width of a console (either the root console or an offscreen console).
int getHeight () const
 This function returns the height of a console (either the root console or an offscreen console).
TCODColor getDefaultBackground () const
 This function returns the default background color of a console.
TCODColor getDefaultForeground () const
 This function returns the default foreground color of a console.
TCODColor getCharBackground (int x, int y) const
 This function returns the background color of a cell.
TCODColor getCharForeground (int x, int y) const
 This function returns the foreground color of a cell.
int getChar (int x, int y) const
 This function returns the ASCII code of a cell.
 TCODConsole (int w, int h)
 You can create as many off-screen consoles as you want by using this function. You can draw on them as you would do with the root console, but you cannot flush them to the screen. Else, you can blit them on other consoles, including the root console. See blit. The C version of this function returns a console handler that you can use in most console drawing functions.
 TCODConsole (const char *filename)
 You can create an offscreen console from a file created with Ascii Paint with this constructor.
bool loadAsc (const char *filename)
 You can load data from a file created with Ascii Paint with this function.
bool loadApf (const char *filename)
 You can load data from a file created with Ascii Paint with this function.
bool saveAsc (const char *filename) const
 You can save data from a console to Ascii Paint format with this function.
bool saveApf (const char *filename) const
 You can save data from a console to Ascii Paint format with this function.
bool loadXp (const char *filename)
bool saveXp (const char *filename, int compress_level)
void setKeyColor (const TCODColor &col)
 This function defines a transparent background color for an offscreen console.
void setDirty (int x, int y, int w, int h)
 TCODConsole (TCOD_Console *console)
 TCODConsole (tcod::ConsolePtr console)
 Construct a new TCODConsole object from a tcod::ConsolePtr.
auto get_data () noexcept -> TCOD_Console *
 Return a pointer to the underlying TCOD_Console struct.
auto get_data () const noexcept -> const TCOD_Console *
auto get () noexcept -> TCOD_Console *
 Return a pointer to the underlying TCOD_Console struct.
auto get () const noexcept -> const TCOD_Console *
 operator TCOD_Console & ()
 Allow implicit conversions into a TCOD_Console reference.
 operator const TCOD_Console & () const
 Allow implicit conversions into a const TCOD_Console reference.
 operator TCOD_Console * () noexcept
 Allow explicit conversions into a TCOD_Console pointer.
 operator const TCOD_Console * () const noexcept
 Allow explicit conversions into a const TCOD_Console pointer.

Static Public Member Functions

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, int h, string title, bool fullscreen) static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen, TCODRendererType renderer)tcod.console.initRoot(w,h,title) – fullscreen = false, renderer = SDL tcod.console.initRoot(w,h,title,fullscreen) – renderer = SDL tcod.console.initRoot(w,h,title,fullscreen,renderer) – renderers : tcod.GLSL, tcod.OpenGL, tcod.SDL
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.
static void mapAsciiCodeToFont (int asciiCode, int fontCharX, int fontCharY)
static void mapAsciiCodesToFont (int firstAsciiCode, int nbCodes, int fontCharX, int fontCharY)
static void mapStringToFont (const char *s, int fontCharX, int fontCharY)
static bool isFullscreen ()
 This function returns true if the current mode is fullscreen.
static void setFullscreen (bool fullscreen)
 This function switches the root console to fullscreen or windowed mode.
static void setWindowTitle (const char *title)
 This function dynamically changes the title of the game window.
static bool isWindowClosed ()
 When you start the program, this returns false.
static bool hasMouseFocus ()
 Returns true if the mouse cursor is inside the game window area and the game window is the active application.
static bool isActive ()
 Returns false if the game window is not the active window or is iconified.
static void credits ()
 You can print a "Powered by libtcod x.y.z" screen during your game startup simply by calling this function after initRoot. The credits screen can be skipped by pressing any key.
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 this function in your main loop.
static void resetCredits ()
 When using renderCredits, you can restart the credits animation from the beginning before it's finished by calling this function.
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 string printing function several times, changing the default colors between each call.
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++).
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. Once they are defined, the fading parameters are valid for ever. You don't have to call setFade for each rendered frame (unless you change the fading parameters).
static uint8_t getFade ()
 This function returns the current fade amount, previously defined by setFade.
static TCODColor getFadingColor ()
 This function returns the current fading color, previously defined by setFade.
static void flush ()
 Once the root console is initialized, you can use one of the printing functions to change the background colors, the foreground colors or the ASCII characters on the console.
static TCOD_key_t waitForKeypress (bool flush)
 Some useful graphic characters in the terminal.bmp font.
static TCOD_key_t checkForKeypress (int flags=TCOD_KEY_RELEASED)
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 status of any special key at any time with :
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 destination console.
static void setKeyboardRepeat (int initialDelay, int interval)
 Use this function to destroy an offscreen console and release any resources allocated.
static void disableKeyboardRepeat ()
static const char * getColorControlString (TCOD_colctrl_t ctrl)
static const char * getRGBColorControlString (TCOD_colctrl_t ctrl, const TCODColor &col)

Static Public Attributes

static TCODConsoleroot

Detailed Description

Classic turn by turn game loop:

TCODConsole::initRoot(80,50,"my game",false); while (!endGame && !TCODConsole::isWindowClosed()) { ... draw on TCODConsole::root TCODConsole::flush(); TCOD_key_t key; TCODConsole::waitForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL,true); ... update world, using key }.

The console emulator handles the rendering of the game screen and the keyboard input. Classic real time game loop:

TCODConsole::initRoot(80,50,"my game",false); TCODSystem::setFps(25); // limit framerate to 25 frames per second while (!endGame && !TCODConsole::isWindowClosed()) { TCOD_key_t key; TCODSystem::checkForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL); updateWorld (key, TCODSystem::getLastFrameLength()); updateWorld(TCOD_key_t key, float elapsed) (using key if key.vk != TCODK_NONE) use elapsed to scale any update that is time dependent. ... draw world+GUI on TCODConsole::root TCODConsole::flush(); }

tcod.console.initRoot(80,50,"my game", false) root=libtcod.TCODConsole_root tcod.system.setFps(25) while not tcod.console.isWindowClosed() do – ... draw on root tcod.console.flush() key=tcod.console.checkForKeypress() – ... update world, using key and tcod.system.getLastFrameLength end

Constructor & Destructor Documentation

◆ TCODConsole() [1/4]

TCODConsole::TCODConsole ( )
default

Default constructor.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ TCODConsole() [2/4]

TCODConsole::TCODConsole ( int w,
int h )

You can create as many off-screen consoles as you want by using this function. You can draw on them as you would do with the root console, but you cannot flush them to the screen. Else, you can blit them on other consoles, including the root console. See blit. The C version of this function returns a console handler that you can use in most console drawing functions.

The offscreen consoles allow you to draw on secondary consoles as you would do with the root console. You can then blit those secondary consoles on the root console. This allows you to use local coordinate space while rendering a portion of the final screen, and easily move components of the screen without modifying the rendering functions.

Parameters
w,hthe console size. 0 < w 0 < h

Creating a 40x20 offscreen console, filling it with red and blitting it on the root console at position 5,5 TCODConsole *offscreenConsole = new TCODConsole(40,20); offscreenConsole->setDefaultBackground(TCODColor::red); offscreenConsole->clear(); TCODConsole::blit(offscreenConsole,0,0,40,20,TCODConsole::root,5,5,255);

TCOD_console_t offscreen_console = TCOD_console_new(40,20); TCOD_console_set_default_background(offscreen_console,TCOD_red); TCOD_console_clear(offscreen_console); TCOD_console_blit(offscreen_console,0,0,40,20,NULL,5,5,255);

offscreen_console = libtcod.console_new(40,20) libtcod.console_set_background_color(offscreen_console,libtcod.red) libtcod.console_clear(offscreen_console) libtcod.console_blit(offscreen_console,0,0,40,20,0,5,5,255)

– Creating a 40x20 offscreen console, filling it with red and blitting it on the root console at position 5,5 offscreenConsole = tcod.Console(40,20) offscreenConsole:setBackgroundColor(tcod.color.red) offscreenConsole:clear() tcod.console.blit(offscreenConsole,0,0,40,20,libtcod.TCODConsole_root,5,5,255)

◆ TCODConsole() [3/4]

TCODConsole::TCODConsole ( const char * filename)

You can create an offscreen console from a file created with Ascii Paint with this constructor.

Parameters
filenamepath to the .asc or .apf file created with Ascii Paint

Creating an offscreen console, filling it with data from the .asc file TCODConsole *offscreenConsole = new TCODConsole("myfile.asc");

TCOD_console_t offscreen_console = TCOD_console_from_file("myfile.apf");

◆ TCODConsole() [4/4]

TCODConsole::TCODConsole ( tcod::ConsolePtr console)
inlineexplicit

Construct a new TCODConsole object from a tcod::ConsolePtr.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

Member Function Documentation

◆ blit()

void TCODConsole::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 )
static

This function allows you to blit a rectangular area of the source console at a specific position on a destination console.

It can also simulate alpha transparency with the fade parameter.

static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst) static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst, float foreground_alpha) static void TCODConsole::blit(TCODConsole src, int xSrc, int ySrc, int wSrc, int hSrc, TCODConsole dst, int xDst, int yDst, float foreground_alpha, float background_alpha)

tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst) tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst, foreground_alpha) tcod.console.blit(src, xSrc, ySrc, wSrc, hSrc, dst, xDst, yDst, foreground_alpha, background_alpha)

Parameters
srcThe source console that must be blitted on another one.
xSrc,ySrc,wSrc,hSrcThe rectangular area of the source console that will be blitted. If wSrc and/or hSrc == 0, the source console width/height are used
dstThe destination console.
xDst,yDstWhere to blit the upper-left corner of the source area in the destination console.
foregroundAlpha,backgroundAlphaAlpha transparency of the blitted console. 0.0 => The source console is completely transparent. This function does nothing. 1.0 => The source console is opaque. Its cells replace the destination cells. 0 < fade < 1.0 => The source console is partially blitted, simulating real transparency.

Cross-fading between two offscreen consoles. We use two offscreen consoles with the same size as the root console. We render a different screen on each offscreen console. When the user hits a key, we do a cross-fading from the first screen to the second screen. TCODConsole *off1 = new TCODConsole(80,50); TCODConsole *off2 = new TCODConsole(80,50); ... print screen1 on off1 ... print screen2 of off2 render screen1 in the game window TCODConsole::blit(off1,0,0,80,50,TCODConsole::root,0,0); TCODConsole::flush(); wait or a keypress TCODConsole::waitForKeypress(true); do a cross-fading from off1 to off2 for (int i=1; i <= 255; i++) { TCODConsole::blit(off1,0,0,80,50,TCODConsole::root,0,0); // renders the first screen (opaque) TCODConsole::blit(off2,0,0,80,50,TCODConsole::root,0,0,i/255.0,i/255.0); // renders the second screen (transparent) TCODConsole::flush(); }

TCOD_console_t off1 = TCOD_console_new(80,50); TCOD_console_t off2 = TCOD_console_new(80,50); int i; ... print screen1 on off1 ... print screen2 of off2 render screen1 in the game window TCOD_console_blit(off1,0,0,80,50,NULL,0,0,1.0,1.0); TCOD_console_flush(); wait or a keypress TCOD_console_wait_for_keypress(true); do a cross-fading from off1 to off2 for (i=1; i <= 255; i++) { TCOD_console_blit(off1,0,0,80,50,NULL,0,0,1.0,1.0); // renders the first screen (opaque) TCOD_console_blit(off2,0,0,80,50,NULL,0,0,i/255.0,i/255.0); // renders the second screen (transparent) TCOD_console_flush(); }

off1 = libtcod.console_new(80,50) off2 = libtcod.console_new(80,50) ... print screen1 on off1 ... print screen2 of off2

render screen1 in the game window

libtcod.console_blit(off1,0,0,80,50,0,0,0) libtcod.console_flush()

wait or a keypress

libtcod.console_wait_for_keypress(True)

do a cross-fading from off1 to off2

for i in range(1,256) : libtcod.console_blit(off1,0,0,80,50,0,0,0) # renders the first screen (opaque) libtcod.console_blit(off2,0,0,80,50,0,0,0,i/255.0,i/255.0) # renders the second screen (transparent) libtcod.console_flush()

– Cross-fading between two offscreen consoles. We use two offscreen consoles with the same size as the root console. We render a different screen on each offscreen console. When the user hits a key, we do a cross-fading from the first screen to the second screen. off1 = tcod.Console(80,50) off2 = tcod.Console(80,50) ... print screen1 on off1 ... print screen2 of off2 – render screen1 in the game window root=libtcod.TCODConsole_root tcod.console.blit(off1,0,0,80,50,root,0,0) tcod.console.flush() – wait or a keypress tcod.console.waitForKeypress(true) – do a cross-fading from off1 to off2 for i=1,255,1 do tcod.console.blit(off1,0,0,80,50,root,0,0) – renders the first screen (opaque) tcod.console.blit(off2,0,0,80,50,root,0,0,i/255,i/255) – renders the second screen (transparent) tcod.console.flush() end

◆ clear()

void TCODConsole::clear ( )

This function modifies all cells of a console : set the cell's background color to the console default background color set the cell's foreground color to the console default foreground color set the cell's ASCII code to 32 (space).

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ credits()

void TCODConsole::credits ( )
static

You can print a "Powered by libtcod x.y.z" screen during your game startup simply by calling this function after initRoot. The credits screen can be skipped by pressing any key.

Use these functions to display credits, as seen in the samples.

◆ flush()

void TCODConsole::flush ( )
static

Once the root console is initialized, you can use one of the printing functions to change the background colors, the foreground colors or the ASCII characters on the console.

Once you've finished rendering the root console, you have to actually apply the updates to the screen with this function.

◆ get()

auto TCODConsole::get ( ) ->TCOD_Console *
inlinenodiscardnoexcept

Return a pointer to the underlying TCOD_Console struct.

Returns
TCOD_Console*
embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ get_data()

auto TCODConsole::get_data ( ) ->TCOD_Console *
inlinenodiscardnoexcept

Return a pointer to the underlying TCOD_Console struct.

embed:rst:leading-asterisk 
.. versionadded:: 1.14

.. versionchanged:: 1.19
    This now returns a non-NULL pointer to the root console.

◆ getAlignment()

TCOD_alignment_t TCODConsole::getAlignment ( ) const

This function returns the default alignment (see TCOD_alignment_t) for the console.

This default mode is used by several functions (print, printRect, ...). Values for alignment : TCOD_LEFT, TCOD_CENTER, TCOD_RIGHT (in Python, remove TCOD_ : libtcod.LEFT). For C# and Lua : LeftAlignment, RightAlignment, CenterAlignment

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ getBackgroundFlag()

TCOD_bkgnd_flag_t TCODConsole::getBackgroundFlag ( ) const

This function returns the background mode (see TCOD_bkgnd_flag_t) for the console.

This default mode is used by several functions (print, printRect, ...)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ getChar()

int TCODConsole::getChar ( int x,
int y ) const

This function returns the ASCII code of a cell.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height

◆ getCharBackground()

TCODColor TCODConsole::getCharBackground ( int x,
int y ) const

This function returns the background color of a cell.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height

◆ getCharForeground()

TCODColor TCODConsole::getCharForeground ( int x,
int y ) const

This function returns the foreground color of a cell.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height

◆ getDefaultBackground()

TCODColor TCODConsole::getDefaultBackground ( ) const

This function returns the default background color of a console.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ getDefaultForeground()

TCODColor TCODConsole::getDefaultForeground ( ) const

This function returns the default foreground color of a console.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ getHeight()

int TCODConsole::getHeight ( ) const

This function returns the height of a console (either the root console or an offscreen console).

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ getHeightRect()

int TCODConsole::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 string with printRect or printRectEx.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinate of the rectangle upper-left corner in the console
w,hsize of the rectangle x <= x+w < 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, except in C#.

◆ getWidth()

int TCODConsole::getWidth ( ) const

This function returns the width of a console (either the root console or an offscreen console).

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console

◆ hline()

void TCODConsole::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 default background/foreground colors.

void TCODConsole::hline(int x,int y, int l) void TCODConsole::hline(int x,int y, int l, TCODBackgroundFlag flag)

Console:hline(x,y, l) Console:hline(x,y, l, flag)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,yCoordinates of the line's left end in the console. 0 <= x < console width 0 <= y < console height
lThe length of the line in cells 1 <= l <= console width - x
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t

◆ initRoot()

void TCODConsole::initRoot ( int w,
int h,
const char * title,
bool fullscreen = false,
TCOD_renderer_t renderer = TCOD_RENDERER_SDL )
static

static void TCODConsole::initRoot(int w, int h, string title) static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen) static void TCODConsole::initRoot(int w, int h, string title, bool fullscreen, TCODRendererType renderer)tcod.console.initRoot(w,h,title) – fullscreen = false, renderer = SDL tcod.console.initRoot(w,h,title,fullscreen) – renderer = SDL tcod.console.initRoot(w,h,title,fullscreen,renderer) – renderers : tcod.GLSL, tcod.OpenGL, tcod.SDL

Parameters
w,hsize of the console(in characters). The default font in libtcod (./terminal.png) uses 8x8 pixels characters. You can change the font by calling TCODConsole::setCustomFont before calling initRoot.
titletitle of the window. It's not visible when you are in fullscreen. Note 1 : you can dynamically change the window title with TCODConsole::setWindowTitle
fullscreenwhether you start in windowed or fullscreen mode. Note 1 : you can dynamically change this mode with TCODConsole::setFullscreen Note 2 : you can get current mode with TCODConsole::isFullscreen
rendererwhich renderer to use. Possible values are : TCOD_RENDERER_GLSL : works only on video cards with pixel shaders TCOD_RENDERER_OPENGL : works on all video cards supporting OpenGL 1.4 TCOD_RENDERER_SDL : should work everywhere! Note 1: if you select a renderer that is not supported by the player's machine, libtcod scan the lower renderers until it finds a working one. Note 2: on recent video cards, GLSL results in up to 900% increase of framerates in the true color sample compared to SDL renderer. Note 3: whatever renderer you use, it can always be overridden by the player through the libtcod.cfg file. Note 4: you can dynamically change the renderer after calling initRoot with TCODSystem::setRenderer. Note 5: you can get current renderer with TCODSystem::getRenderer. It might be different from the one you set in initRoot in case it's not supported on the player's computer.

◆ isKeyPressed()

bool TCODConsole::isKeyPressed ( TCOD_keycode_t key)
static

The preferred way to check for user input is to use checkForEvent below, but you can also get the status of any special key at any time with :

This function stops the application until an event occurs.

Parameters
keyAny key code defined in keycode_t except TCODK_CHAR (Char) and TCODK_NONE (NoKey)

◆ isWindowClosed()

bool TCODConsole::isWindowClosed ( )
static

When you start the program, this returns false.

Once a "close window" event has been sent by the window manager, it will always return true. You're supposed to exit cleanly the game.

◆ loadApf()

bool TCODConsole::loadApf ( const char * filename)

You can load data from a file created with Ascii Paint with this function.

When needed, the console will be resized to fit the file size. The function returns false if it couldn't read the file.

Parameters
conin the C and Python versions, the offscreen console handler
filenamepath to the .apf file created with Ascii Paint

Creating a 40x20 offscreen console TCODConsole *offscreenConsole = new TCODConsole(40,20); possibly resizing it and filling it with data from the .apf file offscreenConsole->loadApf("myfile.apf");

TCOD_console_t offscreen_console = TCOD_console_new(40,20); TCOD_console_load_apf(offscreen_console,"myfile.asc");

◆ loadAsc()

bool TCODConsole::loadAsc ( const char * filename)

You can load data from a file created with Ascii Paint with this function.

When needed, the console will be resized to fit the file size. The function returns false if it couldn't read the file.

Parameters
conin the C and Python versions, the offscreen console handler
filenamepath to the .asc file created with Ascii Paint

Creating a 40x20 offscreen console TCODConsole *offscreenConsole = new TCODConsole(40,20); possibly resizing it and filling it with data from the .asc file offscreenConsole->loadAsc("myfile.asc");

TCOD_console_t offscreen_console = TCOD_console_new(40,20); TCOD_console_load_asc(offscreen_console,"myfile.asc");

◆ mapAsciiCodesToFont()

void TCODConsole::mapAsciiCodesToFont ( int firstAsciiCode,
int nbCodes,
int fontCharX,
int fontCharY )
static
Parameters
firstAsciiCodefirst ASCII code to map
nbCodesnumber of consecutive ASCII codes to map
fontCharX,fontCharYcoordinate of the character in the bitmap font (in characters, not pixels) corresponding to the first ASCII code

◆ mapAsciiCodeToFont()

void TCODConsole::mapAsciiCodeToFont ( int asciiCode,
int fontCharX,
int fontCharY )
static

These functions allow you to map characters in the bitmap font to ASCII codes. They should be called after initializing the root console with initRoot. You can dynamically change the characters mapping at any time, allowing to use several fonts in the same screen.

Parameters
asciiCodeASCII code to map.
fontCharX,fontCharYCoordinate of the character in the bitmap font (in characters, not pixels).

◆ mapStringToFont() [1/2]

void TCODConsole::mapStringToFont ( const char * s,
int fontCharX,
int fontCharY )
static
Parameters
sstring containing the ASCII codes to map
fontCharX,fontCharYcoordinate of the character in the bitmap font (in characters, not pixels) corresponding to the first ASCII code in the string

◆ mapStringToFont() [2/2]

void TCODConsole::mapStringToFont ( const wchar_t * s,
int fontCharX,
int fontCharY )
static

those functions are similar to their ASCII equivalent, but work with unicode strings (wchar_t in C/C++).

Note that unicode is not supported in the Python wrapper.

◆ operator const TCOD_Console &()

TCODConsole::operator const TCOD_Console & ( ) const
inlinenodiscard

Allow implicit conversions into a const TCOD_Console reference.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator const TCOD_Console *()

TCODConsole::operator const TCOD_Console * ( ) const
inlineexplicitnodiscardnoexcept

Allow explicit conversions into a const TCOD_Console pointer.

Same as calling get_data.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator TCOD_Console &()

TCODConsole::operator TCOD_Console & ( )
inlinenodiscard

Allow implicit conversions into a TCOD_Console reference.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ operator TCOD_Console *()

TCODConsole::operator TCOD_Console * ( )
inlineexplicitnodiscardnoexcept

Allow explicit conversions into a TCOD_Console pointer.

Same as calling get_data.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ print() [1/3]

void TCODConsole::print ( int x,
int y,
const char * fmt,
... )

Print an EASCII formatted string to the console.

embed:rst:leading-asterisk 
*  .. deprecated:: 1.8
*    EASCII is being phased out.  Use TCODConsole::printf or one of the
*    UTF-8 overloads.
*  

◆ print() [2/3]

void TCODConsole::print ( int x,
int y,
const std::string & str )

Print an EASCII encoded string to the console.

This method will use this consoles default alignment, blend mode, and colors.

embed:rst:leading-asterisk 
*  .. versionadded:: 1.8
*  

◆ print() [3/3]

void TCODConsole::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.

embed:rst:leading-asterisk 
*  .. versionadded:: 1.8
*  

◆ printEx()

void TCODConsole::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.

embed:rst:leading-asterisk 
*  .. deprecated:: 1.8
*    Use `TCODConsole::print` or `TCODConsole::printf`.
*    These functions have overloads for specifying flag and alignment.
*  

◆ printf() [1/2]

void TCODConsole::printf ( int x,
int y,
const char * fmt,
... )

Format and print a UTF-8 string to the console.

This method will use this consoles default alignment, blend mode, and colors.

embed:rst:leading-asterisk 
*  .. versionadded:: 1.8
*  

◆ printf() [2/2]

void TCODConsole::printf ( int x,
int y,
TCOD_bkgnd_flag_t flag,
TCOD_alignment_t alignment,
const char * fmt,
... )

Format and print a UTF-8 string to the console with specific alignment and blend mode.

embed:rst:leading-asterisk 
*  .. versionadded:: 1.8
*  

◆ printFrame()

void TCODConsole::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 with the console's default foreground color.

If fmt is not NULL, it is printed on the top of the rectangle, using inverted colors.

void TCODConsole::printFrame(int x,int y, int w,int h) void TCODConsole::printFrame(int x,int y, int w,int h, bool clear) void TCODConsole::printFrame(int x,int y, int w,int h, bool clear, TCODBackgroundFlag flag) void TCODConsole::printFrame(int x,int y, int w,int h, bool clear, TCODBackgroundFlag flag, string fmt)

Console:printFrame(x,y, w,h) Console:printFrame(x,y, w,h, clear) Console:printFrame(x,y, w,h, clear, flag) Console:printFrame(x,y, w,h, clear, flag, fmt)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,yCoordinates of the rectangle's upper-left corner in the console. 0 <= x < console width 0 <= y < console height
w,hsize of the rectangle in the console. x <= x+w < console width y <= y+h < console height
clearif true, all characters inside the rectangle are set to ASCII code 32 (space). If false, only the background color is modified
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
fmtif NULL, the function only draws a rectangle. Else, printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string.

◆ printRect()

int TCODConsole::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, alignment and background mode.

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.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinate of the character in the console, depending on the alignment : TCOD_LEFT : leftmost character of the string TCOD_CENTER : center character of the string TCOD_RIGHT : rightmost character of the string
w,hsize of the rectangle x <= x+w < 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, except in C#.

◆ printRectEx()

int TCODConsole::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, but specific alignment and background mode.

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.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinate of the character in the console, depending on the alignment : TCOD_LEFT : leftmost character of the string TCOD_CENTER : center character of the string TCOD_RIGHT : rightmost character of the string
w,hsize of the rectangle x <= x+w < console width y <= y+h < console height
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t
alignmentdefines how the strings are printed on screen.
fmtprintf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string, except in C#.

◆ putChar()

void TCODConsole::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 console default background color (see TCOD_bkgnd_flag_t).

set the cell's foreground color to the console default foreground color set the cell's ASCII code to c

void TCODConsole::putChar(int x, int y, int c) void TCODConsole::putChar(int x, int y, int c, TCODBackgroundFlag flag)

Console:putChar(x, y, c) Console:putChar(x, y, c, flag)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height
cthe new ASCII code for the cell. You can use ASCII constants
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t

◆ putCharEx()

void TCODConsole::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.

set the cell's foreground color to fore. set the cell's ASCII code to c.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height
cthe new ASCII code for the cell. You can use ASCII constants
fore,backnew foreground and background colors for this cell

◆ rect()

void TCODConsole::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.

For each cell in the rectangle : set the cell's background color to the console default background color if clear is true, set the cell's ASCII code to 32 (space)

void TCODConsole::rect(int x, int y, int w, int h, bool clear) void TCODConsole::rect(int x, int y, int w, int h, bool clear, TCODBackgroundFlag flag)

Console:rect(x, y, w, h, clear) Console:rect(x, y, w, h, clear, flag)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of rectangle upper-left corner in the console. 0 <= x < console width 0 <= y < console height
w,hsize of the rectangle in the console. x <= x+w < console width y <= y+h < console height
clearif true, all characters inside the rectangle are set to ASCII code 32 (space). If false, only the background color is modified
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t

◆ renderCredits()

bool TCODConsole::renderCredits ( int x,
int y,
bool alpha )
static

You can also print the credits on one of your game screens (your main menu for example) by calling this function in your main loop.

This function returns true when the credits screen is finished, indicating that you no longer need to call it.

Parameters
x,yPosition of the credits text in your root console
alphaIf true, credits are transparently added on top of the existing screen. For this to work, this function must be placed between your screen rendering code and the console flush.

TCODConsole::initRoot(80,50,"The Chronicles Of Doryen v0.1",false); // initialize the root console bool endCredits=false; while ( ! TCODConsole::isWindowClosed() ) { // your game loop your game rendering here... render transparent credits near the center of the screen if (! endCredits ) endCredits=TCODConsole::renderCredits(35,25,true); TCODConsole::flush(); }

TCOD_console_init_root(80,50,"The Chronicles Of Doryen v0.1",false); bool end_credits=false; while ( ! TCOD_console_is_window_closed() ) { your game rendering here... render transparent credits near the center of the screen if (! end_credits ) end_credits=TCOD_console_credits_render(35,25,true); TCOD_console_flush(); }

libtcod.console_init_root(80,50,"The Chronicles Of Doryen v0.1",False) end_credits=False while not libtcod.console_is_window_closed() : your game rendering here... render transparent credits near the center of the screen if (not end_credits ) : end_credits=libtcod.console_credits_render(35,25,True) libtcod.console_flush()

tcod.console.initRoot(80,50,"The Chronicles Of Doryen v0.1") – initialize the root console endCredits=false while not tcod.console.isWindowClosed() do – your game loop – your game rendering here... – render transparent credits near the center of the screen if not endCredits then endCredits=tcod.console.renderCredits(35,25,true) end tcod.console.flush() end

◆ saveApf()

bool TCODConsole::saveApf ( const char * filename) const

You can save data from a console to Ascii Paint format with this function.

The function returns false if it couldn't write the file. This is the only ASC function that works also with the root console !

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
filenamepath to the .apf file to be created

console->saveApf("myfile.apf");

TCOD_console_save_apf(console,"myfile.apf");

◆ saveAsc()

bool TCODConsole::saveAsc ( const char * filename) const

You can save data from a console to Ascii Paint format with this function.

The function returns false if it couldn't write the file. This is the only ASC function that works also with the root console !

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
filenamepath to the .asc file to be created

console->saveAsc("myfile.asc");

TCOD_console_save_asc(console,"myfile.asc");

◆ setAlignment()

void TCODConsole::setAlignment ( TCOD_alignment_t alignment)

This function defines the default alignment (see TCOD_alignment_t) for the console.

This default alignment is used by several functions (print, printRect, ...). Values for alignment : TCOD_LEFT, TCOD_CENTER, TCOD_RIGHT (in Python, remove TCOD_ : libtcod.LEFT). For C# and Lua : LeftAlignment, RightAlignment, CenterAlignment

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
alignmentdefines how the strings are printed on screen.

◆ setBackgroundFlag()

void TCODConsole::setBackgroundFlag ( TCOD_bkgnd_flag_t flag)

This function defines the background mode (see TCOD_bkgnd_flag_t) for the console.

This flag is used by most functions that modify a cell background color. It defines how the console's current background color is used to modify the cell's existing background color : TCOD_BKGND_NONE : the cell's background color is not modified. TCOD_BKGND_SET : the cell's background color is replaced by the console's default background color : newbk = curbk. TCOD_BKGND_MULTIPLY : the cell's background color is multiplied by the console's default background color : newbk = oldbk * curbk TCOD_BKGND_LIGHTEN : newbk = TCOD_MAX(oldbk,curbk) TCOD_BKGND_DARKEN : newbk = TCOD_MIN(oldbk,curbk) TCOD_BKGND_SCREEN : newbk = white - (white - oldbk) * (white - curbk) // inverse of multiply : (1-newbk) = (1-oldbk)*(1-curbk) TCOD_BKGND_COLOR_DODGE : newbk = curbk / (white - oldbk) TCOD_BKGND_COLOR_BURN : newbk = white - (white - oldbk) / curbk TCOD_BKGND_ADD : newbk = oldbk + curbk TCOD_BKGND_ADDALPHA(alpha) : newbk = oldbk + alpha*curbk TCOD_BKGND_BURN : newbk = oldbk + curbk - white TCOD_BKGND_OVERLAY : newbk = curbk.x <= 0.5 ? 2*curbk*oldbk : white - 2*(white-curbk)*(white-oldbk) TCOD_BKGND_ALPHA(alpha) : newbk = (1.0f-alpha)*oldbk + alpha*(curbk-oldbk) TCOD_BKGND_DEFAULT : use the console's default background flag Note that TCOD_BKGND_ALPHA and TCOD_BKGND_ADDALPHA are MACROS that needs a float parameter between (0.0 and 1.0). TCOD_BKGND_ALPH and TCOD_BKGND_ADDA should not be used directly (else they will have the same effect as TCOD_BKGND_NONE). For Python, remove TCOD_ : libtcod.BKGND_NONE For C# : None, Set, Multiply, Lighten, Darken, Screen, ColorDodge, ColorBurn, Add, Burn Overlay, Default With lua, use tcod.None, ..., tcod.Default, BUT tcod.console.Alpha(value) and tcod.console.AddAlpha(value) This default mode is used by several functions (print, printRect, ...)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t

◆ setChar()

void TCODConsole::setChar ( int x,
int y,
int c )

This function modifies the ASCII code of a cell, leaving other properties (background and foreground colors) unchanged.

Note that since a clear console has both background and foreground colors set to black for every cell, using setChar will produce black characters on black background. Use putchar instead.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height
cthe new ASCII code for the cell. You can use ASCII constants

◆ setCharBackground()

void TCODConsole::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 ASCII code) unchanged.

void TCODConsole::setCharBackground(int x, int y, TCODColor col) void TCODConsole::setCharBackground(int x, int y, TCODColor col, TCODBackgroundFlag flag)

Console:setCharBackground(x, y, col) Console:setCharBackground(x, y, col, flag)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height
colthe background color to use. You can use color constants
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t

◆ setCharForeground()

void TCODConsole::setCharForeground ( int x,
int y,
const TCODColor & col )

This function modifies the foreground color of a cell, leaving other properties (background color and ASCII code) unchanged.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,ycoordinates of the cell in the console. 0 <= x < console width 0 <= y < console height
colthe foreground color to use. You can use color constants

◆ setColorControl()

void TCODConsole::setColorControl ( TCOD_colctrl_t con,
const TCODColor & fore,
const TCODColor & back )
static

If you want to draw a string using different colors for each word, the basic solution is to call a string printing function several times, changing the default colors between each call.

The TCOD library offers a simpler way to do this, allowing you to draw a string using different colors in a single call. For this, you have to insert color control codes in your string. A color control code is associated with a color set (a foreground color and a background color). If you insert this code in your string, the next characters will use the colors associated with the color control code. There are 5 predefined color control codes : For Python, remove TCOD_ : libtcod.COLCTRL_1 TCOD_COLCTRL_1 TCOD_COLCTRL_2 TCOD_COLCTRL_3 TCOD_COLCTRL_4 TCOD_COLCTRL_5 To associate a color with a code, use setColorControl. To go back to the console's default colors, insert in your string the color stop control code : TCOD_COLCTRL_STOP

You can also use any color without assigning it to a control code, using the generic control codes : TCOD_COLCTRL_FORE_RGB TCOD_COLCTRL_BACK_RGB

Those controls respectively change the foreground and background color used to print the string characters. In the string, you must insert the r,g,b components of the color (between 1 and 255. The value 0 is forbidden because it represents the end of the string in C/C++) immediately after this code.

Parameters
conthe color control TCOD_COLCTRL_x, 1<=x<=5
foreforeground color when this control is activated
backbackground color when this control is activated

A string with a red over black word, using predefined color control codes TCODConsole::setColorControl(TCOD_COLCTRL_1,TCODColor::red,TCODColor::black); TCODConsole::root->print(1,1,"String with a %cred%c word.",TCOD_COLCTRL_1,TCOD_COLCTRL_STOP); A string with a red over black word, using generic color control codes TCODConsole::root->print(1,1,"String with a %c%c%c%c%c%c%c%cred%c word.", TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP); A string with a red over black word, using generic color control codes TCODConsole::root->print(1,1,"String with a %c%c%c%c%c%c%c%cred%c word.", TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);

A string with a red over black word, using predefined color control codes TCOD_console_set_color_control(TCOD_COLCTRL_1,red,black); TCOD_console_print(NULL,1,1,"String with a %cred%c word.",TCOD_COLCTRL_1,TCOD_COLCTRL_STOP); A string with a red word (over default background color), using generic color control codes TCOD_console_print(NULL,1,1,"String with a %c%c%c%cred%c word.", TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_STOP); A string with a red over black word, using generic color control codes TCOD_console_print(NULL,1,1,"String with a %c%c%c%c%c%c%c%cred%c word.", TCOD_COLCTRL_FORE_RGB,255,1,1,TCOD_COLCTRL_BACK_RGB,1,1,1,TCOD_COLCTRL_STOP);

A string with a red over black word, using predefined color control codes

libtcod.console_set_color_control(libtcod.COLCTRL_1,libtcod.red,libtcod.black) libtcod.console_print(0,1,1,"String with a %cred%c word."%(libtcod.COLCTRL_1,libtcod.COLCTRL_STOP))

A string with a red word (over default background color), using generic color control codes

libtcod.console_print(0,1,1,"String with a %c%c%c%cred%c word."%(libtcod.COLCTRL_FORE_RGB,255,1,1,libtcod.COLCTRL_STOP))

A string with a red over black word, using generic color control codes

libtcod.console_print(0,1,1,"String with a %c%c%c%c%c%c%c%cred%c word."% (libtcod.COLCTRL_FORE_RGB,255,1,1,libtcod.COLCTRL_BACK_RGB,1,1,1,libtcod.COLCTRL_STOP))

TCODConsole.root.print(1,1,String.Format("String with a {0}red{1} word.", TCODConsole.getRGBColorControlString(ColorControlForeground,TCODColor.red), TCODConsole.getColorControlString(ColorControlStop));

◆ setCustomFont()

void TCODConsole::setCustomFont ( const char * fontFile,
int flags = TCOD_FONT_LAYOUT_ASCII_INCOL,
int nbCharHoriz = 0,
int nbCharVertic = 0 )
static

This function allows you to use a bitmap font (png or bmp) with custom character size or layout.

It should be called before initializing the root console with initRoot. Once this function is called, you can define your own custom mappings using mapping functions

Different font layouts
ASCII_INROWASCII_INCOLTCOD
  • ascii, in columns : characters 0 to 15 are in the first column. The space character is at coordinates 2,0.
  • ascii, in rows : characters 0 to 15 are in the first row. The space character is at coordinates 0,2.
  • tcod : special mapping. Not all ascii values are mapped. The space character is at coordinates 0,0.
Different font types
standard
(non antialiased)
antialiased
(32 bits PNG)
antialiased
(greyscale)
  • standard : transparency is given by a key color automatically detected by looking at the color of the space character
  • 32 bits : transparency is given by the png alpha layer. The font color does not matter but it must be desaturated
  • greyscale : transparency is given by the pixel value. You can use white characters on black background or black characters on white background. The background color is automatically detected by looking at the color of the space character

Examples of fonts can be found in libtcod's fonts directory. Check the Readme file there.

static void TCODConsole::setCustomFont(string fontFile) static void TCODConsole::setCustomFont(string fontFile, int flags) static void TCODConsole::setCustomFont(string fontFile, int flags, int nbCharHoriz) static void TCODConsole::setCustomFont(string fontFile, int flags, int nbCharHoriz, int nbCharVertic)

tcod.console.setCustomFont(fontFile) tcod.console.setCustomFont(fontFile, flags) tcod.console.setCustomFont(fontFile, nbCharHoriz) tcod.console.setCustomFont(fontFile, flags, nbCharHoriz, nbCharVertic) – flags : tcod.LayoutAsciiInColumn, tcod.LayoutAsciiInRow, tcod.LayoutTCOD, tcod.Greyscale

Parameters
fontFileName of a .bmp or .png file containing the font.
flagsUsed to define the characters layout in the bitmap and the font type : TCOD_FONT_LAYOUT_ASCII_INCOL : characters in ASCII order, code 0-15 in the first column TCOD_FONT_LAYOUT_ASCII_INROW : characters in ASCII order, code 0-15 in the first row TCOD_FONT_LAYOUT_TCOD : simplified layout. See examples below. TCOD_FONT_TYPE_GREYSCALE : create an anti-aliased font from a greyscale bitmap For Python, remove TCOD _ : libtcod.FONT_LAYOUT_ASCII_INCOL
nbCharHoriz,nbCharVerticNumber of characters in the font. Should be 16x16 for ASCII layouts, 32x8 for TCOD layout. But you can use any other layout. If set to 0, there are deduced from the font layout flag.

TCODConsole::setCustomFont("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL); TCODConsole::setCustomFont("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW); TCODConsole::setCustomFont("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE);

TCOD_console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL,16,16); TCOD_console_set_custom_font("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW,32,8); TCOD_console_set_custom_font("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE,32,8);

libtcod.console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",libtcod.FONT_LAYOUT_ASCII_INCOL) libtcod.console_set_custom_font("32bits_8x8_ascii_in_row_font.png",libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_set_custom_font("greyscale_8x8_tcod_font.png",libtcod.FONT_LAYOUT_TCOD | libtcod.FONT_TYPE_GREYSCALE)

tcod.console.setCustomFont("standard_8x8_ascii_in_col_font.bmp",tcod.LayoutAsciiInColumn); tcod.console.setCustomFont("32bits_8x8_ascii_in_row_font.png",tcod.LayoutAsciiInRow); tcod.console.setCustomFont("greyscale_8x8_tcod_font.png",tcod.LayoutTCOD + tcod.Greyscale);

◆ setDefaultBackground()

void TCODConsole::setDefaultBackground ( TCODColor back)

This function changes the default background color for a console.

The default background color is used by several drawing functions like clear, putChar, ...

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
backthe new default background color for this console

◆ setDefaultForeground()

void TCODConsole::setDefaultForeground ( TCODColor fore)

This function changes the default foreground color for a console.

The default foreground color is used by several drawing functions like clear, putChar, ...

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
forethe new default foreground color for this console

◆ setFade()

void TCODConsole::setFade ( uint8_t fade,
const TCODColor & fadingColor )
static

This function defines the fading parameters, allowing to easily fade the game screen to/from a color. Once they are defined, the fading parameters are valid for ever. You don't have to call setFade for each rendered frame (unless you change the fading parameters).

Use these functions to easily fade to/from a color

Parameters
fadethe fading amount. 0 => the screen is filled with the fading color. 255 => no fading effect
fadingColorthe color to use during the console flushing operation

for (int fade=255; fade >= 0; fade –) { TCODConsole::setFade(fade,TCODColor::black); TCODConsole::flush(); }

int fade; for (fade=255; fade >= 0; fade –) { TCOD_console_setFade(fade,TCOD_black); TCOD_console_flush(); }

for fade in range(255,0) : libtcod.console_setFade(fade,libtcod.black) libtcod.console_flush()

for fade=255,0,-1 do tcod.console.setFade(fade,tcod.color.black) tcod.console.flush() end

◆ setFullscreen()

void TCODConsole::setFullscreen ( bool fullscreen)
static

This function switches the root console to fullscreen or windowed mode.

Note that there is no predefined key combination to switch to/from fullscreen. You have to do this in your own code.

Parameters
fullscreentrue to switch to fullscreen mode. false to switch to windowed mode.

TCOD_key_t key; TCODConsole::checkForEvent(TCOD_EVENT_KEY_PRESS,&key,NULL); if ( key.vk == TCODK_ENTER && key.lalt ) TCODConsole::setFullscreen(!TCODConsole::isFullscreen());

TCOD_key_t key; TCOD_console_check_for_event(TCOD_EVENT_KEY_PRESS,&key,NULL); if ( key.vk == TCODK_ENTER && key.lalt ) TCOD_console_set_fullscreen(!TCOD_console_is_fullscreen());

key=Key() libtcod.console_check_for_event(libtcod.EVENT_KEY_PRESS,key,0) if key.vk == libtcod.KEY_ENTER and key.lalt : libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

key=tcod.console.checkForKeypress() if key.KeyCode == tcod.Enter and key.LeftAlt then tcod.console.setFullscreen(not tcod.console.isFullscreen()) end

◆ setKeyboardRepeat()

void TCODConsole::setKeyboardRepeat ( int initialDelay,
int interval )
static

Use this function to destroy an offscreen console and release any resources allocated.

Don't use it on the root console.

Parameters
conin the C and Python versions, the offscreen console handler

TCODConsole *off1 = new TCODConsole(80,50); ... use off1 delete off1; // destroy the offscreen console

TCOD_console_t off1 = TCOD_console_new(80,50); ... use off1 TCOD_console_delete(off1); // destroy the offscreen console

off1 = libtcod.console_new(80,50) ... use off1 libtcod.console_delete(off1) # destroy the offscreen console

off1 = tcod.Console(80,50) ... use off1 off1=nil – release the reference

◆ setKeyColor()

void TCODConsole::setKeyColor ( const TCODColor & col)

This function defines a transparent background color for an offscreen console.

All cells with this background color are ignored by the blit operation. You can use it to blit only some parts of the console.

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
colthe transparent background color

◆ setWindowTitle()

void TCODConsole::setWindowTitle ( const char * title)
static

This function dynamically changes the title of the game window.

Note that the window title is not visible while in fullscreen.

Parameters
titleNew title of the game window

◆ vline()

void TCODConsole::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 default background/foreground colors.

void TCODConsole::vline(int x,int y, int l) void TCODConsole::vline(int x,int y, int l, TCODBackgroundFlag flag)

Console:vline(x,y, l) Console:vline(x,y, l, flag)

Parameters
conin the C and Python versions, the offscreen console handler or NULL for the root console
x,yCoordinates of the line's upper end in the console. 0 <= x < console width 0 <= y < console height
lThe length of the line in cells 1 <= l <= console height - y
flagthis flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t

◆ waitForKeypress()

TCOD_key_t TCODConsole::waitForKeypress ( bool flush)
static

Some useful graphic characters in the terminal.bmp font.

For the Python version, remove TCOD_ from the constants. C# and Lua is in parenthesis : Single line walls: TCOD_CHAR_HLINE=196 (HorzLine) TCOD_CHAR_VLINE=179 (VertLine) TCOD_CHAR_NE=191 (NE) TCOD_CHAR_NW=218 (NW) TCOD_CHAR_SE=217 (SE) TCOD_CHAR_SW=192 (SW)

Double lines walls: TCOD_CHAR_DHLINE=205 (DoubleHorzLine) TCOD_CHAR_DVLINE=186 (DoubleVertLine) TCOD_CHAR_DNE=187 (DoubleNE) TCOD_CHAR_DNW=201 (DoubleNW) TCOD_CHAR_DSE=188 (DoubleSE) TCOD_CHAR_DSW=200 (DoubleSW)

Single line vertical/horizontal junctions (T junctions): TCOD_CHAR_TEEW=180 (TeeWest) TCOD_CHAR_TEEE=195 (TeeEast) TCOD_CHAR_TEEN=193 (TeeNorth) TCOD_CHAR_TEES=194 (TeeSouth)

Double line vertical/horizontal junctions (T junctions): TCOD_CHAR_DTEEW=185 (DoubleTeeWest) TCOD_CHAR_DTEEE=204 (DoubleTeeEast) TCOD_CHAR_DTEEN=202 (DoubleTeeNorth) TCOD_CHAR_DTEES=203 (DoubleTeeSouth)

Block characters: TCOD_CHAR_BLOCK1=176 (Block1) TCOD_CHAR_BLOCK2=177 (Block2) TCOD_CHAR_BLOCK3=178 (Block3)

Cross-junction between two single line walls: TCOD_CHAR_CROSS=197 (Cross)

Arrows: TCOD_CHAR_ARROW_N=24 (ArrowNorth) TCOD_CHAR_ARROW_S=25 (ArrowSouth) TCOD_CHAR_ARROW_E=26 (ArrowEast) TCOD_CHAR_ARROW_W=27 (ArrowWest)

Arrows without tail: TCOD_CHAR_ARROW2_N=30 (ArrowNorthNoTail) TCOD_CHAR_ARROW2_S=31 (ArrowSouthNoTail) TCOD_CHAR_ARROW2_E=16 (ArrowEastNoTail) TCOD_CHAR_ARROW2_W=17 (ArrowWestNoTail)

Double arrows: TCOD_CHAR_DARROW_H=29 (DoubleArrowHorz) TCOD_CHAR_ARROW_V=18 (DoubleArrowVert)

GUI stuff: TCOD_CHAR_CHECKBOX_UNSET=224 TCOD_CHAR_CHECKBOX_SET=225 TCOD_CHAR_RADIO_UNSET=9 TCOD_CHAR_RADIO_SET=10

Sub-pixel resolution kit: TCOD_CHAR_SUBP_NW=226 (SubpixelNorthWest) TCOD_CHAR_SUBP_NE=227 (SubpixelNorthEast) TCOD_CHAR_SUBP_N=228 (SubpixelNorth) TCOD_CHAR_SUBP_SE=229 (SubpixelSouthEast) TCOD_CHAR_SUBP_DIAG=230 (SubpixelDiagonal) TCOD_CHAR_SUBP_E=231 (SubpixelEast) TCOD_CHAR_SUBP_SW=232 (SubpixelSouthWest)

Miscellaneous characters: TCOD_CHAR_SMILY = 1 (Smilie) TCOD_CHAR_SMILY_INV = 2 (SmilieInv) TCOD_CHAR_HEART = 3 (Heart) TCOD_CHAR_DIAMOND = 4 (Diamond) TCOD_CHAR_CLUB = 5 (Club) TCOD_CHAR_SPADE = 6 (Spade) TCOD_CHAR_BULLET = 7 (Bullet) TCOD_CHAR_BULLET_INV = 8 (BulletInv) TCOD_CHAR_MALE = 11 (Male) TCOD_CHAR_FEMALE = 12 (Female) TCOD_CHAR_NOTE = 13 (Note) TCOD_CHAR_NOTE_DOUBLE = 14 (NoteDouble) TCOD_CHAR_LIGHT = 15 (Light) TCOD_CHAR_EXCLAM_DOUBLE = 19 (ExclamationDouble) TCOD_CHAR_PILCROW = 20 (Pilcrow) TCOD_CHAR_SECTION = 21 (Section) TCOD_CHAR_POUND = 156 (Pound) TCOD_CHAR_MULTIPLICATION = 158 (Multiplication) TCOD_CHAR_FUNCTION = 159 (Function) TCOD_CHAR_RESERVED = 169 (Reserved) TCOD_CHAR_HALF = 171 (Half) TCOD_CHAR_ONE_QUARTER = 172 (OneQuarter) TCOD_CHAR_COPYRIGHT = 184 (Copyright) TCOD_CHAR_CENT = 189 (Cent) TCOD_CHAR_YEN = 190 (Yen) TCOD_CHAR_CURRENCY = 207 (Currency) TCOD_CHAR_THREE_QUARTERS = 243 (ThreeQuarters) TCOD_CHAR_DIVISION = 246 (Division) TCOD_CHAR_GRADE = 248 (Grade) TCOD_CHAR_UMLAUT = 249 (Umlaut) TCOD_CHAR_POW1 = 251 (Pow1) TCOD_CHAR_POW3 = 252 (Pow2) TCOD_CHAR_POW2 = 253 (Pow3) TCOD_CHAR_BULLET_SQUARE = 254 (BulletSquare)

The user handling functions allow you to get keyboard and mouse input from the user, either for turn by turn games (the function wait until the user press a key or a mouse button), or real time games (non blocking function). WARNING : those functions also handle screen redraw event, so TCODConsole::flush function won't redraw screen if no user input function is called !


The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/console.hpp