Final Submission. I have read and agreed with Statement of Academic Integrity.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bitmap.h Source File

Bitmap.h

00001 #ifndef BITMAP_H
00002 #define BITMAP_H
00003 
00004 #include <vector>
00005 
00006 // Forward declarations
00007 class N5110;
00008 
00009 /**
00010  * @brief  A black & white bitmap that can be rendered on an N5110 screen
00011  * @author Alex Valavanis <a.valavanis@leeds.ac.uk>
00012  * 
00013  * @code
00014   // First declare the pixel map data using '1' for black,
00015   // or '0' for white pixels
00016   static int sprite_data[] = {
00017     0,0,1,0,0,
00018     0,1,1,1,0,
00019     0,0,1,0,0,
00020     0,1,1,1,0,
00021     1,1,1,1,1,
00022     1,1,1,1,1,
00023     1,1,0,1,1,
00024     1,1,0,1,1
00025   };
00026 
00027   // Instantiate the Bitmap object using the data above
00028   Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite
00029   
00030   // We can render the bitmap wherever we want on the screen
00031   sprite.render(lcd, 20, 6); // x and y locations for rendering
00032   sprite.render(lcd, 30, 10);
00033   
00034   // We can also print its values to the terminal
00035   sprite.print();
00036  * @endcode
00037  */
00038  
00039 static int title[] = {
00040     0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
00041     0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,
00042     0,0,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,0,1,0,0,0,0,
00043     0,0,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,
00044     0,0,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,
00045     0,0,0,1,0,0,1,1,1,1,1,0,1,0,0,1,1,0,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,1,1,0,0,1,0,0,0,0,
00046     0,0,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0,0,0,0,
00047     0,0,0,1,0,0,1,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,1,0,1,1,1,1,1,0,0,1,0,0,0,0,
00048     0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,
00049     0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
00050 };
00051   
00052 static int player_ship0[] = {
00053     2,2,2,2,2,2,2,2,2,0,0,2,
00054     2,2,2,2,2,0,0,0,0,1,1,0,
00055     2,2,2,0,0,1,1,1,1,1,1,0,
00056     2,0,0,1,1,1,1,0,0,0,0,0,
00057     0,1,1,1,0,0,1,1,0,2,2,2,
00058     2,0,0,1,1,1,1,0,0,0,0,0,
00059     2,2,2,0,0,1,1,1,1,1,1,0,
00060     2,2,2,2,2,0,0,0,0,1,1,0,
00061     2,2,2,2,2,2,2,2,2,0,0,2,
00062 };
00063 static int player_ship1[] = {
00064     2,2,2,0,1,1,1,0,2,2,2,2,
00065     2,2,2,2,0,1,1,1,0,0,0,2,
00066     2,2,2,0,0,0,1,1,1,1,1,0,
00067     2,0,1,1,1,1,1,0,0,0,2,2,
00068     1,1,1,0,1,0,1,1,0,2,2,2,
00069     2,0,1,1,1,1,1,0,0,0,2,2,
00070     2,2,2,0,0,0,1,1,1,1,1,0,
00071     2,2,2,2,0,1,1,1,0,0,0,2,
00072     2,2,2,0,1,1,1,0,2,2,2,2
00073 };//see line 93 of Bitmap.cpp
00074 
00075   
00076 class Bitmap{
00077 private:
00078     /**
00079      * @brief The contents of the drawing, with pixels stored in row-major order
00080      * @details '1' represents a black pixel; '0' represents white
00081      */
00082     std::vector<int> _contents;
00083     
00084     unsigned int _height; ///< The height of the drawing in pixels
00085     unsigned int _width;  ///< The width of the drawing in pixels
00086     
00087 public:
00088     Bitmap(int const          *contents,
00089            unsigned int const  height,
00090            unsigned int const  width);
00091 
00092     int get_pixel(unsigned int const row,
00093                   unsigned int const column) const;
00094 
00095     void print() const;
00096 
00097     void render(N5110 &lcd,
00098                 unsigned int const x0,
00099                 unsigned int const y0) const;
00100 };
00101 
00102   
00103 #endif // BITMAP_H