/********************************************************************* * * GUI_CURSOR_Select */ const GUI_CURSOR GUI_UNI_PTR * GUI_CURSOR_Select(const GUI_CURSOR GUI_UNI_PTR * pCursor) { int AllocSize; const GUI_BITMAP GUI_UNI_PTR * pBM; const GUI_CURSOR GUI_UNI_PTR * pOldCursor; GUI_LOCK(); pOldCursor = _pCursor; if (pCursor != _pCursor) { int i; pBM = pCursor->pBitmap; i = pBM->pPal->NumEntries > 4 ? 4 : pBM->pPal->NumEntries; while (i--) { LCD_COLOR Color = *(pBM->pPal->pPalEntries + i); _ColorIndex[i] = LCD_Color2Index(Color); } _Hide(); AllocSize = pBM->XSize * pBM->YSize * sizeof(LCD_PIXELINDEX); if (AllocSize != _AllocSize) { GUI_ALLOC_Free(_hBuffer); _hBuffer = 0; } _hBuffer = GUI_ALLOC_AllocZero(AllocSize); _CursorOn = 1; _pCursor = pCursor; _CalcRect(); _Show(); } GUI_UNLOCK(); return pOldCursor; }
BOOL CChart2D::Create(DWORD dwStyle, CRect &rect, CWnd *pParent, UINT id) { BOOL result = CWnd::CreateEx(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE, NULL, NULL, dwStyle, rect.left, rect.top, rect.Width(), rect.Height(), pParent->GetSafeHwnd(), (HMENU)id); if (!result) AfxMessageBox(_T("Error creating Chart2D control's window!")); m_ctlRect = rect; m_ctlRect.DeflateRect(2, 2, 2, 2); pParent->ClientToScreen(m_ctlRect); ScreenToClient(m_ctlRect); _CreateFont(); _CalcRect(); _CalcMapFactors(); if (result) { _SetStateColors(IsWindowEnabled()); Invalidate(TRUE); } return result; }
/********************************************************************* * * 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(); }