Max Houghton
/
MazeGame_el15mh
el15mh 200929957
N5110/Bitmap.h@9:960dfc71c224, 2017-05-04 (annotated)
- Committer:
- el15mh
- Date:
- Thu May 04 14:43:29 2017 +0000
- Revision:
- 9:960dfc71c224
Documented using doxygen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15mh | 9:960dfc71c224 | 1 | #ifndef BITMAP_H |
el15mh | 9:960dfc71c224 | 2 | #define BITMAP_H |
el15mh | 9:960dfc71c224 | 3 | |
el15mh | 9:960dfc71c224 | 4 | #include <vector> |
el15mh | 9:960dfc71c224 | 5 | |
el15mh | 9:960dfc71c224 | 6 | // Forward declarations |
el15mh | 9:960dfc71c224 | 7 | class N5110; |
el15mh | 9:960dfc71c224 | 8 | |
el15mh | 9:960dfc71c224 | 9 | /** |
el15mh | 9:960dfc71c224 | 10 | * @brief A black & white bitmap that can be rendered on an N5110 screen |
el15mh | 9:960dfc71c224 | 11 | * @author Alex Valavanis <a.valavanis@leeds.ac.uk> |
el15mh | 9:960dfc71c224 | 12 | * |
el15mh | 9:960dfc71c224 | 13 | * @code |
el15mh | 9:960dfc71c224 | 14 | // First declare the pixel map data using '1' for black, |
el15mh | 9:960dfc71c224 | 15 | // or '0' for white pixels |
el15mh | 9:960dfc71c224 | 16 | static int sprite_data[] = { |
el15mh | 9:960dfc71c224 | 17 | 0,0,1,0,0, |
el15mh | 9:960dfc71c224 | 18 | 0,1,1,1,0, |
el15mh | 9:960dfc71c224 | 19 | 0,0,1,0,0, |
el15mh | 9:960dfc71c224 | 20 | 0,1,1,1,0, |
el15mh | 9:960dfc71c224 | 21 | 1,1,1,1,1, |
el15mh | 9:960dfc71c224 | 22 | 1,1,1,1,1, |
el15mh | 9:960dfc71c224 | 23 | 1,1,0,1,1, |
el15mh | 9:960dfc71c224 | 24 | 1,1,0,1,1 |
el15mh | 9:960dfc71c224 | 25 | }; |
el15mh | 9:960dfc71c224 | 26 | |
el15mh | 9:960dfc71c224 | 27 | // Instantiate the Bitmap object using the data above |
el15mh | 9:960dfc71c224 | 28 | Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite |
el15mh | 9:960dfc71c224 | 29 | |
el15mh | 9:960dfc71c224 | 30 | // We can render the bitmap wherever we want on the screen |
el15mh | 9:960dfc71c224 | 31 | sprite.render(lcd, 20, 6); // x and y locations for rendering |
el15mh | 9:960dfc71c224 | 32 | sprite.render(lcd, 30, 10); |
el15mh | 9:960dfc71c224 | 33 | |
el15mh | 9:960dfc71c224 | 34 | // We can also print its values to the terminal |
el15mh | 9:960dfc71c224 | 35 | sprite.print(); |
el15mh | 9:960dfc71c224 | 36 | * @endcode |
el15mh | 9:960dfc71c224 | 37 | */ |
el15mh | 9:960dfc71c224 | 38 | class Bitmap |
el15mh | 9:960dfc71c224 | 39 | { |
el15mh | 9:960dfc71c224 | 40 | private: |
el15mh | 9:960dfc71c224 | 41 | /** |
el15mh | 9:960dfc71c224 | 42 | * @brief The contents of the drawing, with pixels stored in row-major order |
el15mh | 9:960dfc71c224 | 43 | * @details '1' represents a black pixel; '0' represents white |
el15mh | 9:960dfc71c224 | 44 | */ |
el15mh | 9:960dfc71c224 | 45 | std::vector<int> _contents; |
el15mh | 9:960dfc71c224 | 46 | |
el15mh | 9:960dfc71c224 | 47 | unsigned int _height; ///< The height of the drawing in pixels |
el15mh | 9:960dfc71c224 | 48 | unsigned int _width; ///< The width of the drawing in pixels |
el15mh | 9:960dfc71c224 | 49 | |
el15mh | 9:960dfc71c224 | 50 | public: |
el15mh | 9:960dfc71c224 | 51 | Bitmap(int const *contents, |
el15mh | 9:960dfc71c224 | 52 | unsigned int const height, |
el15mh | 9:960dfc71c224 | 53 | unsigned int const width); |
el15mh | 9:960dfc71c224 | 54 | |
el15mh | 9:960dfc71c224 | 55 | int get_pixel(unsigned int const row, |
el15mh | 9:960dfc71c224 | 56 | unsigned int const column) const; |
el15mh | 9:960dfc71c224 | 57 | |
el15mh | 9:960dfc71c224 | 58 | void print() const; |
el15mh | 9:960dfc71c224 | 59 | |
el15mh | 9:960dfc71c224 | 60 | void render(N5110 &lcd, |
el15mh | 9:960dfc71c224 | 61 | unsigned int const x0, |
el15mh | 9:960dfc71c224 | 62 | unsigned int const y0) const; |
el15mh | 9:960dfc71c224 | 63 | }; |
el15mh | 9:960dfc71c224 | 64 | |
el15mh | 9:960dfc71c224 | 65 | #endif // BITMAP_H |