/* 2012 Copyright (c) Seeed Technology Inc. Authors: Albert.Miao & Loovee, Visweswara R (with initializtion code from TFT vendor) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc.,51 Franklin St,Fifth Floor, Boston, MA 02110-1301 USA */ #include #include "stdlib.h" #if defined(__LINKIT_ONE__) uint8_t bg_buffer[153600]; #endif INT16U constrain(INT16U input, INT16U limitL, INT16U limitH) { if (input > limitH) return limitH; else if (input < limitL) return limitL; else return input; } void TFT::fillRectangle(INT16U poX, INT16U poY, INT16U length, INT16U width, INT16U color) { unsigned long XY = 0; INT16U XL, XR, YU, YD; XL = constrain(poX, MIN_X,MAX_X); XR = constrain((poX + length - 1), MIN_X,MAX_X); YU = constrain(poY, MIN_Y,MAX_Y); YD = constrain((poY + width - 1), MIN_Y,MAX_Y); XY = (XR-XL+1); XY = XY*(YD-YU+1); LCD_setRect(XL, XR, YU, YD); for(unsigned long i=0; i < XY; i++) LCD_writePixel(color); } void TFT::setPixel(INT16U poX, INT16U poY,INT16U color) { LCD_setXY(poX, poY); LCD_writePixel(color); } void TFT::drawChar( INT8U ascii, INT16U poX, INT16U poY,INT16U size, INT16U fgcolor) { if((ascii>=32)&&(ascii<=127)) { ; } else { ascii = '?'; } for (int i =0; i>f)&0x01) { fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor); //fillRectangle(poX+f*size, poY+i*size, size, size, fgcolor); } } } } void TFT::drawString(char *string,INT16U poX, INT16U poY, INT16U size,INT16U fgcolor) { int StartX; StartX = poX; // Startposition für Zeilenumbruch merken while(*string != 0) { if (*string != '\n') { drawChar(*string, poX, poY, size, fgcolor); poX = poX + FONT_SPACE*size; } if ((poX > (MAX_X - (FONT_SPACE-1)*size)) || (*string == '\n')) { // Zeilenumbruch am Zeilenende oder mit Steuerzeichen poX = StartX; poY = poY + size * (FONT_Y + 1); } string = string + 1; } // end while } void TFT::drawHorizontalLine( INT16U poX, INT16U poY, INT16U length,INT16U color) { LCD_setRect(poX, poX + length, poY, poY); for(int i=0; i= dy) { /* e_xy+e_x > 0 */ if (x0 == x1) break; err += dy; x0 += sx; } if (e2 <= dx) { /* e_xy+e_y < 0 */ if (y0 == y1) break; err += dx; y0 += sy; } } } void TFT::drawVerticalLine( INT16U poX, INT16U poY, INT16U length,INT16U color) { LCD_setRect(poX, poX, poY, poY + length); for(int i=0; i x) err += ++x*2+1; } while (x <= 0); } void TFT::fillCircle(int poX, int poY, int r,INT16U color) { int x = -r, y = 0, err = 2-2*r, e2; do { drawVerticalLine(poX-x, poY-y, 2*y, color); drawVerticalLine(poX+x, poY-y, 2*y, color); e2 = err; if (e2 <= y) { err += ++y*2+1; if (-x == y && e2 <= x) e2 = 0; } if (e2 > x) err += ++x*2+1; } while (x <= 0); } void TFT::drawTriangle( int poX1, int poY1, int poX2, int poY2, int poX3, int poY3, INT16U color) { drawLine(poX1, poY1, poX2, poY2,color); drawLine(poX1, poY1, poX3, poY3,color); drawLine(poX2, poY2, poX3, poY3,color); } INT8U TFT::drawNumber(long long_num,INT16U poX, INT16U poY,INT16U size,INT16U fgcolor) { INT8U char_buffer[10] = ""; INT8U i = 0; INT8U f = 0; if (long_num < 0) { f=1; drawChar('-',poX, poY, size, fgcolor); long_num = -long_num; if(poX < MAX_X) { poX += FONT_SPACE*size; /* Move cursor right */ } } else if (long_num == 0) { f=1; drawChar('0',poX, poY, size, fgcolor); return f; if(poX < MAX_X) { poX += FONT_SPACE*size; /* Move cursor right */ } } while (long_num > 0) { char_buffer[i++] = long_num % 10; long_num /= 10; } f = f+i; for(; i > 0; i--) { drawChar('0'+ char_buffer[i - 1],poX, poY, size, fgcolor); if(poX < MAX_X) { poX+=FONT_SPACE*size; /* Move cursor right */ } } return f; } INT8U TFT::drawFloat(float floatNumber,INT8U decimal,INT16U poX, INT16U poY,INT16U size,INT16U fgcolor) { INT16U temp=0; float decy=0.0; float rounding = 0.5; INT8U f=0; if(floatNumber<0.0) { drawChar('-',poX, poY, size, fgcolor); floatNumber = -floatNumber; if(poX < MAX_X) { poX+=FONT_SPACE*size; /* Move cursor right */ } f =1; } for (INT8U i=0; i0) { drawChar('.',poX, poY, size, fgcolor); if(poX < MAX_X) { poX+=FONT_SPACE*size; /* Move cursor right */ } f +=1; } decy = floatNumber-temp; /* decimal part, 4 */ for(INT8U i=0;i0) { drawChar('.',poX, poY, size, fgcolor); if(poX < MAX_X) { poX += FONT_SPACE*size; /* Move cursor right */ } f +=1; } decy = floatNumber-temp; /* decimal part, */ for(INT8U i=0;i> 1); LeftTop.y = Position.y - (Dimension.y >> 1); WidthHigh = Dimension; Tft.drawRectangle(LeftTop.x, LeftTop.y, Dimension.x, Dimension.y, LineC); LineColor = LineC; Tft.fillRectangle(LeftTop.x + 1, LeftTop.y + 1, Dimension.x - 2, Dimension.y - 2, FillColor); } // schreibt zentrierten Text in Taste void Button_t::setText(const char* Text, int16_t Size, INT16U Color) { int i = 0; int len = 0; while (Text[i] != 0) { len = len + FONT_SPACE * Size; // Stringlänge in Pixel bestimmen i = i + 1; } Tft.drawString(Text, LeftTop.x + ((WidthHigh.x - len) >> 1), LeftTop.y + ((WidthHigh.y - FONT_Y * Size) >> 1), Size, Color); } void Button_t::setText(const char* Text1, const char* Text2, int16_t Size, INT16U Color) { int i = 0; int len = 0; while (Text1[i] != 0) { len = len + FONT_SPACE * Size; // Stringlänge in Pixel bestimmen i = i + 1; } Tft.drawString(Text1, LeftTop.x + ((WidthHigh.x - len) >> 1), LeftTop.y + (WidthHigh.y >> 1) - FONT_Y * Size, Size, Color); // 2. Zeile len = 0; i = 0; while (Text2[i] != 0) { len = len + FONT_SPACE * Size; // Stringlänge in Pixel bestimmen i = i + 1; } Tft.drawString(Text2, LeftTop.x + ((WidthHigh.x - len) >> 1), LeftTop.y + (WidthHigh.y >> 1) + Size, Size, Color); } // ändert Farbe der Umrandung entsprechend Parameter void Button_t::hilite(INT16U Color) { Tft.drawRectangle(LeftTop.x, LeftTop.y, WidthHigh.x, WidthHigh.y, Color); } // setzt Farbe der Umrandung wieder zurück void Button_t::unhilite(void) { Tft.drawRectangle(LeftTop.x, LeftTop.y, WidthHigh.x, WidthHigh.y, LineColor); } // übermalt Fläche der Taste mit übergebener Farbe void Button_t::remove(INT16U Color) { Tft.fillRectangle(LeftTop.x, LeftTop.y, WidthHigh.x, WidthHigh.y, Color); } // prüft, ob übergebene Koordinaten im Feld der Taste liegen (z.B. ein Touch) int Button_t::touch(Point_t Point) { int deltaX, deltaY; deltaX = Point.x - LeftTop.x; deltaY = Point.y - LeftTop.y; if ((deltaX < 0) || (deltaX > (WidthHigh.x - 1))) return 0; if ((deltaY < 0) || (deltaY > (WidthHigh.y - 1))) return 0; else return 1; }