Clone of the Adafruit Graphics Library

Fork of Adafruit_GFX by justin kim

Committer:
Cognoscan
Date:
Wed Dec 16 18:43:48 2015 +0000
Revision:
5:ba163fcbfbf1
Parent:
4:256d9b541ab0
Updated to work with ST7735S (teal-colored tab)

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 #define swap(a, b) { int16_t t = a; a = b; b = t; }
SomeRandomBloke 0:08cfbae05724 41
SomeRandomBloke 1:e67555532f16 42 class Adafruit_GFX : public Stream
SomeRandomBloke 0:08cfbae05724 43 {
SomeRandomBloke 0:08cfbae05724 44 public:
SomeRandomBloke 0:08cfbae05724 45
SomeRandomBloke 0:08cfbae05724 46 //Adafruit_GFX();
SomeRandomBloke 1:e67555532f16 47 Adafruit_GFX(int16_t w, int16_t h); // Constructor
SomeRandomBloke 0:08cfbae05724 48 // i have no idea why we have to formally call the constructor. kinda sux
SomeRandomBloke 1:e67555532f16 49 //void constructor(int16_t w, int16_t h);
SomeRandomBloke 0:08cfbae05724 50
SomeRandomBloke 0:08cfbae05724 51 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
Cognoscan 5:ba163fcbfbf1 52 void invertDisplay(bool i);
SomeRandomBloke 0:08cfbae05724 53
SomeRandomBloke 0:08cfbae05724 54 // these are 'generic' drawing functions, so we can share them!
justinkim 3:04b9498d00d8 55 virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,uint16_t color);
SomeRandomBloke 0:08cfbae05724 56 virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
SomeRandomBloke 0:08cfbae05724 57 virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
SomeRandomBloke 0:08cfbae05724 58 virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
SomeRandomBloke 0:08cfbae05724 59 virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
SomeRandomBloke 0:08cfbae05724 60 virtual void fillScreen(uint16_t color);
justinkim 3:04b9498d00d8 61
SomeRandomBloke 0:08cfbae05724 62 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
SomeRandomBloke 0:08cfbae05724 63 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
SomeRandomBloke 0:08cfbae05724 64 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
SomeRandomBloke 0:08cfbae05724 65 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
SomeRandomBloke 0:08cfbae05724 66
SomeRandomBloke 0:08cfbae05724 67 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 68 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 69 void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
SomeRandomBloke 0:08cfbae05724 70 void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
SomeRandomBloke 0:08cfbae05724 71
SomeRandomBloke 0:08cfbae05724 72 void drawBitmap(int16_t x, int16_t y,
SomeRandomBloke 0:08cfbae05724 73 const uint8_t *bitmap, int16_t w, int16_t h,
SomeRandomBloke 0:08cfbae05724 74 uint16_t color);
SomeRandomBloke 0:08cfbae05724 75 void drawChar(int16_t x, int16_t y, unsigned char c,
SomeRandomBloke 0:08cfbae05724 76 uint16_t color, uint16_t bg, uint8_t size);
SomeRandomBloke 0:08cfbae05724 77
SomeRandomBloke 0:08cfbae05724 78 void setCursor(int16_t x, int16_t y);
SomeRandomBloke 0:08cfbae05724 79 void setTextColor(uint16_t c);
SomeRandomBloke 0:08cfbae05724 80 void setTextColor(uint16_t c, uint16_t bg);
SomeRandomBloke 0:08cfbae05724 81 void setTextSize(uint8_t s);
Cognoscan 5:ba163fcbfbf1 82 void setTextWrap(bool w);
SomeRandomBloke 0:08cfbae05724 83
SomeRandomBloke 0:08cfbae05724 84 int16_t height(void);
SomeRandomBloke 0:08cfbae05724 85 int16_t width(void);
SomeRandomBloke 0:08cfbae05724 86
SomeRandomBloke 0:08cfbae05724 87 void setRotation(uint8_t r);
SomeRandomBloke 0:08cfbae05724 88 uint8_t getRotation(void);
SomeRandomBloke 0:08cfbae05724 89
SomeRandomBloke 0:08cfbae05724 90 protected:
SomeRandomBloke 0:08cfbae05724 91 virtual int _putc(int value);
SomeRandomBloke 0:08cfbae05724 92 virtual int _getc();
SomeRandomBloke 0:08cfbae05724 93
SomeRandomBloke 1:e67555532f16 94 const int16_t WIDTH, HEIGHT; // this is the 'raw' display w/h - never changes
SomeRandomBloke 0:08cfbae05724 95 int16_t _width, _height; // dependent on rotation
SomeRandomBloke 0:08cfbae05724 96 int16_t cursor_x, cursor_y;
SomeRandomBloke 0:08cfbae05724 97 uint16_t textcolor, textbgcolor;
SomeRandomBloke 0:08cfbae05724 98 uint8_t textsize;
SomeRandomBloke 0:08cfbae05724 99 uint8_t rotation;
Cognoscan 5:ba163fcbfbf1 100 bool wrap; // If set, 'wrap' text at right edge of display
SomeRandomBloke 0:08cfbae05724 101 };
SomeRandomBloke 0:08cfbae05724 102
SomeRandomBloke 0:08cfbae05724 103 #endif
justinkim 4:256d9b541ab0 104