ELEC2645 (2018/19) / Mbed 2 deprecated el18jz

Dependencies:   mbed

Committer:
jiaxinZHOU
Date:
Wed May 08 21:44:02 2019 +0000
Revision:
0:07c4fef6c0af
1st edition

Who changed what in which revision?

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