Eric Coyle / TFT_ST7735

Dependents:   ME503_VehicleAssembly

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Adafruit_GFX.h Source File

Adafruit_GFX.h

00001 #ifndef _ADAFRUIT_GFX_H
00002 #define _ADAFRUIT_GFX_H
00003  
00004 #include "mbed.h"
00005 #include "glcdfont.h"
00006  
00007 #define BLACK 0
00008 #define WHITE 1
00009 #ifndef _BV
00010 #define _BV(bit) (1<<(bit))
00011 #endif
00012 #define swap(a, b) { int16_t t = a; a = b; b = t; }
00013  
00014 /** Adafruit_GFX class. This is the Adafruit_GFX class.\n drawPixel(int16_t x,int16_t y,uint16_t color) needing implementation in derived implementation class
00015 */
00016 class Adafruit_GFX : public Stream
00017 {
00018 public:
00019     Adafruit_GFX(int16_t w, int16_t h)
00020         : _rawWidth(w),_rawHeight(h)
00021         ,_width(w),_height(h)
00022         ,cursor_x(0),cursor_y(0)
00023         ,textcolor(WHITE),textbgcolor(BLACK)
00024         ,textsize(1)
00025         ,rotation(0)
00026         ,wrap(true)
00027     {};
00028  
00029     /** @fn void Adafruit_GFX::drawPixel(int16_t x, int16_t y, uint16_t color) = 0
00030     *   @bref This MUST be defined by the subclass!
00031     *   @param x x
00032     *   @param y y
00033     *   @param color 16bit color
00034     */
00035     virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
00036 // These are overridden for the Stream subclass
00037     virtual int _putc(int value) {
00038         return writeChar(value);
00039     };
00040     virtual int _getc() {
00041         return -1;
00042     };
00043     /** @fn void Adafruit_GFX::invertDisplay(bool i)
00044     *   @bref Do nothing, must be subclassed if supported
00045     *   @param i invert
00046     */
00047     virtual void invertDisplay(bool i);
00048  
00049 // These MAY be overridden by the subclass to provide device-specific
00050 // optimized code.  Otherwise 'generic' versions are used.
00051     virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
00052     virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
00053     virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
00054     virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
00055     virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
00056     virtual void fillScreen(uint16_t color);
00057     
00058     //Changes the buffer for text writing
00059     void clearTextBuf(int x,int y,int w,int h); //Generic is a 128x128 text buffer
00060     
00061     //Sets all Text on the Screen to Background Color
00062     void clearText();
00063  
00064 //These exist only with Adafruit_GFX (no subclass overrides)
00065     /** @fn void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
00066     *   @bref draw a circle outline from the coordinates of the center.
00067     *   @param x0 x position
00068     *   @param y0 y position
00069     *   @param r Radius of the circle
00070     *   @param color 16bit color
00071     */
00072     void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
00073     void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
00074     /** @fn void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
00075     *   @bref draw a circle from the coordinates of the center.
00076     *   @param x0 x position
00077     *   @param y0 y position
00078     *   @param r Radius of the circle
00079     *   @param color 16bit color
00080     */
00081     void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
00082     void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
00083  
00084     /** @fn void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
00085     *   @bref draw a triangle outline from the vertex with color.
00086     *   @param x0 first vertex x
00087     *   @param y0 first vertex y
00088     *   @param x1 second vertex x
00089     *   @param y1 second vertex y
00090     *   @param x2 third vertex x
00091     *   @param y2 third vertex y
00092     *   @param color 16bit color
00093     */
00094     void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
00095     /** @fn void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
00096     *   @bref draw a triangle from the vertex with color.
00097     *   @param x0 first vertex x
00098     *   @param y0 first vertex y
00099     *   @param x1 second vertex x
00100     *   @param y1 second vertex y
00101     *   @param x2 third vertex x
00102     *   @param y2 third vertex y
00103     *   @param color 16bit color
00104     */
00105     void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
00106  
00107     /** @fn void Adafruit_GFX::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
00108     *   @bref draw a round rectangle outline with color.
00109     *   @param x0 first vertex x
00110     *   @param y0 first vertex y
00111     *   @param w width
00112     *   @param h height
00113     *   @param radius radius
00114     *   @param color 16bit color
00115     */
00116     void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
00117     /** @fn void Adafruit_GFX::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
00118     *   @bref draw a round rectangle with color.
00119     *   @param x0 first vertex x
00120     *   @param y0 first vertex y
00121     *   @param w width
00122     *   @param h height
00123     *   @param radius radius
00124     *   @param color 16bit color
00125     */
00126     void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
00127  
00128     void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
00129  
00130     void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
00131  
00132     void setCursor(int16_t x, int16_t y) {
00133         cursor_x = x;
00134         cursor_y = y;
00135     };
00136  
00137     void setTextSize(uint8_t s) {
00138         textsize = (s > 0) ? s : 1;
00139     };
00140  
00141     void setTextColor(uint16_t c) {
00142         textcolor = c;
00143         textbgcolor = c;
00144     }
00145     void setTextColor(uint16_t c, uint16_t b) {
00146         textcolor = c;
00147         textbgcolor = b;
00148     };
00149     void setTextWrap(bool w) {
00150         wrap = w;
00151     };
00152  
00153     virtual size_t writeChar(uint8_t);
00154  
00155     int16_t height(void) {
00156         return _height;
00157     };
00158  
00159     int16_t width(void) {
00160         return _width;
00161     };
00162     void setRotation(uint8_t r) {
00163         rotation = r;
00164     }
00165  
00166     uint8_t getRotation(void) {
00167         rotation%=4;
00168         return rotation;
00169     };
00170  
00171 protected:
00172     int16_t _rawWidth, _rawHeight; // Display w/h as modified by current rotation
00173     int16_t _width, _height; // Display w/h as modified by current rotation
00174     int16_t cursor_x, cursor_y;
00175     uint16_t    textcolor, textbgcolor;
00176     uint8_t textsize,rotation;
00177     bool    wrap; // If set, 'wrap' text at right edge of display
00178     bool textbuf[128][128];
00179 };
00180  
00181 #endif // _ADAFRUIT_GFX_H