| 587 | } |
| 588 | |
| 589 | void FillGradientColors(HDC hdc, const LPRECT lpRect, COLORREF c1, COLORREF c2, bool vertical) |
| 590 | { |
| 591 | if (lpRect->left >= lpRect->right || lpRect->top >= lpRect->bottom) |
| 592 | return; |
| 593 | |
| 594 | if (ri::HaveMsImg()) |
| 595 | { |
| 596 | bool haveAlpha = false; |
| 597 | HDC hdcDest = hdc; |
| 598 | HBITMAP hbm = NULL; |
| 599 | RECT rc = *lpRect; |
| 600 | if (c1 == CLR_NONE || c2 == CLR_NONE) |
| 601 | { |
| 602 | haveAlpha = true; |
| 603 | |
| 604 | bool firstTrans = c1 == CLR_NONE; |
| 605 | |
| 606 | // This is gonna suck |
| 607 | |
| 608 | // Create a compatible DC and a backing bitmap |
| 609 | hdcDest = CreateCompatibleDC(hdc); |
| 610 | OffsetRect(&rc, -rc.left, -rc.top); |
| 611 | |
| 612 | //hbm = CreateCompatibleBitmap(hdc, rc.right, rc.bottom); |
| 613 | BITMAPINFO bmi{}; |
| 614 | ULONG ulWidth, ulHeight; |
| 615 | bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 616 | bmi.bmiHeader.biWidth = ulWidth = rc.right; |
| 617 | bmi.bmiHeader.biHeight = ulHeight = rc.bottom; |
| 618 | bmi.bmiHeader.biPlanes = 1; |
| 619 | bmi.bmiHeader.biBitCount = 32; // four 8-bit components |
| 620 | bmi.bmiHeader.biCompression = BI_RGB; |
| 621 | bmi.bmiHeader.biSizeImage = ulWidth * ulHeight * 4; |
| 622 | |
| 623 | void* pvBits = NULL; |
| 624 | hbm = ri::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0); |
| 625 | if (!hbm) { |
| 626 | DbgPrintW("FillGradientColors : Could not create bitmap object!"); |
| 627 | goto _FALLBACK; |
| 628 | } |
| 629 | |
| 630 | SelectObject(hdcDest, hbm); |
| 631 | |
| 632 | // Alpha Gradient |
| 633 | PUINT32 puBits = (PUINT32)pvBits; |
| 634 | COLORREF clr = (c1 == CLR_NONE ? c2 : c1); |
| 635 | |
| 636 | BYTE bytes[sizeof(COLORREF)]; |
| 637 | memcpy(bytes, &clr, sizeof(COLORREF)); |
| 638 | |
| 639 | for (ULONG y = 0, index = 0; y < ulHeight; y++) |
| 640 | { |
| 641 | UCHAR pcalpha; |
| 642 | if (vertical) { |
| 643 | if (firstTrans) |
| 644 | pcalpha = (UCHAR)((ulHeight - y) * 255 / ulHeight); |
| 645 | else |
| 646 | pcalpha = (UCHAR)(y * 255 / ulHeight); |
no test coverage detected