36#ifndef TCOD_IMAGE_HPP_
37#define TCOD_IMAGE_HPP_
47 void operator()(
TCOD_Image* image)
const { TCOD_image_delete(image); }
54typedef std::unique_ptr<TCOD_Image, ImageDeleter>
ImagePtr;
58class TCODLIB_API TCODImage {
68 TCODImage() noexcept = default;
85 TCODImage(
int width,
int height);
101 TCODImage(const
char *filename);
127 TCODImage(
tcod::ImagePtr image) noexcept: data{image.release()}, deleteData{
true} {};
129 TCODImage(
const TCODImage&) =
delete;
130 TCODImage& operator=(
const TCODImage&) =
delete;
131 TCODImage(TCODImage&& rhs)
noexcept {
132 std::swap(data, rhs.data);
133 std::swap(deleteData, rhs.deleteData);
135 TCODImage& operator=(TCODImage&& rhs)
noexcept {
136 std::swap(data, rhs.data);
137 std::swap(deleteData, rhs.deleteData);
149 explicit TCODImage(
const tcod::Matrix<TCOD_ColorRGB, 2>& pixels)
150 : TCODImage(pixels.get_shape().at(0), pixels.get_shape().at(1)) {
151 for (
int y = 0; y < pixels.
get_shape().at(1); ++y) {
152 for (
int x = 0; x < pixels.
get_shape().at(0); ++x) {
153 putPixel(x, y, pixels[{x, y}]);
182 void refreshConsole(
const TCODConsole *console);
209 void getSize(
int *w,
int *h)
const;
218 [[nodiscard]]
auto getSize() const noexcept -> std::array<
int, 2> {
219 std::array<int, 2> out{};
220 TCOD_image_get_size(data, &out[0], &out[1]);
245 TCODColor getPixel(
int x,
int y)
const;
260 int getAlpha(
int x,
int y)
const;
275 bool isPixelTransparent(
int x,
int y)
const;
304 TCODColor getMipmapPixel(
float x0,
float y0,
float x1,
float y1);
319 void clear(
const TCODColor col);
334 void putPixel(
int x,
int y,
const TCODColor col);
347 void scale(
int new_w,
int new_h);
382 void rotate90(
int numRotations=1);
416 void save(
const char *filename)
const;
438 void blitRect(TCODConsole *console,
int x,
int y,
int w=-1,
int h=-1,
TCOD_bkgnd_flag_t bkgnd_flag = TCOD_BKGND_SET )
const;
439 void blitRect(TCOD_Console &console,
int x,
int y,
int w=-1,
int h=-1,
TCOD_bkgnd_flag_t bkgnd_flag = TCOD_BKGND_SET )
const {
440 TCOD_image_blit_rect(data, &console, x, y, w, h, bkgnd_flag);
464 void blit(TCODConsole *console,
float x,
float y,
TCOD_bkgnd_flag_t bkgnd_flag = TCOD_BKGND_SET,
float scale_x=1.0f,
float scale_y=1.0f,
float angle=0.0f)
const;
465 void blit(TCOD_Console& console,
float x,
float y,
TCOD_bkgnd_flag_t bkgnd_flag = TCOD_BKGND_SET,
float scale_x=1.0f,
float scale_y=1.0f,
float angle=0.0f)
const {
466 TCOD_image_blit(data, &console, x, y, bkgnd_flag, scale_x, scale_y, angle);
493 void setKeyColor(
const TCODColor keyColor);
520 void blit2x(TCODConsole *dest,
int dx,
int dy,
int sx=0,
int sy=0,
int w=-1,
int h=-1)
const;
521 [[deprecated(
"This call is replaced by tcod::draw_quartergraphics.")]]
522 void blit2x(TCOD_Console& dest,
int dx,
int dy,
int sx=0,
int sy=0,
int w=-1,
int h=-1)
const {
523 TCOD_image_blit_2x(data, &dest, dx, dy, sx, sy, w, h);
533 TCOD_Image* get_data() noexcept {
return data; }
541 const TCOD_Image* get_data() const noexcept {
return data; }
543 [[deprecated(
"This only makes a reference to the image data."
544 " If you intended to pass ownership then use `TCODImage{tcod::ImagePtr{image_ptr}}`")]]
545 TCODImage(TCOD_image_t img) : data(img), deleteData(false) {}
546 virtual ~TCODImage();
553 [[nodiscard]]
operator TCOD_Image&() {
return *data; }
560 [[nodiscard]]
operator const TCOD_Image&()
const {
return *data; }
563 struct TCOD_Image *data{
nullptr};
564 bool deleteData{
false};
584inline void draw_quartergraphics(
586 const TCOD_Image& source,
587 const std::array<int, 2>& dest_xy = {0, 0},
588 const std::array<int, 4>& src_rect = {0, 0, -1, -1}) {
590 &source, &dest, dest_xy.at(0), dest_xy.at(1), src_rect.at(0), src_rect.at(1), src_rect.at(2), src_rect.at(3));
Classic turn by turn game loop:TCODConsole::initRoot(80,50,"my game",false); while (!...
Definition console.hpp:137
constexpr const shape_type & get_shape() const noexcept
Return the shape of this matrix.
Definition matrix.hpp:180
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
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
The libtcod namespace.
Definition color.hpp:45
std::unique_ptr< TCOD_Image, ImageDeleter > ImagePtr
A unique pointer to a TCOD_Image.
Definition image.hpp:54