mp_stickers
Shocking Stickers
StickerSheet Class Reference

Represents an arrangement of many sticker that is output as a single Image when the user calls render(). More...

#include <StickerSheet.h>

Public Member Functions

 StickerSheet (const Image &picture, unsigned max)
 Initializes this StickerSheet with a deep copy of the base picture and the ability to hold a max number of stickers (Images) with indices 0 through max - 1. More...
 
 ~StickerSheet ()
 Frees all space that was dynamically allocated by this StickerSheet. More...
 
 StickerSheet (const StickerSheet &other)
 The copy constructor makes this StickerSheet an independent copy of the source. More...
 
const StickerSheetoperator= (const StickerSheet &other)
 The assignment operator for the StickerSheet class. More...
 
void changeMaxStickers (unsigned max)
 Modifies the maximum number of stickers that can be stored on this StickerSheet without changing existing stickers' indices. More...
 
int addSticker (Image &sticker, unsigned x, unsigned y)
 Adds a sticker to the StickerSheet, so that the top-left of the sticker's Image is at (x, y) on the StickerSheet. More...
 
bool translate (unsigned index, unsigned x, unsigned y)
 Changes the x and y coordinates of the Image in the specified layer. More...
 
void removeSticker (unsigned index)
 Removes the sticker at the given zero-based layer index. More...
 
ImagegetSticker (unsigned index)
 Returns a pointer to the sticker at the specified index, not a copy of it. More...
 
Image render () const
 Renders the whole StickerSheet on one Image and returns that Image. More...
 

Detailed Description

Represents an arrangement of many sticker that is output as a single Image when the user calls render().

Constructor & Destructor Documentation

◆ StickerSheet() [1/2]

StickerSheet::StickerSheet ( const Image picture,
unsigned  max 
)

Initializes this StickerSheet with a deep copy of the base picture and the ability to hold a max number of stickers (Images) with indices 0 through max - 1.

Parameters
pictureThe base picture to use in the StickerSheet
maxThe maximum number of stickers (Images) on this StickerSheet

◆ ~StickerSheet()

StickerSheet::~StickerSheet ( )

Frees all space that was dynamically allocated by this StickerSheet.

◆ StickerSheet() [2/2]

StickerSheet::StickerSheet ( const StickerSheet other)

The copy constructor makes this StickerSheet an independent copy of the source.

Hint: Code is likely shared between all of the "Rule of Three" functions. Would a helper function (or two) make your life easier?

Parameters
otherThe other StickerSheet object to copy data from

Member Function Documentation

◆ addSticker()

int StickerSheet::addSticker ( Image sticker,
unsigned  x,
unsigned  y 
)

Adds a sticker to the StickerSheet, so that the top-left of the sticker's Image is at (x, y) on the StickerSheet.

The sticker must be added to the lowest possible layer available.

Parameters
stickerThe Image of the sticker.
xThe x location of the sticker on the StickerSheet
yThe y location of the sticker on the StickerSheet
Returns
The zero-based layer index the sticker was added to, or -1 if the sticker cannot be added.

◆ changeMaxStickers()

void StickerSheet::changeMaxStickers ( unsigned  max)

Modifies the maximum number of stickers that can be stored on this StickerSheet without changing existing stickers' indices.

If the new maximum number of stickers is smaller than the current number number of stickers, the stickers with indices above max - 1 will be lost.

Parameters
maxThe new value for the maximum number of Images in the StickerSheet.

◆ getSticker()

Image * StickerSheet::getSticker ( unsigned  index)

Returns a pointer to the sticker at the specified index, not a copy of it.

That way, the user can modify the Image.

If the index is invalid, return NULL.

Parameters
indexThe layer in which to get the sticker.
Returns
A pointer to a specific Image in the StickerSheet

◆ operator=()

const StickerSheet & StickerSheet::operator= ( const StickerSheet other)

The assignment operator for the StickerSheet class.

Hint: Code is likely shared between all of the "Rule of Three" functions. Would a helper function (or two) make your life easier?

Parameters
otherThe other Scene object to copy data from
Returns
a constant Scene reference

◆ removeSticker()

void StickerSheet::removeSticker ( unsigned  index)

Removes the sticker at the given zero-based layer index.

Make sure that the other stickers don't change order.

Parameters
indexThe layer in which to delete the png

◆ render()

Image StickerSheet::render ( ) const

Renders the whole StickerSheet on one Image and returns that Image.

The base picture is drawn first and then each sticker is drawn in order starting with layer zero (0), then layer one (1), and so on.

If a pixel's alpha channel in a sticker is zero (0), no pixel is drawn for that sticker at that pixel. If the alpha channel is non-zero, a pixel is drawn. (Alpha blending is awesome, but not required.)

The returned Image always includes the full contents of the picture and all stickers. This means that the size of the result image may be larger than the base picture if some stickers go beyond the edge of the picture.

Returns
an Image object representing the drawn scene

◆ translate()

bool StickerSheet::translate ( unsigned  index,
unsigned  x,
unsigned  y 
)

Changes the x and y coordinates of the Image in the specified layer.

If the layer is invalid or does not contain a sticker, this function must return false. Otherwise, this function returns true.

Parameters
indexZero-based layer index of the sticker.
xThe new x location of the sticker on the StickerSheet
yThe new y location of the sticker on the StickerSheet
Returns
true if the translate was successful; otherwise false.

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