/********************************************************************* * * GUI_TOUCH_Calibrate */ int GUI_TOUCH_Calibrate(int Coord, int Log0, int Log1, int Phys0, int Phys1) { int l0 = 0; int l1 = (Coord == GUI_COORD_X) ? LCD_XSIZE - 1 : LCD_YSIZE - 1; if (labs(Phys0 - Phys1) < 20) { return 1; } if (labs(Log0 - Log1) < 20) { return 1; } xyMinMax[Coord].Min = _Log2Phys(l0, Log0, Log1, Phys0, Phys1); xyMinMax[Coord].Max = _Log2Phys(l1, Log0, Log1, Phys0, Phys1); return 0; }
/********************************************************************* * * _Draw */ static void _Draw(void) { int x, y, xSize, ySize; LCD_PIXELINDEX* pData; const GUI_BITMAP GUI_UNI_PTR * pBM; GUI_LOCK(); if (_hBuffer) { /* Save bitmap data */ pBM = _pCursor->pBitmap; pData = (LCD_PIXELINDEX*)GUI_ALLOC_h2p(_hBuffer); xSize = _Rect.x1 - _Rect.x0 + 1; ySize = _Rect.y1 - _Rect.y0 + 1; for (y = 0; y < ySize; y++) { for (x = 0; x < xSize; x++) { int BitmapPixel; *(pData + x) = _GetPixelIndex(_Rect.x0 + x, _Rect.y0 + y); BitmapPixel = GUI_GetBitmapPixelIndex(pBM, x, y); if (BitmapPixel) { _SetPixelIndex(_Rect.x0 + x, _Rect.y0 + y, _Log2Phys(BitmapPixel)); } } pData += pBM->XSize; } } GUI_UNLOCK(); }
static void _Calibrate(int Coord, int Log0, int Log1, int Phys0, int Phys1, int *p0, int *p1) { int l0 = 0; int l1 = (Coord == GUI_COORD_X) ? LCD_XSIZE - 1 : LCD_YSIZE - 1; *p0 = _Log2Phys(l0, Log0, Log1, Phys0, Phys1); *p1 = _Log2Phys(l1, Log0, Log1, Phys0, Phys1); }
/********************************************************************* * * GUI_CURSOR_SetPosition */ void GUI_CURSOR_SetPosition(int xNewPos, int yNewPos) { int x, xStart, xStep, xEnd, xOff, xOverlapMin, xOverlapMax; int y, yStart, yStep, yEnd, yOff, yOverlapMin, yOverlapMax; int xSize; LCD_PIXELINDEX* pData; GUI_LOCK(); if (_hBuffer) { if ((_x != xNewPos) | (_y != yNewPos)) { if (_CursorOn) { const GUI_BITMAP GUI_UNI_PTR * pBM = _pCursor->pBitmap; /* Save & set clip rect */ /* Compute helper variables */ pData = (LCD_PIXELINDEX*)GUI_ALLOC_h2p(_hBuffer); xSize = _pCursor->pBitmap->XSize; xOff = xNewPos - _x; if (xOff > 0) { xStep = 1; xStart = 0; xEnd = _pCursor->pBitmap->XSize; xOverlapMax = xEnd -1; xOverlapMin = xOff; } else { xStep = -1; xStart = xSize - 1; xEnd = -1; xOverlapMin = 0; xOverlapMax = xStart + xOff; } yOff = yNewPos - _y; if (yOff > 0) { yStep = 1; yStart = 0; yEnd = _pCursor->pBitmap->YSize; yOverlapMax = yEnd -1; yOverlapMin = yOff; } else { yStep = -1; yStart = _pCursor->pBitmap->YSize - 1; yEnd = -1; yOverlapMin = 0; yOverlapMax = yStart + yOff; } /* Restore & Draw */ for (y = yStart; y != yEnd; y += yStep) { char yOverlaps; char yNewOverlaps; int yNew = y + yOff; yOverlaps = (y >= yOverlapMin) && (y <= yOverlapMax); yNewOverlaps = (yNew >= yOverlapMin) && (yNew <= yOverlapMax); for (x= xStart; x != xEnd; x += xStep) { char xyOverlaps, xyNewOverlaps; int BitmapPixel; LCD_PIXELINDEX Pixel; LCD_PIXELINDEX* pSave = pData + x + y * xSize; int xNew = x + xOff; BitmapPixel = GUI_GetBitmapPixelIndex(pBM, x, y); xyOverlaps = (x >= xOverlapMin) && (x <= xOverlapMax) && yOverlaps; xyNewOverlaps = (xNew >= xOverlapMin) && (xNew <= xOverlapMax) && yNewOverlaps; /* Restore old pixel if it was not transparent */ if (BitmapPixel) { if (!xyOverlaps || (GUI_GetBitmapPixelIndex(pBM, x - xOff, y - yOff) == 0)) { _SetPixelIndex(x + _Rect.x0, y + _Rect.y0, *(pSave)); } } /* Save */ if (xyNewOverlaps) { Pixel = *(pData + xNew + yNew * xSize); } else { Pixel = _GetPixelIndex(_Rect.x0 + xNew, _Rect.y0 + yNew); } *pSave = Pixel; /* Write new ... We could write pixel by pixel here */ if (BitmapPixel) { LCD_PIXELINDEX NewPixel = _Log2Phys(BitmapPixel); _SetPixelIndex(_Rect.x0 + xNew, _Rect.y0 + yNew, NewPixel); } } } } _x = xNewPos; _y = yNewPos; _CalcRect(); } } GUI_UNLOCK(); }