Yang Hongxiao 201199678

Dependencies:   mbed

Committer:
YHX
Date:
Thu May 14 17:00:34 2020 +0000
Revision:
1:a6ead8050c23
Parent:
0:4b02786450c0
Yang Hongxiao; el17hy; 201199678

Who changed what in which revision?

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