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