tbx  0.7.3
Classes | Public Member Functions | Static Public Member Functions | List of all members
tbx::SpriteArea Class Reference

A SpriteArea holds zero or more user sprites. More...

#include <sprite.h>

Classes

class  iterator
 Iterator class for iterating through UserSprites in a sprite area. More...
 

Public Member Functions

 SpriteArea ()
 Construct an uninitialised sprite area.
 
 ~SpriteArea ()
 Destructor deletes the RISC OS sprite area if it owns it.
 
 SpriteArea (OsSpriteAreaPtr data, bool ownsarea=false)
 Construct a SpriteArea from a RISC OS sprite area pointer. More...
 
 SpriteArea (int size)
 Construct an empty sprite area with the initial capacity. More...
 
 SpriteArea (const SpriteArea &other)
 Constructs a sprite area that is a copy of the given area.
 
SpriteAreaoperator= (const SpriteArea &other)
 Deletes current area and replaces it with a copy of the given area.
 
void set (OsSpriteAreaPtr data, bool ownsarea=false)
 Assign this sprite area to a sprite area pointer. More...
 
bool is_valid () const
 Returns true if area is valid.
 
bool initialise (int size)
 Initialise a new user sprite area. More...
 
bool load (const std::string &file_name)
 Load a sprite area from a file. More...
 
bool merge (const std::string &file_name)
 Merge a sprite area from a file into this sprite area. More...
 
bool save (const std::string &file_name) const
 Save the sprite area to a file. More...
 
int size () const
 Get the size of the sprite area. More...
 
int free_space () const
 Get the free space in the sprite area. More...
 
bool resize (int new_size)
 Resize the sprite area. More...
 
int sprite_count () const
 Return the number of sprites in the sprite area.
 
UserSprite get_sprite (const std::string &name)
 Get a sprite from this sprite area by name. More...
 
UserSprite create_sprite (const std::string &name, int width, int height, int mode, bool palette=false)
 Create a new sprite. More...
 
UserSprite create_sprite_pixels (const std::string &name, int width, int height, int mode, bool palette=false)
 Create a new sprite, size measured in pixels. More...
 
OsSpriteAreaPtr pointer () const
 Return pointer to underlying sprite are that can be used when using low-level area manipulation.
 
bool rename (UserSprite &sprite, const std::string &newname)
 Rename a sprite in a sprite area. More...
 
bool erase (UserSprite &sprite)
 Erase a sprite from the sprite area. More...
 
bool erase (const std::string name)
 Erase the a sprite from the sprite area. More...
 
iterator begin ()
 Return an iterator to the first sprite in the sprite area.
 
iterator end ()
 Return an iterator to the sprite after the last one in the sprite area. More...
 
UserSprite get_sprite (OsSpritePtr sprite_ptr)
 Get sprite for area given a pointer to it. More...
 

Static Public Member Functions

static int calculate_memory (int width, int height, int mode, bool withPalette)
 Calculate the memory required to create a sprite. More...
 
static int calculate_mask_size (int width, int height, int mode)
 Calculate the size required for a sprite mask. More...
 
static int get_bits_per_pixel (int mode)
 Calculate the number of bits required for one pixel for the given mode. More...
 

Detailed Description

A SpriteArea holds zero or more user sprites.

New sprites can be created within it.

Constructor & Destructor Documentation

SpriteArea::SpriteArea ( OsSpriteAreaPtr  data,
bool  ownsarea = false 
)

Construct a SpriteArea from a RISC OS sprite area pointer.

Parameters
dataRISC OS sprite area pointer
ownsareatrue if the SpriteArea now looks after the area
SpriteArea::SpriteArea ( int  size)

Construct an empty sprite area with the initial capacity.

Parameters
sizesize of area in bytes.

Member Function Documentation

int SpriteArea::calculate_mask_size ( int  width,
int  height,
int  mode 
)
static

Calculate the size required for a sprite mask.

Parameters
widthwidth of sprite in pixels
heightheight of sprite in pixels
modescreen mode for sprite
Returns
number of bytes required for the mask
int SpriteArea::calculate_memory ( int  width,
int  height,
int  mode,
bool  withPalette 
)
static

Calculate the memory required to create a sprite.

Parameters
widthwidth of sprite in pixels
heightheight of sprite in pixels
modescreen mode to create the sprite for
withPalettetrue to create a palette for the sprite
Returns
number of bytes required to create the sprite
UserSprite SpriteArea::create_sprite ( const std::string &  name,
int  width,
int  height,
int  mode,
bool  palette = false 
)

Create a new sprite.

Parameters
namename of sprite (max length 12)
widthWidth of sprite in OS units
heightHeight of sprite in OS units
mode- Use SpriteFormat enum or value returned from SpriteMode
palette- true to create with a palette
Returns
Pointer to sprite if successful or 0
UserSprite SpriteArea::create_sprite_pixels ( const std::string &  name,
int  width,
int  height,
int  mode,
bool  palette = false 
)

Create a new sprite, size measured in pixels.

Parameters
namename of sprite (max length 12)
widthWidth of sprite in pixels
heightHeight of sprite in pixels
mode- Use SpriteFormat enum or value returned from SpriteMode
palette- true to create with a palette
Returns
Pointer to sprite if successful or 0
SpriteArea::iterator SpriteArea::end ( )

Return an iterator to the sprite after the last one in the sprite area.

This is always an invalid sprite

bool SpriteArea::erase ( UserSprite s)

Erase a sprite from the sprite area.

Parameters
ssprite to erase
Returns
true if successful
bool SpriteArea::erase ( const std::string  name)

Erase the a sprite from the sprite area.

Parameters
nameName of sprite to erase
Returns
true if sprite was erased.
int SpriteArea::free_space ( ) const

Get the free space in the sprite area.

Returns
number of unused bytes at the end of the sprite area
int SpriteArea::get_bits_per_pixel ( int  mode)
static

Calculate the number of bits required for one pixel for the given mode.

Parameters
modescreen mode number
Returns
number of bits per pixel
UserSprite SpriteArea::get_sprite ( const std::string &  name)

Get a sprite from this sprite area by name.

Check is_valid on returned sprite to check it was found.

Returns
UserSprite. If the name is not found sprite returned is not valid.
UserSprite SpriteArea::get_sprite ( OsSpritePtr  sprite_ptr)

Get sprite for area given a pointer to it.

Parameters
sprite_ptr- pointer to sprite
Exceptions
std::out_of_range
bool SpriteArea::initialise ( int  size)

Initialise a new user sprite area.

Parameters
sizesize of sprite area in bytes
Returns
true if successful
bool SpriteArea::load ( const std::string &  file_name)

Load a sprite area from a file.

Parameters
file_namename of sprite area file
Returns
true if load is successful
bool SpriteArea::merge ( const std::string &  file_name)

Merge a sprite area from a file into this sprite area.

Warning: Any UserSprites returned from the area will be invalid

Parameters
file_namename of tile to merge sprites from
Returns
true if successful
bool SpriteArea::rename ( UserSprite s,
const std::string &  name 
)

Rename a sprite in a sprite area.

Parameters
sUserSprite to rename
namenew name for the sprite
Returns
true if successful
bool SpriteArea::resize ( int  newSize)

Resize the sprite area.

Parameters
newSizenew size for the area
Returns
true if successful
bool SpriteArea::save ( const std::string &  file_name) const

Save the sprite area to a file.

Parameters
file_namename of file to save to
Returns
true if successful
void SpriteArea::set ( OsSpriteAreaPtr  data,
bool  ownsarea = false 
)

Assign this sprite area to a sprite area pointer.

Parameters
dataRISC OS sprite area pointer
ownsareatrue if the SpriteArea now looks after the area
int SpriteArea::size ( ) const

Get the size of the sprite area.

Returns
number of bytes in the sprite area

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