mp_stickers
Shocking Stickers
|
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 (const StickerSheet &other) | |
The copy constructor makes this StickerSheet an independent copy of the source. More... | |
const StickerSheet & | operator= (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, int x, int 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... | |
int | setStickerAtLayer (Image &sticker, unsigned layer, int x, int y) |
Adds a sticker to the StickerSheet at layer layer , so that the top-left of the sticker's Image is at (x, y) on the StickerSheet. More... | |
bool | translate (unsigned index, int x, int 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... | |
Image * | getSticker (unsigned index) |
Returns a pointer to the sticker at the specified index, not a copy of it. More... | |
int | layers () const |
Returns the total number of layers available on the Stickersheet. More... | |
Image | render () const |
Renders the whole StickerSheet on one Image and returns that Image. More... | |
Represents an arrangement of many sticker that is output as a single Image when the user calls render().
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
.
picture | The base picture to use in the StickerSheet |
max | The maximum number of stickers (Images) on this StickerSheet |
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?
other | The other StickerSheet object to copy data from |
int StickerSheet::addSticker | ( | Image & | sticker, |
int | x, | ||
int | 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.
If all available layers have been filled, a new layer must be added above all existing layers.
sticker | The Image of the sticker. |
x | The x location of the sticker on the StickerSheet |
y | The y location of the sticker on the StickerSheet |
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.
max | The new value for the maximum number of Images in the StickerSheet. |
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.
index | The layer in which to get the sticker. |
int StickerSheet::layers | ( | ) | const |
Returns the total number of layers available on the Stickersheet.
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?
other | The other Scene object to copy data from |
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.
index | The layer in which to delete the png |
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. It should expand in each corresponding direction if stickers go beyond the edge of the picture.
int StickerSheet::setStickerAtLayer | ( | Image & | sticker, |
unsigned | layer, | ||
int | x, | ||
int | y | ||
) |
Adds a sticker
to the StickerSheet at layer layer
, so that the top-left of the sticker's Image
is at (x, y)
on the StickerSheet.
sticker | The Image of the sticker. |
layer | The layer where the sticker is to be placed. |
x | The x location of the sticker on the StickerSheet |
y | The y location of the sticker on the StickerSheet |
bool StickerSheet::translate | ( | unsigned | index, |
int | x, | ||
int | 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.
index | Zero-based layer index of the sticker. |
x | The new x location of the sticker on the StickerSheet |
y | The new y location of the sticker on the StickerSheet |
true
if the translate was successful; otherwise false
.