Coursework

Committer:
sesa514652
Date:
Fri Feb 04 16:44:14 2022 +0000
Revision:
45:f1db729741f7
Parent:
0:1f799c7cce2b
Submission

Who changed what in which revision?

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