Li Ruofan 201199450

Dependencies:   mbed

Committer:
DannyLee
Date:
Thu May 14 13:12:28 2020 +0000
Revision:
3:cf9fead9c3f4
Parent:
Bitmap/Bitmap.h@0:44c1a60f8732
aaa

Who changed what in which revision?

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