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

#include <image.hpp>

Inheritance diagram for fcn::sdl2::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 (Image &&)=delete
 Image (Image const &)=delete
 Image (SDL_Surface *surface, bool autoFree, SDL_Renderer *renderer=nullptr)
Imageoperator= (Image &&)=delete
Imageoperator= (Image const &)=delete
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 setImageLoader (ImageLoader *imageLoader)
Static Protected Attributes inherited from fcn::Image
static ImageLoadermImageLoader = nullptr

Detailed Description

SDL2-specific implementation of Image.

Definition at line 23 of file backends/sdl2/image.hpp.

Constructor & Destructor Documentation

◆ Image()

fcn::sdl2::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 18 of file backends/sdl2/image.cpp.

References mAutoFree, mRenderer, mTexture, and mTransientSurface.

◆ ~Image()

fcn::sdl2::Image::~Image ( )
overridevirtual

Reimplemented from fcn::Image.

Definition at line 100 of file backends/sdl2/image.cpp.

Member Function Documentation

◆ convertToDisplayFormat()

void fcn::sdl2::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 162 of file backends/sdl2/image.cpp.

References mTexture.

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

◆ free()

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

Frees an image.

Implements fcn::Image.

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

References mTexture, and mTransientSurface.

◆ getHeight()

int fcn::sdl2::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/sdl2/image.cpp.

References mTexture.

◆ getPixel()

Color fcn::sdl2::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 144 of file backends/sdl2/image.cpp.

References mTransientSurface, and fcn::sdl2::SDLgetPixel().

◆ getSurface()

SDL_Surface * fcn::sdl2::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 110 of file backends/sdl2/image.cpp.

References mTransientSurface.

◆ getTexture()

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

Gets the SDL texture for the image.

Returns
the SDL texture for the image.

Definition at line 115 of file backends/sdl2/image.cpp.

References mTexture.

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

◆ getWidth()

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

Gets the width of the image.

Returns
The width of the image.

Implements fcn::Image.

Definition at line 120 of file backends/sdl2/image.cpp.

References mTexture.

◆ putPixel()

void fcn::sdl2::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 153 of file backends/sdl2/image.cpp.

References mTransientSurface, and fcn::sdl2::SDLputPixel().

Member Data Documentation

◆ mAutoFree

bool fcn::sdl2::Image::mAutoFree
protected

Whether the transient surface should be freed on destruction.

Definition at line 85 of file backends/sdl2/image.hpp.

Referenced by Image().

◆ mRenderer

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

SDL renderer associated with the texture.

Definition at line 79 of file backends/sdl2/image.hpp.

Referenced by Image().

◆ mTexture

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

SDL texture for accelerated rendering (primary storage).

Definition at line 76 of file backends/sdl2/image.hpp.

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

◆ mTransientSurface

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

Transient surface for pixel operations (getPixel/putPixel).

Definition at line 82 of file backends/sdl2/image.hpp.

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


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