ELEC2645 (2018/19) / Mbed 2 deprecated ll16o2l_ELEC2645

Dependencies:   mbed Gamepad

Committer:
ll16o2l
Date:
Tue Mar 05 09:24:19 2019 +0000
Revision:
0:03363a508918
initial commit

Who changed what in which revision?

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