36#ifndef TCOD_IMAGE_HPP_
37#define TCOD_IMAGE_HPP_
47 void operator()(
TCOD_Image* image)
const { TCOD_image_delete(image); }
56typedef std::unique_ptr<TCOD_Image, ImageDeleter>
ImagePtr;
129 TCODImage(
tcod::ImagePtr image) noexcept: data{image.release()}, deleteData{
true} {};
131 TCODImage(
const TCODImage&) =
delete;
132 TCODImage& operator=(
const TCODImage&) =
delete;
133 TCODImage(TCODImage&& rhs)
noexcept {
134 std::swap(data, rhs.data);
135 std::swap(deleteData, rhs.deleteData);
137 TCODImage& operator=(TCODImage&& rhs)
noexcept {
138 std::swap(data, rhs.data);
139 std::swap(deleteData, rhs.deleteData);
152 :
TCODImage(pixels.get_shape().at(0), pixels.get_shape().at(1)) {
153 for (
int y = 0; y < pixels.
get_shape().at(1); ++y) {
154 for (
int x = 0; x < pixels.
get_shape().at(0); ++x) {
220 [[nodiscard]]
auto getSize() const noexcept -> std::array<
int, 2> {
221 std::array<int, 2> out{};
222 TCOD_image_get_size(data, &out[0], &out[1]);
418 void save(
const char *filename)
const;
442 TCOD_image_blit_rect(data, &console, x, y, w, h, bkgnd_flag);
467 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 {
468 TCOD_image_blit(data, &console, x, y, bkgnd_flag, scale_x, scale_y, angle);
523 [[deprecated(
"This call is replaced by tcod::draw_quartergraphics.")]]
524 void blit2x(
TCOD_Console& dest,
int dx,
int dy,
int sx=0,
int sy=0,
int w=-1,
int h=-1)
const {
525 TCOD_image_blit_2x(data, &dest, dx, dy, sx, sy, w, h);
545 [[deprecated(
"This only makes a reference to the image data."
546 " If you intended to pass ownership then use `TCODImage{tcod::ImagePtr{image_ptr}}`")]]
547 TCODImage(TCOD_image_t img) : data(img), deleteData(false) {}
548 virtual ~TCODImage();
562 [[nodiscard]]
operator const TCOD_Image&()
const {
return *data; }
566 bool deleteData{
false};
591 const std::array<int, 2>& dest_xy = {0, 0},
592 const std::array<int, 4>& src_rect = {0, 0, -1, -1}) {
594 &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
void blit2x(TCODConsole *dest, int dx, int dy, int sx=0, int sy=0, int w=-1, int h=-1) const
Eventually, you can use some special characters in the libtcod fonts :
auto getSize() const noexcept -> std::array< int, 2 >
Get the {width, height} of this image.
Definition image.hpp:220
bool isPixelTransparent(int x, int y) const
You can use this simpler version (for images with alpha layer, returns true only if alpha == 0) :
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
This function allows you to specify the floating point coordinates of the center of the image,...
void rotate90(int numRotations=1)
Rotate the image clockwise by increment of 90 degrees.
void blitRect(TCODConsole *console, int x, int y, int w=-1, int h=-1, TCOD_bkgnd_flag_t bkgnd_flag=TCOD_BKGND_SET) const
This function blits a rectangular part of the image on a console without scaling it or rotating it.
TCODImage(const tcod::Matrix< TCOD_ColorRGB, 2 > &pixels)
Construct a new TCODImage object from a Matrix of pixels.
Definition image.hpp:151
int getAlpha(int x, int y) const
If you have set a key color for this image with setKeyColor, or if this image was created from a 32 b...
void setKeyColor(const TCODColor keyColor)
When blitting an image, you can define a key color that will be ignored by the blitting function.
TCOD_Image * get_data() noexcept
Return the pointer to this objects TCOD_Image data.
Definition image.hpp:535
void scale(int new_w, int new_h)
You can resize an image and scale its content.
void putPixel(int x, int y, const TCODColor col)
void clear(const TCODColor col)
You can fill the whole image with a color with :
TCODColor getMipmapPixel(float x0, float y0, float x1, float y1)
This method uses mipmaps to get the average color of an arbitrary rectangular region of the image.
void save(const char *filename) const
TCODImage() noexcept=default
Default constructs an image. This will be in a partially invalid state until assigned a real image.
void getSize(int *w, int *h) const
You can read the size of an image in pixels with this function.
const TCOD_Image * get_data() const noexcept
Return the const pointer to this objects TCOD_Image data.
Definition image.hpp:543
TCODColor getPixel(int x, int y) const
You can read the colors from an image with this function.
void refreshConsole(const TCODConsole *console)
If you need to refresh the image with the console's new content, you don't have to delete it and crea...
A template container for holding a multi-dimensional array of items.
Definition matrix.hpp:139
constexpr const shape_type & get_shape() const noexcept
Return the shape of this matrix.
Definition matrix.hpp:180
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
The libtcod namespace.
Definition bresenham.hpp:157
std::unique_ptr< TCOD_Image, ImageDeleter > ImagePtr
A unique pointer to a TCOD_Image.
Definition image.hpp:56
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
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:125