Clone of the Adafruit Graphics Library

Fork of Adafruit_GFX by justin kim

Committer:
SomeRandomBloke
Date:
Fri Jul 17 09:37:26 2015 +0000
Revision:
2:a7d4ac7ed08a
Parent:
1:e67555532f16
Child:
3:04b9498d00d8
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 2:a7d4ac7ed08a 1 /*
SomeRandomBloke 2:a7d4ac7ed08a 2 This is the core graphics library for all our displays, providing a common
SomeRandomBloke 2:a7d4ac7ed08a 3 set of graphics primitives (points, lines, circles, etc.). It needs to be
SomeRandomBloke 2:a7d4ac7ed08a 4 paired with a hardware-specific library for each display device we carry
SomeRandomBloke 2:a7d4ac7ed08a 5 (to handle the lower-level functions).
SomeRandomBloke 2:a7d4ac7ed08a 6
SomeRandomBloke 2:a7d4ac7ed08a 7 Adafruit invests time and resources providing this open source code, please
SomeRandomBloke 2:a7d4ac7ed08a 8 support Adafruit & open-source hardware by purchasing products from Adafruit!
SomeRandomBloke 2:a7d4ac7ed08a 9
SomeRandomBloke 2:a7d4ac7ed08a 10 Copyright (c) 2013 Adafruit Industries. All rights reserved.
SomeRandomBloke 2:a7d4ac7ed08a 11
SomeRandomBloke 2:a7d4ac7ed08a 12 Redistribution and use in source and binary forms, with or without
SomeRandomBloke 2:a7d4ac7ed08a 13 modification, are permitted provided that the following conditions are met:
SomeRandomBloke 0:08cfbae05724 14
SomeRandomBloke 2:a7d4ac7ed08a 15 - Redistributions of source code must retain the above copyright notice,
SomeRandomBloke 2:a7d4ac7ed08a 16 this list of conditions and the following disclaimer.
SomeRandomBloke 2:a7d4ac7ed08a 17 - Redistributions in binary form must reproduce the above copyright notice,
SomeRandomBloke 2:a7d4ac7ed08a 18 this list of conditions and the following disclaimer in the documentation
SomeRandomBloke 2:a7d4ac7ed08a 19 and/or other materials provided with the distribution.
SomeRandomBloke 0:08cfbae05724 20
SomeRandomBloke 2:a7d4ac7ed08a 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
SomeRandomBloke 2:a7d4ac7ed08a 22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
SomeRandomBloke 2:a7d4ac7ed08a 23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
SomeRandomBloke 2:a7d4ac7ed08a 24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
SomeRandomBloke 2:a7d4ac7ed08a 25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
SomeRandomBloke 2:a7d4ac7ed08a 26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SomeRandomBloke 2:a7d4ac7ed08a 27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
SomeRandomBloke 2:a7d4ac7ed08a 28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
SomeRandomBloke 2:a7d4ac7ed08a 29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
SomeRandomBloke 2:a7d4ac7ed08a 30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
SomeRandomBloke 2:a7d4ac7ed08a 31 POSSIBILITY OF SUCH DAMAGE.
SomeRandomBloke 2:a7d4ac7ed08a 32 */
SomeRandomBloke 0:08cfbae05724 33
SomeRandomBloke 0:08cfbae05724 34 #ifndef _ADAFRUIT_GFX_H
SomeRandomBloke 0:08cfbae05724 35 #define _ADAFRUIT_GFX_H
SomeRandomBloke 0:08cfbae05724 36
SomeRandomBloke 0:08cfbae05724 37 #include "mbed.h"
SomeRandomBloke 0:08cfbae05724 38 #include "Stream.h"
SomeRandomBloke 0:08cfbae05724 39
SomeRandomBloke 0:08cfbae05724 40
SomeRandomBloke 0:08cfbae05724 41 #define swap(a, b) { int16_t t = a; a = b; b = t; }
SomeRandomBloke 0:08cfbae05724 42 #define boolean bool
SomeRandomBloke 0:08cfbae05724 43
SomeRandomBloke 1:e67555532f16 44 class Adafruit_GFX : public Stream
SomeRandomBloke 0:08cfbae05724 45 {
SomeRandomBloke 0:08cfbae05724 46 public:
SomeRandomBloke 0:08cfbae05724 47
SomeRandomBloke 0:08cfbae05724 48 //Adafruit_GFX();
SomeRandomBloke 1:e67555532f16 49 Adafruit_GFX(int16_t w, int16_t h); // Constructor
SomeRandomBloke 0:08cfbae05724 50 // i have no idea why we have to formally call the constructor. kinda sux
SomeRandomBloke 1:e67555532f16 51 //void constructor(int16_t w, int16_t h);
SomeRandomBloke 0:08cfbae05724 52
SomeRandomBloke 0:08cfbae05724 53 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
SomeRandomBloke 0:08cfbae05724 54 virtual void invertDisplay(boolean i);
SomeRandomBloke 0:08cfbae05724 55
SomeRandomBloke 0:08cfbae05724 56 // these are 'generic' drawing functions, so we can share them!
SomeRandomBloke 0:08cfbae05724 57 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,uint16_t color);
SomeRandomBloke 0:08cfbae05724 58 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
SomeRandomBloke 0:08cfbae05724 59 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
SomeRandomBloke 0:08cfbae05724 60 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
SomeRandomBloke 0:08cfbae05724 61 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
SomeRandomBloke 0:08cfbae05724 62 virtual void fillScreen(uint16_t color);
SomeRandomBloke 0:08cfbae05724 63
SomeRandomBloke 0:08cfbae05724 64 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
SomeRandomBloke 0:08cfbae05724 65 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
SomeRandomBloke 0:08cfbae05724 66 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
SomeRandomBloke 0:08cfbae05724 67 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
SomeRandomBloke 0:08cfbae05724 68
SomeRandomBloke 0:08cfbae05724 69 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 70 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 71 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
SomeRandomBloke 0:08cfbae05724 72 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
SomeRandomBloke 0:08cfbae05724 73
SomeRandomBloke 0:08cfbae05724 74 void drawBitmap(int16_t x, int16_t y,
SomeRandomBloke 0:08cfbae05724 75 const uint8_t *bitmap, int16_t w, int16_t h,
SomeRandomBloke 0:08cfbae05724 76 uint16_t color);
SomeRandomBloke 0:08cfbae05724 77 void drawChar(int16_t x, int16_t y, unsigned char c,
SomeRandomBloke 0:08cfbae05724 78 uint16_t color, uint16_t bg, uint8_t size);
SomeRandomBloke 0:08cfbae05724 79
SomeRandomBloke 0:08cfbae05724 80 void setCursor(int16_t x, int16_t y);
SomeRandomBloke 0:08cfbae05724 81 void setTextColor(uint16_t c);
SomeRandomBloke 0:08cfbae05724 82 void setTextColor(uint16_t c, uint16_t bg);
SomeRandomBloke 0:08cfbae05724 83 void setTextSize(uint8_t s);
SomeRandomBloke 0:08cfbae05724 84 void setTextWrap(boolean w);
SomeRandomBloke 0:08cfbae05724 85
SomeRandomBloke 0:08cfbae05724 86 int16_t height(void);
SomeRandomBloke 0:08cfbae05724 87 int16_t width(void);
SomeRandomBloke 0:08cfbae05724 88
SomeRandomBloke 0:08cfbae05724 89 void setRotation(uint8_t r);
SomeRandomBloke 0:08cfbae05724 90 uint8_t getRotation(void);
SomeRandomBloke 0:08cfbae05724 91
SomeRandomBloke 0:08cfbae05724 92 protected:
SomeRandomBloke 0:08cfbae05724 93 virtual int _putc(int value);
SomeRandomBloke 0:08cfbae05724 94 virtual int _getc();
SomeRandomBloke 0:08cfbae05724 95
SomeRandomBloke 1:e67555532f16 96 const int16_t WIDTH, HEIGHT; // this is the 'raw' display w/h - never changes
SomeRandomBloke 0:08cfbae05724 97 int16_t _width, _height; // dependent on rotation
SomeRandomBloke 0:08cfbae05724 98 int16_t cursor_x, cursor_y;
SomeRandomBloke 0:08cfbae05724 99 uint16_t textcolor, textbgcolor;
SomeRandomBloke 0:08cfbae05724 100 uint8_t textsize;
SomeRandomBloke 0:08cfbae05724 101 uint8_t rotation;
SomeRandomBloke 0:08cfbae05724 102 boolean wrap; // If set, 'wrap' text at right edge of display
SomeRandomBloke 0:08cfbae05724 103 };
SomeRandomBloke 0:08cfbae05724 104
SomeRandomBloke 0:08cfbae05724 105 #endif