Project Submission (late)

Dependencies:   mbed

Committer:
el17tc
Date:
Fri May 10 14:52:28 2019 +0000
Revision:
3:83e79d31930c
Parent:
0:72f372170a73
final commit, API is added.; I'm not sure if there is a specific statement of academic integrity wanted but- I declare that this work is 100% my own, I have not plagiarised any work or attempted to fabricate any part of it for extra marks.

Who changed what in which revision?

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