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