this hurts
Dependencies: FFT
Adafruit_LEDBackpack/Adafruit_GFX.h@7:0d62545e6d73, 2020-12-03 (annotated)
- Committer:
- shyamgatech
- Date:
- Thu Dec 03 18:15:35 2020 +0000
- Revision:
- 7:0d62545e6d73
- Parent:
- 0:d6c9b09b4042
addded gui mbed code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annieluo2 | 0:d6c9b09b4042 | 1 | /*********************************** |
annieluo2 | 0:d6c9b09b4042 | 2 | This is a our graphics core library, for all our displays. |
annieluo2 | 0:d6c9b09b4042 | 3 | We'll be adapting all the |
annieluo2 | 0:d6c9b09b4042 | 4 | existing libaries to use this core to make updating, support |
annieluo2 | 0:d6c9b09b4042 | 5 | and upgrading easier! |
annieluo2 | 0:d6c9b09b4042 | 6 | |
annieluo2 | 0:d6c9b09b4042 | 7 | Adafruit invests time and resources providing this open source code, |
annieluo2 | 0:d6c9b09b4042 | 8 | please support Adafruit and open-source hardware by purchasing |
annieluo2 | 0:d6c9b09b4042 | 9 | products from Adafruit! |
annieluo2 | 0:d6c9b09b4042 | 10 | |
annieluo2 | 0:d6c9b09b4042 | 11 | Written by Limor Fried/Ladyada for Adafruit Industries. |
annieluo2 | 0:d6c9b09b4042 | 12 | BSD license, check license.txt for more information |
annieluo2 | 0:d6c9b09b4042 | 13 | All text above must be included in any redistribution |
annieluo2 | 0:d6c9b09b4042 | 14 | ****************************************/ |
annieluo2 | 0:d6c9b09b4042 | 15 | |
annieluo2 | 0:d6c9b09b4042 | 16 | /* |
annieluo2 | 0:d6c9b09b4042 | 17 | * Modified by Neal Horman 7/14/2012 for use in LPC1768 |
annieluo2 | 0:d6c9b09b4042 | 18 | */ |
annieluo2 | 0:d6c9b09b4042 | 19 | |
annieluo2 | 0:d6c9b09b4042 | 20 | #ifndef _ADAFRUIT_GFX_H_ |
annieluo2 | 0:d6c9b09b4042 | 21 | #define _ADAFRUIT_GFX_H_ |
annieluo2 | 0:d6c9b09b4042 | 22 | |
annieluo2 | 0:d6c9b09b4042 | 23 | static inline void swap(int16_t &a, int16_t &b) |
annieluo2 | 0:d6c9b09b4042 | 24 | { |
annieluo2 | 0:d6c9b09b4042 | 25 | int16_t t = a; |
annieluo2 | 0:d6c9b09b4042 | 26 | |
annieluo2 | 0:d6c9b09b4042 | 27 | a = b; |
annieluo2 | 0:d6c9b09b4042 | 28 | b = t; |
annieluo2 | 0:d6c9b09b4042 | 29 | } |
annieluo2 | 0:d6c9b09b4042 | 30 | |
annieluo2 | 0:d6c9b09b4042 | 31 | #ifndef _BV |
annieluo2 | 0:d6c9b09b4042 | 32 | #define _BV(bit) (1<<(bit)) |
annieluo2 | 0:d6c9b09b4042 | 33 | #endif |
annieluo2 | 0:d6c9b09b4042 | 34 | |
annieluo2 | 0:d6c9b09b4042 | 35 | #define BLACK 0 |
annieluo2 | 0:d6c9b09b4042 | 36 | #define WHITE 1 |
annieluo2 | 0:d6c9b09b4042 | 37 | |
annieluo2 | 0:d6c9b09b4042 | 38 | class Adafruit_GFX : public Stream |
annieluo2 | 0:d6c9b09b4042 | 39 | { |
annieluo2 | 0:d6c9b09b4042 | 40 | public: |
annieluo2 | 0:d6c9b09b4042 | 41 | Adafruit_GFX(int16_t w, int16_t h) |
annieluo2 | 0:d6c9b09b4042 | 42 | : _rawWidth(w) |
annieluo2 | 0:d6c9b09b4042 | 43 | , _rawHeight(h) |
annieluo2 | 0:d6c9b09b4042 | 44 | , _width(w) |
annieluo2 | 0:d6c9b09b4042 | 45 | , _height(h) |
annieluo2 | 0:d6c9b09b4042 | 46 | , cursor_x(0) |
annieluo2 | 0:d6c9b09b4042 | 47 | , cursor_y(0) |
annieluo2 | 0:d6c9b09b4042 | 48 | , textcolor(WHITE) |
annieluo2 | 0:d6c9b09b4042 | 49 | , textbgcolor(BLACK) |
annieluo2 | 0:d6c9b09b4042 | 50 | , textsize(1) |
annieluo2 | 0:d6c9b09b4042 | 51 | , rotation(0) |
annieluo2 | 0:d6c9b09b4042 | 52 | , wrap(true) |
annieluo2 | 0:d6c9b09b4042 | 53 | {}; |
annieluo2 | 0:d6c9b09b4042 | 54 | |
annieluo2 | 0:d6c9b09b4042 | 55 | // this must be defined by the subclass |
annieluo2 | 0:d6c9b09b4042 | 56 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; |
annieluo2 | 0:d6c9b09b4042 | 57 | // this is optional |
annieluo2 | 0:d6c9b09b4042 | 58 | virtual void invertDisplay(bool i) {}; |
annieluo2 | 0:d6c9b09b4042 | 59 | |
annieluo2 | 0:d6c9b09b4042 | 60 | // Stream implementation - provides printf() interface |
annieluo2 | 0:d6c9b09b4042 | 61 | // You would otherwise be forced to use writeChar() |
annieluo2 | 0:d6c9b09b4042 | 62 | virtual int _putc(int value) { return writeChar(value); }; |
annieluo2 | 0:d6c9b09b4042 | 63 | virtual int _getc() { return -1; }; |
annieluo2 | 0:d6c9b09b4042 | 64 | |
annieluo2 | 0:d6c9b09b4042 | 65 | #ifdef WANT_ABSTRACTS |
annieluo2 | 0:d6c9b09b4042 | 66 | // these are 'generic' drawing functions, so we can share them! |
annieluo2 | 0:d6c9b09b4042 | 67 | virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 68 | virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 69 | virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 70 | virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 71 | virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 72 | virtual void fillScreen(uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 73 | |
annieluo2 | 0:d6c9b09b4042 | 74 | void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 75 | void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 76 | void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 77 | void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 78 | |
annieluo2 | 0:d6c9b09b4042 | 79 | void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 80 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 81 | void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 82 | void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 83 | #endif |
annieluo2 | 0:d6c9b09b4042 | 84 | |
annieluo2 | 0:d6c9b09b4042 | 85 | void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); |
annieluo2 | 0:d6c9b09b4042 | 86 | void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); |
annieluo2 | 0:d6c9b09b4042 | 87 | size_t writeChar(uint8_t); |
annieluo2 | 0:d6c9b09b4042 | 88 | |
annieluo2 | 0:d6c9b09b4042 | 89 | int16_t width(void) { return _width; }; |
annieluo2 | 0:d6c9b09b4042 | 90 | int16_t height(void) { return _height; }; |
annieluo2 | 0:d6c9b09b4042 | 91 | |
annieluo2 | 0:d6c9b09b4042 | 92 | void setCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; }; |
annieluo2 | 0:d6c9b09b4042 | 93 | void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; }; |
annieluo2 | 0:d6c9b09b4042 | 94 | void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; } |
annieluo2 | 0:d6c9b09b4042 | 95 | void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; }; |
annieluo2 | 0:d6c9b09b4042 | 96 | void setTextWrap(bool w) { wrap = w; }; |
annieluo2 | 0:d6c9b09b4042 | 97 | |
annieluo2 | 0:d6c9b09b4042 | 98 | void setRotation(uint8_t r); |
annieluo2 | 0:d6c9b09b4042 | 99 | uint8_t getRotation(void) { rotation %= 4; return rotation; }; |
annieluo2 | 0:d6c9b09b4042 | 100 | |
annieluo2 | 0:d6c9b09b4042 | 101 | protected: |
annieluo2 | 0:d6c9b09b4042 | 102 | int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes |
annieluo2 | 0:d6c9b09b4042 | 103 | int16_t _width, _height; // dependent on rotation |
annieluo2 | 0:d6c9b09b4042 | 104 | int16_t cursor_x, cursor_y; |
annieluo2 | 0:d6c9b09b4042 | 105 | uint16_t textcolor, textbgcolor; |
annieluo2 | 0:d6c9b09b4042 | 106 | uint8_t textsize; |
annieluo2 | 0:d6c9b09b4042 | 107 | uint8_t rotation; |
annieluo2 | 0:d6c9b09b4042 | 108 | bool wrap; // If set, 'wrap' text at right edge of display |
annieluo2 | 0:d6c9b09b4042 | 109 | }; |
annieluo2 | 0:d6c9b09b4042 | 110 | |
annieluo2 | 0:d6c9b09b4042 | 111 | #endif |