| 1080 | } |
| 1081 | |
| 1082 | void CRenderEngine::DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps) |
| 1083 | { |
| 1084 | typedef BOOL (WINAPI *LPALPHABLEND)(HDC, int, int, int, int,HDC, int, int, int, int, BLENDFUNCTION); |
| 1085 | static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend"); |
| 1086 | if( lpAlphaBlend == NULL ) lpAlphaBlend = AlphaBitBlt; |
| 1087 | typedef BOOL (WINAPI *PGradientFill)(HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG); |
| 1088 | static PGradientFill lpGradientFill = (PGradientFill) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "GradientFill"); |
| 1089 | |
| 1090 | BYTE bAlpha = (BYTE)(((dwFirst >> 24) + (dwSecond >> 24)) >> 1); |
| 1091 | if( bAlpha == 0 ) return; |
| 1092 | int cx = rc.right - rc.left; |
| 1093 | int cy = rc.bottom - rc.top; |
| 1094 | RECT rcPaint = rc; |
| 1095 | HDC hPaintDC = hDC; |
| 1096 | HBITMAP hPaintBitmap = NULL; |
| 1097 | HBITMAP hOldPaintBitmap = NULL; |
| 1098 | if( bAlpha < 255 ) { |
| 1099 | rcPaint.left = rcPaint.top = 0; |
| 1100 | rcPaint.right = cx; |
| 1101 | rcPaint.bottom = cy; |
| 1102 | hPaintDC = ::CreateCompatibleDC(hDC); |
| 1103 | hPaintBitmap = ::CreateCompatibleBitmap(hDC, cx, cy); |
| 1104 | ASSERT(hPaintDC); |
| 1105 | ASSERT(hPaintBitmap); |
| 1106 | hOldPaintBitmap = (HBITMAP) ::SelectObject(hPaintDC, hPaintBitmap); |
| 1107 | } |
| 1108 | if( lpGradientFill != NULL ) |
| 1109 | { |
| 1110 | TRIVERTEX triv[2] = |
| 1111 | { |
| 1112 | { rcPaint.left, rcPaint.top, GetBValue(dwFirst) << 8, GetGValue(dwFirst) << 8, GetRValue(dwFirst) << 8, 0xFF00 }, |
| 1113 | { rcPaint.right, rcPaint.bottom, GetBValue(dwSecond) << 8, GetGValue(dwSecond) << 8, GetRValue(dwSecond) << 8, 0xFF00 } |
| 1114 | }; |
| 1115 | GRADIENT_RECT grc = { 0, 1 }; |
| 1116 | lpGradientFill(hPaintDC, triv, 2, &grc, 1, bVertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H); |
| 1117 | } |
| 1118 | else |
| 1119 | { |
| 1120 | // Determine how many shades |
| 1121 | int nShift = 1; |
| 1122 | if( nSteps >= 64 ) nShift = 6; |
| 1123 | else if( nSteps >= 32 ) nShift = 5; |
| 1124 | else if( nSteps >= 16 ) nShift = 4; |
| 1125 | else if( nSteps >= 8 ) nShift = 3; |
| 1126 | else if( nSteps >= 4 ) nShift = 2; |
| 1127 | int nLines = 1 << nShift; |
| 1128 | for( int i = 0; i < nLines; i++ ) { |
| 1129 | // Do a little alpha blending |
| 1130 | BYTE bR = (BYTE) ((GetBValue(dwSecond) * (nLines - i) + GetBValue(dwFirst) * i) >> nShift); |
| 1131 | BYTE bG = (BYTE) ((GetGValue(dwSecond) * (nLines - i) + GetGValue(dwFirst) * i) >> nShift); |
| 1132 | BYTE bB = (BYTE) ((GetRValue(dwSecond) * (nLines - i) + GetRValue(dwFirst) * i) >> nShift); |
| 1133 | // ... then paint with the resulting color |
| 1134 | HBRUSH hBrush = ::CreateSolidBrush(RGB(bR,bG,bB)); |
| 1135 | RECT r2 = rcPaint; |
| 1136 | if( bVertical ) { |
| 1137 | r2.bottom = rc.bottom - ((i * (rc.bottom - rc.top)) >> nShift); |
| 1138 | r2.top = rc.bottom - (((i + 1) * (rc.bottom - rc.top)) >> nShift); |
| 1139 | if( (r2.bottom - r2.top) > 0 ) ::FillRect(hDC, &r2, hBrush); |
nothing calls this directly
no outgoing calls
no test coverage detected