2012-03-12 20:32:18 -04:00
# ifndef _ADAFRUIT_GFX_H
# define _ADAFRUIT_GFX_H
# if ARDUINO >= 100
# include "Arduino.h"
# include "Print.h"
# else
# include "WProgram.h"
# endif
2015-12-22 12:02:43 -08:00
# include "gfxfont.h"
2015-11-24 00:06:48 -05:00
2018-07-14 15:21:57 -04:00
/// A generic graphics superclass that can handle all sorts of drawing. At a minimum you can subclass and provide drawPixel(). At a maximum you can do a ton of overriding to optimize. Used for any/all Adafruit displays!
2012-03-16 14:25:07 -04:00
class Adafruit_GFX : public Print {
2013-07-05 11:37:02 -07:00
public :
2012-03-16 14:25:07 -04:00
2013-07-05 11:37:02 -07:00
Adafruit_GFX ( int16_t w , int16_t h ) ; // Constructor
2012-03-12 20:32:18 -04:00
2013-07-05 11:37:02 -07:00
// This MUST be defined by the subclass:
2018-07-14 15:21:57 -04:00
virtual void drawPixel ( int16_t x , int16_t y , uint16_t color ) = 0 ; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
2012-03-12 20:32:18 -04:00
2017-02-23 03:11:09 +02:00
// TRANSACTION API / CORE DRAW API
// These MAY be overridden by the subclass to provide device-specific
// optimized code. Otherwise 'generic' versions are used.
virtual void startWrite ( void ) ;
virtual void writePixel ( int16_t x , int16_t y , uint16_t color ) ;
virtual void writeFillRect ( int16_t x , int16_t y , int16_t w , int16_t h , uint16_t color ) ;
virtual void writeFastVLine ( int16_t x , int16_t y , int16_t h , uint16_t color ) ;
virtual void writeFastHLine ( int16_t x , int16_t y , int16_t w , uint16_t color ) ;
virtual void writeLine ( int16_t x0 , int16_t y0 , int16_t x1 , int16_t y1 , uint16_t color ) ;
virtual void endWrite ( void ) ;
// CONTROL API
// These MAY be overridden by the subclass to provide device-specific
// optimized code. Otherwise 'generic' versions are used.
virtual void setRotation ( uint8_t r ) ;
virtual void invertDisplay ( boolean i ) ;
// BASIC DRAW API
2013-07-05 11:37:02 -07:00
// These MAY be overridden by the subclass to provide device-specific
// optimized code. Otherwise 'generic' versions are used.
virtual void
2017-02-23 03:11:09 +02:00
// It's good to implement those, even if using transaction API
2013-07-05 11:37:02 -07:00
drawFastVLine ( int16_t x , int16_t y , int16_t h , uint16_t color ) ,
drawFastHLine ( int16_t x , int16_t y , int16_t w , uint16_t color ) ,
fillRect ( int16_t x , int16_t y , int16_t w , int16_t h , uint16_t color ) ,
fillScreen ( uint16_t color ) ,
2017-02-23 03:11:09 +02:00
// Optional and probably not necessary to change
drawLine ( int16_t x0 , int16_t y0 , int16_t x1 , int16_t y1 , uint16_t color ) ,
drawRect ( int16_t x , int16_t y , int16_t w , int16_t h , uint16_t color ) ;
2012-04-09 20:46:33 -07:00
2013-07-05 11:37:02 -07:00
// These exist only with Adafruit_GFX (no subclass overrides)
void
drawCircle ( int16_t x0 , int16_t y0 , int16_t r , uint16_t color ) ,
drawCircleHelper ( int16_t x0 , int16_t y0 , int16_t r , uint8_t cornername ,
uint16_t color ) ,
fillCircle ( int16_t x0 , int16_t y0 , int16_t r , uint16_t color ) ,
fillCircleHelper ( int16_t x0 , int16_t y0 , int16_t r , uint8_t cornername ,
int16_t delta , uint16_t color ) ,
drawTriangle ( int16_t x0 , int16_t y0 , int16_t x1 , int16_t y1 ,
int16_t x2 , int16_t y2 , uint16_t color ) ,
fillTriangle ( int16_t x0 , int16_t y0 , int16_t x1 , int16_t y1 ,
int16_t x2 , int16_t y2 , uint16_t color ) ,
drawRoundRect ( int16_t x0 , int16_t y0 , int16_t w , int16_t h ,
int16_t radius , uint16_t color ) ,
fillRoundRect ( int16_t x0 , int16_t y0 , int16_t w , int16_t h ,
int16_t radius , uint16_t color ) ,
2017-05-09 15:35:44 -07:00
drawBitmap ( int16_t x , int16_t y , const uint8_t bitmap [ ] ,
2013-07-05 11:37:02 -07:00
int16_t w , int16_t h , uint16_t color ) ,
2017-05-09 15:35:44 -07:00
drawBitmap ( int16_t x , int16_t y , const uint8_t bitmap [ ] ,
2014-09-21 17:35:37 -07:00
int16_t w , int16_t h , uint16_t color , uint16_t bg ) ,
2015-12-27 21:29:50 -08:00
drawBitmap ( int16_t x , int16_t y , uint8_t * bitmap ,
int16_t w , int16_t h , uint16_t color ) ,
drawBitmap ( int16_t x , int16_t y , uint8_t * bitmap ,
int16_t w , int16_t h , uint16_t color , uint16_t bg ) ,
2017-05-09 15:35:44 -07:00
drawXBitmap ( int16_t x , int16_t y , const uint8_t bitmap [ ] ,
2014-04-15 21:05:51 +02:00
int16_t w , int16_t h , uint16_t color ) ,
2017-05-09 15:35:44 -07:00
drawGrayscaleBitmap ( int16_t x , int16_t y , const uint8_t bitmap [ ] ,
2017-05-05 19:57:52 -07:00
int16_t w , int16_t h ) ,
drawGrayscaleBitmap ( int16_t x , int16_t y , uint8_t * bitmap ,
int16_t w , int16_t h ) ,
drawGrayscaleBitmap ( int16_t x , int16_t y ,
2017-05-09 15:35:44 -07:00
const uint8_t bitmap [ ] , const uint8_t mask [ ] ,
2017-05-06 12:06:51 -07:00
int16_t w , int16_t h ) ,
2017-05-05 19:57:52 -07:00
drawGrayscaleBitmap ( int16_t x , int16_t y ,
uint8_t * bitmap , uint8_t * mask , int16_t w , int16_t h ) ,
2017-05-09 15:35:44 -07:00
drawRGBBitmap ( int16_t x , int16_t y , const uint16_t bitmap [ ] ,
2017-05-05 19:57:52 -07:00
int16_t w , int16_t h ) ,
drawRGBBitmap ( int16_t x , int16_t y , uint16_t * bitmap ,
int16_t w , int16_t h ) ,
drawRGBBitmap ( int16_t x , int16_t y ,
2017-05-09 15:35:44 -07:00
const uint16_t bitmap [ ] , const uint8_t mask [ ] ,
2017-05-06 12:06:51 -07:00
int16_t w , int16_t h ) ,
2017-05-05 19:57:52 -07:00
drawRGBBitmap ( int16_t x , int16_t y ,
uint16_t * bitmap , uint8_t * mask , int16_t w , int16_t h ) ,
2013-07-05 11:37:02 -07:00
drawChar ( int16_t x , int16_t y , unsigned char c , uint16_t color ,
uint16_t bg , uint8_t size ) ,
setCursor ( int16_t x , int16_t y ) ,
setTextColor ( uint16_t c ) ,
setTextColor ( uint16_t c , uint16_t bg ) ,
setTextSize ( uint8_t s ) ,
setTextWrap ( boolean w ) ,
2015-12-22 12:02:43 -08:00
cp437 ( boolean x = true ) ,
setFont ( const GFXfont * f = NULL ) ,
getTextBounds ( char * string , int16_t x , int16_t y ,
int16_t * x1 , int16_t * y1 , uint16_t * w , uint16_t * h ) ,
getTextBounds ( const __FlashStringHelper * s , int16_t x , int16_t y ,
int16_t * x1 , int16_t * y1 , uint16_t * w , uint16_t * h ) ;
2012-04-09 20:46:33 -07:00
2012-03-12 20:32:18 -04:00
# if ARDUINO >= 100
virtual size_t write ( uint8_t ) ;
# else
virtual void write ( uint8_t ) ;
# endif
2013-07-18 23:21:21 -04:00
int16_t height ( void ) const ;
int16_t width ( void ) const ;
2012-03-12 20:32:18 -04:00
2013-07-18 23:21:21 -04:00
uint8_t getRotation ( void ) const ;
2012-03-12 20:32:18 -04:00
2015-04-25 19:20:49 +02:00
// get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
int16_t getCursorX ( void ) const ;
int16_t getCursorY ( void ) const ;
2012-03-12 20:32:18 -04:00
protected :
2017-05-05 19:57:52 -07:00
void
charBounds ( char c , int16_t * x , int16_t * y ,
int16_t * minx , int16_t * miny , int16_t * maxx , int16_t * maxy ) ;
2013-07-05 17:32:41 -04:00
const int16_t
2018-07-14 13:05:06 -04:00
WIDTH , ///< This is the 'raw' display width - never changes
HEIGHT ; ///< This is the 'raw' display height - never changes
2013-07-05 11:37:02 -07:00
int16_t
2018-07-14 13:05:06 -04:00
_width , ///< Display width as modified by current rotation
_height , ///< Display height as modified by current rotation
cursor_x , ///< x location to start print()ing text
cursor_y ; ///< y location to start print()ing text
2013-07-05 11:37:02 -07:00
uint16_t
2018-07-14 13:05:06 -04:00
textcolor , ///< 16-bit background color for print()
textbgcolor ; ///< 16-bit text color for print()
2013-07-05 11:37:02 -07:00
uint8_t
2018-07-14 13:05:06 -04:00
textsize , ///< Desired magnification of text to print()
rotation ; ///< Display rotation (0 thru 3)
2013-07-05 11:37:02 -07:00
boolean
2018-07-14 13:05:06 -04:00
wrap , ///< If set, 'wrap' text at right edge of display
_cp437 ; ///< If set, use correct CP437 charset (default is off)
2015-12-22 12:02:43 -08:00
GFXfont
2018-07-14 13:05:06 -04:00
* gfxFont ; ///< Pointer to special font
2012-03-12 20:32:18 -04:00
} ;
2018-07-14 15:21:57 -04:00
/// A simple drawn button UI element
2015-05-20 13:55:54 -04:00
class Adafruit_GFX_Button {
public :
Adafruit_GFX_Button ( void ) ;
2017-03-07 10:24:06 -08:00
// "Classic" initButton() uses center & size
2015-12-22 12:02:43 -08:00
void initButton ( Adafruit_GFX * gfx , int16_t x , int16_t y ,
2017-03-07 10:24:06 -08:00
uint16_t w , uint16_t h , uint16_t outline , uint16_t fill ,
uint16_t textcolor , char * label , uint8_t textsize ) ;
// New/alt initButton() uses upper-left corner & size
void initButtonUL ( Adafruit_GFX * gfx , int16_t x1 , int16_t y1 ,
uint16_t w , uint16_t h , uint16_t outline , uint16_t fill ,
2015-12-22 12:02:43 -08:00
uint16_t textcolor , char * label , uint8_t textsize ) ;
2015-05-20 13:55:54 -04:00
void drawButton ( boolean inverted = false ) ;
boolean contains ( int16_t x , int16_t y ) ;
void press ( boolean p ) ;
boolean isPressed ( ) ;
boolean justPressed ( ) ;
boolean justReleased ( ) ;
private :
Adafruit_GFX * _gfx ;
2017-03-07 10:24:06 -08:00
int16_t _x1 , _y1 ; // Coordinates of top-left corner
uint16_t _w , _h ;
uint8_t _textsize ;
uint16_t _outlinecolor , _fillcolor , _textcolor ;
char _label [ 10 ] ;
2015-05-20 13:55:54 -04:00
boolean currstate , laststate ;
} ;
2018-07-14 15:21:57 -04:00
/// A GFX 1-bit canvas context for graphics
2015-12-28 10:58:40 -08:00
class GFXcanvas1 : public Adafruit_GFX {
public :
GFXcanvas1 ( uint16_t w , uint16_t h ) ;
~ GFXcanvas1 ( void ) ;
2017-05-05 19:57:52 -07:00
void drawPixel ( int16_t x , int16_t y , uint16_t color ) ,
fillScreen ( uint16_t color ) ;
2017-05-04 22:06:09 -07:00
uint8_t * getBuffer ( void ) ;
private :
uint8_t * buffer ;
} ;
2018-07-14 15:21:57 -04:00
/// A GFX 8-bit canvas context for graphics
2017-05-04 22:06:09 -07:00
class GFXcanvas8 : public Adafruit_GFX {
public :
GFXcanvas8 ( uint16_t w , uint16_t h ) ;
~ GFXcanvas8 ( void ) ;
2017-05-05 19:57:52 -07:00
void drawPixel ( int16_t x , int16_t y , uint16_t color ) ,
fillScreen ( uint16_t color ) ,
writeFastHLine ( int16_t x , int16_t y , int16_t w , uint16_t color ) ;
2015-12-28 10:58:40 -08:00
uint8_t * getBuffer ( void ) ;
private :
uint8_t * buffer ;
} ;
2018-07-14 15:21:57 -04:00
/// A GFX 16-bit canvas context for graphics
2015-12-28 10:58:40 -08:00
class GFXcanvas16 : public Adafruit_GFX {
2017-05-04 22:06:09 -07:00
public :
2015-12-28 10:58:40 -08:00
GFXcanvas16 ( uint16_t w , uint16_t h ) ;
~ GFXcanvas16 ( void ) ;
void drawPixel ( int16_t x , int16_t y , uint16_t color ) ,
fillScreen ( uint16_t color ) ;
uint16_t * getBuffer ( void ) ;
private :
uint16_t * buffer ;
} ;
2013-07-05 11:37:02 -07:00
# endif // _ADAFRUIT_GFX_H