added advanced scrolling options.

Fork of Adafruit_GFX by Neal Horman

Committer:
hthoffma
Date:
Fri Feb 24 09:17:19 2017 +0000
Revision:
18:de8c0b7e17c4
Parent:
17:005fab139cc2
added various scrolling options.

Who changed what in which revision?

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