FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::sdl3::Image Class Reference

#include <image.hpp>

Inheritance diagram for fcn::sdl3::Image:
fcn::Image

Public Member Functions

void convertToDisplayFormat () override
void free () override
int getHeight () const override
Color getPixel (int x, int y) override
virtual SDL_Surface * getSurface () const
virtual SDL_Texture * getTexture () const
int getWidth () const override
 Image (SDL_Surface *surface, bool autoFree, SDL_Renderer *renderer=nullptr)
void putPixel (int x, int y, Color const &color) override
Public Member Functions inherited from fcn::Image
 Image (Image &&)=delete
 Image (Image const &)=delete
Image & operator= (Image &&)=delete
Image & operator= (Image const &)=delete

Protected Attributes

bool mAutoFree
SDL_Renderer * mRenderer = nullptr
SDL_Texture * mTexture = nullptr
SDL_Surface * mTransientSurface = nullptr

Additional Inherited Members

Static Public Member Functions inherited from fcn::Image
static ImageLoadergetImageLoader ()
static Image * load (std::string const &filename, bool convertToDisplayFormat=true)
static void resetImageLoader ()
static void setImageLoader (ImageLoader *imageLoader)
Static Protected Attributes inherited from fcn::Image
static ImageLoadermImageLoader = nullptr

Detailed Description

SDL3-specific implementation of Image.

Definition at line 28 of file backends/sdl3/image.hpp.

Constructor & Destructor Documentation

◆ Image()

fcn::sdl3::Image::Image ( SDL_Surface * surface,
bool autoFree,
SDL_Renderer * renderer = nullptr )

Constructor.

Load an image from an SDL surface.

Note
The functions getPixel and putPixel are only guaranteed to work before an image has been converted to display format.
Parameters
surfacethe surface from which to load.
autoFreetrue if the surface should automatically be deleted.
rendererthe renderer to use for creating the texture.

Definition at line 21 of file backends/sdl3/image.cpp.

References mAutoFree, mRenderer, mTexture, mTransientSurface, and fcn::throwException().

◆ ~Image()

fcn::sdl3::Image::~Image ( )
overridevirtual

Reimplemented from fcn::Image.

Definition at line 99 of file backends/sdl3/image.cpp.

Member Function Documentation

◆ convertToDisplayFormat()

void fcn::sdl3::Image::convertToDisplayFormat ( )
overridevirtual

Converts the image, if possible, to display format.

IMPORTANT: Only guaranteed to work before the image has been converted to display format.

Implements fcn::Image.

Definition at line 169 of file backends/sdl3/image.cpp.

References mRenderer, mTexture, mTransientSurface, and fcn::throwException().

Referenced by fcn::sdl3::ImageLoader::load().

◆ free()

void fcn::sdl3::Image::free ( )
overridevirtual

Frees an image.

Implements fcn::Image.

Definition at line 188 of file backends/sdl3/image.cpp.

References mTexture, and mTransientSurface.

◆ getHeight()

int fcn::sdl3::Image::getHeight ( ) const
overridevirtual

Gets the height of the image.

Returns
The height of the image.

Implements fcn::Image.

Definition at line 132 of file backends/sdl3/image.cpp.

References mTexture, and fcn::throwException().

◆ getPixel()

Color fcn::sdl3::Image::getPixel ( int x,
int y )
overridevirtual

Gets the color of a pixel at coordinate (x, y) in the image.

IMPORTANT: Only guaranteed to work before the image has been converted to display format.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The color of the pixel.

Implements fcn::Image.

Definition at line 145 of file backends/sdl3/image.cpp.

References mTransientSurface, and fcn::throwException().

◆ getSurface()

SDL_Surface * fcn::sdl3::Image::getSurface ( ) const
virtual

Gets the SDL surface for the image.

Returns
the SDL surface for the image (transient, for pixel operations only).
Deprecated
Use getTexture() for rendering. Returns nullptr if only texture is available.

Definition at line 109 of file backends/sdl3/image.cpp.

References mTransientSurface.

◆ getTexture()

SDL_Texture * fcn::sdl3::Image::getTexture ( ) const
virtual

Gets the SDL texture for the image.

Returns
the SDL texture for the image.

Definition at line 114 of file backends/sdl3/image.cpp.

References mTexture.

Referenced by fcn::sdl3::Graphics::drawImage().

◆ getWidth()

int fcn::sdl3::Image::getWidth ( ) const
overridevirtual

Gets the width of the image.

Returns
The width of the image.

Implements fcn::Image.

Definition at line 119 of file backends/sdl3/image.cpp.

References mTexture, and fcn::throwException().

◆ putPixel()

void fcn::sdl3::Image::putPixel ( int x,
int y,
Color const & color )
overridevirtual

Puts a pixel with a certain color at coordinate (x, y).

Parameters
xThe x coordinate.
yThe y coordinate.
colorThe color of the pixel to put.

Implements fcn::Image.

Definition at line 160 of file backends/sdl3/image.cpp.

References fcn::Color::a, fcn::Color::b, fcn::Color::g, mTransientSurface, fcn::Color::r, and fcn::throwException().

Member Data Documentation

◆ mAutoFree

bool fcn::sdl3::Image::mAutoFree
protected

Whether the transient surface should be freed on destruction.

Definition at line 86 of file backends/sdl3/image.hpp.

Referenced by Image().

◆ mRenderer

SDL_Renderer* fcn::sdl3::Image::mRenderer = nullptr
protected

SDL renderer associated with the texture.

Definition at line 80 of file backends/sdl3/image.hpp.

Referenced by convertToDisplayFormat(), and Image().

◆ mTexture

SDL_Texture* fcn::sdl3::Image::mTexture = nullptr
protected

SDL texture for accelerated rendering (primary storage).

Definition at line 77 of file backends/sdl3/image.hpp.

Referenced by convertToDisplayFormat(), free(), getHeight(), getTexture(), getWidth(), and Image().

◆ mTransientSurface

SDL_Surface* fcn::sdl3::Image::mTransientSurface = nullptr
protected

Transient surface for pixel operations (getPixel/putPixel).

Definition at line 83 of file backends/sdl3/image.hpp.

Referenced by convertToDisplayFormat(), free(), getPixel(), getSurface(), Image(), and putPixel().


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