35#ifndef TCOD_CONSOLE_TYPES_HPP_
36#define TCOD_CONSOLE_TYPES_HPP_
56typedef std::unique_ptr<struct TCOD_Console, ConsoleDeleter>
ConsolePtr;
82 TCODLIB_BEGIN_IGNORE_DEPRECATIONS
106 std::copy(other.console_->
begin(), other.console_->
end(), console_->begin());
114 if (!console_)
throw std::invalid_argument(
"Pointer must not be nullptr.");
122 if (!console_)
throw std::invalid_argument(
"TCOD_Console pointer must not be nullptr.");
128 if (console_->w != rhs.console_->w || console_->h != rhs.console_->h) {
129 *
this =
Console{{rhs.console_->w, rhs.console_->h}};
131 std::copy(rhs.console_->
begin(), rhs.console_->
end(), console_->begin());
154 swap(lhs.console_, rhs.console_);
163 [[nodiscard]]
operator const TCOD_Console&()
const {
return *console_; }
171 [[nodiscard]]
auto get() const noexcept -> const
TCOD_Console* {
return console_.get(); }
193 [[nodiscard]]
auto end() const noexcept -> const
TCOD_ConsoleTile* {
return console_->tiles + console_->elements; }
197 [[nodiscard]]
auto get_width() const noexcept ->
int {
return console_->w; }
201 [[nodiscard]]
auto get_height() const noexcept ->
int {
return console_->h; }
211 [[nodiscard]]
auto get_shape() const noexcept -> std::array<
int, 2> {
return {console_->w, console_->h}; }
227 for (
auto& it : *
this) it = tile;
233 return console_->tiles[get_index(xy)];
239 return console_->tiles[get_index(xy)];
246 [[nodiscard]]
auto at(
const std::array<int, 2>& xy) ->
TCOD_ConsoleTile& {
return console_->tiles[bounds_check(xy)]; }
253 return console_->tiles[bounds_check(xy)];
270 [[nodiscard]]
bool in_bounds(
const std::array<int, 2>& xy)
const noexcept {
return console_->in_bounds(xy); }
271 TCODLIB_END_IGNORE_DEPRECATIONS
279 auto bounds_check(
const std::array<int, 2>& xy)
const ->
int {
281 throw std::out_of_range(
282 std::string(
"Out of bounds lookup {") + std::to_string(xy[0]) +
", " + std::to_string(xy[1]) +
283 "} on console of shape {" + std::to_string(console_->w) +
", " + std::to_string(console_->h) +
"}.");
285 return get_index(xy);
292 [[nodiscard]]
auto get_index(
const std::array<int, 2>& xy)
const noexcept ->
int {
293 return console_->w * xy[1] + xy[0];
auto get_width() const noexcept -> int
Return the width of this console.
Definition console_types.hpp:197
auto at(int x, int y) const -> const TCOD_ConsoleTile &
Return a constant reference to the tile at x,y.
Definition console_types.hpp:266
auto at(const std::array< int, 2 > &xy) -> TCOD_ConsoleTile &
Return a reference to the tile at xy.
Definition console_types.hpp:246
auto at(int x, int y) -> TCOD_ConsoleTile &
Return a reference to the tile at x,y.
Definition console_types.hpp:260
auto at(const std::array< int, 2 > &xy) const -> const TCOD_ConsoleTile &
Return a constant reference to the tile at xy.
Definition console_types.hpp:252
Console & operator=(const Console &rhs)
Copy the shape and tile data of another console.
Definition console_types.hpp:127
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
auto get_shape() const noexcept -> std::array< int, 2 >
Return the {width, height} shape of this console as a std::array<int, 2>.
Definition console_types.hpp:211
auto operator[](const std::array< int, 2 > &xy) noexcept -> TCOD_ConsoleTile &
Return a reference to the tile at xy.
Definition console_types.hpp:232
Console(const Console &other)
Clone the shape and tile data of a Console.
Definition console_types.hpp:105
auto begin() const noexcept -> const TCOD_ConsoleTile *
Return a const pointer to the beginning of this consoles tile data.
Definition console_types.hpp:185
Console(TCOD_Console *ptr)
Takes ownership of a raw TCOD_Console pointer.
Definition console_types.hpp:121
Console(int width, int height)
Create a new Console with the given size.
Definition console_types.hpp:93
auto get() const noexcept -> const TCOD_Console *
Return a const pointer to the internal TCOD_Console struct.
Definition console_types.hpp:171
auto end() noexcept -> TCOD_ConsoleTile *
Return a pointer to the end of this consoles tile data.
Definition console_types.hpp:189
~Console() noexcept=default
Standard destructor.
auto get() noexcept -> TCOD_Console *
Return a pointer to the internal TCOD_Console struct.
Definition console_types.hpp:167
auto end() const noexcept -> const TCOD_ConsoleTile *
Return a const pointer to the end of this consoles tile data.
Definition console_types.hpp:193
TCODLIB_BEGIN_IGNORE_DEPRECATIONS Console()
Default initializer.
Definition console_types.hpp:86
friend void swap(Console &lhs, Console &rhs) noexcept
Swap two console objects.
Definition console_types.hpp:152
Console(const std::array< int, 2 > &size)
Create a new Console with the given size.
Definition console_types.hpp:101
bool in_bounds(const std::array< int, 2 > &xy) const noexcept
Return true if xy are within the bounds of this console.
Definition console_types.hpp:270
auto get_height() const noexcept -> int
Return the height of this console.
Definition console_types.hpp:201
Console(ConsolePtr ptr)
Pass ownership of a ConsolePtr to a new Console.
Definition console_types.hpp:113
auto operator[](const std::array< int, 2 > &xy) const noexcept -> const TCOD_ConsoleTile &
Return a constant reference to the tile at xy.
Definition console_types.hpp:238
auto begin() noexcept -> TCOD_ConsoleTile *
Return a pointer to the beginning of this consoles tile data.
Definition console_types.hpp:181
Console(Console &&) noexcept=default
Standard move constructor.
auto release() noexcept -> TCOD_Console *
Release ownership of this Console's TCOD_Console* and return the pointer.
Definition console_types.hpp:177
Various console functions.
const char * TCOD_get_error(void)
Return the last error message.
void TCOD_console_delete(TCOD_Console *console)
Delete a console.
TCOD_Console * TCOD_console_new(int w, int h)
Return a new console with a specific number of columns and rows.
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
The raw data for a single TCOD_Console tile.
Definition console.h:89
Definition console_types.hpp:46