Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GFX.h
00001 /* 00002 This is the core graphics library for all our displays, providing a common 00003 set of graphics primitives (points, lines, circles, etc.). It needs to be 00004 paired with a hardware-specific library for each display device we carry 00005 (to handle the lower-level functions). 00006 00007 Adafruit invests time and resources providing this open source code, please 00008 support Adafruit & open-source hardware by purchasing products from Adafruit! 00009 00010 Copyright (c) 2013 Adafruit Industries. All rights reserved. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 00015 - Redistributions of source code must retain the above copyright notice, 00016 this list of conditions and the following disclaimer. 00017 - Redistributions in binary form must reproduce the above copyright notice, 00018 this list of conditions and the following disclaimer in the documentation 00019 and/or other materials provided with the distribution. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00025 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00026 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00027 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00028 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00029 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00030 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 /*Modified for MBED usage and tested with STM32F411RE on a Nucleo board. 00035 Embedded Print methods from Arduino Print.Cpp/Print.h 00036 00037 by James Kidd 2014 00038 * */ 00039 #include <stdint.h> 00040 #include <stdbool.h> 00041 #include <stddef.h> 00042 #include <string.h> 00043 #include <stdlib.h> 00044 #ifndef _GFX_H 00045 #define _GFX_H 00046 00047 #define DEC 10 00048 00049 #define swap(a, b) { int16_t t = a; a = b; b = t; } 00050 00051 class GFX { 00052 00053 public: 00054 00055 GFX(int16_t w, int16_t h); // Constructor 00056 00057 // This MUST be defined by the subclass: 00058 virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 00059 00060 // These MAY be overridden by the subclass to provide device-specific 00061 // optimized code. Otherwise 'generic' versions are used. 00062 virtual void 00063 drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), 00064 drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 00065 drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 00066 drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 00067 fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 00068 fillScreen(uint16_t color), 00069 fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 00070 invertDisplay(bool i); 00071 00072 // These exist only with GFX (no subclass overrides) 00073 void 00074 drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 00075 drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 00076 uint16_t color), 00077 00078 fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 00079 int16_t delta, uint16_t color), 00080 drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 00081 int16_t x2, int16_t y2, uint16_t color), 00082 fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 00083 int16_t x2, int16_t y2, uint16_t color), 00084 drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 00085 int16_t radius, uint16_t color), 00086 fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 00087 int16_t radius, uint16_t color), 00088 drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 00089 int16_t w, int16_t h, uint16_t color), 00090 drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 00091 int16_t w, int16_t h, uint16_t color, uint16_t bg), 00092 drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 00093 int16_t w, int16_t h, uint16_t color), 00094 drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, 00095 uint16_t bg, uint8_t size), 00096 setCursor(int16_t x, int16_t y), 00097 setTextColor(uint16_t c), 00098 setTextColor(uint16_t c, uint16_t bg), 00099 setTextSize(uint8_t s), 00100 setTextWrap(bool w), //retour a la ligne 00101 setRotation(uint8_t r); 00102 00103 00104 int16_t height(void) const; 00105 int16_t width(void) const; 00106 00107 uint8_t getRotation(void) const; 00108 00109 protected: 00110 const int16_t 00111 WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes 00112 int16_t 00113 _width, _height, // Display w/h as modified by current rotation 00114 cursor_x, cursor_y; 00115 uint16_t 00116 textcolor, textbgcolor; 00117 uint8_t 00118 textsize, 00119 rotation; 00120 bool 00121 wrap; // If set, 'wrap' text at right edge of display 00122 00123 00124 //Print Methods 00125 private: 00126 uint8_t printNumber(unsigned long, uint8_t); 00127 uint8_t printFloat(double, uint8_t); 00128 public: 00129 uint8_t write(uint8_t); 00130 uint8_t write(const char *str) { 00131 if (str == NULL) return 0; 00132 return write((const uint8_t *)str, strlen(str)); 00133 } 00134 uint8_t write(const uint8_t *buffer, uint8_t size); 00135 uint8_t write(const char *buffer, uint8_t size) { 00136 return write((const uint8_t *)buffer, size); 00137 } 00138 00139 uint8_t print(const char[]); 00140 uint8_t print(char); 00141 uint8_t print(unsigned char, int = DEC); 00142 uint8_t print(int, int = DEC); 00143 uint8_t print(unsigned int, int = DEC); 00144 uint8_t print(long, int = DEC); 00145 uint8_t print(unsigned long, int = DEC); 00146 uint8_t print(double, int = 2); 00147 00148 uint8_t println(const char[]); 00149 uint8_t println(char); 00150 uint8_t println(unsigned char, int = DEC); 00151 uint8_t println(int, int = DEC); 00152 uint8_t println(unsigned int, int = DEC); 00153 uint8_t println(long, int = DEC); 00154 uint8_t println(unsigned long, int = DEC); 00155 uint8_t println(double, int = 2); 00156 00157 uint8_t println(void); 00158 }; 00159 00160 #endif // _GFX_H
Generated on Tue Jul 12 2022 15:05:43 by
1.7.2