Adafruit_GFX.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /******************************************************************
  2. This is the core graphics library for all our displays, providing
  3. basic graphics primitives (points, lines, circles, etc.). It needs
  4. to be paired with a hardware-specific library for each display
  5. device we carry (handling the lower-level functions).
  6. Adafruit invests time and resources providing this open
  7. source code, please support Adafruit and open-source hardware
  8. by purchasing products from Adafruit!
  9. Written by Limor Fried/Ladyada for Adafruit Industries.
  10. BSD license, check license.txt for more information.
  11. All text above must be included in any redistribution.
  12. ******************************************************************/
  13. #ifndef _ADAFRUIT_GFX_H
  14. #define _ADAFRUIT_GFX_H
  15. #if ARDUINO >= 100
  16. #include "Arduino.h"
  17. #include "Print.h"
  18. #else
  19. #include "WProgram.h"
  20. #endif
  21. #define swap(a, b) { int16_t t = a; a = b; b = t; }
  22. class Adafruit_GFX : public Print {
  23. public:
  24. //Adafruit_GFX();
  25. // i have no idea why we have to formally call the constructor. kinda sux
  26. void constructor(int16_t w, int16_t h);
  27. // this must be defined by the subclass
  28. virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
  29. virtual void invertDisplay(boolean i);
  30. // these are 'generic' drawing functions, so we can share them!
  31. virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  32. uint16_t color);
  33. virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
  34. virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
  35. virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h,
  36. uint16_t color);
  37. virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
  38. uint16_t color);
  39. virtual void fillScreen(uint16_t color);
  40. void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
  41. void drawCircleHelper(int16_t x0, int16_t y0,
  42. int16_t r, uint8_t cornername, uint16_t color);
  43. void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
  44. void fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
  45. uint8_t cornername, int16_t delta, uint16_t color);
  46. void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  47. int16_t x2, int16_t y2, uint16_t color);
  48. void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  49. int16_t x2, int16_t y2, uint16_t color);
  50. void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
  51. int16_t radius, uint16_t color);
  52. void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
  53. int16_t radius, uint16_t color);
  54. void drawBitmap(int16_t x, int16_t y,
  55. const uint8_t *bitmap, int16_t w, int16_t h,
  56. uint16_t color);
  57. void drawChar(int16_t x, int16_t y, unsigned char c,
  58. uint16_t color, uint16_t bg, uint8_t size);
  59. #if ARDUINO >= 100
  60. virtual size_t write(uint8_t);
  61. #else
  62. virtual void write(uint8_t);
  63. #endif
  64. void setCursor(int16_t x, int16_t y);
  65. void setTextColor(uint16_t c);
  66. void setTextColor(uint16_t c, uint16_t bg);
  67. void setTextSize(uint8_t s);
  68. void setTextWrap(boolean w);
  69. int16_t height(void);
  70. int16_t width(void);
  71. void setRotation(uint8_t r);
  72. uint8_t getRotation(void);
  73. protected:
  74. int16_t WIDTH, HEIGHT; // this is the 'raw' display w/h - never changes
  75. int16_t _width, _height; // dependent on rotation
  76. int16_t cursor_x, cursor_y;
  77. uint16_t textcolor, textbgcolor;
  78. uint8_t textsize;
  79. uint8_t rotation;
  80. boolean wrap; // If set, 'wrap' text at right edge of display
  81. };
  82. #endif