Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RGB_matrix_Panel RGB_matrix_Panel_modif RGB_matrix_Panel Pmod_OLEDrgb_ALS1_K64F ... more
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 //These exist only with Adafruit_GFX (no subclass overrides) 00059 /** @fn void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) 00060 * @bref draw a circle outline from the coordinates of the center. 00061 * @param x0 x position 00062 * @param y0 y position 00063 * @param r Radius of the circle 00064 * @param color 16bit color 00065 */ 00066 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 00067 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); 00068 /** @fn void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) 00069 * @bref draw a circle from the coordinates of the center. 00070 * @param x0 x position 00071 * @param y0 y position 00072 * @param r Radius of the circle 00073 * @param color 16bit color 00074 */ 00075 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 00076 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); 00077 00078 /** @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) 00079 * @bref draw a triangle outline from the vertex with color. 00080 * @param x0 first vertex x 00081 * @param y0 first vertex y 00082 * @param x1 second vertex x 00083 * @param y1 second vertex y 00084 * @param x2 third vertex x 00085 * @param y2 third vertex y 00086 * @param color 16bit color 00087 */ 00088 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 00089 /** @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) 00090 * @bref draw a triangle from the vertex with color. 00091 * @param x0 first vertex x 00092 * @param y0 first vertex y 00093 * @param x1 second vertex x 00094 * @param y1 second vertex y 00095 * @param x2 third vertex x 00096 * @param y2 third vertex y 00097 * @param color 16bit color 00098 */ 00099 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 00100 00101 /** @fn void Adafruit_GFX::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color) 00102 * @bref draw a round rectangle outline with color. 00103 * @param x0 first vertex x 00104 * @param y0 first vertex y 00105 * @param w width 00106 * @param h height 00107 * @param radius radius 00108 * @param color 16bit color 00109 */ 00110 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); 00111 /** @fn void Adafruit_GFX::drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color) 00112 * @bref draw a round rectangle with color. 00113 * @param x0 first vertex x 00114 * @param y0 first vertex y 00115 * @param w width 00116 * @param h height 00117 * @param radius radius 00118 * @param color 16bit color 00119 */ 00120 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); 00121 00122 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 00123 00124 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); 00125 00126 void setCursor(int16_t x, int16_t y) { 00127 cursor_x = x; 00128 cursor_y = y; 00129 }; 00130 00131 void setTextSize(uint8_t s) { 00132 textsize = (s > 0) ? s : 1; 00133 }; 00134 00135 void setTextColor(uint16_t c) { 00136 textcolor = c; 00137 textbgcolor = c; 00138 } 00139 void setTextColor(uint16_t c, uint16_t b) { 00140 textcolor = c; 00141 textbgcolor = b; 00142 }; 00143 void setTextWrap(bool w) { 00144 wrap = w; 00145 }; 00146 00147 virtual size_t writeChar(uint8_t); 00148 00149 int16_t height(void) { 00150 return _height; 00151 }; 00152 00153 int16_t width(void) { 00154 return _width; 00155 }; 00156 void setRotation(uint8_t r) { 00157 rotation = r; 00158 } 00159 00160 uint8_t getRotation(void) { 00161 rotation%=4; 00162 return rotation; 00163 }; 00164 00165 protected: 00166 int16_t _rawWidth, _rawHeight; // Display w/h as modified by current rotation 00167 int16_t _width, _height; // Display w/h as modified by current rotation 00168 int16_t cursor_x, cursor_y; 00169 uint16_t textcolor, textbgcolor; 00170 uint8_t textsize,rotation; 00171 bool wrap; // If set, 'wrap' text at right edge of display 00172 }; 00173 00174 #endif // _ADAFRUIT_GFX_H
Generated on Tue Jul 12 2022 21:11:52 by
1.7.2