Joshua O'hara 201291390

Dependencies:   mbed

Committer:
josh_ohara
Date:
Tue May 26 15:15:46 2020 +0000
Revision:
44:3b904d25ee12
Parent:
1:9b659b3c092b
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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