Helios Lyons 201239214

Dependencies:   mbed

Committer:
helioslyons
Date:
Tue Apr 14 13:22:35 2020 +0000
Revision:
5:72f59786b695
Parent:
1:a3f43007030e
Import to Mbed Studio

Who changed what in which revision?

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