OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / Utils / MiscUI / Gradient.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2007 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #include "StdAfx.h"\r
20 #include "gradient.h"\r
21 \r
22 CGradient::CGradient(void)\r
23 {\r
24 }\r
25 \r
26 CGradient::~CGradient(void)\r
27 {\r
28 }\r
29 \r
30 void CGradient::SplitRect(const CRect& rSource, CRect& rHalf1, CRect& rHalf2, BOOL bHorz)\r
31 {\r
32         rHalf1 = rSource;\r
33         rHalf2 = rSource;\r
34         if (!bHorz)\r
35         {\r
36                 rHalf1.bottom = (rSource.bottom + rSource.top) / 2;\r
37                 rHalf2.top = rHalf1.bottom;\r
38         }\r
39         else\r
40         {\r
41                 rHalf1.right = (rSource.left + rSource.right) / 2;\r
42                 rHalf2.left = rHalf1.right;\r
43         }\r
44 }\r
45 \r
46 void CGradient::Draw(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorEnd, BOOL bHorz/* = TRUE*/, UINT nSteps/* = 64*/)\r
47 {\r
48     for (UINT i = 0; i < nSteps; i++)\r
49     {\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
53 \r
54                 CBrush br (RGB(bR, bG, bB));\r
55 \r
56         CRect r2 = rect;\r
57         if (!bHorz)\r
58         {\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
63         }\r
64         else\r
65         {\r
66             r2.left = rect.left + ((i * rect.Width()) / nSteps);\r
67             r2.right = rect.left + (((i + 1) * rect.Width()) / nSteps);\r
68             if (r2.Width() > 0)\r
69                 pDC->FillRect(r2, &br);\r
70         }\r
71     }\r
72 }\r
73 \r
74 void CGradient::Draw(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorMid, COLORREF colorEnd, BOOL bHorz/* = TRUE*/, UINT nSteps/* = 64*/)\r
75 {\r
76         CRect rect1, rect2;\r
77         SplitRect(rect, rect1, rect2, bHorz);\r
78 \r
79         Draw(pDC, rect1, colorStart, colorMid, bHorz, nSteps/2);\r
80         Draw(pDC, rect2, colorMid, colorEnd, bHorz, nSteps/2);\r
81 }\r
82 \r
83 #ifdef USE_GDI_GRADIENT\r
84 \r
85 void CGradient::DrawGDI(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorEnd, BOOL bHorz/* = TRUE*/)\r
86 {\r
87         TRIVERTEX        vert[2] ;\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
95 \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
102 \r
103         gRect.UpperLeft  = 0;\r
104         gRect.LowerRight = 1;\r
105         if (bHorz)\r
106                 pDC->GradientFill(vert, 2, &gRect, 1, GRADIENT_FILL_RECT_H);\r
107         else\r
108                 pDC->GradientFill(vert, 2, &gRect, 1, GRADIENT_FILL_RECT_V);\r
109 \r
110 }\r
111 \r
112 void CGradient::DrawGDI(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorMid, COLORREF colorEnd, BOOL bHorz/* = TRUE*/)\r
113 {\r
114         CRect rect1, rect2;\r
115         SplitRect(rect, rect1, rect2, bHorz);\r
116 \r
117         DrawGDI(pDC, rect1, colorStart, colorMid, bHorz);\r
118         DrawGDI(pDC, rect2, colorMid, colorEnd, bHorz);\r
119 }\r
120 \r
121 #endif\r