libtcod
Loading...
Searching...
No Matches
tcod Namespace Reference

The libtcod namespace. More...

Classes

class  BresenhamLine
 Encapsulates a Bresenham line drawing algorithm. More...
struct  ColorRGB
 A C++ RGB color, used to handle conversions between color types. More...
struct  ColorRGBA
 A C++ RGBA color, used to handle conversions between color types. More...
struct  ConsoleDeleter
class  Console
 A managed libtcod console containing a grid of tiles with {ch, fg, bg} information. More...
struct  ContextDeleter
struct  MapDeleter_
struct  ImageDeleter
class  MatrixView
 A view into a strided multi-dimensional array. More...
class  Matrix
 A template container for holding a multi-dimensional array of items. More...
struct  TilesetDeleter
class  Tileset
 A C++ Tileset container. More...
class  Timer
 A timing class based on SDL's high performance time counter. More...

Typedefs

typedef std::unique_ptr< struct TCOD_Console, ConsoleDeleterConsolePtr
 A unique pointer to a TCOD_Console.
typedef std::unique_ptr< TCOD_Context, ContextDeleterContextPtr
typedef std::shared_ptr< TCOD_ContextContextSharedPtr
typedef std::unique_ptr< TCOD_Image, ImageDeleterImagePtr
 A unique pointer to a TCOD_Image.
typedef std::unique_ptr< TCOD_Tileset, TilesetDeleterTilesetPtr
 A unique pointer to a TCOD_Tileset.

Functions

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.
void draw_rect (TCOD_Console &console, const std::array< int, 4 > &rect, int ch, std::optional< TCOD_ColorRGB > fg, std::optional< TCOD_ColorRGB > bg, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET)
 Fill a region with the given graphic.
void draw_frame (TCOD_Console &console, const std::array< int, 4 > &rect, const std::array< int, 9 > &decoration, std::optional< TCOD_ColorRGB > fg, std::optional< TCOD_ColorRGB > bg, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET, bool clear=true)
 Draw a decorative frame.
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.
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.
int get_height_rect (int width, std::string_view str)
 Return the height of the word-wrapped text with the given width.
TCODLIB_BEGIN_IGNORE_DEPRECATIONS void print_frame (struct TCOD_Console &console, const std::array< int, 4 > &rect, std::string_view title, const TCOD_ColorRGB *fg, const TCOD_ColorRGB *bg, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET, bool clear=true)
template<typename... T>
TCODLIB_END_IGNORE_DEPRECATIONS std::string stringf (const char *format, T... args)
 Return a formatted string as a std::string object.
std::vector< tcod::ConsolePtrload_xp (const std::filesystem::path &path)
 Load an array of consoles from a REXPaint file.
void save_xp (const std::vector< const TCOD_Console * > &consoles, const std::filesystem::path &path, int compress_level=9)
 Save an array of consoles to a REXPaint file.
auto new_context (const TCOD_ContextParams &params, TCOD_Error &out_code) -> ContextPtr
 Initialize and return a new libtcod context.
auto new_context (const TCOD_ContextParams &params) -> ContextPtr
 Initialize and return a new libtcod context.
TCOD_Error set_error (const std::string &msg)
 Set an error message and return a relevant error code, usually -1.
TCOD_Error set_error (const std::exception &e)
int check_throw_error (int error)
 Check and throw error messages.
TCOD_Error check_throw_error (TCOD_Error error)
void check_path (const std::filesystem::path &path)
 Throw an exception if the given path does not exist.
void draw_quartergraphics (TCOD_Console &dest, const TCOD_Image &source, const std::array< int, 2 > &dest_xy={0, 0}, const std::array< int, 4 > &src_rect={0, 0, -1, -1})
 Draw a double resolution image on a console using quadrant character glyphs.
template<typename ArrayType>
auto load_tilesheet (const std::filesystem::path &path, const std::array< int, 2 > &columns_rows, const ArrayType &charmap) -> Tileset
 Load a tilesheet from a PNG file.
auto load_bdf (const std::filesystem::path &path) -> TilesetPtr
 Load a Tileset from a BDF font file.

Detailed Description

The libtcod namespace.

Typedef Documentation

◆ ConsolePtr

typedef std::unique_ptr<struct TCOD_Console, ConsoleDeleter> tcod::ConsolePtr

A unique pointer to a TCOD_Console.

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

◆ ImagePtr

typedef std::unique_ptr<TCOD_Image, ImageDeleter> tcod::ImagePtr

A unique pointer to a TCOD_Image.

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

Function Documentation

◆ check_path()

void tcod::check_path ( const std::filesystem::path & path)
inline

Throw an exception if the given path does not exist.

Used internally.

◆ check_throw_error()

int tcod::check_throw_error ( int error)
inline

Check and throw error messages.

Used internally.

◆ draw_quartergraphics()

void tcod::draw_quartergraphics ( TCOD_Console & dest,
const TCOD_Image & source,
const std::array< int, 2 > & dest_xy = {0, 0},
const std::array< int, 4 > & src_rect = {0, 0, -1, -1} )
inline

Draw a double resolution image on a console using quadrant character glyphs.

Parameters
destThe console to draw to.
sourceThe source image which will be rendered.
dest_xyThe upper-left position to where the source will be drawn.
source_rectThe {left, top, width, height} region of the source image to draw. A width or height of -1 will use the full size of the image.
auto console = tcod::Console{80, 50};
TCODImage* image = new TCODImage(console.get_width() * 2, console.get_height() * 2);
Definition image.hpp:60
A managed libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console_types.hpp:80
void draw_quartergraphics(TCOD_Console &dest, const TCOD_Image &source, const std::array< int, 2 > &dest_xy={0, 0}, const std::array< int, 4 > &src_rect={0, 0, -1, -1})
Draw a double resolution image on a console using quadrant character glyphs.
Definition image.hpp:588
embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ new_context() [1/2]

auto tcod::new_context ( const TCOD_ContextParams & params) ->ContextPtr
inline

Initialize and return a new libtcod context.

Parameters
paramsOptions to configure the new context with.
Returns
ContextPtr A pointer to the new context.
embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ new_context() [2/2]

auto tcod::new_context ( const TCOD_ContextParams & params,
TCOD_Error & out_code )->ContextPtr
inline

Initialize and return a new libtcod context.

Also returns an error code for non-critical issues.

Parameters
paramsOptions to configure the new context with.
out_codeWill be set to an error code on non-critical issues.
Returns
ContextPtr A pointer to the new context.

For critical issues an exception is thrown as usual. Non-critical issues are things such as being unable to create a desired renderer and using to a fallback instead.

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

◆ set_error()

TCOD_Error tcod::set_error ( const std::string & msg)
inline

Set an error message and return a relevant error code, usually -1.

Used internally.

◆ stringf()

template<typename... T>
TCODLIB_END_IGNORE_DEPRECATIONS std::string tcod::stringf ( const char * format,
T... args )
inline

Return a formatted string as a std::string object.

This is a convience function for code using printf-like formatted strings. Newer more modern code might want to use the fmt library instead.

Template Parameters
TParameter packed arguments.
Parameters
formatA printf-like format string.
argsAny printf-like arguments.
Returns
A std::string object with the resulting output.

fmt::sprintf is a faster and safer alternative to this function.

auto console = tcod::Console{80, 50};
// Use tcod::stringf to encapsulate printf-like parameters.
tcod::print(console, {0, 0}, tcod::stringf("%s %s", "Hello", "World"), nullptr, nullptr);
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
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
embed:rst:leading-asterisk 
.. versionadded:: 1.19