demo

Dependencies:   mbed

Committer:
sjuzyz
Date:
Mon Apr 27 13:53:33 2020 +0000
Revision:
4:7743a7670ae7
Parent:
0:6fe791dc9958
demo

Who changed what in which revision?

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