Adafruit-GFX porting for mbed
Dependents: RGB_matrix_Panel RGB_matrix_Panel_modif RGB_matrix_Panel Pmod_OLEDrgb_ALS1_K64F ... more
Adafruit_GFX.h@2:66a3fe0dc83a, 2014-05-26 (annotated)
- Committer:
- lelect
- Date:
- Mon May 26 09:14:33 2014 +0000
- Revision:
- 2:66a3fe0dc83a
- Parent:
- 1:c2715acb7466
- Child:
- 3:3ffdf181555c
update 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 | 2:66a3fe0dc83a | 11 | * This is the Adafruit_GFX class.\n |
lelect | 2:66a3fe0dc83a | 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 | 2:66a3fe0dc83a | 19 | : _rawWidth(w),_rawHeight(h) |
lelect | 2:66a3fe0dc83a | 20 | ,_width(w),_height(h) |
lelect | 2:66a3fe0dc83a | 21 | ,cursor_x(0),cursor_y(0) |
lelect | 2:66a3fe0dc83a | 22 | ,textcolor(WHITE),textbgcolor(BLACK) |
lelect | 1:c2715acb7466 | 23 | ,textsize(1) |
lelect | 1:c2715acb7466 | 24 | ,rotation(0) |
lelect | 1:c2715acb7466 | 25 | ,wrap(true) |
lelect | 2:66a3fe0dc83a | 26 | {}; |
lelect | 0:3e9c32359703 | 27 | |
lelect | 2:66a3fe0dc83a | 28 | /** @fn void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t color) = 0 |
lelect | 2:66a3fe0dc83a | 29 | * @bref This MUST be defined by the subclass! |
lelect | 2:66a3fe0dc83a | 30 | * @param x x |
lelect | 2:66a3fe0dc83a | 31 | * @param y y |
lelect | 2:66a3fe0dc83a | 32 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 33 | */ |
lelect | 0:3e9c32359703 | 34 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; |
lelect | 0:3e9c32359703 | 35 | |
lelect | 0:3e9c32359703 | 36 | virtual int _putc(int value) { |
lelect | 0:3e9c32359703 | 37 | return writeChar(value); |
lelect | 0:3e9c32359703 | 38 | }; |
lelect | 0:3e9c32359703 | 39 | virtual int _getc() { |
lelect | 0:3e9c32359703 | 40 | return -1; |
lelect | 0:3e9c32359703 | 41 | }; |
lelect | 2:66a3fe0dc83a | 42 | /** @fn void RGBmatrixPanel::invertDisplay(bool i) |
lelect | 2:66a3fe0dc83a | 43 | * @bref Do nothing, must be subclassed if supported |
lelect | 2:66a3fe0dc83a | 44 | * @param i invert |
lelect | 2:66a3fe0dc83a | 45 | */ |
lelect | 0:3e9c32359703 | 46 | virtual void invertDisplay(bool i); |
lelect | 0:3e9c32359703 | 47 | |
lelect | 2:66a3fe0dc83a | 48 | // These MAY be overridden by the subclass to provide device-specific |
lelect | 2:66a3fe0dc83a | 49 | // optimized code. Otherwise 'generic' versions are used. |
lelect | 0:3e9c32359703 | 50 | virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); |
lelect | 0:3e9c32359703 | 51 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 52 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
lelect | 0:3e9c32359703 | 53 | virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 54 | virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lelect | 0:3e9c32359703 | 55 | virtual void fillScreen(uint16_t color); |
lelect | 0:3e9c32359703 | 56 | |
lelect | 2:66a3fe0dc83a | 57 | //These exist only with Adafruit_GFX (no subclass overrides) |
lelect | 2:66a3fe0dc83a | 58 | /** @fn void RGBmatrixPanel::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) |
lelect | 2:66a3fe0dc83a | 59 | * @bref draw a circle outline from the coordinates of the center. |
lelect | 2:66a3fe0dc83a | 60 | * @param x0 x position |
lelect | 2:66a3fe0dc83a | 61 | * @param y0 y position |
lelect | 2:66a3fe0dc83a | 62 | * @param r Radius of the circle |
lelect | 2:66a3fe0dc83a | 63 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 64 | */ |
lelect | 0:3e9c32359703 | 65 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
lelect | 0:3e9c32359703 | 66 | void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); |
lelect | 2:66a3fe0dc83a | 67 | /** @fn void RGBmatrixPanel::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) |
lelect | 2:66a3fe0dc83a | 68 | * @bref draw a circle from the coordinates of the center. |
lelect | 2:66a3fe0dc83a | 69 | * @param x0 x position |
lelect | 2:66a3fe0dc83a | 70 | * @param y0 y position |
lelect | 2:66a3fe0dc83a | 71 | * @param r Radius of the circle |
lelect | 2:66a3fe0dc83a | 72 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 73 | */ |
lelect | 0:3e9c32359703 | 74 | void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
lelect | 0:3e9c32359703 | 75 | void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); |
lelect | 0:3e9c32359703 | 76 | |
lelect | 2:66a3fe0dc83a | 77 | /** @fn void RGBmatrixPanel::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) |
lelect | 2:66a3fe0dc83a | 78 | * @bref draw a triangle outline from the vertex with color. |
lelect | 2:66a3fe0dc83a | 79 | * @param x0 first vertex x |
lelect | 2:66a3fe0dc83a | 80 | * @param y0 first vertex y |
lelect | 2:66a3fe0dc83a | 81 | * @param x1 second vertex x |
lelect | 2:66a3fe0dc83a | 82 | * @param y1 second vertex y |
lelect | 2:66a3fe0dc83a | 83 | * @param x2 third vertex x |
lelect | 2:66a3fe0dc83a | 84 | * @param y2 third vertex y |
lelect | 2:66a3fe0dc83a | 85 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 86 | */ |
lelect | 0:3e9c32359703 | 87 | void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
lelect | 2:66a3fe0dc83a | 88 | /** @fn void RGBmatrixPanel::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) |
lelect | 2:66a3fe0dc83a | 89 | * @bref draw a triangle from the vertex with color. |
lelect | 2:66a3fe0dc83a | 90 | * @param x0 first vertex x |
lelect | 2:66a3fe0dc83a | 91 | * @param y0 first vertex y |
lelect | 2:66a3fe0dc83a | 92 | * @param x1 second vertex x |
lelect | 2:66a3fe0dc83a | 93 | * @param y1 second vertex y |
lelect | 2:66a3fe0dc83a | 94 | * @param x2 third vertex x |
lelect | 2:66a3fe0dc83a | 95 | * @param y2 third vertex y |
lelect | 2:66a3fe0dc83a | 96 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 97 | */ |
lelect | 0:3e9c32359703 | 98 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
lelect | 2:66a3fe0dc83a | 99 | |
lelect | 2:66a3fe0dc83a | 100 | /** @fn void RGBmatrixPanel::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color) |
lelect | 2:66a3fe0dc83a | 101 | * @bref draw a round rectangle outline with color. |
lelect | 2:66a3fe0dc83a | 102 | * @param x0 first vertex x |
lelect | 2:66a3fe0dc83a | 103 | * @param y0 first vertex y |
lelect | 2:66a3fe0dc83a | 104 | * @param w width |
lelect | 2:66a3fe0dc83a | 105 | * @param h height |
lelect | 2:66a3fe0dc83a | 106 | * @param radius radius |
lelect | 2:66a3fe0dc83a | 107 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 108 | */ |
lelect | 0:3e9c32359703 | 109 | void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
lelect | 2:66a3fe0dc83a | 110 | /** @fn void RGBmatrixPanel::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color) |
lelect | 2:66a3fe0dc83a | 111 | * @bref draw a round rectangle with color. |
lelect | 2:66a3fe0dc83a | 112 | * @param x0 first vertex x |
lelect | 2:66a3fe0dc83a | 113 | * @param y0 first vertex y |
lelect | 2:66a3fe0dc83a | 114 | * @param w width |
lelect | 2:66a3fe0dc83a | 115 | * @param h height |
lelect | 2:66a3fe0dc83a | 116 | * @param radius radius |
lelect | 2:66a3fe0dc83a | 117 | * @param color 16bit color |
lelect | 2:66a3fe0dc83a | 118 | */ |
lelect | 0:3e9c32359703 | 119 | void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
lelect | 0:3e9c32359703 | 120 | |
lelect | 0:3e9c32359703 | 121 | void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); |
lelect | 2:66a3fe0dc83a | 122 | |
lelect | 0:3e9c32359703 | 123 | void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); |
lelect | 0:3e9c32359703 | 124 | |
lelect | 0:3e9c32359703 | 125 | void setCursor(int16_t x, int16_t y) { |
lelect | 0:3e9c32359703 | 126 | cursor_x = x; |
lelect | 0:3e9c32359703 | 127 | cursor_y = y; |
lelect | 0:3e9c32359703 | 128 | }; |
lelect | 2:66a3fe0dc83a | 129 | |
lelect | 0:3e9c32359703 | 130 | void setTextSize(uint8_t s) { |
lelect | 0:3e9c32359703 | 131 | textsize = (s > 0) ? s : 1; |
lelect | 0:3e9c32359703 | 132 | }; |
lelect | 2:66a3fe0dc83a | 133 | |
lelect | 0:3e9c32359703 | 134 | void setTextColor(uint16_t c) { |
lelect | 0:3e9c32359703 | 135 | textcolor = c; |
lelect | 0:3e9c32359703 | 136 | textbgcolor = c; |
lelect | 0:3e9c32359703 | 137 | } |
lelect | 0:3e9c32359703 | 138 | void setTextColor(uint16_t c, uint16_t b) { |
lelect | 0:3e9c32359703 | 139 | textcolor = c; |
lelect | 0:3e9c32359703 | 140 | textbgcolor = b; |
lelect | 0:3e9c32359703 | 141 | }; |
lelect | 0:3e9c32359703 | 142 | void setTextWrap(bool w) { |
lelect | 0:3e9c32359703 | 143 | wrap = w; |
lelect | 0:3e9c32359703 | 144 | }; |
lelect | 0:3e9c32359703 | 145 | |
lelect | 0:3e9c32359703 | 146 | virtual size_t writeChar(uint8_t); |
lelect | 0:3e9c32359703 | 147 | |
lelect | 0:3e9c32359703 | 148 | int16_t height(void) { |
lelect | 0:3e9c32359703 | 149 | return _height; |
lelect | 0:3e9c32359703 | 150 | }; |
lelect | 2:66a3fe0dc83a | 151 | |
lelect | 0:3e9c32359703 | 152 | int16_t width(void) { |
lelect | 0:3e9c32359703 | 153 | return _width; |
lelect | 0:3e9c32359703 | 154 | }; |
lelect | 2:66a3fe0dc83a | 155 | void setRotation(uint8_t r); |
lelect | 0:3e9c32359703 | 156 | |
lelect | 0:3e9c32359703 | 157 | uint8_t getRotation(void) { |
lelect | 0:3e9c32359703 | 158 | rotation%=4; |
lelect | 0:3e9c32359703 | 159 | return rotation; |
lelect | 0:3e9c32359703 | 160 | }; |
lelect | 0:3e9c32359703 | 161 | |
lelect | 0:3e9c32359703 | 162 | protected: |
lelect | 0:3e9c32359703 | 163 | int16_t _rawWidth, _rawHeight; // Display w/h as modified by current rotation |
lelect | 0:3e9c32359703 | 164 | int16_t _width, _height; // Display w/h as modified by current rotation |
lelect | 0:3e9c32359703 | 165 | int16_t cursor_x, cursor_y; |
lelect | 0:3e9c32359703 | 166 | uint16_t textcolor, textbgcolor; |
lelect | 0:3e9c32359703 | 167 | uint8_t textsize,rotation; |
lelect | 0:3e9c32359703 | 168 | bool wrap; // If set, 'wrap' text at right edge of display |
lelect | 0:3e9c32359703 | 169 | }; |
lelect | 0:3e9c32359703 | 170 | |
lelect | 0:3e9c32359703 | 171 | #endif // _ADAFRUIT_GFX_H |