A first port of the excellent Adafruit GFX library

Dependents:   Adafruit_GFX

Committer:
SomeRandomBloke
Date:
Tue Mar 26 23:08:53 2013 +0000
Revision:
0:08cfbae05724
Child:
1:e67555532f16
New commit

Who changed what in which revision?

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