Adafruit-GFX porting for mbed
Dependents: Adafruit_SHARP_Memory_Display
Fork of Adafruit-GFX by
Adafruit_GFX.h@1:c2715acb7466, 2014-05-25 (annotated)
- Committer:
- lelect
- Date:
- Sun May 25 13:40:59 2014 +0000
- Revision:
- 1:c2715acb7466
- Parent:
- 0:3e9c32359703
- Child:
- 2:66a3fe0dc83a
add doxygen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lelect | 0:3e9c32359703 | 1 | #ifndef _ADAFRUIT_GFX_H |
lelect | 0:3e9c32359703 | 2 | #define _ADAFRUIT_GFX_H |
lelect | 0:3e9c32359703 | 3 | #define BLACK 0 |
lelect | 0:3e9c32359703 | 4 | #define WHITE 1 |
lelect | 0:3e9c32359703 | 5 | #ifndef _BV |
lelect | 0:3e9c32359703 | 6 | #define _BV(bit) (1<<(bit)) |
lelect | 0:3e9c32359703 | 7 | #endif |
lelect | 0:3e9c32359703 | 8 | |
lelect | 0:3e9c32359703 | 9 | #define swap(a, b) { int16_t t = a; a = b; b = t; } |
lelect | 1:c2715acb7466 | 10 | /** Adafruit_GFX class |
lelect | 1:c2715acb7466 | 11 | * @bref This is the Adafruit_GFX class.\\ |
lelect | 1:c2715acb7466 | 12 | * drawPixel(int16_t x,int16_t y,uint16_t color) needing implementation in derived implementation class |
lelect | 1:c2715acb7466 | 13 | */ |
lelect | 0:3e9c32359703 | 14 | class Adafruit_GFX : public Stream |
lelect | 0:3e9c32359703 | 15 | { |
lelect | 0:3e9c32359703 | 16 | |
lelect | 0:3e9c32359703 | 17 | public: |
lelect | 0:3e9c32359703 | 18 | Adafruit_GFX(int16_t w, int16_t h) |
lelect | 0:3e9c32359703 | 19 | : _rawWidth(w) |
lelect | 1:c2715acb7466 | 20 | ,_rawHeight(h) |
lelect | 1:c2715acb7466 | 21 | ,_width(w) |
lelect | 1:c2715acb7466 | 22 | ,_height(h) |
lelect | 1:c2715acb7466 | 23 | ,cursor_x(0) |
lelect | 1:c2715acb7466 | 24 | ,cursor_y(0) |
lelect | 1:c2715acb7466 | 25 | ,textcolor(WHITE) |
lelect | 1:c2715acb7466 | 26 | ,textbgcolor(BLACK) |
lelect | 1:c2715acb7466 | 27 | ,textsize(1) |
lelect | 1:c2715acb7466 | 28 | ,rotation(0) |
lelect | 1:c2715acb7466 | 29 | ,wrap(true) |
lelect | 1:c2715acb7466 | 30 | {}; |
lelect | 0:3e9c32359703 | 31 | |
lelect | 0:3e9c32359703 | 32 | // This MUST be defined by the subclass: |
lelect | 0:3e9c32359703 | 33 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; |
lelect | 0:3e9c32359703 | 34 | |
lelect | 0:3e9c32359703 | 35 | virtual int _putc(int value) { |
lelect | 0:3e9c32359703 | 36 | return writeChar(value); |
lelect | 0:3e9c32359703 | 37 | }; |
lelect | 0:3e9c32359703 | 38 | virtual int _getc() { |
lelect | 0:3e9c32359703 | 39 | return -1; |
lelect | 0:3e9c32359703 | 40 | }; |
lelect | 0:3e9c32359703 | 41 | |
lelect | 0:3e9c32359703 | 42 | virtual void invertDisplay(bool i); |
lelect | 0:3e9c32359703 | 43 | |
lelect | 0:3e9c32359703 | 44 | // These MAY be overridden by the subclass to provide device-specific |
lelect | 0:3e9c32359703 | 45 | // optimized code. Otherwise 'generic' versions are used. |
lelect | 0:3e9c32359703 | 46 | virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); |
lelect | 0:3e9c32359703 | 47 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 48 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
lelect | 0:3e9c32359703 | 49 | virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 50 | virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 51 | virtual void fillScreen(uint16_t color); |
lelect | 0:3e9c32359703 | 52 | |
lelect | 0:3e9c32359703 | 53 | // These exist only with Adafruit_GFX (no subclass overrides) |
lelect | 0:3e9c32359703 | 54 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
lelect | 0:3e9c32359703 | 55 | void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); |
lelect | 0:3e9c32359703 | 56 | void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
lelect | 0:3e9c32359703 | 57 | void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); |
lelect | 0:3e9c32359703 | 58 | |
lelect | 0:3e9c32359703 | 59 | void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
lelect | 0:3e9c32359703 | 60 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
lelect | 0:3e9c32359703 | 61 | void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
lelect | 0:3e9c32359703 | 62 | void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
lelect | 0:3e9c32359703 | 63 | |
lelect | 0:3e9c32359703 | 64 | void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 65 | void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); |
lelect | 0:3e9c32359703 | 66 | |
lelect | 0:3e9c32359703 | 67 | void setCursor(int16_t x, int16_t y) { |
lelect | 0:3e9c32359703 | 68 | cursor_x = x; |
lelect | 0:3e9c32359703 | 69 | cursor_y = y; |
lelect | 0:3e9c32359703 | 70 | }; |
lelect | 0:3e9c32359703 | 71 | void setTextSize(uint8_t s) { |
lelect | 0:3e9c32359703 | 72 | textsize = (s > 0) ? s : 1; |
lelect | 0:3e9c32359703 | 73 | }; |
lelect | 0:3e9c32359703 | 74 | void setTextColor(uint16_t c) { |
lelect | 0:3e9c32359703 | 75 | textcolor = c; |
lelect | 0:3e9c32359703 | 76 | textbgcolor = c; |
lelect | 0:3e9c32359703 | 77 | } |
lelect | 0:3e9c32359703 | 78 | void setTextColor(uint16_t c, uint16_t b) { |
lelect | 0:3e9c32359703 | 79 | textcolor = c; |
lelect | 0:3e9c32359703 | 80 | textbgcolor = b; |
lelect | 0:3e9c32359703 | 81 | }; |
lelect | 0:3e9c32359703 | 82 | void setTextWrap(bool w) { |
lelect | 0:3e9c32359703 | 83 | wrap = w; |
lelect | 0:3e9c32359703 | 84 | }; |
lelect | 0:3e9c32359703 | 85 | |
lelect | 0:3e9c32359703 | 86 | virtual size_t writeChar(uint8_t); |
lelect | 0:3e9c32359703 | 87 | |
lelect | 0:3e9c32359703 | 88 | int16_t height(void) { |
lelect | 0:3e9c32359703 | 89 | return _height; |
lelect | 0:3e9c32359703 | 90 | }; |
lelect | 0:3e9c32359703 | 91 | int16_t width(void) { |
lelect | 0:3e9c32359703 | 92 | return _width; |
lelect | 0:3e9c32359703 | 93 | }; |
lelect | 0:3e9c32359703 | 94 | |
lelect | 0:3e9c32359703 | 95 | void setRotation(uint8_t r); |
lelect | 0:3e9c32359703 | 96 | uint8_t getRotation(void) { |
lelect | 0:3e9c32359703 | 97 | rotation%=4; |
lelect | 0:3e9c32359703 | 98 | return rotation; |
lelect | 0:3e9c32359703 | 99 | }; |
lelect | 0:3e9c32359703 | 100 | |
lelect | 0:3e9c32359703 | 101 | protected: |
lelect | 0:3e9c32359703 | 102 | int16_t _rawWidth, _rawHeight; // Display w/h as modified by current rotation |
lelect | 0:3e9c32359703 | 103 | int16_t _width, _height; // Display w/h as modified by current rotation |
lelect | 0:3e9c32359703 | 104 | int16_t cursor_x, cursor_y; |
lelect | 0:3e9c32359703 | 105 | uint16_t textcolor, textbgcolor; |
lelect | 0:3e9c32359703 | 106 | uint8_t textsize,rotation; |
lelect | 0:3e9c32359703 | 107 | bool wrap; // If set, 'wrap' text at right edge of display |
lelect | 0:3e9c32359703 | 108 | }; |
lelect | 0:3e9c32359703 | 109 | |
lelect | 0:3e9c32359703 | 110 | #endif // _ADAFRUIT_GFX_H |