ELEC2645 (2018/19) / Mbed 2 deprecated el17ph

Dependencies:   mbed

Committer:
el17ph
Date:
Sun May 12 13:43:27 2019 +0000
Revision:
1:679d7ada8de7
Parent:
0:8fb740fa6356
el17ph

Who changed what in which revision?

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