Zikang Qian / Mbed 2 deprecated el17z2q

Dependencies:   mbed

Fork of el17z2q by ELEC2645 (2017/18)

Committer:
yzjdxl
Date:
Mon May 07 22:11:43 2018 +0000
Branch:
GameEngine
Revision:
2:6dc7bc55c1cb
Parent:
0:f707ce1010fa
publish

Who changed what in which revision?

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