MP 2
Image Manipulation II
|
Represents an arrangement of many images that is output as a single image when the user calls drawscene(). More...
#include "scene.h"
Public Member Functions | |
Scene (int max) | |
Initializes this Scene object to be able to hold "max" number of images with indices 0 through max-1. More... | |
~Scene () | |
Frees all space that was dynamically allocated by this Scene. More... | |
Scene (const Scene &source) | |
The copy constructor makes this Scene an independent copy of the source. More... | |
const Scene & | operator= (const Scene &source) |
The assignment operator for the Scene class. More... | |
void | changemaxlayers (int newmax) |
Modifies the size of the array of Image pointers without changing their indices. More... | |
void | addpicture (const char *FileName, int index, int x, int y) |
This function will add a picture to the scene, by placing it in the array cell corresponding to the given index, and storing its x coordinate and y coordinate. More... | |
void | changelayer (int index, int newindex) |
Moves an Image from one layer to another. More... | |
void | translate (int index, int xcoord, int ycoord) |
Changes the x and y coordinates of the Image in the specified layer. More... | |
void | deletepicture (int index) |
Deletes the Image at the given index. More... | |
Image * | getpicture (int index) const |
This function will return a pointer to the Image at the specified index, not a copy of it. More... | |
Image | drawscene () const |
Draws the whole scene on one Image and returns that Image by value. More... | |
Represents an arrangement of many images that is output as a single image when the user calls drawscene().
Scene::Scene | ( | int | max | ) |
Initializes this Scene object to be able to hold "max" number of images with indices 0 through max-1.
This function will set up the Scene to hold "max" Images by (1) dynamically allocating an array of Image pointers of size "max", (2) initializing all of them to NULL, (3) creating storage for the coordinates, and (4) storing "max" as a member variable.
max | The maximum number of layers in this Scene |
Scene::~Scene | ( | ) |
Frees all space that was dynamically allocated by this Scene.
Scene::Scene | ( | const Scene & | source | ) |
The assignment operator for the Scene class.
It does the following: (1) checks for self assignment, (2) then deletes everything this Scene has allocated, (3) then makes this Scene an independent copy of the source, (4) then returns a reference to the current instance.
Hint: Create copy() and clear() helper functions and call them here.
source | The other Scene object to copy data from |
void Scene::changemaxlayers | ( | int | newmax | ) |
Modifies the size of the array of Image pointers without changing their indices.
The new set of valid indices will be from 0 to (newmax - 1).
A new array of Image pointers of size newmax will be allocated, and the non-null pointers in the old array will be copied over before the old array is deleted. If this cannot be done because there are non-null pointers outside the range [0, newmax-1], use the following code to print an error message:
cout << "invalid newmax" << endl;
In the case of an error this function call should not cause any change to the Scene.
newmax | The new value for the maximum number of Images in the Scene. |
void Scene::addpicture | ( | const char * | FileName, |
int | index, | ||
int | x, | ||
int | y | ||
) |
This function will add a picture to the scene, by placing it in the array cell corresponding to the given index, and storing its x coordinate and y coordinate.
If there is already an Image in cell location index it should be replaced by the new Image. If the index is not within the range [0, max-1], use the following code to print an error message:
cout << "index out of bounds" << endl;
Hint: Make use of the PNG member function (which was inherited by the Image class) for loading an Image from a file.
FileName | The name of the image file to read in |
index | Which "layer" this png resides in |
x | The x location of the new png |
y | The y location of the new png |
void Scene::changelayer | ( | int | index, |
int | newindex | ||
) |
Moves an Image from one layer to another.
You are not allowed to dynamically allocate anything in this function. Rather, just move the pointer.
If the new index is the same as the old index, do nothing and return. If the destination is already occupied, delete the image there. The source index should be marked vacant by making it value NULL. If either index is invalid, do nothing and use the following code to print an error message:
cout << "invalid index" << endl;
index | The source index location |
newindex | The destination index location |
Note that we do not prevent the user from requesting that a NULL Image pointer be moved to an occupied spot.
void Scene::translate | ( | int | index, |
int | xcoord, | ||
int | ycoord | ||
) |
Changes the x and y coordinates of the Image in the specified layer.
If the index is invalid or if it contains a NULL pointer, do nothing and use the following code to print an error message:
cout << "invalid index" << endl;
index | Which layer to operate on |
xcoord | The x coordinate value to move the png to |
ycoord | The y coordinate value to move the png to |
void Scene::deletepicture | ( | int | index | ) |
Deletes the Image at the given index.
If the index is invalid or if it contains a NULL pointer, do nothing and use the following code to print an error message:
cout << "invalid index" << endl;
index | The layer in which to delete the png |
Image * Scene::getpicture | ( | int | index | ) | const |
Image Scene::drawscene | ( | ) | const |
Draws the whole scene on one Image and returns that Image by value.
Images in the scene will be drawn in order from index 0 to index (max-1) at the stored coordinates. Do not use the alpha channel or any other transparency.
Hint: The x and y coordinates of an Image are the coordinates of its upper-left corner pixel in the output of this function.
Hint: First determine the minimum width and height necessary to ensure that none of the images go off of the bottom or the right edge of the returned image, and make sure your returned image has that width and height.