Dependencies:   RemoteIR

Committer:
sb8718
Date:
Tue Jun 02 08:33:56 2020 +0000
Revision:
142:cb9e8d32d1b9
Parent:
136:53a83b91854c
un - new commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sb8718 136:53a83b91854c 1 /***********************************
sb8718 136:53a83b91854c 2 This is a our graphics core library, for all our displays.
sb8718 136:53a83b91854c 3 We'll be adapting all the
sb8718 136:53a83b91854c 4 existing libaries to use this core to make updating, support
sb8718 136:53a83b91854c 5 and upgrading easier!
sb8718 136:53a83b91854c 6
sb8718 136:53a83b91854c 7 Adafruit invests time and resources providing this open source code,
sb8718 136:53a83b91854c 8 please support Adafruit and open-source hardware by purchasing
sb8718 136:53a83b91854c 9 products from Adafruit!
sb8718 136:53a83b91854c 10
sb8718 136:53a83b91854c 11 Written by Limor Fried/Ladyada for Adafruit Industries.
sb8718 136:53a83b91854c 12 BSD license, check license.txt for more information
sb8718 136:53a83b91854c 13 All text above must be included in any redistribution
sb8718 136:53a83b91854c 14 ****************************************/
sb8718 136:53a83b91854c 15
sb8718 136:53a83b91854c 16 /*
sb8718 136:53a83b91854c 17 * Modified by Neal Horman 7/14/2012 for use in mbed
sb8718 136:53a83b91854c 18 */
sb8718 136:53a83b91854c 19
sb8718 136:53a83b91854c 20 #ifndef _ADAFRUIT_GFX_H_
sb8718 136:53a83b91854c 21 #define _ADAFRUIT_GFX_H_
sb8718 136:53a83b91854c 22
sb8718 136:53a83b91854c 23 #include "Adafruit_GFX_Config.h"
sb8718 136:53a83b91854c 24
sb8718 136:53a83b91854c 25 static inline void swap(int16_t &a, int16_t &b)
sb8718 136:53a83b91854c 26 {
sb8718 136:53a83b91854c 27 int16_t t = a;
sb8718 136:53a83b91854c 28
sb8718 136:53a83b91854c 29 a = b;
sb8718 136:53a83b91854c 30 b = t;
sb8718 136:53a83b91854c 31 }
sb8718 136:53a83b91854c 32
sb8718 136:53a83b91854c 33 #ifndef _BV
sb8718 136:53a83b91854c 34 #define _BV(bit) (1<<(bit))
sb8718 136:53a83b91854c 35 #endif
sb8718 136:53a83b91854c 36
sb8718 136:53a83b91854c 37 #define BLACK 0
sb8718 136:53a83b91854c 38 #define WHITE 1
sb8718 136:53a83b91854c 39
sb8718 136:53a83b91854c 40 /**
sb8718 136:53a83b91854c 41 * This is a Text and Graphics element drawing class.
sb8718 136:53a83b91854c 42 * These functions draw to the display buffer.
sb8718 136:53a83b91854c 43 *
sb8718 136:53a83b91854c 44 * Display drivers should be derived from here.
sb8718 136:53a83b91854c 45 * The Display drivers push the display buffer to the
sb8718 136:53a83b91854c 46 * hardware based on application control.
sb8718 136:53a83b91854c 47 *
sb8718 136:53a83b91854c 48 */
sb8718 136:53a83b91854c 49 class Adafruit_GFX : public Stream
sb8718 136:53a83b91854c 50 {
sb8718 136:53a83b91854c 51 public:
sb8718 136:53a83b91854c 52 Adafruit_GFX(int16_t w, int16_t h)
sb8718 136:53a83b91854c 53 : _rawWidth(w)
sb8718 136:53a83b91854c 54 , _rawHeight(h)
sb8718 136:53a83b91854c 55 , _width(w)
sb8718 136:53a83b91854c 56 , _height(h)
sb8718 136:53a83b91854c 57 , cursor_x(0)
sb8718 136:53a83b91854c 58 , cursor_y(0)
sb8718 136:53a83b91854c 59 , textcolor(WHITE)
sb8718 136:53a83b91854c 60 , textbgcolor(BLACK)
sb8718 136:53a83b91854c 61 , textsize(1)
sb8718 136:53a83b91854c 62 , rotation(0)
sb8718 136:53a83b91854c 63 , wrap(true)
sb8718 136:53a83b91854c 64 {};
sb8718 136:53a83b91854c 65
sb8718 136:53a83b91854c 66 /// Paint one BLACK or WHITE pixel in the display buffer
sb8718 136:53a83b91854c 67 // this must be defined by the subclass
sb8718 136:53a83b91854c 68 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
sb8718 136:53a83b91854c 69 // this is optional
sb8718 136:53a83b91854c 70 virtual void invertDisplay(bool i) {};
sb8718 136:53a83b91854c 71
sb8718 136:53a83b91854c 72 // Stream implementation - provides printf() interface
sb8718 136:53a83b91854c 73 // You would otherwise be forced to use writeChar()
sb8718 136:53a83b91854c 74 virtual int _putc(int value) { return writeChar(value); };
sb8718 136:53a83b91854c 75 virtual int _getc() { return -1; };
sb8718 136:53a83b91854c 76
sb8718 136:53a83b91854c 77 #ifdef GFX_WANT_ABSTRACTS
sb8718 136:53a83b91854c 78 // these are 'generic' drawing functions, so we can share them!
sb8718 136:53a83b91854c 79
sb8718 136:53a83b91854c 80 /** Draw a Horizontal Line
sb8718 136:53a83b91854c 81 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 82 */
sb8718 136:53a83b91854c 83 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
sb8718 136:53a83b91854c 84 /** Draw a rectangle
sb8718 136:53a83b91854c 85 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 86 */
sb8718 136:53a83b91854c 87 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
sb8718 136:53a83b91854c 88 /** Fill the entire display
sb8718 136:53a83b91854c 89 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 90 */
sb8718 136:53a83b91854c 91 virtual void fillScreen(uint16_t color);
sb8718 136:53a83b91854c 92
sb8718 136:53a83b91854c 93 /** Draw a circle
sb8718 136:53a83b91854c 94 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 95 */
sb8718 136:53a83b91854c 96 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
sb8718 136:53a83b91854c 97 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
sb8718 136:53a83b91854c 98
sb8718 136:53a83b91854c 99 /** Draw and fill a circle
sb8718 136:53a83b91854c 100 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 101 */
sb8718 136:53a83b91854c 102 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
sb8718 136:53a83b91854c 103 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
sb8718 136:53a83b91854c 104
sb8718 136:53a83b91854c 105 /** Draw a triangle
sb8718 136:53a83b91854c 106 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 107 */
sb8718 136:53a83b91854c 108 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
sb8718 136:53a83b91854c 109 /** Draw and fill a triangle
sb8718 136:53a83b91854c 110 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 111 */
sb8718 136:53a83b91854c 112 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
sb8718 136:53a83b91854c 113
sb8718 136:53a83b91854c 114 /** Draw a rounded rectangle
sb8718 136:53a83b91854c 115 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 116 */
sb8718 136:53a83b91854c 117 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
sb8718 136:53a83b91854c 118 /** Draw and fill a rounded rectangle
sb8718 136:53a83b91854c 119 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 120 */
sb8718 136:53a83b91854c 121 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
sb8718 136:53a83b91854c 122 /** Draw a bitmap
sb8718 136:53a83b91854c 123 * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 124 */
sb8718 136:53a83b91854c 125 void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
sb8718 136:53a83b91854c 126 #endif
sb8718 136:53a83b91854c 127
sb8718 136:53a83b91854c 128 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
sb8718 136:53a83b91854c 129 /** Draw a line
sb8718 136:53a83b91854c 130 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 131 */
sb8718 136:53a83b91854c 132 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
sb8718 136:53a83b91854c 133 /** Draw a vertical line
sb8718 136:53a83b91854c 134 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 135 */
sb8718 136:53a83b91854c 136 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
sb8718 136:53a83b91854c 137 /** Draw and fill a rectangle
sb8718 136:53a83b91854c 138 * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
sb8718 136:53a83b91854c 139 */
sb8718 136:53a83b91854c 140 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
sb8718 136:53a83b91854c 141 #endif
sb8718 136:53a83b91854c 142
sb8718 136:53a83b91854c 143 /// Draw a text character at a specified pixel location
sb8718 136:53a83b91854c 144 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
sb8718 136:53a83b91854c 145 /// Draw a text character at the text cursor location
sb8718 136:53a83b91854c 146 size_t writeChar(uint8_t);
sb8718 136:53a83b91854c 147
sb8718 136:53a83b91854c 148 /// Get the width of the display in pixels
sb8718 136:53a83b91854c 149 inline int16_t width(void) { return _width; };
sb8718 136:53a83b91854c 150 /// Get the height of the display in pixels
sb8718 136:53a83b91854c 151 inline int16_t height(void) { return _height; };
sb8718 136:53a83b91854c 152
sb8718 136:53a83b91854c 153 /// Set the text cursor location, based on the size of the text
sb8718 136:53a83b91854c 154 inline void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
sb8718 136:53a83b91854c 155 #if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
sb8718 136:53a83b91854c 156 /** Set the size of the text to be drawn
sb8718 136:53a83b91854c 157 * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS
sb8718 136:53a83b91854c 158 */
sb8718 136:53a83b91854c 159 inline void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
sb8718 136:53a83b91854c 160 #endif
sb8718 136:53a83b91854c 161 /// Set the text foreground and background colors to be the same
sb8718 136:53a83b91854c 162 inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
sb8718 136:53a83b91854c 163 /// Set the text foreground and background colors independantly
sb8718 136:53a83b91854c 164 inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
sb8718 136:53a83b91854c 165 /// Set text wraping mode true or false
sb8718 136:53a83b91854c 166 inline void setTextWrap(bool w) { wrap = w; };
sb8718 136:53a83b91854c 167
sb8718 136:53a83b91854c 168 /// Set the display rotation, 1, 2, 3, or 4
sb8718 136:53a83b91854c 169 void setRotation(uint8_t r);
sb8718 136:53a83b91854c 170 /// Get the current rotation
sb8718 136:53a83b91854c 171 inline uint8_t getRotation(void) { rotation %= 4; return rotation; };
sb8718 136:53a83b91854c 172
sb8718 136:53a83b91854c 173 int16_t cursor_x, cursor_y;
sb8718 136:53a83b91854c 174
sb8718 136:53a83b91854c 175 protected:
sb8718 136:53a83b91854c 176 int16_t _rawWidth, _rawHeight; // this is the 'raw' display w/h - never changes
sb8718 136:53a83b91854c 177 int16_t _width, _height; // dependent on rotation
sb8718 136:53a83b91854c 178 uint16_t textcolor, textbgcolor;
sb8718 136:53a83b91854c 179 uint8_t textsize;
sb8718 136:53a83b91854c 180 uint8_t rotation;
sb8718 136:53a83b91854c 181 bool wrap; // If set, 'wrap' text at right edge of display
sb8718 136:53a83b91854c 182 };
sb8718 136:53a83b91854c 183
sb8718 136:53a83b91854c 184 #endif