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: unytelogo_animation
Fork of Adafruit_GFX by
Adafruit_GFX.h
00001 /*********************************** 00002 This is a our graphics core library, for all our displays. 00003 We'll be adapting all the 00004 existing libaries to use this core to make updating, support 00005 and upgrading easier! 00006 Adafruit invests time and resources providing this open source code, 00007 please support Adafruit and open-source hardware by purchasing 00008 products from Adafruit! 00009 Written by Limor Fried/Ladyada for Adafruit Industries. 00010 BSD license, check license.txt for more information 00011 All text above must be included in any redistribution 00012 ****************************************/ 00013 00014 /* 00015 * Modified by Neal Horman 7/14/2012 for use in mbed 00016 */ 00017 00018 #ifndef _ADAFRUIT_GFX_H_ 00019 #define _ADAFRUIT_GFX_H_ 00020 00021 #include "Adafruit_GFX_Config.h" 00022 00023 static inline void swap(int16_t &a, int16_t &b) 00024 { 00025 int16_t t = a; 00026 00027 a = b; 00028 b = t; 00029 } 00030 00031 #ifndef _BV 00032 #define _BV(bit) (1<<(bit)) 00033 #endif 00034 00035 #define BLACK 0 00036 #define WHITE 1 00037 00038 /** 00039 * This is a Text and Graphics element drawing class. 00040 * These functions draw to the display buffer. 00041 * 00042 * Display drivers should be derived from here. 00043 * The Display drivers push the display buffer to the 00044 * hardware based on application control. 00045 * 00046 */ 00047 class Adafruit_GFX : public Stream 00048 { 00049 public: 00050 Adafruit_GFX(int16_t w, int16_t h) 00051 : _rawWidth(w) 00052 , _rawHeight(h) 00053 , _width(w) 00054 , _height(h) 00055 , cursor_x(0) 00056 , cursor_y(0) 00057 , textcolor(WHITE) 00058 , textbgcolor(BLACK) 00059 , textsize(1) 00060 , rotation(0) 00061 , wrap(true) 00062 {}; 00063 00064 /// Paint one BLACK or WHITE pixel in the display buffer 00065 // this must be defined by the subclass 00066 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 00067 // this is optional 00068 virtual void invertDisplay(bool i) {}; 00069 00070 // Stream implementation - provides printf() interface 00071 // You would otherwise be forced to use writeChar() 00072 virtual int _putc(int value) { return writeChar(value); }; 00073 virtual int _getc() { return -1; }; 00074 00075 #ifdef GFX_WANT_ABSTRACTS 00076 // these are 'generic' drawing functions, so we can share them! 00077 00078 /** Draw a Horizontal Line 00079 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00080 */ 00081 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 00082 /** Draw a rectangle 00083 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00084 */ 00085 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 00086 /** Fill the entire display 00087 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00088 */ 00089 virtual void fillScreen(uint16_t color); 00090 00091 /** Draw a circle 00092 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00093 */ 00094 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 00095 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); 00096 00097 /** Draw and fill a circle 00098 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00099 */ 00100 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 00101 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); 00102 00103 /** Draw a triangle 00104 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00105 */ 00106 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 00107 /** Draw and fill a triangle 00108 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00109 */ 00110 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 00111 00112 /** Draw a rounded rectangle 00113 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00114 */ 00115 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); 00116 /** Draw and fill a rounded rectangle 00117 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00118 */ 00119 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color); 00120 /** Draw a bitmap 00121 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h 00122 */ 00123 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 00124 #endif 00125 00126 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) 00127 /** Draw a line 00128 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h 00129 */ 00130 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); 00131 /** Draw a vertical line 00132 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h 00133 */ 00134 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 00135 /** Draw and fill a rectangle 00136 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h 00137 */ 00138 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 00139 #endif 00140 00141 /// Draw a text character at a specified pixel location 00142 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); 00143 /// Draw a text character at the text cursor location 00144 size_t writeChar(uint8_t); 00145 00146 /// Get the width of the display in pixels 00147 inline int16_t width(void) { return _width; }; 00148 /// Get the height of the display in pixels 00149 inline int16_t height(void) { return _height; }; 00150 00151 /// Set the text cursor location, based on the size of the text 00152 inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; }; 00153 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT) 00154 /** Set the size of the text to be drawn 00155 * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS 00156 */ 00157 inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; }; 00158 #endif 00159 /// Set the text foreground and background colors to be the same 00160 inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; } 00161 /// Set the text foreground and background colors independantly 00162 inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; }; 00163 /// Set text wraping mode true or false 00164 inline void setTextWrap(bool w) { wrap = w; }; 00165 00166 /// Set the display rotation, 1, 2, 3, or 4 00167 void setRotation(uint8_t r); 00168 /// Get the current rotation 00169 inline uint8_t getRotation(void) { rotation %= 4; return rotation; }; 00170 00171 protected: 00172 int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes 00173 int16_t _width, _height; // dependent on rotation 00174 int16_t cursor_x, cursor_y; 00175 uint16_t textcolor, textbgcolor; 00176 uint8_t textsize; 00177 uint8_t rotation; 00178 bool wrap; // If set, 'wrap' text at right edge of display 00179 }; 00180 00181 #endif
Generated on Fri Jul 15 2022 23:19:51 by
1.7.2
