p kj
/
LPC824-BlynkWeatherstation
Microduino
Fork of Io_moon by
Adafruit_GFX/Adafruit_GFX.h@0:740c1eb2df13, 2016-06-23 (annotated)
- Committer:
- lixianyu
- Date:
- Thu Jun 23 11:16:14 2016 +0000
- Revision:
- 0:740c1eb2df13
* AM2321?????????2s????i2c?????; * SimpleTimer??bug?????????????????????????; * Blynk??bug??????????????; * ?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:740c1eb2df13 | 1 | /*********************************** |
lixianyu | 0:740c1eb2df13 | 2 | This is a our graphics core library, for all our displays. |
lixianyu | 0:740c1eb2df13 | 3 | We'll be adapting all the |
lixianyu | 0:740c1eb2df13 | 4 | existing libaries to use this core to make updating, support |
lixianyu | 0:740c1eb2df13 | 5 | and upgrading easier! |
lixianyu | 0:740c1eb2df13 | 6 | |
lixianyu | 0:740c1eb2df13 | 7 | Adafruit invests time and resources providing this open source code, |
lixianyu | 0:740c1eb2df13 | 8 | please support Adafruit and open-source hardware by purchasing |
lixianyu | 0:740c1eb2df13 | 9 | products from Adafruit! |
lixianyu | 0:740c1eb2df13 | 10 | |
lixianyu | 0:740c1eb2df13 | 11 | Written by Limor Fried/Ladyada for Adafruit Industries. |
lixianyu | 0:740c1eb2df13 | 12 | BSD license, check license.txt for more information |
lixianyu | 0:740c1eb2df13 | 13 | All text above must be included in any redistribution |
lixianyu | 0:740c1eb2df13 | 14 | ****************************************/ |
lixianyu | 0:740c1eb2df13 | 15 | |
lixianyu | 0:740c1eb2df13 | 16 | /* |
lixianyu | 0:740c1eb2df13 | 17 | * Modified by Neal Horman 7/14/2012 for use in mbed |
lixianyu | 0:740c1eb2df13 | 18 | */ |
lixianyu | 0:740c1eb2df13 | 19 | |
lixianyu | 0:740c1eb2df13 | 20 | #ifndef _ADAFRUIT_GFX_H_ |
lixianyu | 0:740c1eb2df13 | 21 | #define _ADAFRUIT_GFX_H_ |
lixianyu | 0:740c1eb2df13 | 22 | |
lixianyu | 0:740c1eb2df13 | 23 | #include "Adafruit_GFX_Config.h" |
lixianyu | 0:740c1eb2df13 | 24 | |
lixianyu | 0:740c1eb2df13 | 25 | static inline void swap(int16_t &a, int16_t &b) |
lixianyu | 0:740c1eb2df13 | 26 | { |
lixianyu | 0:740c1eb2df13 | 27 | int16_t t = a; |
lixianyu | 0:740c1eb2df13 | 28 | |
lixianyu | 0:740c1eb2df13 | 29 | a = b; |
lixianyu | 0:740c1eb2df13 | 30 | b = t; |
lixianyu | 0:740c1eb2df13 | 31 | } |
lixianyu | 0:740c1eb2df13 | 32 | |
lixianyu | 0:740c1eb2df13 | 33 | #ifndef _BV |
lixianyu | 0:740c1eb2df13 | 34 | #define _BV(bit) (1<<(bit)) |
lixianyu | 0:740c1eb2df13 | 35 | #endif |
lixianyu | 0:740c1eb2df13 | 36 | |
lixianyu | 0:740c1eb2df13 | 37 | #define BLACK 0 |
lixianyu | 0:740c1eb2df13 | 38 | #define WHITE 1 |
lixianyu | 0:740c1eb2df13 | 39 | |
lixianyu | 0:740c1eb2df13 | 40 | /** |
lixianyu | 0:740c1eb2df13 | 41 | * This is a Text and Graphics element drawing class. |
lixianyu | 0:740c1eb2df13 | 42 | * These functions draw to the display buffer. |
lixianyu | 0:740c1eb2df13 | 43 | * |
lixianyu | 0:740c1eb2df13 | 44 | * Display drivers should be derived from here. |
lixianyu | 0:740c1eb2df13 | 45 | * The Display drivers push the display buffer to the |
lixianyu | 0:740c1eb2df13 | 46 | * hardware based on application control. |
lixianyu | 0:740c1eb2df13 | 47 | * |
lixianyu | 0:740c1eb2df13 | 48 | */ |
lixianyu | 0:740c1eb2df13 | 49 | class Adafruit_GFX : public Stream |
lixianyu | 0:740c1eb2df13 | 50 | { |
lixianyu | 0:740c1eb2df13 | 51 | public: |
lixianyu | 0:740c1eb2df13 | 52 | Adafruit_GFX(int16_t w, int16_t h) |
lixianyu | 0:740c1eb2df13 | 53 | : _rawWidth(w) |
lixianyu | 0:740c1eb2df13 | 54 | , _rawHeight(h) |
lixianyu | 0:740c1eb2df13 | 55 | , _width(w) |
lixianyu | 0:740c1eb2df13 | 56 | , _height(h) |
lixianyu | 0:740c1eb2df13 | 57 | , cursor_x(0) |
lixianyu | 0:740c1eb2df13 | 58 | , cursor_y(0) |
lixianyu | 0:740c1eb2df13 | 59 | , textcolor(WHITE) |
lixianyu | 0:740c1eb2df13 | 60 | , textbgcolor(BLACK) |
lixianyu | 0:740c1eb2df13 | 61 | , textsize(1) |
lixianyu | 0:740c1eb2df13 | 62 | , rotation(0) |
lixianyu | 0:740c1eb2df13 | 63 | , wrap(true) |
lixianyu | 0:740c1eb2df13 | 64 | {}; |
lixianyu | 0:740c1eb2df13 | 65 | |
lixianyu | 0:740c1eb2df13 | 66 | /// Paint one BLACK or WHITE pixel in the display buffer |
lixianyu | 0:740c1eb2df13 | 67 | // this must be defined by the subclass |
lixianyu | 0:740c1eb2df13 | 68 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; |
lixianyu | 0:740c1eb2df13 | 69 | // this is optional |
lixianyu | 0:740c1eb2df13 | 70 | virtual void invertDisplay(bool i) {}; |
lixianyu | 0:740c1eb2df13 | 71 | |
lixianyu | 0:740c1eb2df13 | 72 | // Stream implementation - provides printf() interface |
lixianyu | 0:740c1eb2df13 | 73 | // You would otherwise be forced to use writeChar() |
lixianyu | 0:740c1eb2df13 | 74 | virtual int _putc(int value) { return writeChar(value); }; |
lixianyu | 0:740c1eb2df13 | 75 | virtual int _getc() { return -1; }; |
lixianyu | 0:740c1eb2df13 | 76 | |
lixianyu | 0:740c1eb2df13 | 77 | #ifdef GFX_WANT_ABSTRACTS |
lixianyu | 0:740c1eb2df13 | 78 | // these are 'generic' drawing functions, so we can share them! |
lixianyu | 0:740c1eb2df13 | 79 | |
lixianyu | 0:740c1eb2df13 | 80 | /** Draw a Horizontal Line |
lixianyu | 0:740c1eb2df13 | 81 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 82 | */ |
lixianyu | 0:740c1eb2df13 | 83 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 84 | /** Draw a rectangle |
lixianyu | 0:740c1eb2df13 | 85 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 86 | */ |
lixianyu | 0:740c1eb2df13 | 87 | virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 88 | /** Fill the entire display |
lixianyu | 0:740c1eb2df13 | 89 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 90 | */ |
lixianyu | 0:740c1eb2df13 | 91 | virtual void fillScreen(uint16_t color); |
lixianyu | 0:740c1eb2df13 | 92 | |
lixianyu | 0:740c1eb2df13 | 93 | /** Draw a circle |
lixianyu | 0:740c1eb2df13 | 94 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 95 | */ |
lixianyu | 0:740c1eb2df13 | 96 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 97 | void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 98 | |
lixianyu | 0:740c1eb2df13 | 99 | /** Draw and fill a circle |
lixianyu | 0:740c1eb2df13 | 100 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 101 | */ |
lixianyu | 0:740c1eb2df13 | 102 | void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 103 | void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 104 | |
lixianyu | 0:740c1eb2df13 | 105 | /** Draw a triangle |
lixianyu | 0:740c1eb2df13 | 106 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 107 | */ |
lixianyu | 0:740c1eb2df13 | 108 | void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 109 | /** Draw and fill a triangle |
lixianyu | 0:740c1eb2df13 | 110 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 111 | */ |
lixianyu | 0:740c1eb2df13 | 112 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 113 | |
lixianyu | 0:740c1eb2df13 | 114 | /** Draw a rounded rectangle |
lixianyu | 0:740c1eb2df13 | 115 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 116 | */ |
lixianyu | 0:740c1eb2df13 | 117 | void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 118 | /** Draw and fill a rounded rectangle |
lixianyu | 0:740c1eb2df13 | 119 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 120 | */ |
lixianyu | 0:740c1eb2df13 | 121 | void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 122 | /** Draw a bitmap |
lixianyu | 0:740c1eb2df13 | 123 | * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 124 | */ |
lixianyu | 0:740c1eb2df13 | 125 | void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 126 | #endif |
lixianyu | 0:740c1eb2df13 | 127 | |
lixianyu | 0:740c1eb2df13 | 128 | #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) |
lixianyu | 0:740c1eb2df13 | 129 | /** Draw a line |
lixianyu | 0:740c1eb2df13 | 130 | * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 131 | */ |
lixianyu | 0:740c1eb2df13 | 132 | virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 133 | /** Draw a vertical line |
lixianyu | 0:740c1eb2df13 | 134 | * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 135 | */ |
lixianyu | 0:740c1eb2df13 | 136 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 137 | /** Draw and fill a rectangle |
lixianyu | 0:740c1eb2df13 | 138 | * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h |
lixianyu | 0:740c1eb2df13 | 139 | */ |
lixianyu | 0:740c1eb2df13 | 140 | virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
lixianyu | 0:740c1eb2df13 | 141 | #endif |
lixianyu | 0:740c1eb2df13 | 142 | |
lixianyu | 0:740c1eb2df13 | 143 | /// Draw a text character at a specified pixel location |
lixianyu | 0:740c1eb2df13 | 144 | void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); |
lixianyu | 0:740c1eb2df13 | 145 | /// Draw a text character at the text cursor location |
lixianyu | 0:740c1eb2df13 | 146 | size_t writeChar(uint8_t); |
lixianyu | 0:740c1eb2df13 | 147 | |
lixianyu | 0:740c1eb2df13 | 148 | /// Get the width of the display in pixels |
lixianyu | 0:740c1eb2df13 | 149 | inline int16_t width(void) { return _width; }; |
lixianyu | 0:740c1eb2df13 | 150 | /// Get the height of the display in pixels |
lixianyu | 0:740c1eb2df13 | 151 | inline int16_t height(void) { return _height; }; |
lixianyu | 0:740c1eb2df13 | 152 | |
lixianyu | 0:740c1eb2df13 | 153 | /// Set the text cursor location, based on the size of the text |
lixianyu | 0:740c1eb2df13 | 154 | inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; }; |
lixianyu | 0:740c1eb2df13 | 155 | #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) |
lixianyu | 0:740c1eb2df13 | 156 | /** Set the size of the text to be drawn |
lixianyu | 0:740c1eb2df13 | 157 | * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS |
lixianyu | 0:740c1eb2df13 | 158 | */ |
lixianyu | 0:740c1eb2df13 | 159 | inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; }; |
lixianyu | 0:740c1eb2df13 | 160 | #endif |
lixianyu | 0:740c1eb2df13 | 161 | /// Set the text foreground and background colors to be the same |
lixianyu | 0:740c1eb2df13 | 162 | inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; } |
lixianyu | 0:740c1eb2df13 | 163 | /// Set the text foreground and background colors independantly |
lixianyu | 0:740c1eb2df13 | 164 | inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; }; |
lixianyu | 0:740c1eb2df13 | 165 | /// Set text wraping mode true or false |
lixianyu | 0:740c1eb2df13 | 166 | inline void setTextWrap(bool w) { wrap = w; }; |
lixianyu | 0:740c1eb2df13 | 167 | |
lixianyu | 0:740c1eb2df13 | 168 | /// Set the display rotation, 1, 2, 3, or 4 |
lixianyu | 0:740c1eb2df13 | 169 | void setRotation(uint8_t r); |
lixianyu | 0:740c1eb2df13 | 170 | /// Get the current rotation |
lixianyu | 0:740c1eb2df13 | 171 | inline uint8_t getRotation(void) { rotation %= 4; return rotation; }; |
lixianyu | 0:740c1eb2df13 | 172 | |
lixianyu | 0:740c1eb2df13 | 173 | protected: |
lixianyu | 0:740c1eb2df13 | 174 | int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes |
lixianyu | 0:740c1eb2df13 | 175 | int16_t _width, _height; // dependent on rotation |
lixianyu | 0:740c1eb2df13 | 176 | int16_t cursor_x, cursor_y; |
lixianyu | 0:740c1eb2df13 | 177 | uint16_t textcolor, textbgcolor; |
lixianyu | 0:740c1eb2df13 | 178 | uint8_t textsize; |
lixianyu | 0:740c1eb2df13 | 179 | uint8_t rotation; |
lixianyu | 0:740c1eb2df13 | 180 | bool wrap; // If set, 'wrap' text at right edge of display |
lixianyu | 0:740c1eb2df13 | 181 | }; |
lixianyu | 0:740c1eb2df13 | 182 | |
lixianyu | 0:740c1eb2df13 | 183 | #endif |