Fork of the latest Adafruit GFX Library as of 2017-12-13 to make it compatible with Mbed
Adafruit_GFX.h@0:cc4253367fc7, 2017-12-13 (annotated)
- Committer:
- mjromeijn
- Date:
- Wed Dec 13 20:24:59 2017 +0000
- Revision:
- 0:cc4253367fc7
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjromeijn | 0:cc4253367fc7 | 1 | #ifndef _ADAFRUIT_GFX_H |
mjromeijn | 0:cc4253367fc7 | 2 | #define _ADAFRUIT_GFX_H |
mjromeijn | 0:cc4253367fc7 | 3 | |
mjromeijn | 0:cc4253367fc7 | 4 | #include <stdint.h> |
mjromeijn | 0:cc4253367fc7 | 5 | #include <stdlib.h> |
mjromeijn | 0:cc4253367fc7 | 6 | #include <string.h> |
mjromeijn | 0:cc4253367fc7 | 7 | #define boolean bool |
mjromeijn | 0:cc4253367fc7 | 8 | #define NULL 0 |
mjromeijn | 0:cc4253367fc7 | 9 | |
mjromeijn | 0:cc4253367fc7 | 10 | #if ARDUINO >= 100 |
mjromeijn | 0:cc4253367fc7 | 11 | #include "Arduino.h" |
mjromeijn | 0:cc4253367fc7 | 12 | #include "Print.h" |
mjromeijn | 0:cc4253367fc7 | 13 | #else |
mjromeijn | 0:cc4253367fc7 | 14 | //#include "WProgram.h" |
mjromeijn | 0:cc4253367fc7 | 15 | #endif |
mjromeijn | 0:cc4253367fc7 | 16 | #include "gfxfont.h" |
mjromeijn | 0:cc4253367fc7 | 17 | |
mjromeijn | 0:cc4253367fc7 | 18 | class Adafruit_GFX { |
mjromeijn | 0:cc4253367fc7 | 19 | |
mjromeijn | 0:cc4253367fc7 | 20 | public: |
mjromeijn | 0:cc4253367fc7 | 21 | |
mjromeijn | 0:cc4253367fc7 | 22 | Adafruit_GFX(int16_t w, int16_t h); // Constructor |
mjromeijn | 0:cc4253367fc7 | 23 | |
mjromeijn | 0:cc4253367fc7 | 24 | // This MUST be defined by the subclass: |
mjromeijn | 0:cc4253367fc7 | 25 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; |
mjromeijn | 0:cc4253367fc7 | 26 | |
mjromeijn | 0:cc4253367fc7 | 27 | // TRANSACTION API / CORE DRAW API |
mjromeijn | 0:cc4253367fc7 | 28 | // These MAY be overridden by the subclass to provide device-specific |
mjromeijn | 0:cc4253367fc7 | 29 | // optimized code. Otherwise 'generic' versions are used. |
mjromeijn | 0:cc4253367fc7 | 30 | virtual void startWrite(void); |
mjromeijn | 0:cc4253367fc7 | 31 | virtual void writePixel(int16_t x, int16_t y, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 32 | virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 33 | virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 34 | virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 35 | virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 36 | virtual void endWrite(void); |
mjromeijn | 0:cc4253367fc7 | 37 | |
mjromeijn | 0:cc4253367fc7 | 38 | // CONTROL API |
mjromeijn | 0:cc4253367fc7 | 39 | // These MAY be overridden by the subclass to provide device-specific |
mjromeijn | 0:cc4253367fc7 | 40 | // optimized code. Otherwise 'generic' versions are used. |
mjromeijn | 0:cc4253367fc7 | 41 | virtual void setRotation(uint8_t r); |
mjromeijn | 0:cc4253367fc7 | 42 | virtual void invertDisplay(boolean i); |
mjromeijn | 0:cc4253367fc7 | 43 | |
mjromeijn | 0:cc4253367fc7 | 44 | // BASIC DRAW API |
mjromeijn | 0:cc4253367fc7 | 45 | // These MAY be overridden by the subclass to provide device-specific |
mjromeijn | 0:cc4253367fc7 | 46 | // optimized code. Otherwise 'generic' versions are used. |
mjromeijn | 0:cc4253367fc7 | 47 | virtual void |
mjromeijn | 0:cc4253367fc7 | 48 | // It's good to implement those, even if using transaction API |
mjromeijn | 0:cc4253367fc7 | 49 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 50 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 51 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 52 | fillScreen(uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 53 | // Optional and probably not necessary to change |
mjromeijn | 0:cc4253367fc7 | 54 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 55 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 56 | |
mjromeijn | 0:cc4253367fc7 | 57 | // These exist only with Adafruit_GFX (no subclass overrides) |
mjromeijn | 0:cc4253367fc7 | 58 | void |
mjromeijn | 0:cc4253367fc7 | 59 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 60 | drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, |
mjromeijn | 0:cc4253367fc7 | 61 | uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 62 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 63 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, |
mjromeijn | 0:cc4253367fc7 | 64 | int16_t delta, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 65 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, |
mjromeijn | 0:cc4253367fc7 | 66 | int16_t x2, int16_t y2, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 67 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, |
mjromeijn | 0:cc4253367fc7 | 68 | int16_t x2, int16_t y2, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 69 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, |
mjromeijn | 0:cc4253367fc7 | 70 | int16_t radius, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 71 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, |
mjromeijn | 0:cc4253367fc7 | 72 | int16_t radius, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 73 | drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], |
mjromeijn | 0:cc4253367fc7 | 74 | int16_t w, int16_t h, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 75 | drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], |
mjromeijn | 0:cc4253367fc7 | 76 | int16_t w, int16_t h, uint16_t color, uint16_t bg), |
mjromeijn | 0:cc4253367fc7 | 77 | drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, |
mjromeijn | 0:cc4253367fc7 | 78 | int16_t w, int16_t h, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 79 | drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, |
mjromeijn | 0:cc4253367fc7 | 80 | int16_t w, int16_t h, uint16_t color, uint16_t bg), |
mjromeijn | 0:cc4253367fc7 | 81 | drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], |
mjromeijn | 0:cc4253367fc7 | 82 | int16_t w, int16_t h, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 83 | drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[], |
mjromeijn | 0:cc4253367fc7 | 84 | int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 85 | drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, |
mjromeijn | 0:cc4253367fc7 | 86 | int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 87 | drawGrayscaleBitmap(int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 88 | const uint8_t bitmap[], const uint8_t mask[], |
mjromeijn | 0:cc4253367fc7 | 89 | int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 90 | drawGrayscaleBitmap(int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 91 | uint8_t *bitmap, uint8_t *mask, int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 92 | drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[], |
mjromeijn | 0:cc4253367fc7 | 93 | int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 94 | drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, |
mjromeijn | 0:cc4253367fc7 | 95 | int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 96 | drawRGBBitmap(int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 97 | const uint16_t bitmap[], const uint8_t mask[], |
mjromeijn | 0:cc4253367fc7 | 98 | int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 99 | drawRGBBitmap(int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 100 | uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h), |
mjromeijn | 0:cc4253367fc7 | 101 | drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, |
mjromeijn | 0:cc4253367fc7 | 102 | uint16_t bg, uint8_t size), |
mjromeijn | 0:cc4253367fc7 | 103 | setCursor(int16_t x, int16_t y), |
mjromeijn | 0:cc4253367fc7 | 104 | setTextColor(uint16_t c), |
mjromeijn | 0:cc4253367fc7 | 105 | setTextColor(uint16_t c, uint16_t bg), |
mjromeijn | 0:cc4253367fc7 | 106 | setTextSize(uint8_t s), |
mjromeijn | 0:cc4253367fc7 | 107 | setTextWrap(boolean w), |
mjromeijn | 0:cc4253367fc7 | 108 | cp437(boolean x=true), |
mjromeijn | 0:cc4253367fc7 | 109 | setFont(const GFXfont *f = NULL), |
mjromeijn | 0:cc4253367fc7 | 110 | getTextBounds(char *string, int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 111 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h); |
mjromeijn | 0:cc4253367fc7 | 112 | /*getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 113 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);*/ |
mjromeijn | 0:cc4253367fc7 | 114 | |
mjromeijn | 0:cc4253367fc7 | 115 | #if ARDUINO >= 100 |
mjromeijn | 0:cc4253367fc7 | 116 | virtual size_t write(uint8_t); |
mjromeijn | 0:cc4253367fc7 | 117 | #else |
mjromeijn | 0:cc4253367fc7 | 118 | virtual void write(uint8_t); |
mjromeijn | 0:cc4253367fc7 | 119 | #endif |
mjromeijn | 0:cc4253367fc7 | 120 | virtual void print(char*); |
mjromeijn | 0:cc4253367fc7 | 121 | |
mjromeijn | 0:cc4253367fc7 | 122 | int16_t height(void) const; |
mjromeijn | 0:cc4253367fc7 | 123 | int16_t width(void) const; |
mjromeijn | 0:cc4253367fc7 | 124 | |
mjromeijn | 0:cc4253367fc7 | 125 | uint8_t getRotation(void) const; |
mjromeijn | 0:cc4253367fc7 | 126 | |
mjromeijn | 0:cc4253367fc7 | 127 | // get current cursor position (get rotation safe maximum values, using: width() for x, height() for y) |
mjromeijn | 0:cc4253367fc7 | 128 | int16_t getCursorX(void) const; |
mjromeijn | 0:cc4253367fc7 | 129 | int16_t getCursorY(void) const; |
mjromeijn | 0:cc4253367fc7 | 130 | |
mjromeijn | 0:cc4253367fc7 | 131 | protected: |
mjromeijn | 0:cc4253367fc7 | 132 | void |
mjromeijn | 0:cc4253367fc7 | 133 | charBounds(char c, int16_t *x, int16_t *y, |
mjromeijn | 0:cc4253367fc7 | 134 | int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy); |
mjromeijn | 0:cc4253367fc7 | 135 | const int16_t |
mjromeijn | 0:cc4253367fc7 | 136 | WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes |
mjromeijn | 0:cc4253367fc7 | 137 | int16_t |
mjromeijn | 0:cc4253367fc7 | 138 | _width, _height, // Display w/h as modified by current rotation |
mjromeijn | 0:cc4253367fc7 | 139 | cursor_x, cursor_y; |
mjromeijn | 0:cc4253367fc7 | 140 | uint16_t |
mjromeijn | 0:cc4253367fc7 | 141 | textcolor, textbgcolor; |
mjromeijn | 0:cc4253367fc7 | 142 | uint8_t |
mjromeijn | 0:cc4253367fc7 | 143 | textsize, |
mjromeijn | 0:cc4253367fc7 | 144 | rotation; |
mjromeijn | 0:cc4253367fc7 | 145 | boolean |
mjromeijn | 0:cc4253367fc7 | 146 | wrap, // If set, 'wrap' text at right edge of display |
mjromeijn | 0:cc4253367fc7 | 147 | _cp437; // If set, use correct CP437 charset (default is off) |
mjromeijn | 0:cc4253367fc7 | 148 | GFXfont |
mjromeijn | 0:cc4253367fc7 | 149 | *gfxFont; |
mjromeijn | 0:cc4253367fc7 | 150 | }; |
mjromeijn | 0:cc4253367fc7 | 151 | |
mjromeijn | 0:cc4253367fc7 | 152 | class Adafruit_GFX_Button { |
mjromeijn | 0:cc4253367fc7 | 153 | |
mjromeijn | 0:cc4253367fc7 | 154 | public: |
mjromeijn | 0:cc4253367fc7 | 155 | Adafruit_GFX_Button(void); |
mjromeijn | 0:cc4253367fc7 | 156 | // "Classic" initButton() uses center & size |
mjromeijn | 0:cc4253367fc7 | 157 | void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, |
mjromeijn | 0:cc4253367fc7 | 158 | uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, |
mjromeijn | 0:cc4253367fc7 | 159 | uint16_t textcolor, char *label, uint8_t textsize); |
mjromeijn | 0:cc4253367fc7 | 160 | // New/alt initButton() uses upper-left corner & size |
mjromeijn | 0:cc4253367fc7 | 161 | void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1, |
mjromeijn | 0:cc4253367fc7 | 162 | uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, |
mjromeijn | 0:cc4253367fc7 | 163 | uint16_t textcolor, char *label, uint8_t textsize); |
mjromeijn | 0:cc4253367fc7 | 164 | void drawButton(boolean inverted = false); |
mjromeijn | 0:cc4253367fc7 | 165 | boolean contains(int16_t x, int16_t y); |
mjromeijn | 0:cc4253367fc7 | 166 | |
mjromeijn | 0:cc4253367fc7 | 167 | void press(boolean p); |
mjromeijn | 0:cc4253367fc7 | 168 | boolean isPressed(); |
mjromeijn | 0:cc4253367fc7 | 169 | boolean justPressed(); |
mjromeijn | 0:cc4253367fc7 | 170 | boolean justReleased(); |
mjromeijn | 0:cc4253367fc7 | 171 | |
mjromeijn | 0:cc4253367fc7 | 172 | private: |
mjromeijn | 0:cc4253367fc7 | 173 | Adafruit_GFX *_gfx; |
mjromeijn | 0:cc4253367fc7 | 174 | int16_t _x1, _y1; // Coordinates of top-left corner |
mjromeijn | 0:cc4253367fc7 | 175 | uint16_t _w, _h; |
mjromeijn | 0:cc4253367fc7 | 176 | uint8_t _textsize; |
mjromeijn | 0:cc4253367fc7 | 177 | uint16_t _outlinecolor, _fillcolor, _textcolor; |
mjromeijn | 0:cc4253367fc7 | 178 | char _label[10]; |
mjromeijn | 0:cc4253367fc7 | 179 | |
mjromeijn | 0:cc4253367fc7 | 180 | boolean currstate, laststate; |
mjromeijn | 0:cc4253367fc7 | 181 | }; |
mjromeijn | 0:cc4253367fc7 | 182 | |
mjromeijn | 0:cc4253367fc7 | 183 | class GFXcanvas1 : public Adafruit_GFX { |
mjromeijn | 0:cc4253367fc7 | 184 | public: |
mjromeijn | 0:cc4253367fc7 | 185 | GFXcanvas1(uint16_t w, uint16_t h); |
mjromeijn | 0:cc4253367fc7 | 186 | ~GFXcanvas1(void); |
mjromeijn | 0:cc4253367fc7 | 187 | void drawPixel(int16_t x, int16_t y, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 188 | fillScreen(uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 189 | uint8_t *getBuffer(void); |
mjromeijn | 0:cc4253367fc7 | 190 | private: |
mjromeijn | 0:cc4253367fc7 | 191 | uint8_t *buffer; |
mjromeijn | 0:cc4253367fc7 | 192 | }; |
mjromeijn | 0:cc4253367fc7 | 193 | |
mjromeijn | 0:cc4253367fc7 | 194 | class GFXcanvas8 : public Adafruit_GFX { |
mjromeijn | 0:cc4253367fc7 | 195 | public: |
mjromeijn | 0:cc4253367fc7 | 196 | GFXcanvas8(uint16_t w, uint16_t h); |
mjromeijn | 0:cc4253367fc7 | 197 | ~GFXcanvas8(void); |
mjromeijn | 0:cc4253367fc7 | 198 | void drawPixel(int16_t x, int16_t y, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 199 | fillScreen(uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 200 | writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 201 | |
mjromeijn | 0:cc4253367fc7 | 202 | uint8_t *getBuffer(void); |
mjromeijn | 0:cc4253367fc7 | 203 | private: |
mjromeijn | 0:cc4253367fc7 | 204 | uint8_t *buffer; |
mjromeijn | 0:cc4253367fc7 | 205 | }; |
mjromeijn | 0:cc4253367fc7 | 206 | |
mjromeijn | 0:cc4253367fc7 | 207 | class GFXcanvas16 : public Adafruit_GFX { |
mjromeijn | 0:cc4253367fc7 | 208 | public: |
mjromeijn | 0:cc4253367fc7 | 209 | GFXcanvas16(uint16_t w, uint16_t h); |
mjromeijn | 0:cc4253367fc7 | 210 | ~GFXcanvas16(void); |
mjromeijn | 0:cc4253367fc7 | 211 | void drawPixel(int16_t x, int16_t y, uint16_t color), |
mjromeijn | 0:cc4253367fc7 | 212 | fillScreen(uint16_t color); |
mjromeijn | 0:cc4253367fc7 | 213 | uint16_t *getBuffer(void); |
mjromeijn | 0:cc4253367fc7 | 214 | private: |
mjromeijn | 0:cc4253367fc7 | 215 | uint16_t *buffer; |
mjromeijn | 0:cc4253367fc7 | 216 | }; |
mjromeijn | 0:cc4253367fc7 | 217 | |
mjromeijn | 0:cc4253367fc7 | 218 | #endif // _ADAFRUIT_GFX_H |