From 98ba22e7064db57316dfff1ae127feb3dceeb73e Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 31 Jul 2014 13:58:22 +0200 Subject: Initial commit --- source/presentation/ScreenPanel.h | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 source/presentation/ScreenPanel.h (limited to 'source/presentation/ScreenPanel.h') diff --git a/source/presentation/ScreenPanel.h b/source/presentation/ScreenPanel.h new file mode 100644 index 0000000..13b4978 --- /dev/null +++ b/source/presentation/ScreenPanel.h @@ -0,0 +1,98 @@ +#ifndef SCREENPANEL_H +#define SCREENPANEL_H + +#include + +#include "../logic/Maze.h" +#include "../logic/GameObject.h" +#include "../logic/PlayerCar.h" +#include "../logic/EnemyCar.h" +#include "../logic/Checkpoint.h" +#include "../logic/Rock.h" +#include "../logic/Smokescreen.h" +#include "../logic/DestroyedObjectPopup.h" +#include "../logic/AllegroWrappers.h" + +/** +* @brief Parent class for panels that are drawn on the screen. +* +* Panels are given a sub-bitmap of the Screen bitmap, which they draw their panel specific outputs on. +* The ScreenPanel class is subclassed to give specific drawing functions, like drawing the Maze and +* GameObjects on the screen. +* +* When the object is created, the back bitmap and front bitmap should correspond to the back and front buffers +* of the display respectively. This should be kept in sync by calling flip every time the display is flipped. +* +* @author Justin Wernick +* @author David Schneider +*/ +class ScreenPanel +{ + public: + /** + * @brief Creates a ScreenPanel from the given back and front buffers. + * + * The sub-bitmaps that ScreenPanel uses are created from a rectangular region on back and front + * that has its top left corner at the coordinate x,y, is width long in the x direction, and + * height long in the y direction. + * + * @param [in] back The current back buffer of the display being sub-bitmapped. + * @param [in] front The current front buffer (image currently being displayed) of the display being sub-bitmapped. + * @param [in] x The x coordinate of the left side of the sub-bitmap in pixels. + * @param [in] y The x coordinate of the top of the sub-bitmap in pixels. + * @param [in] width The length in the x direction of the new sub-bitmap in pixels. + * @param [in] height The length in the y direction of the new sub-bitmap in pixels. + */ + ScreenPanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height); + + /** + * @brief Destructor to ensure that sub-bitmap memory is deallocated. + */ + virtual ~ScreenPanel(); + + /** + * @brief Pure virtual method for drawing a collection of objects onto the panel. + * + * Implementations do not need to draw all of the objects if it is not neccesary for the + * type of panel, but the interface accepts all of them to be general. + * + * @param [in] maze The Maze that all of the objects are in. + * @param [in] players The list of PlayerCars to be drawn. + * @param [in] enemies The list of EnemyCars to be drawn. + * @param [in] checkpoints The list of Checkpoints to be drawn. + * @param [in] rocks The list of Rocks to be drawn. + * @param [in] smokescreens The list of Smokescreens to be drawn. + * @param [in] popups The list of DestroyedObjectPopups to be drawn. + */ + virtual void draw(const Maze& maze, const list& players, const list& enemies, const list& checkpoints, const list& rocks, const list& smokescreens, const list& popups) = 0; + + /** + * @brief Swaps the front and back buffers. + * + * This function should be called every time the display is flipped. + */ + virtual void flip(); + + protected: + static const ALLEGRO_COLOR BLANK; ///< Colour used to clear the screen at the beginning of drawing operations. + + ALLEGRO_BITMAP* _back; ///< The back buffer. Only the back buffer can be drawn to. + + int _width; ///< The width of the sub-bitmaps being drawn to in pixels. + int _height; ///< The height of the sub-bitmaps being drawn to in pixels. + private: + /** + * @brief Copy constructor not implemented, ScreenPanels should not be copied. + */ + ScreenPanel(const ScreenPanel& ref); + /** + * @brief Assignment operator not implemented, ScreenPanels should not be copied. + */ + ScreenPanel& operator=(const ScreenPanel& rhs); + + AllegroInit _allegro; ///< Handles dependencies on Allegro being initialised. + + ALLEGRO_BITMAP* _front; ///< The front buffer, that is currently being shown on the screen. +}; + +#endif // SCREENPANEL_H -- cgit v1.2.3