Albert Tan Mulligan Submission

Dependencies:   mbed

Committer:
Albutt
Date:
Wed May 27 00:57:33 2020 +0000
Revision:
24:19994f789276
Parent:
1:a52187d01a78
Testing Documentation

Who changed what in which revision?

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