Adafruit_GFX.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef _ADAFRUIT_GFX_H
  2. #define _ADAFRUIT_GFX_H
  3. #if ARDUINO >= 100
  4. #include "Arduino.h"
  5. #include "Print.h"
  6. #else
  7. #include "WProgram.h"
  8. #endif
  9. #include "gfxfont.h"
  10. #define adagfxswap(a, b) { int16_t t = a; a = b; b = t; }
  11. #if !defined(ESP8266)
  12. #define swap(a, b) adagfxswap(a, b)
  13. #endif
  14. class Adafruit_GFX : public Print {
  15. public:
  16. Adafruit_GFX(int16_t w, int16_t h); // Constructor
  17. // This MUST be defined by the subclass:
  18. virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
  19. // These MAY be overridden by the subclass to provide device-specific
  20. // optimized code. Otherwise 'generic' versions are used.
  21. virtual void
  22. drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
  23. drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
  24. drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
  25. drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
  26. fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
  27. fillScreen(uint16_t color),
  28. invertDisplay(boolean i);
  29. // These exist only with Adafruit_GFX (no subclass overrides)
  30. void
  31. drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
  32. drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
  33. uint16_t color),
  34. fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
  35. fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
  36. int16_t delta, uint16_t color),
  37. drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  38. int16_t x2, int16_t y2, uint16_t color),
  39. fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  40. int16_t x2, int16_t y2, uint16_t color),
  41. drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
  42. int16_t radius, uint16_t color),
  43. fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
  44. int16_t radius, uint16_t color),
  45. drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
  46. int16_t w, int16_t h, uint16_t color),
  47. drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
  48. int16_t w, int16_t h, uint16_t color, uint16_t bg),
  49. drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
  50. int16_t w, int16_t h, uint16_t color),
  51. drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
  52. uint16_t bg, uint8_t size),
  53. setCursor(int16_t x, int16_t y),
  54. setTextColor(uint16_t c),
  55. setTextColor(uint16_t c, uint16_t bg),
  56. setTextSize(uint8_t s),
  57. setTextWrap(boolean w),
  58. setRotation(uint8_t r),
  59. cp437(boolean x=true),
  60. setFont(const GFXfont *f = NULL),
  61. getTextBounds(char *string, int16_t x, int16_t y,
  62. int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
  63. getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
  64. int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
  65. #if ARDUINO >= 100
  66. virtual size_t write(uint8_t);
  67. #else
  68. virtual void write(uint8_t);
  69. #endif
  70. int16_t height(void) const;
  71. int16_t width(void) const;
  72. uint8_t getRotation(void) const;
  73. // get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
  74. int16_t getCursorX(void) const;
  75. int16_t getCursorY(void) const;
  76. protected:
  77. const int16_t
  78. WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
  79. int16_t
  80. _width, _height, // Display w/h as modified by current rotation
  81. cursor_x, cursor_y;
  82. uint16_t
  83. textcolor, textbgcolor;
  84. uint8_t
  85. textsize,
  86. rotation;
  87. boolean
  88. wrap, // If set, 'wrap' text at right edge of display
  89. _cp437; // If set, use correct CP437 charset (default is off)
  90. GFXfont
  91. *gfxFont;
  92. };
  93. class Adafruit_GFX_Button {
  94. public:
  95. Adafruit_GFX_Button(void);
  96. void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
  97. uint8_t w, uint8_t h, uint16_t outline, uint16_t fill,
  98. uint16_t textcolor, char *label, uint8_t textsize);
  99. void drawButton(boolean inverted = false);
  100. boolean contains(int16_t x, int16_t y);
  101. void press(boolean p);
  102. boolean isPressed();
  103. boolean justPressed();
  104. boolean justReleased();
  105. private:
  106. Adafruit_GFX *_gfx;
  107. int16_t _x, _y;
  108. uint16_t _w, _h;
  109. uint8_t _textsize;
  110. uint16_t _outlinecolor, _fillcolor, _textcolor;
  111. char _label[10];
  112. boolean currstate, laststate;
  113. };
  114. #endif // _ADAFRUIT_GFX_H