void TFT_ILI9163C::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){ SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); HLine(x, y, w, color); HLine(x, y+h-1, w, color); VLine(x, y, h, color); VLine(x+w-1, y, h, color); writecommand_last(CMD_NOP); SPI.endTransaction(); }
void BigButtonPressed(int x, int y, char *str) { stdwindow(x,y,x+50,y+10); HLine(x+1, y+1, 48, darkw); VLine(x+1, y+1, 8, darkw); HLine(x+2, y+8, 47, winbg); VLine(x+48, y+2, 7, winbg); GotoXY(x+1+(25-(pixels(str)/2)), y+3); printstring(str); }
void TextField(int x, int y, int width, char *str, int blink) { FilledBox(x, y, width, 9, 0); HLine(x, y, width+1, darkw); VLine(x, y, 9, darkw); HLine(x+1, y+8, width-1, brightw); VLine(x+width, y+1, 8, brightw); GotoXY(x+2, y+2); printstring(str); if (blink) printstring("_"); }
void ButtonPressed(int x, int y, char *str) /* -- ric: 13/Jun/98 -- */ /* Draws a depressed button */ { stdwindow(x,y,x+30,y+10); HLine(x+1, y+1, 28, darkw); VLine(x+1, y+1, 8, darkw); HLine(x+2, y+8, 27, winbg); VLine(x+28, y+2, 7, winbg); GotoXY(x+1+(15-(pixels(str)/2)), y+3); printstring(str); }
void CheckBox(int x, int y, int checked) { FilledBox(x, y, 7, 6, 0); HLine(x, y, 8, darkw); VLine(x, y, 7, darkw); HLine(x+1, y+6, 7, brightw); VLine(x+7, y+1, 5, brightw); if (checked) { GotoXY(x+2, y+2); printstring("*"); } }
void stdwindow(int x1, int y1, int x2, int y2) { FilledBox(x1, y1, x2-x1, y2-y1, winbg); HLine(x1, y1, x2-x1, black); /* -- ric: 13/Jun/98 -- */ VLine(x1, y1, y2-y1, black); /* Outline window in black */ HLine(x1+1, y2-1, x2-x1-1, black); VLine(x2-1, y1+1, y2-y1-1, black); HLine(x1+1, y1+1, x2-x1-2, brightw); VLine(x1+1, y1+1, y2-y1-2, brightw); HLine(x1+2, y2-2, x2-x1-3, darkw); VLine(x2-2, y1+2, y2-y1-3, darkw); }
void Window(int x1, int y1, int x2, int y2, char *title) { FilledBox(x1, y1, x2-x1, y2-y1, winbg); FilledBox(x1, y1, x2-x1, 8, titlebg); HLine(x1, y1, x2-x1, brightw); VLine(x1, y1, y2-y1, brightw); HLine(x1+1, y2-1, x2-x1-1, darkw); VLine(x2-1, y1+1, y2-y1-1, darkw); FilledBox(x2-8, y1+2, 5, 5, winbg); HLine(x2-8, y1+2, 6, brightw); VLine(x2-8, y1+2, 5, brightw); HLine(x2-7, y1+6, 4, darkw); VLine(x2-3, y1+3, 4, darkw); GotoXY(x1+2, y1+2); printstring(title); }
void DrawColorCol (PLEGEND pLegend, PLINE pLine, int iCol, HDC hDC, int yPos) /* Effect: Draw the "color" column of a legend entry. The color column displays a small sample of the line drawing. For charts, the sample is a line of the correct style, color, and width. Since we are using wide lines, the round endcaps of the lines will breach the column. Therefore we need to set the clip region. We could remove this clipping if we find a way to change the end cap design. For alerts, the sample is a small circle which echos the design in the alert log itself. */ { // DrawColorCol HBRUSH hBrush, hBrushPrevious ; RECT rect ; int yMiddle ; int iCircle ; rect.left = pLegend->aCols[iCol].xPos - LegendLeftMargin () + 2 ; rect.top = yPos + 1 ; rect.right = rect.left + pLegend->aCols[iCol].xWidth - LegendHorzMargin () ; rect.bottom = yPos + pLegend->yItemHeight - 1 ; yMiddle = rect.top + (rect.bottom - rect.top) / 2 ; iCircle = rect.bottom - rect.top - 2 ; switch (pLegend->iLineType) { // switch case LineTypeChart: if (pLine->Visual.iWidth == 1) { // simple case with thin pen // hBrush = SelectBrush (hDC, hbLightGray) ; hBrush = SelectBrush (hDC, hBrushFace) ; Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ; HLine (hDC, pLine->hPen, rect.left + 1, rect.right - 1, yMiddle) ; SelectBrush (hDC, hBrush) ; } else { // thicker pen width, have to set ClipRect so // it will not draw otherside the rect. SaveDC (hDC) ; // hBrush = SelectBrush (hDC, hbLightGray) ; hBrush = SelectBrush (hDC, hBrushFace) ; Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ; IntersectClipRect (hDC, rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1) ; HLine (hDC, pLine->hPen, rect.left + 1, rect.right - 1, yMiddle) ; SelectBrush (hDC, hBrush) ; RestoreDC (hDC, -1) ; } break ; case LineTypeAlert: hBrushPrevious = SelectBrush (hDC, pLine->hBrush) ; Ellipse (hDC, rect.left + 2, rect.top + 2, rect.left + 2 + iCircle, rect.top + 2 + iCircle) ; SelectBrush (hDC, hBrushPrevious) ; break ; } // switch } // DrawColorCol
void CSurface8::Box(int iX, int iY, int iX2, int iY2, int iCol) { for (int cy=iY; cy<=iY2; cy++) HLine(iX,iX2,cy,iCol); }
void static OnPaint ( HWND hWnd, BOOL bEraseBackground) /* Effect: Paint the invalid surface of hWnd. Draw each label, each recessed value box, and each value. Called By: GraphStatusWndProc only, in response to a WM_PAINT message. */ { HDC hDC ; PAINTSTRUCT ps ; RECT rectClient ; int i ; PLINESTRUCT pLine; hDC = BeginPaint (hWnd, &ps) ; SetBkMode (hDC, (bEraseBackground ? OPAQUE : TRANSPARENT)) ; SetBkColor (hDC, ColorBtnFace) ; GetClientRect (hWnd, &rectClient) ; HLine (hDC, GetStockObject (BLACK_PEN), rectClient.left, rectClient.right, rectClient.bottom - 1) ; if ((pGraphs->gOptions.bStatusBarChecked) && (pGraphs->gOptions.bLegendChecked)) { // if UINT hPrevTextAlign = SetTextAlign (hDC, TA_LEFT | TA_TOP) ; for (i = 0 ; i < StatusNumElts ; i++) { // for // Draw the label TextOut (hDC, StatusData.aElts[i].xTextPos, StatusTopMargin () + ThreeDPad, StatusData.aElts[i].szText, lstrlen (StatusData.aElts[i].szText)) ; // Draw the recesed value box ThreeDConcave1 (hDC, StatusData.aElts[i].xValuePos - ThreeDPad, StatusTopMargin (), StatusData.aElts[i].xValuePos + StatusData.sizeValue.cx + ThreeDPad, StatusTopMargin () + StatusData.sizeValue.cy + 2 * ThreeDPad ) ; } // for // restore TextAlign for drawing values SetTextAlign (hDC, hPrevTextAlign) ; // Draw the values themselves pLine = CurrentGraphLine (hWndGraph) ; StatusDrawTime (hDC, TRUE) ; StatusDrawLast (hDC, pLine, TRUE) ; if (pLine) { StatusDrawAvg (hDC, pLine->lnAveValue, TRUE) ; StatusDrawMin (hDC, pLine->lnMinValue, TRUE) ; StatusDrawMax (hDC, pLine->lnMaxValue, TRUE) ; } else { StatusDrawAvg (hVBarDC, (FLOAT)0.0, TRUE) ; StatusDrawMax (hVBarDC, (FLOAT)0.0, TRUE) ; StatusDrawMin (hVBarDC, (FLOAT)0.0, TRUE) ; } } // if EndPaint (hWnd, &ps) ; } // StatusPaint
void TFT_ILI9163C::drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1, uint16_t color){ if (y0 == y1) { if (x1 > x0) { drawFastHLine(x0, y0, x1 - x0 + 1, color); } else if (x1 < x0) { drawFastHLine(x1, y0, x0 - x1 + 1, color); } else { drawPixel(x0, y0, color); } return; } else if (x0 == x1) { if (y1 > y0) { drawFastVLine(x0, y0, y1 - y0 + 1, color); } else { drawFastVLine(x0, y1, y0 - y1 + 1, color); } return; } bool steep = abs(y1 - y0) > abs(x1 - x0); if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0, x1); swap(y0, y1); } int16_t dx, dy; dx = x1 - x0; dy = abs(y1 - y0); int16_t err = dx / 2; int16_t ystep; if (y0 < y1) { ystep = 1; } else { ystep = -1; } SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); int16_t xbegin = x0; if (steep) { for (; x0<=x1; x0++) { err -= dy; if (err < 0) { int16_t len = x0 - xbegin; if (len) { VLine(y0, xbegin, len + 1, color); } else { Pixel(y0, x0, color); } xbegin = x0 + 1; y0 += ystep; err += dx; } } if (x0 > xbegin + 1) { VLine(y0, xbegin, x0 - xbegin, color); } } else { for (; x0<=x1; x0++) { err -= dy; if (err < 0) { int16_t len = x0 - xbegin; if (len) { HLine(xbegin, y0, len + 1, color); } else { Pixel(x0, y0, color); } xbegin = x0 + 1; y0 += ystep; err += dx; } } if (x0 > xbegin + 1) { HLine(xbegin, y0, x0 - xbegin, color); } } writecommand_last(CMD_NOP); SPI.endTransaction(); }
void CGraphView::AlphaBlit(const Canvas& src,int x,int y) { const int bpp=4; int nDestwidth=pDib->Width(); int nDestheight=pDib->Height(); int xstart=0; int ystart=0; int xlen=src.Width(); int ylen=src.Height(); int ox=x; int oy=y; DoClipping(x,y,xstart,xlen,ystart,ylen); if (xlen<1 || ylen<1) return; // offscreen u32* pDest=(u32*)(pDib->GetPixels())+(y*nDestwidth+x); u32* pSrc =(u32*)src.GetPixels() +(ystart*src.Width()+xstart); while (ylen) { int x=xlen; while (x) { // convert from ARGB to ABGR /* u32 c=*pSrc++; u8 r=(u8)((c>>16)&255); u8 b=(u8)(c&255); c&=0xFF00FF00; // the alpha and green channels don't move, keep them intact *pDest++=c|(b<<16)|r; /*/ // Did I need to convert this to ASM? Doubt it. ;D __asm { mov ebx,[pSrc] mov eax,[ebx] test eax,0xFF000000 jz nodraw mov ebx,[pDest] mov [ebx],eax mov al,[ebx] mov ah,[ebx+2] mov [ebx],ah // have to switch from BGRA to RGBA mov [ebx+2],al nodraw: } ++pSrc; ++pDest; //*/ x--; } pDest+=nDestwidth-xlen; pSrc+=src.Width()-xlen; --ylen; } } void CGraphView::HLine(int x1,int x2,int y,u32 colour) { if (x1>x2) std::swap<int>(x1,x2); if (y<0 || y>=nDIBsize) return; if (x1<0) x1=0; if (x2<0) return; if (x1>=nDIBsize) return; if (x2>=nDIBsize) x2=nDIBsize-1; u32* p=(u32*)pDib->GetPixels()+(y*pDib->Width())+x1; int xlen=x2-x1+1; while (xlen--) *p++=colour; } void CGraphView::VLine(int x,int y1,int y2,u32 colour) { if (y1>y2) std::swap<int>(y1,y2); if (x<0 || x>=nDIBsize) return; if (y1<0) y1=0; if (y2<0) return; if (y1>=nDIBsize) return; if (y2>=nDIBsize) y2=nDIBsize-1; u32* p=(u32*)pDib->GetPixels()+(y1*pDib->Width())+x; int ylen=y2-y1+1; while (ylen--) { *p=colour; p+=pDib->Width(); } } void CGraphView::DrawRect(int x1,int y1,int x2,int y2,u32 colour) { HLine(x1,x2,y1,colour); HLine(x1,x2,y2,colour); VLine(x1,y1,y2,colour); VLine(x2,y1,y2,colour); }