1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2007 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "gradient.h"
\r
22 CGradient::CGradient(void)
\r
26 CGradient::~CGradient(void)
\r
30 void CGradient::SplitRect(const CRect& rSource, CRect& rHalf1, CRect& rHalf2, BOOL bHorz)
\r
36 rHalf1.bottom = (rSource.bottom + rSource.top) / 2;
\r
37 rHalf2.top = rHalf1.bottom;
\r
41 rHalf1.right = (rSource.left + rSource.right) / 2;
\r
42 rHalf2.left = rHalf1.right;
\r
46 void CGradient::Draw(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorEnd, BOOL bHorz/* = TRUE*/, UINT nSteps/* = 64*/)
\r
48 for (UINT i = 0; i < nSteps; i++)
\r
50 BYTE bR = (BYTE) ((GetRValue(colorStart) * (nSteps - i) + GetRValue(colorEnd) * i) / nSteps);
\r
51 BYTE bG = (BYTE) ((GetGValue(colorStart) * (nSteps - i) + GetGValue(colorEnd) * i) / nSteps);
\r
52 BYTE bB = (BYTE) ((GetBValue(colorStart) * (nSteps - i) + GetBValue(colorEnd) * i) / nSteps);
\r
54 CBrush br (RGB(bR, bG, bB));
\r
59 r2.top = rect.top + ((i * rect.Height()) / nSteps);
\r
60 r2.bottom = rect.top + (((i + 1) * rect.Height()) / nSteps);
\r
61 if (r2.Height() > 0)
\r
62 pDC->FillRect(r2, &br);
\r
66 r2.left = rect.left + ((i * rect.Width()) / nSteps);
\r
67 r2.right = rect.left + (((i + 1) * rect.Width()) / nSteps);
\r
69 pDC->FillRect(r2, &br);
\r
74 void CGradient::Draw(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorMid, COLORREF colorEnd, BOOL bHorz/* = TRUE*/, UINT nSteps/* = 64*/)
\r
77 SplitRect(rect, rect1, rect2, bHorz);
\r
79 Draw(pDC, rect1, colorStart, colorMid, bHorz, nSteps/2);
\r
80 Draw(pDC, rect2, colorMid, colorEnd, bHorz, nSteps/2);
\r
83 #ifdef USE_GDI_GRADIENT
\r
85 void CGradient::DrawGDI(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorEnd, BOOL bHorz/* = TRUE*/)
\r
88 GRADIENT_RECT gRect;
\r
89 vert [0] .x = rect.left;
\r
90 vert [0] .y = rect.top;
\r
91 vert [0] .Red = GetRValue(colorStart)<<8;
\r
92 vert [0] .Green = GetGValue(colorStart)<<8;
\r
93 vert [0] .Blue = GetBValue(colorStart)<<8;
\r
94 vert [0] .Alpha = 0x0000;
\r
96 vert [1] .x = rect.right;
\r
97 vert [1] .y = rect.bottom;
\r
98 vert [1] .Red = GetRValue(colorEnd)<<8;
\r
99 vert [1] .Green = GetGValue(colorEnd)<<8;
\r
100 vert [1] .Blue = GetBValue(colorEnd)<<8;
\r
101 vert [1] .Alpha = 0x0000;
\r
103 gRect.UpperLeft = 0;
\r
104 gRect.LowerRight = 1;
\r
106 pDC->GradientFill(vert, 2, &gRect, 1, GRADIENT_FILL_RECT_H);
\r
108 pDC->GradientFill(vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V);
\r
112 void CGradient::DrawGDI(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorMid, COLORREF colorEnd, BOOL bHorz/* = TRUE*/)
\r
114 CRect rect1, rect2;
\r
115 SplitRect(rect, rect1, rect2, bHorz);
\r
117 DrawGDI(pDC, rect1, colorStart, colorMid, bHorz);
\r
118 DrawGDI(pDC, rect2, colorMid, colorEnd, bHorz);
\r