Basic Adafruit_GFX v1.10.7 library files with ADA_GFX_kbv.h and renamed glcdfont.inc MCUFRIEND_kbv library inherits from Adafruit_GFX

Dependents:   TFT_Touch_botao_v1 TFT_Touch_exemplo5_git_touch TESTE_1 TFT_Touch_exemplo6_git_touch_button_3_ ... more

Committer:
davidprentice
Date:
Mon Apr 26 14:39:27 2021 +0000
Revision:
0:8ee30e15ac7b
Basic Adafruit_GFX v1.10.7 Arduino library files; with ADA_GFX_kbv.h and renamed glcdfont.inc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidprentice 0:8ee30e15ac7b 1 #ifndef _ADAFRUIT_GFX_H
davidprentice 0:8ee30e15ac7b 2 #define _ADAFRUIT_GFX_H
davidprentice 0:8ee30e15ac7b 3
davidprentice 0:8ee30e15ac7b 4 #if ARDUINO >= 100
davidprentice 0:8ee30e15ac7b 5 #include "Arduino.h"
davidprentice 0:8ee30e15ac7b 6 #include "Print.h"
davidprentice 0:8ee30e15ac7b 7 #else
davidprentice 0:8ee30e15ac7b 8 #include "WProgram.h"
davidprentice 0:8ee30e15ac7b 9 #endif
davidprentice 0:8ee30e15ac7b 10 #include "gfxfont.h"
davidprentice 0:8ee30e15ac7b 11
davidprentice 0:8ee30e15ac7b 12 /// A generic graphics superclass that can handle all sorts of drawing. At a
davidprentice 0:8ee30e15ac7b 13 /// minimum you can subclass and provide drawPixel(). At a maximum you can do a
davidprentice 0:8ee30e15ac7b 14 /// ton of overriding to optimize. Used for any/all Adafruit displays!
davidprentice 0:8ee30e15ac7b 15 class Adafruit_GFX : public Print {
davidprentice 0:8ee30e15ac7b 16
davidprentice 0:8ee30e15ac7b 17 public:
davidprentice 0:8ee30e15ac7b 18 Adafruit_GFX(int16_t w, int16_t h); // Constructor
davidprentice 0:8ee30e15ac7b 19
davidprentice 0:8ee30e15ac7b 20 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 21 /*!
davidprentice 0:8ee30e15ac7b 22 @brief Draw to the screen/framebuffer/etc.
davidprentice 0:8ee30e15ac7b 23 Must be overridden in subclass.
davidprentice 0:8ee30e15ac7b 24 @param x X coordinate in pixels
davidprentice 0:8ee30e15ac7b 25 @param y Y coordinate in pixels
davidprentice 0:8ee30e15ac7b 26 @param color 16-bit pixel color.
davidprentice 0:8ee30e15ac7b 27 */
davidprentice 0:8ee30e15ac7b 28 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 29 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
davidprentice 0:8ee30e15ac7b 30
davidprentice 0:8ee30e15ac7b 31 // TRANSACTION API / CORE DRAW API
davidprentice 0:8ee30e15ac7b 32 // These MAY be overridden by the subclass to provide device-specific
davidprentice 0:8ee30e15ac7b 33 // optimized code. Otherwise 'generic' versions are used.
davidprentice 0:8ee30e15ac7b 34 virtual void startWrite(void);
davidprentice 0:8ee30e15ac7b 35 virtual void writePixel(int16_t x, int16_t y, uint16_t color);
davidprentice 0:8ee30e15ac7b 36 virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 37 uint16_t color);
davidprentice 0:8ee30e15ac7b 38 virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 39 virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 40 virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
davidprentice 0:8ee30e15ac7b 41 uint16_t color);
davidprentice 0:8ee30e15ac7b 42 virtual void endWrite(void);
davidprentice 0:8ee30e15ac7b 43
davidprentice 0:8ee30e15ac7b 44 // CONTROL API
davidprentice 0:8ee30e15ac7b 45 // These MAY be overridden by the subclass to provide device-specific
davidprentice 0:8ee30e15ac7b 46 // optimized code. Otherwise 'generic' versions are used.
davidprentice 0:8ee30e15ac7b 47 virtual void setRotation(uint8_t r);
davidprentice 0:8ee30e15ac7b 48 virtual void invertDisplay(bool i);
davidprentice 0:8ee30e15ac7b 49
davidprentice 0:8ee30e15ac7b 50 // BASIC DRAW API
davidprentice 0:8ee30e15ac7b 51 // These MAY be overridden by the subclass to provide device-specific
davidprentice 0:8ee30e15ac7b 52 // optimized code. Otherwise 'generic' versions are used.
davidprentice 0:8ee30e15ac7b 53
davidprentice 0:8ee30e15ac7b 54 // It's good to implement those, even if using transaction API
davidprentice 0:8ee30e15ac7b 55 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 56 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 57 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 58 uint16_t color);
davidprentice 0:8ee30e15ac7b 59 virtual void fillScreen(uint16_t color);
davidprentice 0:8ee30e15ac7b 60 // Optional and probably not necessary to change
davidprentice 0:8ee30e15ac7b 61 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
davidprentice 0:8ee30e15ac7b 62 uint16_t color);
davidprentice 0:8ee30e15ac7b 63 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 64 uint16_t color);
davidprentice 0:8ee30e15ac7b 65
davidprentice 0:8ee30e15ac7b 66 // These exist only with Adafruit_GFX (no subclass overrides)
davidprentice 0:8ee30e15ac7b 67 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
davidprentice 0:8ee30e15ac7b 68 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
davidprentice 0:8ee30e15ac7b 69 uint16_t color);
davidprentice 0:8ee30e15ac7b 70 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
davidprentice 0:8ee30e15ac7b 71 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
davidprentice 0:8ee30e15ac7b 72 int16_t delta, uint16_t color);
davidprentice 0:8ee30e15ac7b 73 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
davidprentice 0:8ee30e15ac7b 74 int16_t y2, uint16_t color);
davidprentice 0:8ee30e15ac7b 75 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
davidprentice 0:8ee30e15ac7b 76 int16_t y2, uint16_t color);
davidprentice 0:8ee30e15ac7b 77 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 78 int16_t radius, uint16_t color);
davidprentice 0:8ee30e15ac7b 79 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 80 int16_t radius, uint16_t color);
davidprentice 0:8ee30e15ac7b 81 void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
davidprentice 0:8ee30e15ac7b 82 int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 83 void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
davidprentice 0:8ee30e15ac7b 84 int16_t h, uint16_t color, uint16_t bg);
davidprentice 0:8ee30e15ac7b 85 void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 86 uint16_t color);
davidprentice 0:8ee30e15ac7b 87 void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h,
davidprentice 0:8ee30e15ac7b 88 uint16_t color, uint16_t bg);
davidprentice 0:8ee30e15ac7b 89 void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
davidprentice 0:8ee30e15ac7b 90 int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 91 void drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
davidprentice 0:8ee30e15ac7b 92 int16_t w, int16_t h);
davidprentice 0:8ee30e15ac7b 93 void drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w,
davidprentice 0:8ee30e15ac7b 94 int16_t h);
davidprentice 0:8ee30e15ac7b 95 void drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
davidprentice 0:8ee30e15ac7b 96 const uint8_t mask[], int16_t w, int16_t h);
davidprentice 0:8ee30e15ac7b 97 void drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, uint8_t *mask,
davidprentice 0:8ee30e15ac7b 98 int16_t w, int16_t h);
davidprentice 0:8ee30e15ac7b 99 void drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w,
davidprentice 0:8ee30e15ac7b 100 int16_t h);
davidprentice 0:8ee30e15ac7b 101 void drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w,
davidprentice 0:8ee30e15ac7b 102 int16_t h);
davidprentice 0:8ee30e15ac7b 103 void drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[],
davidprentice 0:8ee30e15ac7b 104 const uint8_t mask[], int16_t w, int16_t h);
davidprentice 0:8ee30e15ac7b 105 void drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, uint8_t *mask,
davidprentice 0:8ee30e15ac7b 106 int16_t w, int16_t h);
davidprentice 0:8ee30e15ac7b 107 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
davidprentice 0:8ee30e15ac7b 108 uint16_t bg, uint8_t size);
davidprentice 0:8ee30e15ac7b 109 void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
davidprentice 0:8ee30e15ac7b 110 uint16_t bg, uint8_t size_x, uint8_t size_y);
davidprentice 0:8ee30e15ac7b 111 void getTextBounds(const char *string, int16_t x, int16_t y, int16_t *x1,
davidprentice 0:8ee30e15ac7b 112 int16_t *y1, uint16_t *w, uint16_t *h);
davidprentice 0:8ee30e15ac7b 113 //void getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
davidprentice 0:8ee30e15ac7b 114 // int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
davidprentice 0:8ee30e15ac7b 115 //void getTextBounds(const String &str, int16_t x, int16_t y, int16_t *x1,
davidprentice 0:8ee30e15ac7b 116 // int16_t *y1, uint16_t *w, uint16_t *h);
davidprentice 0:8ee30e15ac7b 117 void setTextSize(uint8_t s);
davidprentice 0:8ee30e15ac7b 118 void setTextSize(uint8_t sx, uint8_t sy);
davidprentice 0:8ee30e15ac7b 119 void setFont(const GFXfont *f = NULL);
davidprentice 0:8ee30e15ac7b 120
davidprentice 0:8ee30e15ac7b 121 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 122 /*!
davidprentice 0:8ee30e15ac7b 123 @brief Set text cursor location
davidprentice 0:8ee30e15ac7b 124 @param x X coordinate in pixels
davidprentice 0:8ee30e15ac7b 125 @param y Y coordinate in pixels
davidprentice 0:8ee30e15ac7b 126 */
davidprentice 0:8ee30e15ac7b 127 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 128 void setCursor(int16_t x, int16_t y) {
davidprentice 0:8ee30e15ac7b 129 cursor_x = x;
davidprentice 0:8ee30e15ac7b 130 cursor_y = y;
davidprentice 0:8ee30e15ac7b 131 }
davidprentice 0:8ee30e15ac7b 132
davidprentice 0:8ee30e15ac7b 133 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 134 /*!
davidprentice 0:8ee30e15ac7b 135 @brief Set text font color with transparant background
davidprentice 0:8ee30e15ac7b 136 @param c 16-bit 5-6-5 Color to draw text with
davidprentice 0:8ee30e15ac7b 137 @note For 'transparent' background, background and foreground
davidprentice 0:8ee30e15ac7b 138 are set to same color rather than using a separate flag.
davidprentice 0:8ee30e15ac7b 139 */
davidprentice 0:8ee30e15ac7b 140 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 141 void setTextColor(uint16_t c) { textcolor = textbgcolor = c; }
davidprentice 0:8ee30e15ac7b 142
davidprentice 0:8ee30e15ac7b 143 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 144 /*!
davidprentice 0:8ee30e15ac7b 145 @brief Set text font color with custom background color
davidprentice 0:8ee30e15ac7b 146 @param c 16-bit 5-6-5 Color to draw text with
davidprentice 0:8ee30e15ac7b 147 @param bg 16-bit 5-6-5 Color to draw background/fill with
davidprentice 0:8ee30e15ac7b 148 */
davidprentice 0:8ee30e15ac7b 149 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 150 void setTextColor(uint16_t c, uint16_t bg) {
davidprentice 0:8ee30e15ac7b 151 textcolor = c;
davidprentice 0:8ee30e15ac7b 152 textbgcolor = bg;
davidprentice 0:8ee30e15ac7b 153 }
davidprentice 0:8ee30e15ac7b 154
davidprentice 0:8ee30e15ac7b 155 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 156 /*!
davidprentice 0:8ee30e15ac7b 157 @brief Set whether text that is too long for the screen width should
davidprentice 0:8ee30e15ac7b 158 automatically wrap around to the next line (else clip right).
davidprentice 0:8ee30e15ac7b 159 @param w true for wrapping, false for clipping
davidprentice 0:8ee30e15ac7b 160 */
davidprentice 0:8ee30e15ac7b 161 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 162 void setTextWrap(bool w) { wrap = w; }
davidprentice 0:8ee30e15ac7b 163
davidprentice 0:8ee30e15ac7b 164 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 165 /*!
davidprentice 0:8ee30e15ac7b 166 @brief Enable (or disable) Code Page 437-compatible charset.
davidprentice 0:8ee30e15ac7b 167 There was an error in glcdfont.c for the longest time -- one
davidprentice 0:8ee30e15ac7b 168 character (#176, the 'light shade' block) was missing -- this
davidprentice 0:8ee30e15ac7b 169 threw off the index of every character that followed it.
davidprentice 0:8ee30e15ac7b 170 But a TON of code has been written with the erroneous
davidprentice 0:8ee30e15ac7b 171 character indices. By default, the library uses the original
davidprentice 0:8ee30e15ac7b 172 'wrong' behavior and old sketches will still work. Pass
davidprentice 0:8ee30e15ac7b 173 'true' to this function to use correct CP437 character values
davidprentice 0:8ee30e15ac7b 174 in your code.
davidprentice 0:8ee30e15ac7b 175 @param x true = enable (new behavior), false = disable (old behavior)
davidprentice 0:8ee30e15ac7b 176 */
davidprentice 0:8ee30e15ac7b 177 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 178 void cp437(bool x = true) { _cp437 = x; }
davidprentice 0:8ee30e15ac7b 179
davidprentice 0:8ee30e15ac7b 180 using Print::write;
davidprentice 0:8ee30e15ac7b 181 #if ARDUINO >= 100
davidprentice 0:8ee30e15ac7b 182 virtual size_t write(uint8_t);
davidprentice 0:8ee30e15ac7b 183 #else
davidprentice 0:8ee30e15ac7b 184 virtual void write(uint8_t);
davidprentice 0:8ee30e15ac7b 185 #endif
davidprentice 0:8ee30e15ac7b 186
davidprentice 0:8ee30e15ac7b 187 /************************************************************************/
davidprentice 0:8ee30e15ac7b 188 /*!
davidprentice 0:8ee30e15ac7b 189 @brief Get width of the display, accounting for current rotation
davidprentice 0:8ee30e15ac7b 190 @returns Width in pixels
davidprentice 0:8ee30e15ac7b 191 */
davidprentice 0:8ee30e15ac7b 192 /************************************************************************/
davidprentice 0:8ee30e15ac7b 193 int16_t width(void) const { return _width; };
davidprentice 0:8ee30e15ac7b 194
davidprentice 0:8ee30e15ac7b 195 /************************************************************************/
davidprentice 0:8ee30e15ac7b 196 /*!
davidprentice 0:8ee30e15ac7b 197 @brief Get height of the display, accounting for current rotation
davidprentice 0:8ee30e15ac7b 198 @returns Height in pixels
davidprentice 0:8ee30e15ac7b 199 */
davidprentice 0:8ee30e15ac7b 200 /************************************************************************/
davidprentice 0:8ee30e15ac7b 201 int16_t height(void) const { return _height; }
davidprentice 0:8ee30e15ac7b 202
davidprentice 0:8ee30e15ac7b 203 /************************************************************************/
davidprentice 0:8ee30e15ac7b 204 /*!
davidprentice 0:8ee30e15ac7b 205 @brief Get rotation setting for display
davidprentice 0:8ee30e15ac7b 206 @returns 0 thru 3 corresponding to 4 cardinal rotations
davidprentice 0:8ee30e15ac7b 207 */
davidprentice 0:8ee30e15ac7b 208 /************************************************************************/
davidprentice 0:8ee30e15ac7b 209 uint8_t getRotation(void) const { return rotation; }
davidprentice 0:8ee30e15ac7b 210
davidprentice 0:8ee30e15ac7b 211 // get current cursor position (get rotation safe maximum values,
davidprentice 0:8ee30e15ac7b 212 // using: width() for x, height() for y)
davidprentice 0:8ee30e15ac7b 213 /************************************************************************/
davidprentice 0:8ee30e15ac7b 214 /*!
davidprentice 0:8ee30e15ac7b 215 @brief Get text cursor X location
davidprentice 0:8ee30e15ac7b 216 @returns X coordinate in pixels
davidprentice 0:8ee30e15ac7b 217 */
davidprentice 0:8ee30e15ac7b 218 /************************************************************************/
davidprentice 0:8ee30e15ac7b 219 int16_t getCursorX(void) const { return cursor_x; }
davidprentice 0:8ee30e15ac7b 220
davidprentice 0:8ee30e15ac7b 221 /************************************************************************/
davidprentice 0:8ee30e15ac7b 222 /*!
davidprentice 0:8ee30e15ac7b 223 @brief Get text cursor Y location
davidprentice 0:8ee30e15ac7b 224 @returns Y coordinate in pixels
davidprentice 0:8ee30e15ac7b 225 */
davidprentice 0:8ee30e15ac7b 226 /************************************************************************/
davidprentice 0:8ee30e15ac7b 227 int16_t getCursorY(void) const { return cursor_y; };
davidprentice 0:8ee30e15ac7b 228
davidprentice 0:8ee30e15ac7b 229 protected:
davidprentice 0:8ee30e15ac7b 230 void charBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx,
davidprentice 0:8ee30e15ac7b 231 int16_t *miny, int16_t *maxx, int16_t *maxy);
davidprentice 0:8ee30e15ac7b 232 int16_t WIDTH; ///< This is the 'raw' display width - never changes
davidprentice 0:8ee30e15ac7b 233 int16_t HEIGHT; ///< This is the 'raw' display height - never changes
davidprentice 0:8ee30e15ac7b 234 int16_t _width; ///< Display width as modified by current rotation
davidprentice 0:8ee30e15ac7b 235 int16_t _height; ///< Display height as modified by current rotation
davidprentice 0:8ee30e15ac7b 236 int16_t cursor_x; ///< x location to start print()ing text
davidprentice 0:8ee30e15ac7b 237 int16_t cursor_y; ///< y location to start print()ing text
davidprentice 0:8ee30e15ac7b 238 uint16_t textcolor; ///< 16-bit background color for print()
davidprentice 0:8ee30e15ac7b 239 uint16_t textbgcolor; ///< 16-bit text color for print()
davidprentice 0:8ee30e15ac7b 240 uint8_t textsize_x; ///< Desired magnification in X-axis of text to print()
davidprentice 0:8ee30e15ac7b 241 uint8_t textsize_y; ///< Desired magnification in Y-axis of text to print()
davidprentice 0:8ee30e15ac7b 242 uint8_t rotation; ///< Display rotation (0 thru 3)
davidprentice 0:8ee30e15ac7b 243 bool wrap; ///< If set, 'wrap' text at right edge of display
davidprentice 0:8ee30e15ac7b 244 bool _cp437; ///< If set, use correct CP437 charset (default is off)
davidprentice 0:8ee30e15ac7b 245 GFXfont *gfxFont; ///< Pointer to special font
davidprentice 0:8ee30e15ac7b 246 };
davidprentice 0:8ee30e15ac7b 247
davidprentice 0:8ee30e15ac7b 248 /// A simple drawn button UI element
davidprentice 0:8ee30e15ac7b 249 class Adafruit_GFX_Button {
davidprentice 0:8ee30e15ac7b 250
davidprentice 0:8ee30e15ac7b 251 public:
davidprentice 0:8ee30e15ac7b 252 Adafruit_GFX_Button(void);
davidprentice 0:8ee30e15ac7b 253 // "Classic" initButton() uses center & size
davidprentice 0:8ee30e15ac7b 254 void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w,
davidprentice 0:8ee30e15ac7b 255 uint16_t h, uint16_t outline, uint16_t fill,
davidprentice 0:8ee30e15ac7b 256 uint16_t textcolor, char *label, uint8_t textsize);
davidprentice 0:8ee30e15ac7b 257 void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w,
davidprentice 0:8ee30e15ac7b 258 uint16_t h, uint16_t outline, uint16_t fill,
davidprentice 0:8ee30e15ac7b 259 uint16_t textcolor, char *label, uint8_t textsize_x,
davidprentice 0:8ee30e15ac7b 260 uint8_t textsize_y);
davidprentice 0:8ee30e15ac7b 261 // New/alt initButton() uses upper-left corner & size
davidprentice 0:8ee30e15ac7b 262 void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w,
davidprentice 0:8ee30e15ac7b 263 uint16_t h, uint16_t outline, uint16_t fill,
davidprentice 0:8ee30e15ac7b 264 uint16_t textcolor, char *label, uint8_t textsize);
davidprentice 0:8ee30e15ac7b 265 void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w,
davidprentice 0:8ee30e15ac7b 266 uint16_t h, uint16_t outline, uint16_t fill,
davidprentice 0:8ee30e15ac7b 267 uint16_t textcolor, char *label, uint8_t textsize_x,
davidprentice 0:8ee30e15ac7b 268 uint8_t textsize_y);
davidprentice 0:8ee30e15ac7b 269 void drawButton(bool inverted = false);
davidprentice 0:8ee30e15ac7b 270 bool contains(int16_t x, int16_t y);
davidprentice 0:8ee30e15ac7b 271
davidprentice 0:8ee30e15ac7b 272 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 273 /*!
davidprentice 0:8ee30e15ac7b 274 @brief Sets button state, should be done by some touch function
davidprentice 0:8ee30e15ac7b 275 @param p True for pressed, false for not.
davidprentice 0:8ee30e15ac7b 276 */
davidprentice 0:8ee30e15ac7b 277 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 278 void press(bool p) {
davidprentice 0:8ee30e15ac7b 279 laststate = currstate;
davidprentice 0:8ee30e15ac7b 280 currstate = p;
davidprentice 0:8ee30e15ac7b 281 }
davidprentice 0:8ee30e15ac7b 282
davidprentice 0:8ee30e15ac7b 283 bool justPressed();
davidprentice 0:8ee30e15ac7b 284 bool justReleased();
davidprentice 0:8ee30e15ac7b 285
davidprentice 0:8ee30e15ac7b 286 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 287 /*!
davidprentice 0:8ee30e15ac7b 288 @brief Query whether the button is currently pressed
davidprentice 0:8ee30e15ac7b 289 @returns True if pressed
davidprentice 0:8ee30e15ac7b 290 */
davidprentice 0:8ee30e15ac7b 291 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 292 bool isPressed(void) { return currstate; };
davidprentice 0:8ee30e15ac7b 293
davidprentice 0:8ee30e15ac7b 294 private:
davidprentice 0:8ee30e15ac7b 295 Adafruit_GFX *_gfx;
davidprentice 0:8ee30e15ac7b 296 int16_t _x1, _y1; // Coordinates of top-left corner
davidprentice 0:8ee30e15ac7b 297 uint16_t _w, _h;
davidprentice 0:8ee30e15ac7b 298 uint8_t _textsize_x;
davidprentice 0:8ee30e15ac7b 299 uint8_t _textsize_y;
davidprentice 0:8ee30e15ac7b 300 uint16_t _outlinecolor, _fillcolor, _textcolor;
davidprentice 0:8ee30e15ac7b 301 char _label[10];
davidprentice 0:8ee30e15ac7b 302
davidprentice 0:8ee30e15ac7b 303 bool currstate, laststate;
davidprentice 0:8ee30e15ac7b 304 };
davidprentice 0:8ee30e15ac7b 305
davidprentice 0:8ee30e15ac7b 306 /// A GFX 1-bit canvas context for graphics
davidprentice 0:8ee30e15ac7b 307 class GFXcanvas1 : public Adafruit_GFX {
davidprentice 0:8ee30e15ac7b 308 public:
davidprentice 0:8ee30e15ac7b 309 GFXcanvas1(uint16_t w, uint16_t h);
davidprentice 0:8ee30e15ac7b 310 ~GFXcanvas1(void);
davidprentice 0:8ee30e15ac7b 311 void drawPixel(int16_t x, int16_t y, uint16_t color);
davidprentice 0:8ee30e15ac7b 312 void fillScreen(uint16_t color);
davidprentice 0:8ee30e15ac7b 313 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 314 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 315 bool getPixel(int16_t x, int16_t y) const;
davidprentice 0:8ee30e15ac7b 316 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 317 /*!
davidprentice 0:8ee30e15ac7b 318 @brief Get a pointer to the internal buffer memory
davidprentice 0:8ee30e15ac7b 319 @returns A pointer to the allocated buffer
davidprentice 0:8ee30e15ac7b 320 */
davidprentice 0:8ee30e15ac7b 321 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 322 uint8_t *getBuffer(void) const { return buffer; }
davidprentice 0:8ee30e15ac7b 323
davidprentice 0:8ee30e15ac7b 324 protected:
davidprentice 0:8ee30e15ac7b 325 bool getRawPixel(int16_t x, int16_t y) const;
davidprentice 0:8ee30e15ac7b 326 void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 327 void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 328
davidprentice 0:8ee30e15ac7b 329 private:
davidprentice 0:8ee30e15ac7b 330 uint8_t *buffer;
davidprentice 0:8ee30e15ac7b 331
davidprentice 0:8ee30e15ac7b 332 #ifdef __AVR__
davidprentice 0:8ee30e15ac7b 333 // Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
davidprentice 0:8ee30e15ac7b 334 static const uint8_t PROGMEM GFXsetBit[], GFXclrBit[];
davidprentice 0:8ee30e15ac7b 335 #endif
davidprentice 0:8ee30e15ac7b 336 };
davidprentice 0:8ee30e15ac7b 337
davidprentice 0:8ee30e15ac7b 338 /// A GFX 8-bit canvas context for graphics
davidprentice 0:8ee30e15ac7b 339 class GFXcanvas8 : public Adafruit_GFX {
davidprentice 0:8ee30e15ac7b 340 public:
davidprentice 0:8ee30e15ac7b 341 GFXcanvas8(uint16_t w, uint16_t h);
davidprentice 0:8ee30e15ac7b 342 ~GFXcanvas8(void);
davidprentice 0:8ee30e15ac7b 343 void drawPixel(int16_t x, int16_t y, uint16_t color);
davidprentice 0:8ee30e15ac7b 344 void fillScreen(uint16_t color);
davidprentice 0:8ee30e15ac7b 345 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 346 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 347 uint8_t getPixel(int16_t x, int16_t y) const;
davidprentice 0:8ee30e15ac7b 348 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 349 /*!
davidprentice 0:8ee30e15ac7b 350 @brief Get a pointer to the internal buffer memory
davidprentice 0:8ee30e15ac7b 351 @returns A pointer to the allocated buffer
davidprentice 0:8ee30e15ac7b 352 */
davidprentice 0:8ee30e15ac7b 353 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 354 uint8_t *getBuffer(void) const { return buffer; }
davidprentice 0:8ee30e15ac7b 355
davidprentice 0:8ee30e15ac7b 356 protected:
davidprentice 0:8ee30e15ac7b 357 uint8_t getRawPixel(int16_t x, int16_t y) const;
davidprentice 0:8ee30e15ac7b 358 void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 359 void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 360
davidprentice 0:8ee30e15ac7b 361 private:
davidprentice 0:8ee30e15ac7b 362 uint8_t *buffer;
davidprentice 0:8ee30e15ac7b 363 };
davidprentice 0:8ee30e15ac7b 364
davidprentice 0:8ee30e15ac7b 365 /// A GFX 16-bit canvas context for graphics
davidprentice 0:8ee30e15ac7b 366 class GFXcanvas16 : public Adafruit_GFX {
davidprentice 0:8ee30e15ac7b 367 public:
davidprentice 0:8ee30e15ac7b 368 GFXcanvas16(uint16_t w, uint16_t h);
davidprentice 0:8ee30e15ac7b 369 ~GFXcanvas16(void);
davidprentice 0:8ee30e15ac7b 370 void drawPixel(int16_t x, int16_t y, uint16_t color);
davidprentice 0:8ee30e15ac7b 371 void fillScreen(uint16_t color);
davidprentice 0:8ee30e15ac7b 372 void byteSwap(void);
davidprentice 0:8ee30e15ac7b 373 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 374 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 375 uint16_t getPixel(int16_t x, int16_t y) const;
davidprentice 0:8ee30e15ac7b 376 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 377 /*!
davidprentice 0:8ee30e15ac7b 378 @brief Get a pointer to the internal buffer memory
davidprentice 0:8ee30e15ac7b 379 @returns A pointer to the allocated buffer
davidprentice 0:8ee30e15ac7b 380 */
davidprentice 0:8ee30e15ac7b 381 /**********************************************************************/
davidprentice 0:8ee30e15ac7b 382 uint16_t *getBuffer(void) const { return buffer; }
davidprentice 0:8ee30e15ac7b 383
davidprentice 0:8ee30e15ac7b 384 protected:
davidprentice 0:8ee30e15ac7b 385 uint16_t getRawPixel(int16_t x, int16_t y) const;
davidprentice 0:8ee30e15ac7b 386 void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
davidprentice 0:8ee30e15ac7b 387 void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
davidprentice 0:8ee30e15ac7b 388
davidprentice 0:8ee30e15ac7b 389 private:
davidprentice 0:8ee30e15ac7b 390 uint16_t *buffer;
davidprentice 0:8ee30e15ac7b 391 };
davidprentice 0:8ee30e15ac7b 392
davidprentice 0:8ee30e15ac7b 393 #endif // _ADAFRUIT_GFX_H