deemo1

Dependencies:   mbed

Committer:
haoyan
Date:
Tue Apr 28 14:38:02 2020 +0000
Revision:
0:08b2bdddf22e
deemo

Who changed what in which revision?

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