Template for the ELEC1620 End of year exam

Dependencies:   mbed

Committer:
el16ttb
Date:
Fri Mar 22 13:11:07 2019 +0000
Revision:
0:54721f063ac8
Initial commit

Who changed what in which revision?

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