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