Ahmed Hedait / Mbed 2 deprecated el16ah

Dependencies:   mbed

Committer:
ahmedhedait
Date:
Tue Apr 10 21:59:06 2018 +0000
Revision:
0:1b04b9bacf5a
initial commit

Who changed what in which revision?

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