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