libtcod
Loading...
Searching...
No Matches
tcod::Console Class Reference

A managed libtcod console containing a grid of tiles with {ch, fg, bg} information. More...

#include <console_types.hpp>

Public Member Functions

TCODLIB_BEGIN_IGNORE_DEPRECATIONS Console ()
 Default initializer.
 Console (int width, int height)
 Create a new Console with the given size.
 Console (const std::array< int, 2 > &size)
 Create a new Console with the given size.
 Console (const Console &other)
 Clone the shape and tile data of a Console.
 Console (ConsolePtr ptr)
 Pass ownership of a ConsolePtr to a new Console.
 Console (TCOD_Console *ptr)
 Takes ownership of a raw TCOD_Console pointer.
Consoleoperator= (const Console &rhs)
 Copy the shape and tile data of another console.
 Console (Console &&) noexcept=default
 Standard move constructor.
Consoleoperator= (Console &&rhs) noexcept
 Standard move assignment.
 ~Console () noexcept=default
 Standard destructor.
 operator TCOD_Console & ()
 Allow implicit conversions to a TCOD_Console reference.
 operator const TCOD_Console & () const
 Allow implicit conversions to a const TCOD_Console reference.
auto get () noexcept -> TCOD_Console *
 Return a pointer to the internal TCOD_Console struct.
auto get () const noexcept -> const TCOD_Console *
 Return a const pointer to the internal TCOD_Console struct.
auto release () noexcept -> TCOD_Console *
 Release ownership of this Console's TCOD_Console* and return the pointer.
auto begin () noexcept -> TCOD_ConsoleTile *
 Return a pointer to the beginning of this consoles tile data.
auto begin () const noexcept -> const TCOD_ConsoleTile *
 Return a const pointer to the beginning of this consoles tile data.
auto end () noexcept -> TCOD_ConsoleTile *
 Return a pointer to the end of this consoles tile data.
auto end () const noexcept -> const TCOD_ConsoleTile *
 Return a const pointer to the end of this consoles tile data.
auto get_width () const noexcept -> int
 Return the width of this console.
auto get_height () const noexcept -> int
 Return the height of this console.
auto get_shape () const noexcept -> std::array< int, 2 >
 Return the {width, height} shape of this console as a std::array<int, 2>.
void clear (const TCOD_ConsoleTile &tile={0x20, {255, 255, 255, 255}, {0, 0, 0, 255}}) noexcept
 Clear a console by setting all tiles to the provided TCOD_ConsoleTile object.
auto operator[] (const std::array< int, 2 > &xy) noexcept -> TCOD_ConsoleTile &
 Return a reference to the tile at xy.
auto operator[] (const std::array< int, 2 > &xy) const noexcept -> const TCOD_ConsoleTile &
 Return a constant reference to the tile at xy.
auto at (const std::array< int, 2 > &xy) -> TCOD_ConsoleTile &
 Return a reference to the tile at xy.
auto at (const std::array< int, 2 > &xy) const -> const TCOD_ConsoleTile &
 Return a constant reference to the tile at xy.
auto at (int x, int y) -> TCOD_ConsoleTile &
 Return a reference to the tile at x,y.
auto at (int x, int y) const -> const TCOD_ConsoleTile &
 Return a constant reference to the tile at x,y.
bool in_bounds (const std::array< int, 2 > &xy) const noexcept
 Return true if xy are within the bounds of this console.

Friends

void swap (Console &lhs, Console &rhs) noexcept
 Swap two console objects.

Detailed Description

A managed libtcod console containing a grid of tiles with {ch, fg, bg} information.

Note that all tile references are to TCOD_ConsoleTile structs and will include an alpha channel.

auto console = tcod::Console{80, 50};
console.at({1, 1}).ch = '@'; // Bounds-checked references to a tile.
console[{1, 1}].bg = {0, 0, 255, 255}; // Access a tile without bounds checking, colors are RGBA.
if (console.in_bounds({100, 100})) {} // Test if an index is in bounds.
for (auto& tile : console) tile.fg = {255, 255, 0, 255}; // Iterate over all tiles on a console.
for (auto& tile : console) tile = {0x20, {255, 255, 255, 255}, {0, 0, 0, 255}}; // Same as clearing all tiles.
for (int y = 0; y < console.get_height(); ++y) {
for (int x = 0; x < console.get_width(); ++x) {
auto& tile = console.at({x, y}); // Iterate over the coordinates of a console.
}
}
A managed libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console_types.hpp:80
auto at(const std::array< int, 2 > &xy) -> TCOD_ConsoleTile &
Return a reference to the tile at xy.
Definition console_types.hpp:246
embed:rst:leading-asterisk 
.. versionadded:: 1.19

Constructor & Destructor Documentation

◆ Console() [1/4]

tcod::Console::Console ( int width,
int height )
inlineexplicit

Create a new Console with the given size.

Parameters
widthThe number of columns in the new console.
heightThe number of rows in the new console.

◆ Console() [2/4]

tcod::Console::Console ( const std::array< int, 2 > & size)
inlineexplicit

Create a new Console with the given size.

Parameters
sizeThe new console size of {width, height}.

◆ Console() [3/4]

tcod::Console::Console ( ConsolePtr ptr)
inlineexplicit

Pass ownership of a ConsolePtr to a new Console.

Parameters
ptrA tcod::ConsolePtr, must not be nullptr.

◆ Console() [4/4]

tcod::Console::Console ( TCOD_Console * ptr)
inlineexplicit

Takes ownership of a raw TCOD_Console pointer.

Parameters
ptrA pointer which will now be managed by this Console object. Must not be nullptr.

Member Function Documentation

◆ at() [1/4]

auto tcod::Console::at ( const std::array< int, 2 > & xy) ->TCOD_ConsoleTile &
inlinenodiscard

Return a reference to the tile at xy.

Exceptions
std::out_of_rangeif the index is out-of-bounds

◆ at() [2/4]

auto tcod::Console::at ( const std::array< int, 2 > & xy) const->constTCOD_ConsoleTile &
inlinenodiscard

Return a constant reference to the tile at xy.

Exceptions
std::out_of_rangeif the index is out-of-bounds

◆ at() [3/4]

auto tcod::Console::at ( int x,
int y )->TCOD_ConsoleTile &
inlinenodiscard

Return a reference to the tile at x,y.

Exceptions
std::out_of_rangeif the index is out-of-bounds

◆ at() [4/4]

auto tcod::Console::at ( int x,
int y ) const->constTCOD_ConsoleTile &
inlinenodiscard

Return a constant reference to the tile at x,y.

Exceptions
std::out_of_rangeif the index is out-of-bounds

◆ clear()

void tcod::Console::clear ( const TCOD_ConsoleTile & tile = {0x20, {255, 255, 255, 255}, {0, 0, 0, 255}})
inlinenoexcept

Clear a console by setting all tiles to the provided TCOD_ConsoleTile object.

Parameters
tileA TCOD_ConsoleTile reference which will be used to clear the console.
// New consoles start already cleared with the space character, a white foreground, and a black background.
auto console = tcod::Console{80, 50};
console.clear() // Clear with the above mentioned defaults.
console.clear({0x20, {255, 255, 255, 255}, {0, 0, 0, 255}}); // Same as the above.
console.clear({0x20, tcod::ColorRGB{255, 255, 255}, tcod::ColorRGB{0, 0, 0}}) // Also same as the above.
void clear(const TCOD_ConsoleTile &tile={0x20, {255, 255, 255, 255}, {0, 0, 0, 255}}) noexcept
Clear a console by setting all tiles to the provided TCOD_ConsoleTile object.
Definition console_types.hpp:226

◆ get_shape()

auto tcod::Console::get_shape ( ) const->std::array< int, 2 >
inlinenodiscardnoexcept

Return the {width, height} shape of this console as a std::array<int, 2>.

auto console = tcod::Console{80, 50};
auto same_size = tcod::Console{console.get_shape()} // New console with the same shape of the previous one.

◆ release()

auto tcod::Console::release ( ) ->TCOD_Console *
inlinenoexcept

Release ownership of this Console's TCOD_Console* and return the pointer.

Using this Console afterwards is undefined.


The documentation for this class was generated from the following file: