ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_ll17l2b

Dependencies:   mbed

Committer:
eencae
Date:
Fri Jan 31 12:32:38 2020 +0000
Revision:
0:7423345f87c5
Pong ported to Gamepad2;

Who changed what in which revision?

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