LPCGame
A Simple 2d Game Engine
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Image Class Reference

Wrapper around the SDL_Texture to make things easier. More...

#include <image.h>

Inherited by AnimatedImage.

Public Member Functions

 Image (const std::string &file)
 
 ~Image ()
 
void SetClips (const std::vector< Recti > &clips)
 
void GenClips (int cW, int cH)
 
SDL_Texture * Texture ()
 
Recti Clip (int clipNum) const
 
Recti Clip () const
 
void SetActiveClip (int clip)
 
int ClipCount () const
 
void Size (int *w, int *h=NULL) const
 
int W () const
 Get the Image texture's width.
 
int H () const
 Get the Image texture's height.
 
std::string File () const
 Get the Image filename.
 
virtual void Save (const std::string &file) const
 
virtual void Load (const std::string &file)
 

Protected Member Functions

virtual void Load (Json::Value val)
 
Json::Value SaveClips () const
 

Protected Attributes

std::shared_ptr< SDL_Texture > mTexture
 
std::string mFile
 
RectimClips
 
int mNumClips
 
int mActiveClip
 

Detailed Description

Wrapper around the SDL_Texture to make things easier.

A wrapper around the SDL_Texture class to make using images and setting clips or loading/saving them easier

Constructor & Destructor Documentation

Image::Image ( const std::string &  file)

Setup the Image class, if a filename is passed load the image

Parameters
fileThe filename
See Also
Window::LoadImage for the loading function
Image::~Image ( )

Free the clips vector, b/c the SDL_Surface is a shared ptr it's cleaned up automatically

Member Function Documentation

Recti Image::Clip ( int  clipNum) const

Get the rect for a desired clipnum

Parameters
clipNumThe clip number to get the box of
Returns
The Recti corresponding to the clip box
Recti Image::Clip ( ) const

Get the clip of mActiveClip

Returns
The Recti of the active clip
int Image::ClipCount ( ) const

Returns the number of clips in the image

Returns
int The number of clips.
void Image::GenClips ( int  cW,
int  cH 
)

Generate clips based on the desired width and height of each clip and the size of the image, note that this will only work for uniform clip sizes

Parameters
cWThe desired width of each clip
cHThe desired height of each clip
void Image::Load ( const std::string &  file)
virtual

Load an Image and it's config data from a filename

Parameters
fileThe file to load from, the config file will be file.json
See Also
Window::LoadTexture for the texture loading function
void Image::Load ( Json::Value  val)
protectedvirtual

Load an Image's properties from a Json::Value

Parameters
valThe Json::Value to load from
void Image::Save ( const std::string &  file) const
virtual

Save an Image's properties to a Json formatted file

Parameters
fileThe file to save to

Reimplemented in AnimatedImage.

Json::Value Image::SaveClips ( ) const
protected

Write the clips to a Json::Value and return it

Returns
a Json::Value containing the clips information
void Image::SetActiveClip ( int  clip)

Set the active clip

Parameters
clipThe clip number to set active
void Image::SetClips ( const std::vector< Recti > &  clips)

Set the image's clips to the vector passed

Parameters
clipsThe clips to use for the image

TODO: Will Lua be able to pass a vector to C++? Will a Lua array convert ok? curious what will happen here

void Image::Size ( int *  w,
int *  h = NULL 
) const

Store the width and height values of the texture in the values passed

Parameters
wThe value to store the width in
hThe value to store the height in
SDL_Texture * Image::Texture ( )

Get the raw SDL_Texture pointer, this is only used inside the Window's draw functions as SDL expects a regular SDL_Texture pointer to draw

See Also
Window
Returns
SDL_Texture pointer to the image's texture

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