Bracciale Slave
Adafruit_GFX.h@19:e5d8d6e7fac5, 2019-02-25 (annotated)
- Committer:
- gandhi4
- Date:
- Mon Feb 25 21:14:16 2019 +0000
- Revision:
- 19:e5d8d6e7fac5
- Parent:
- 14:edb3c36aa1a7
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nkhorman | 9:ddb97c9850a2 | 1 | #ifndef _ADAFRUIT_GFX_H_ |
nkhorman | 9:ddb97c9850a2 | 2 | #define _ADAFRUIT_GFX_H_ |
nkhorman | 9:ddb97c9850a2 | 3 | |
nkhorman | 9:ddb97c9850a2 | 4 | static inline void swap(int16_t &a, int16_t &b) |
nkhorman | 9:ddb97c9850a2 | 5 | { |
nkhorman | 9:ddb97c9850a2 | 6 | int16_t t = a; |
nkhorman | 9:ddb97c9850a2 | 7 | |
nkhorman | 9:ddb97c9850a2 | 8 | a = b; |
nkhorman | 9:ddb97c9850a2 | 9 | b = t; |
nkhorman | 9:ddb97c9850a2 | 10 | } |
nkhorman | 9:ddb97c9850a2 | 11 | |
nkhorman | 9:ddb97c9850a2 | 12 | #ifndef _BV |
nkhorman | 9:ddb97c9850a2 | 13 | #define _BV(bit) (1<<(bit)) |
nkhorman | 9:ddb97c9850a2 | 14 | #endif |
nkhorman | 9:ddb97c9850a2 | 15 | |
nkhorman | 9:ddb97c9850a2 | 16 | #define BLACK 0 |
nkhorman | 9:ddb97c9850a2 | 17 | #define WHITE 1 |
nkhorman | 9:ddb97c9850a2 | 18 | |
nkhorman | 9:ddb97c9850a2 | 19 | class Adafruit_GFX : public Stream |
nkhorman | 9:ddb97c9850a2 | 20 | { |
nkhorman | 9:ddb97c9850a2 | 21 | public: |
nkhorman | 9:ddb97c9850a2 | 22 | Adafruit_GFX(int16_t w, int16_t h) |
nkhorman | 9:ddb97c9850a2 | 23 | : _rawWidth(w) |
nkhorman | 9:ddb97c9850a2 | 24 | , _rawHeight(h) |
nkhorman | 9:ddb97c9850a2 | 25 | , _width(w) |
nkhorman | 9:ddb97c9850a2 | 26 | , _height(h) |
nkhorman | 9:ddb97c9850a2 | 27 | , cursor_x(0) |
nkhorman | 9:ddb97c9850a2 | 28 | , cursor_y(0) |
nkhorman | 9:ddb97c9850a2 | 29 | , textcolor(WHITE) |
nkhorman | 9:ddb97c9850a2 | 30 | , textbgcolor(BLACK) |
nkhorman | 9:ddb97c9850a2 | 31 | , textsize(1) |
nkhorman | 9:ddb97c9850a2 | 32 | , rotation(0) |
nkhorman | 9:ddb97c9850a2 | 33 | , wrap(true) |
nkhorman | 9:ddb97c9850a2 | 34 | {}; |
nkhorman | 9:ddb97c9850a2 | 35 | |
nkhorman | 11:86909e6db3c8 | 36 | /// Paint one BLACK or WHITE pixel in the display buffer |
nkhorman | 9:ddb97c9850a2 | 37 | // this must be defined by the subclass |
nkhorman | 9:ddb97c9850a2 | 38 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; |
nkhorman | 9:ddb97c9850a2 | 39 | // this is optional |
nkhorman | 9:ddb97c9850a2 | 40 | virtual void invertDisplay(bool i) {}; |
nkhorman | 9:ddb97c9850a2 | 41 | |
nkhorman | 9:ddb97c9850a2 | 42 | // Stream implementation - provides printf() interface |
nkhorman | 9:ddb97c9850a2 | 43 | // You would otherwise be forced to use writeChar() |
nkhorman | 9:ddb97c9850a2 | 44 | virtual int _putc(int value) { return writeChar(value); }; |
nkhorman | 9:ddb97c9850a2 | 45 | virtual int _getc() { return -1; }; |
nkhorman | 9:ddb97c9850a2 | 46 | |
nkhorman | 9:ddb97c9850a2 | 47 | |
nkhorman | 9:ddb97c9850a2 | 48 | |
nkhorman | 9:ddb97c9850a2 | 49 | |
nkhorman | 11:86909e6db3c8 | 50 | /// Draw a text character at a specified pixel location |
nkhorman | 9:ddb97c9850a2 | 51 | void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); |
nkhorman | 11:86909e6db3c8 | 52 | /// Draw a text character at the text cursor location |
nkhorman | 9:ddb97c9850a2 | 53 | size_t writeChar(uint8_t); |
nkhorman | 9:ddb97c9850a2 | 54 | |
nkhorman | 11:86909e6db3c8 | 55 | /// Get the width of the display in pixels |
nkhorman | 14:edb3c36aa1a7 | 56 | inline int16_t width(void) { return _width; }; |
nkhorman | 11:86909e6db3c8 | 57 | /// Get the height of the display in pixels |
nkhorman | 14:edb3c36aa1a7 | 58 | inline int16_t height(void) { return _height; }; |
nkhorman | 9:ddb97c9850a2 | 59 | |
nkhorman | 11:86909e6db3c8 | 60 | /// Set the text cursor location, based on the size of the text |
nkhorman | 14:edb3c36aa1a7 | 61 | inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; }; |
nkhorman | 14:edb3c36aa1a7 | 62 | #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) |
nkhorman | 11:86909e6db3c8 | 63 | /** Set the size of the text to be drawn |
nkhorman | 11:86909e6db3c8 | 64 | * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS |
nkhorman | 11:86909e6db3c8 | 65 | */ |
nkhorman | 14:edb3c36aa1a7 | 66 | inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; }; |
nkhorman | 9:ddb97c9850a2 | 67 | #endif |
nkhorman | 11:86909e6db3c8 | 68 | /// Set the text foreground and background colors to be the same |
nkhorman | 14:edb3c36aa1a7 | 69 | inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; } |
nkhorman | 11:86909e6db3c8 | 70 | /// Set the text foreground and background colors independantly |
nkhorman | 14:edb3c36aa1a7 | 71 | inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; }; |
nkhorman | 11:86909e6db3c8 | 72 | /// Set text wraping mode true or false |
nkhorman | 14:edb3c36aa1a7 | 73 | inline void setTextWrap(bool w) { wrap = w; }; |
nkhorman | 9:ddb97c9850a2 | 74 | |
nkhorman | 9:ddb97c9850a2 | 75 | |
nkhorman | 9:ddb97c9850a2 | 76 | protected: |
nkhorman | 9:ddb97c9850a2 | 77 | int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes |
nkhorman | 9:ddb97c9850a2 | 78 | int16_t _width, _height; // dependent on rotation |
nkhorman | 9:ddb97c9850a2 | 79 | int16_t cursor_x, cursor_y; |
nkhorman | 9:ddb97c9850a2 | 80 | uint16_t textcolor, textbgcolor; |
nkhorman | 9:ddb97c9850a2 | 81 | uint8_t textsize; |
nkhorman | 9:ddb97c9850a2 | 82 | uint8_t rotation; |
nkhorman | 9:ddb97c9850a2 | 83 | bool wrap; // If set, 'wrap' text at right edge of display |
nkhorman | 9:ddb97c9850a2 | 84 | }; |
nkhorman | 9:ddb97c9850a2 | 85 | |
nkhorman | 9:ddb97c9850a2 | 86 | #endif |