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