Mohamed Moawya / SnakeGame

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  * @code
00011   // First declare the pixel map data using '1' for black,
00012   // or '0' for white pixels
00013   static int sprite_data[] = {
00014     0,0,1,0,0,
00015     0,1,1,1,0,
00016     0,0,1,0,0,
00017     0,1,1,1,0,
00018     1,1,1,1,1,
00019     1,1,1,1,1,
00020     1,1,0,1,1,
00021     1,1,0,1,1
00022   };
00023 
00024   // Instantiate the Bitmap object using the data above
00025   Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite
00026   
00027   // We can render the bitmap wherever we want on the screen
00028   sprite.render(lcd, 20, 6); // x and y locations for rendering
00029   sprite.render(lcd, 30, 10);
00030   
00031   // We can also print its values to the terminal
00032   sprite.print();
00033  * @endcode
00034  */
00035 class Bitmap
00036 {
00037 private:
00038     /**
00039      * @brief The contents of the drawing, with pixels stored in row-major order
00040      * @details '1' represents a black pixel; '0' represents white
00041      */
00042     std::vector<int> _contents;
00043     
00044     unsigned int _height; ///< The height of the drawing in pixels
00045     unsigned int _width;  ///< The width of the drawing in pixels
00046     
00047 public:
00048     Bitmap(int const          *contents,
00049            unsigned int const  height,
00050            unsigned int const  width);
00051 
00052     int get_pixel(unsigned int const row,
00053                   unsigned int const column) const;
00054 
00055     void print() const;
00056 
00057     void render(N5110 &lcd,
00058                 unsigned int const x0,
00059                 unsigned int const y0) const;
00060 };
00061 
00062 #endif // BITMAP_H