tbx  0.7.3
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
tbx::UserSprite Class Reference

Sprite from a user sprite area. More...

#include <sprite.h>

Inheritance diagram for tbx::UserSprite:
tbx::Sprite tbx::Image

Public Member Functions

 UserSprite ()
 Construct an unassigned sprite. More...
 
 UserSprite (SpriteArea *area, const std::string &name)
 Construct a user sprite from a sprite area and name. More...
 
virtual ~UserSprite ()
 Destructor - not this does not delete the sprite from the sprite area as this class is just a reference to the sprite.
 
bool operator== (const UserSprite &other) const
 Check if two sprite classes refer to the same underlying sprite.
 
bool operator!= (const UserSprite &other) const
 Check if two sprite classes DO NOT refer to the same underlying sprite.
 
bool is_valid () const
 Check this sprite object is valid.
 
bool rename (const std::string &name)
 Renames the sprite. More...
 
virtual void plot_raw (const Point &pos, int code=SPA_USE_MASK) const
 Plot this sprite at the given position with no scaling or colour conversions.
 
virtual void plot_scaled (const Point &pos, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const
 Plot this sprite scaled using the given colour translation. More...
 
virtual void plot_screen (const Point &pos, int code=SPA_USE_MASK) const
 Plot sprite to screen. More...
 
virtual void plot_raw (int x, int y, int code=SPA_USE_MASK) const
 Plot this sprite at the given position with no scaling or colour conversions.
 
virtual void plot_scaled (int x, int y, const ScaleFactors *sf, const TranslationTable *tt=0, int code=SPA_USE_MASK) const
 Plot this sprite scaled using the given colour translation. More...
 
virtual void plot_screen (int x, int y, int code=SPA_USE_MASK) const
 Plot sprite to screen. More...
 
virtual std::string name () const
 Get the name of the sprite. More...
 
virtual bool info (Size *pixel_size, int *mode=NULL, bool *mask=NULL) const
 Get information about the sprite. More...
 
bool get_palette (ColourPalette &pal) const
 Get palette (non-flashing colours only) for this sprite. More...
 
bool set_palette (ColourPalette &pal)
 Set the sprites palette. More...
 
bool create_palette (bool col256=false)
 Create a palette for a sprite. More...
 
bool create_palette (ColourPalette &pal)
 Create a palette for a sprite. More...
 
bool remove_palette ()
 Remove palette from a sprite.
 
bool create_mask ()
 Create a mask for the sprite. More...
 
bool remove_mask ()
 Remove sprite mask. More...
 
int pixel (int x, int y) const
 Get pixel at given location. More...
 
void pixel (int x, int y, int gcol)
 Set pixel at given location. More...
 
void pixel (int x, int y, int gcol, int tint)
 Set pixel at given location. More...
 
int pixel (int x, int y, int *tint) const
 Get pixel at given location. More...
 
bool mask_pixel (int x, int y) const
 Check is mask pixel is set at given location. More...
 
void mask_pixel (int x, int y, bool on)
 Set or clear mask pixel is at given location. More...
 
SpriteAreaget_sprite_area () const
 Return SpriteArea this sprite is from.
 
int offset () const
 Return offset of this sprite in the sprite area.
 
OsSpritePtr pointer () const
 Return pointer to underlying RISC OS sprite.
 
virtual int area_id () const
 Return sprite area id used for calls that take an area pointer or a special value for WIMP/System areas.
 
bool has_palette () const
 Returns true if this sprite has a palette.
 
virtual void get_wimp_scale (ScaleFactors &factor) const
 Get the scale factors required to plot this sprite in the WIMP as its logical size. More...
 
- Public Member Functions inherited from tbx::Sprite
virtual void plot (int x, int y) const
 Plot sprite to screen. More...
 
virtual void plot (const Point &pos) const
 Plot sprite to screen. More...
 
Size size () const
 Return the size of the sprite. More...
 
int width () const
 Return the width of the sprite. More...
 
int height () const
 Return the height of the sprite. More...
 
Size pixel_size () const
 Get size of the sprite in pixels. More...
 
int mode () const
 Get the mode of the sprite. More...
 
bool has_mask () const
 Check if the sprite has a mask. More...
 

Protected Member Functions

 UserSprite (SpriteArea *area, int offset)
 Private constructor used by sprite area to return a sprite.
 

Protected Attributes

SpriteArea_area
 Sprite area containing this sprite.
 
int _offset
 offset of sprite within the sprite area
 

Friends

class SpriteArea
 

Detailed Description

Sprite from a user sprite area.

A sprite reference is returned using the SpriteArea::get_sprite method.

A runtime error or crash will occur is you try to use a sprite after the SpriteArea it was retrieved from has been deleted.

Constructor & Destructor Documentation

UserSprite::UserSprite ( )

Construct an unassigned sprite.

UserSprite::UserSprite ( SpriteArea area,
const std::string &  name 
)

Construct a user sprite from a sprite area and name.

Exceptions
SpriteExceptionif name is not in the sprite area.

Member Function Documentation

bool UserSprite::create_mask ( )

Create a mask for the sprite.

The mask is created all solid

Returns
true if mask created successfully
bool UserSprite::create_palette ( bool  col256 = false)

Create a palette for a sprite.

Will only create a palette if one doesn't already exist

Parameters
col256- use full 256 colour palette for 256 colour sprites
Returns
true if create is successful.
bool UserSprite::create_palette ( ColourPalette pal)

Create a palette for a sprite.

Will only create a palette if one doesn't already exist

Parameters
palinitial palette required
Returns
true if create is successful.
bool UserSprite::get_palette ( ColourPalette pal) const

Get palette (non-flashing colours only) for this sprite.

Parameters
palpalette to copy entries to
Returns
true is sprite has a palette
void UserSprite::get_wimp_scale ( ScaleFactors factor) const
virtual

Get the scale factors required to plot this sprite in the WIMP as its logical size.

Parameters
factorscale factors updated with the correct value

Implements tbx::Sprite.

bool UserSprite::info ( Size pixel_size,
int *  mode = NULL,
bool *  mask = NULL 
) const
virtual

Get information about the sprite.

Parameters
pixel_sizepointer to Size to be updated with size of sprite in pixels
modepointer to integer to receive the sprite mode number or 0 (the default) not to return the mode
maskpointer to a boolean which will be set to true if the sprite has a mask or 0 (the default) not to return the mask
Returns
true if successfule

Implements tbx::Sprite.

bool UserSprite::mask_pixel ( int  x,
int  y 
) const

Check is mask pixel is set at given location.

Parameters
xx coordinate to get the mask pixel for in pixels
yy coordinate to get the mask pixel for in pixels
Returns
true if mask pixel is set
Exceptions
OSErrorfailed to retrieve mask pixel
void UserSprite::mask_pixel ( int  x,
int  y,
bool  on 
)

Set or clear mask pixel is at given location.

Parameters
xx coordinate to set the mask pixel for in pixels
yy coordinate to set the mask pixel for in pixels
ontrue to set the mask pixel, false to unset it
Exceptions
OSErrorfailed to set mask pixel
std::string UserSprite::name ( ) const
virtual

Get the name of the sprite.

Returns
the name of the sprite as a string

Implements tbx::Sprite.

int UserSprite::pixel ( int  x,
int  y 
) const

Get pixel at given location.

The returned pixel colour is from 0 to number of colours in the sprite -1. For a 256 colour sprite this will only return 0-63, for full colour information use pixel(x,y,&tint) to return the tint information as well.

Parameters
xx coordinate to get the pixel for in pixels
yy coordinate to get the pixel for in pixels
Returns
gcol pixel value in sprite
Exceptions
OSErrorfailed to retrieve pixel
void UserSprite::pixel ( int  x,
int  y,
int  gcol 
)

Set pixel at given location.

For a 256 colour sprite the gcol parameter is 0-63, and the tint is set to 0, use pixel(x,y,gcol, tint) to set the tint information as well.

Parameters
xx coordinate to set the pixel for in pixels
yy coordinate to set the pixel for in pixels
gcolpixel value to set from 0 to number colours in sprite-1
Exceptions
OSErrorfailed to set pixel
void UserSprite::pixel ( int  x,
int  y,
int  gcol,
int  tint 
)

Set pixel at given location.

For a 256 colour sprite the gcol parameter is 0-63 and the tint is also used.

Parameters
xx coordinate to set the pixel for in pixels
yy coordinate to set the pixel for in pixels
gcolpixel value to set from 0 to number colours in sprite-1
tintvalue to of tint (0, 64, 128 or 192 in 256 colour modes, ignored in all other modes)
Exceptions
OSErrorfailed to set pixel
int UserSprite::pixel ( int  x,
int  y,
int *  tint 
) const

Get pixel at given location.

The returned pixel colour is from 0 to number of colours in the sprite -1. For a 256 colour sprite this will only return 0-63, and the tint of the colour is return in tint

Parameters
xx coordinate to get the pixel for in pixels
yy coordinate to get the pixel for in pixels
tintvalue to receive tint (0, 64, 128 or 192 in 256 colour modes, 0 in all other modes)
Returns
gcol pixel value in sprite
Exceptions
OSErrorfailed to retrieve pixel
void UserSprite::plot_scaled ( const Point pos,
const ScaleFactors sf,
const TranslationTable tbl = 0,
int  code = SPA_USE_MASK 
) const
virtual

Plot this sprite scaled using the given colour translation.

  • x os x position for plot
  • y os y position for plot
  • sf scale factors (0 = don't scale)
  • table colour translation table (0 = don't translate colours)

Implements tbx::Sprite.

void UserSprite::plot_scaled ( int  x,
int  y,
const ScaleFactors sf,
const TranslationTable tbl = 0,
int  code = SPA_USE_MASK 
) const
virtual

Plot this sprite scaled using the given colour translation.

  • x os x position for plot
  • y os y position for plot
  • sf scale factors (0 = don't scale)
  • table colour translation table (0 = don't translate colours)

Implements tbx::Sprite.

void UserSprite::plot_screen ( const Point pos,
int  code = SPA_USE_MASK 
) const
virtual

Plot sprite to screen.

Calculates the translation table and scale factors for the current screen and plots the sprite

Implements tbx::Sprite.

void UserSprite::plot_screen ( int  x,
int  y,
int  code = SPA_USE_MASK 
) const
virtual

Plot sprite to screen.

Calculates the translation table and scale factors for the current screen and plots the sprite

Implements tbx::Sprite.

bool UserSprite::remove_mask ( )

Remove sprite mask.

Returns
true if mask removed successfully
bool UserSprite::rename ( const std::string &  name)

Renames the sprite.

Returns true if successful

bool UserSprite::set_palette ( ColourPalette pal)

Set the sprites palette.

Note: Does not create a palette if there it not already one

Parameters
palnew value for palette
Returns
true if palette set.

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