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