Update version of EALib.
Dependencies: FATFileSystem
Fork of EALib by
GFXFb.cpp
00001 /* 00002 * Copyright 2013 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /****************************************************************************** 00018 * Includes 00019 *****************************************************************************/ 00020 00021 #include "mbed.h" 00022 #include "GFXFb.h" 00023 00024 00025 GFXFb::GFXFb(uint16_t w, uint16_t h, uint16_t* fb) : Adafruit_GFX(w, h) { 00026 _fb = fb; 00027 } 00028 00029 00030 void GFXFb::drawPixel(int16_t x, int16_t y, uint16_t color) { 00031 if (_fb == 0) return; 00032 00033 if (x < 0 || x >= width() || y < 0 || y >= height()) return; 00034 00035 *(_fb + x + y*_width ) = color; 00036 } 00037 00038 void GFXFb::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { 00039 int16_t y2 = y + h - 1; 00040 00041 if (y < 0) y = 0; 00042 if (y2 >= _height) y2 = _height-1; 00043 00044 if (_fb == 0) return; 00045 if (x < 0 || x >= _width || y >= _height || y2 < y) return; 00046 00047 uint16_t* f = (_fb + x + y*_width); 00048 while(y <= y2) { 00049 00050 *f = color; 00051 f += _width; 00052 y++; 00053 } 00054 00055 } 00056 00057 void GFXFb::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { 00058 int16_t x2 = x + w - 1; 00059 00060 if (x < 0) x = 0; 00061 if (x2 >= _width) x2 = _width-1; 00062 00063 if (_fb == 0) return; 00064 if (x >= _width || x2 < x || y < 0 || y >= _height) return; 00065 00066 uint16_t* f = (_fb + x + y*_width); 00067 while(x <= x2) { 00068 00069 *f++ = color; 00070 x++; 00071 } 00072 00073 } 00074 00075 00076 void GFXFb::fillScreen(uint16_t color) { 00077 00078 if (_fb == 0) return; 00079 00080 int len = _width*_height; 00081 for (int i = 0; i < len; i++) { 00082 *(_fb+i) = color; 00083 } 00084 } 00085 00086 void GFXFb::writeString(const char* s) { 00087 if (s == NULL) return; 00088 00089 while(*s != 0) { 00090 write(*s); 00091 s++; 00092 } 00093 } 00094 00095 int16_t GFXFb::getStringWidth(const char* s) { 00096 // the default font in GFX is 6 pixels in width 00097 int chWidth = 6*textsize; 00098 int sz = 0; 00099 00100 while(*s != 0) { 00101 sz += chWidth; 00102 s++; 00103 } 00104 00105 return sz; 00106 } 00107 00108 int16_t GFXFb::getStringHeight(const char* s) { 00109 (void)s; 00110 // the default font in GFX is 8 pixels in height 00111 return 8; 00112 } 00113 00114
Generated on Thu Jul 14 2022 09:42:14 by 1.7.2