FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::SDLImage Class Reference

The SDL implementation of the Image base class. More...

#include <sdlimage.h>

+ Inheritance diagram for FIFE::SDLImage:
+ Collaboration diagram for FIFE::SDLImage:

Public Member Functions

 SDLImage (IResourceLoader *loader=0)
 
 SDLImage (const std::string &name, IResourceLoader *loader=0)
 
 SDLImage (SDL_Surface *surface)
 
 SDLImage (const std::string &name, SDL_Surface *surface)
 
 SDLImage (const uint8_t *data, uint32_t width, uint32_t height)
 
 SDLImage (const std::string &name, const uint8_t *data, uint32_t width, uint32_t height)
 
virtual ~SDLImage ()
 
virtual void invalidate ()
 Invalidates the Image causing it to be reset or re-loaded. More...
 
virtual void setSurface (SDL_Surface *surface)
 This frees the current suface and replaces it with the surface passed in the parameter (which can be NULL). More...
 
virtual void render (const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)
 Renders itself to the current render target (main screen or attached destination image) at the rectangle rect. More...
 
virtual size_t getSize ()
 
virtual void useSharedImage (const ImagePtr &shared, const Rect &region)
 After this call all image data will be taken from the given image and its subregion. More...
 
virtual void forceLoadInternal ()
 Forces to load the image into internal memory of GPU. More...
 
virtual void load ()
 
virtual void free ()
 
SDL_Texture * getTexture ()
 
void setTexture (SDL_Texture *texture)
 
- Public Member Functions inherited from FIFE::Image
 Image (IResourceLoader *loader=0)
 Constructor. More...
 
 Image (const std::string &name, IResourceLoader *loader=0)
 
 Image (SDL_Surface *surface)
 Constructor. More...
 
 Image (const std::string &name, SDL_Surface *surface)
 
 Image (const uint8_t *data, uint32_t width, uint32_t height)
 Constructor. More...
 
 Image (const std::string &name, const uint8_t *data, uint32_t width, uint32_t height)
 
virtual ~Image ()
 Destructor. More...
 
virtual void render (const Rect &rect, const ImagePtr &overlay, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, const ImagePtr &overlay, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, uint8_t alpha=255, bool forceNewBatch=false, uint8_t const *rgb=0)
 
SDL_Surface * detachSurface ()
 Removes underlying SDL_Surface from the image (if exists) and returns this. More...
 
SDL_Surface * getSurface ()
 
const SDL_Surface * getSurface () const
 
void saveImage (const std::string &filename)
 Saves the image using given filename. More...
 
uint32_t getWidth () const
 
uint32_t getHeight () const
 
Rect getArea () const
 
void setXShift (int32_t xshift)
 
int32_t getXShift () const
 
void setYShift (int32_t yshift)
 
int32_t getYShift () const
 
void getPixelRGBA (int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
 
bool isSharedImage () const
 Returns true if this image shares data with another one. More...
 
const RectgetSubImageRect () const
 Returns area of the image it occupies in the shared image. More...
 
virtual void copySubimage (uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
 Copies given image into this one with respect to given offsets. More...
 
- Public Member Functions inherited from FIFE::IResource
 IResource (const std::string &name, IResourceLoader *loader=0)
 
virtual ~IResource ()
 
virtual const std::string & getName ()
 
ResourceHandle getHandle ()
 
virtual ResourceState getState ()
 
virtual void setState (const ResourceState &state)
 

Private Member Functions

void resetSdlimage ()
 
void validateShared ()
 

Private Attributes

SDL_Color m_colorkey
 
SDL_Texture * m_texture
 
ImagePtr m_atlas_img
 
std::string m_atlas_name
 

Additional Inherited Members

- Public Types inherited from FIFE::IResource
enum  ResourceState { RES_INVALID = 0, RES_NOT_LOADED, RES_LOADED }
 
- Static Public Member Functions inherited from FIFE::Image
static void saveAsPng (const std::string &filename, const SDL_Surface &surface)
 Saves the SDL_Surface to png format. More...
 
static bool putPixel (SDL_Surface *surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 
- Protected Member Functions inherited from FIFE::Image
void reset (SDL_Surface *surface)
 Resets the image to default values (including the x and y shift values), frees the current surface and sets the surface to the passed SDL_Surface (which can be NULL). More...
 
- Protected Attributes inherited from FIFE::Image
SDL_Surface * m_surface
 
int32_t m_xshift
 
int32_t m_yshift
 
bool m_shared
 
Rect m_subimagerect
 
- Protected Attributes inherited from FIFE::IResource
std::string m_name
 
IResourceLoaderm_loader
 
ResourceState m_state
 

Detailed Description

The SDL implementation of the Image base class.

Definition at line 40 of file sdlimage.h.

Constructor & Destructor Documentation

◆ SDLImage() [1/6]

FIFE::SDLImage::SDLImage ( IResourceLoader loader = 0)

Definition at line 47 of file sdlimage.cpp.

References resetSdlimage().

◆ SDLImage() [2/6]

FIFE::SDLImage::SDLImage ( const std::string &  name,
IResourceLoader loader = 0 
)

Definition at line 52 of file sdlimage.cpp.

References resetSdlimage().

◆ SDLImage() [3/6]

FIFE::SDLImage::SDLImage ( SDL_Surface *  surface)

Definition at line 57 of file sdlimage.cpp.

References resetSdlimage().

◆ SDLImage() [4/6]

FIFE::SDLImage::SDLImage ( const std::string &  name,
SDL_Surface *  surface 
)

Definition at line 62 of file sdlimage.cpp.

References resetSdlimage().

◆ SDLImage() [5/6]

FIFE::SDLImage::SDLImage ( const uint8_t *  data,
uint32_t  width,
uint32_t  height 
)

Definition at line 67 of file sdlimage.cpp.

References resetSdlimage().

◆ SDLImage() [6/6]

FIFE::SDLImage::SDLImage ( const std::string &  name,
const uint8_t *  data,
uint32_t  width,
uint32_t  height 
)

Definition at line 72 of file sdlimage.cpp.

References resetSdlimage().

◆ ~SDLImage()

FIFE::SDLImage::~SDLImage ( )
virtual

Definition at line 82 of file sdlimage.cpp.

References invalidate().

Member Function Documentation

◆ forceLoadInternal()

void FIFE::SDLImage::forceLoadInternal ( )
virtual

Forces to load the image into internal memory of GPU.

Implements FIFE::Image.

Definition at line 185 of file sdlimage.cpp.

References validateShared().

◆ free()

void FIFE::SDLImage::free ( )
virtual

◆ getSize()

size_t FIFE::SDLImage::getSize ( )
virtual

Reimplemented from FIFE::Image.

Definition at line 151 of file sdlimage.cpp.

References FIFE::Image::m_shared, and FIFE::Image::m_surface.

◆ getTexture()

SDL_Texture * FIFE::SDLImage::getTexture ( )

Definition at line 224 of file sdlimage.cpp.

References m_texture.

Referenced by FIFE::RenderBackendSDL::attachRenderTarget(), and useSharedImage().

+ Here is the caller graph for this function:

◆ invalidate()

void FIFE::SDLImage::invalidate ( )
virtual

Invalidates the Image causing it to be reset or re-loaded.

Implements FIFE::Image.

Definition at line 86 of file sdlimage.cpp.

References FIFE::Image::m_shared, and m_texture.

Referenced by setSurface(), and ~SDLImage().

+ Here is the caller graph for this function:

◆ load()

void FIFE::SDLImage::load ( )
virtual

◆ render()

void FIFE::SDLImage::render ( const Rect rect,
uint8_t  alpha = 255,
uint8_t const *  rgb = 0 
)
virtual

Renders itself to the current render target (main screen or attached destination image) at the rectangle rect.

Convenience function

Parameters
rectThe position and clipping where to draw this image to.
alphaThe alpha value, with which to draw self.
rgbThe color value of overlay if any.

Implements FIFE::Image.

Definition at line 99 of file sdlimage.cpp.

References FIFE::RectType< T >::bottom(), FIFE::Image::getArea(), FIFE::RenderBackend::getRenderTargetSurface(), FIFE::Image::getSubImageRect(), FIFE::RectType< T >::h, FIFE::DynamicSingleton< RenderBackend >::instance(), load(), FIFE::Image::m_shared, FIFE::Image::m_surface, m_texture, FIFE::RectType< T >::right(), FIFE::RectType< T >::w, FIFE::RectType< T >::x, and FIFE::RectType< T >::y.

◆ resetSdlimage()

void FIFE::SDLImage::resetSdlimage ( )
private

Definition at line 77 of file sdlimage.cpp.

References FIFE::RenderBackend::getColorKey(), FIFE::DynamicSingleton< RenderBackend >::instance(), m_colorkey, and m_texture.

Referenced by SDLImage(), and setSurface().

+ Here is the caller graph for this function:

◆ setSurface()

void FIFE::SDLImage::setSurface ( SDL_Surface *  surface)
virtual

This frees the current suface and replaces it with the surface passed in the parameter (which can be NULL).

See also
Image::reset(SDL_Surface* surface)
Parameters
surfacethe SDL_Surface to use for this image

Implements FIFE::Image.

Definition at line 93 of file sdlimage.cpp.

References invalidate(), FIFE::Image::reset(), and resetSdlimage().

Referenced by free(), and useSharedImage().

+ Here is the caller graph for this function:

◆ setTexture()

void FIFE::SDLImage::setTexture ( SDL_Texture *  texture)

Definition at line 228 of file sdlimage.cpp.

References FIFE::Image::m_shared, and m_texture.

Referenced by FIFE::RenderBackendSDL::attachRenderTarget(), and useSharedImage().

+ Here is the caller graph for this function:

◆ useSharedImage()

void FIFE::SDLImage::useSharedImage ( const ImagePtr shared,
const Rect region 
)
virtual

◆ validateShared()

void FIFE::SDLImage::validateShared ( )
private

Definition at line 189 of file sdlimage.cpp.

References FIFE::IResource::getState(), load(), m_atlas_img, m_atlas_name, and FIFE::IResource::RES_NOT_LOADED.

Referenced by forceLoadInternal().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_atlas_img

ImagePtr FIFE::SDLImage::m_atlas_img
private

Definition at line 72 of file sdlimage.h.

Referenced by load(), useSharedImage(), and validateShared().

◆ m_atlas_name

std::string FIFE::SDLImage::m_atlas_name
private

Definition at line 74 of file sdlimage.h.

Referenced by load(), useSharedImage(), and validateShared().

◆ m_colorkey

SDL_Color FIFE::SDLImage::m_colorkey
private

Definition at line 67 of file sdlimage.h.

Referenced by resetSdlimage().

◆ m_texture

SDL_Texture* FIFE::SDLImage::m_texture
private

Definition at line 69 of file sdlimage.h.

Referenced by getTexture(), invalidate(), render(), resetSdlimage(), setTexture(), and useSharedImage().


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