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