[175] | 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 |
|
---|
| 11 | #define swap(a, b) { int16_t t = a; a = b; b = t; }
|
---|
| 12 |
|
---|
| 13 | class Adafruit_GFX : public Print {
|
---|
| 14 |
|
---|
| 15 | public:
|
---|
| 16 |
|
---|
| 17 | Adafruit_GFX(int16_t w, int16_t h); // Constructor
|
---|
| 18 |
|
---|
| 19 | // This MUST be defined by the subclass:
|
---|
| 20 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
|
---|
| 21 |
|
---|
| 22 | // These MAY be overridden by the subclass to provide device-specific
|
---|
| 23 | // optimized code. Otherwise 'generic' versions are used.
|
---|
| 24 | virtual void
|
---|
| 25 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
|
---|
| 26 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
|
---|
| 27 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
|
---|
| 28 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
|
---|
| 29 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
|
---|
| 30 | fillScreen(uint16_t color),
|
---|
| 31 | invertDisplay(boolean i);
|
---|
| 32 |
|
---|
| 33 | // These exist only with Adafruit_GFX (no subclass overrides)
|
---|
| 34 | void
|
---|
| 35 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
|
---|
| 36 | drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
---|
| 37 | uint16_t color),
|
---|
| 38 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
|
---|
| 39 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
---|
| 40 | int16_t delta, uint16_t color),
|
---|
| 41 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
---|
| 42 | int16_t x2, int16_t y2, uint16_t color),
|
---|
| 43 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
---|
| 44 | int16_t x2, int16_t y2, uint16_t color),
|
---|
| 45 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
---|
| 46 | int16_t radius, uint16_t color),
|
---|
| 47 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
---|
| 48 | int16_t radius, uint16_t color),
|
---|
| 49 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
|
---|
| 50 | int16_t w, int16_t h, uint16_t color),
|
---|
| 51 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
|
---|
| 52 | int16_t w, int16_t h, uint16_t color, uint16_t bg),
|
---|
| 53 | drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
|
---|
| 54 | int16_t w, int16_t h, uint16_t color),
|
---|
| 55 | drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
|
---|
| 56 | uint16_t bg, uint8_t size),
|
---|
| 57 | setCursor(int16_t x, int16_t y),
|
---|
| 58 | setTextColor(uint16_t c),
|
---|
| 59 | setTextColor(uint16_t c, uint16_t bg),
|
---|
| 60 | setTextSize(uint8_t s),
|
---|
| 61 | setTextWrap(boolean w),
|
---|
| 62 | setRotation(uint8_t r),
|
---|
| 63 | cp437(boolean x=true);
|
---|
| 64 |
|
---|
| 65 | #if ARDUINO >= 100
|
---|
| 66 | virtual size_t write(uint8_t);
|
---|
| 67 | #else
|
---|
| 68 | virtual void write(uint8_t);
|
---|
| 69 | #endif
|
---|
| 70 |
|
---|
| 71 | int16_t height(void) const;
|
---|
| 72 | int16_t width(void) const;
|
---|
| 73 |
|
---|
| 74 | uint8_t getRotation(void) const;
|
---|
| 75 |
|
---|
| 76 | // get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
|
---|
| 77 | int16_t getCursorX(void) const;
|
---|
| 78 | int16_t getCursorY(void) const;
|
---|
| 79 |
|
---|
| 80 | protected:
|
---|
| 81 | const int16_t
|
---|
| 82 | WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
|
---|
| 83 | int16_t
|
---|
| 84 | _width, _height, // Display w/h as modified by current rotation
|
---|
| 85 | cursor_x, cursor_y;
|
---|
| 86 | uint16_t
|
---|
| 87 | textcolor, textbgcolor;
|
---|
| 88 | uint8_t
|
---|
| 89 | textsize,
|
---|
| 90 | rotation;
|
---|
| 91 | boolean
|
---|
| 92 | wrap, // If set, 'wrap' text at right edge of display
|
---|
| 93 | _cp437; // If set, use correct CP437 charset (default is off)
|
---|
| 94 | };
|
---|
| 95 |
|
---|
| 96 | class Adafruit_GFX_Button {
|
---|
| 97 |
|
---|
| 98 | public:
|
---|
| 99 | Adafruit_GFX_Button(void);
|
---|
| 100 | void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
|
---|
| 101 | uint8_t w, uint8_t h,
|
---|
| 102 | uint16_t outline, uint16_t fill, uint16_t textcolor,
|
---|
| 103 | char *label, uint8_t textsize);
|
---|
| 104 | void drawButton(boolean inverted = false);
|
---|
| 105 | boolean contains(int16_t x, int16_t y);
|
---|
| 106 |
|
---|
| 107 | void press(boolean p);
|
---|
| 108 | boolean isPressed();
|
---|
| 109 | boolean justPressed();
|
---|
| 110 | boolean justReleased();
|
---|
| 111 | Adafruit_GFX *_gfx;
|
---|
| 112 |
|
---|
| 113 | private:
|
---|
| 114 | //Adafruit_GFX *_gfx;
|
---|
| 115 | int16_t _x, _y;
|
---|
| 116 | uint16_t _w, _h;
|
---|
| 117 | uint8_t _textsize;
|
---|
| 118 | uint16_t _outlinecolor, _fillcolor, _textcolor;
|
---|
| 119 | char _label[10];
|
---|
| 120 |
|
---|
| 121 | boolean currstate, laststate;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | #endif // _ADAFRUIT_GFX_H
|
---|