Li Ruofan 201199450

Dependencies:   mbed

Committer:
DannyLee
Date:
Sun May 24 08:16:35 2020 +0000
Revision:
1:bd7c99a5bd10
Parent:
0:80a59a49d504
Li Ruofan 201199450

Who changed what in which revision?

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