ZIWEI LIU / Mbed 2 deprecated ELEC2645_Project_el19z2l

Dependencies:   mbed

Committer:
alexliu0812
Date:
Thu May 14 06:54:58 2020 +0000
Revision:
1:11854f815cc8
welcome

Who changed what in which revision?

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