OSDN Git Service

Add TortoiseProc
[tortoisegit/TortoiseGitJp.git] / Utils / MiscUI / WaterEffect.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2006,2008 - 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 #pragma once\r
20 \r
21 #define random( min, max ) (( rand() % (int)((( max ) + 1 ) - ( min ))) + ( min ))\r
22 \r
23 /**\r
24  * \ingroup Utils\r
25  * \r
26  * Provides a water effect on a picture. To do that the class needs\r
27  * the picture as an array of pixels. See CDIB class for information\r
28  * of that format.\r
29  * The formulas used in this class I found on a website: http://freespace.virgin.net/hugo.elias/graphics/x_water.htm \n\r
30  * An example of how to use this class and produce a water effect:\r
31  * \code\r
32  * //in your initialization code (e.g. OnInitDialog() )\r
33  * CPictureHolder tmpPic;\r
34  * tmpPic.CreateFromBitmap(IDB_LOGOFLIPPED);\r
35  * m_renderSrc.Create32BitFromPicture(&tmpPic,301,167);\r
36  * m_renderDest.Create32BitFromPicture(&tmpPic,301,167);\r
37  * m_waterEffect.Create(301,167);\r
38  * \endcode\r
39  * In a timer function / method you need to render the picture:\r
40  * \code\r
41  * m_waterEffect.Render((DWORD*)m_renderSrc.GetDIBits(), (DWORD*)m_renderDest.GetDIBits());\r
42  * CClientDC dc(this);\r
43  * CPoint ptOrigin(15,20);\r
44  * m_renderDest.Draw(&dc,ptOrigin);\r
45  * \endcode\r
46  * To add blobs you can do that either in a timer too\r
47  * \code\r
48  * CRect r;\r
49  * r.left = 15;\r
50  * r.top = 20;\r
51  * r.right = r.left + m_renderSrc.GetWidth();\r
52  * r.bottom = r.top + m_renderSrc.GetHeight();\r
53  * m_waterEffect.Blob(random(r.left,r.right), random(r.top, r.bottom), 2, 200, m_waterEffect.m_iHpage);\r
54  * \endcode\r
55  * or/and in a mouse-event handler\r
56  * \code\r
57  * void CTestDlg::OnMouseMove(UINT nFlags, CPoint point)\r
58  * {\r
59  *      CRect r;\r
60  *      r.left = 15;\r
61  *      r.top = 20;\r
62  *      r.right = r.left + m_renderSrc.GetWidth();\r
63  *      r.bottom = r.top + m_renderSrc.GetHeight();\r
64  * \r
65  *      if(r.PtInRect(point) == TRUE)\r
66  *      {\r
67  *              // dibs are drawn upside down...\r
68  *              point.y -= 20;\r
69  *              point.y = 167-point.y;\r
70  * \r
71  *              if (nFlags & MK_LBUTTON)\r
72  *                      m_waterEffect.Blob(point.x -15,point.y,5,80,m_waterEffect.m_iHpage);\r
73  *              else\r
74  *                      m_waterEffect.Blob(point.x -15,point.y,2,30,m_waterEffect.m_iHpage);\r
75  *      }\r
76  *      CDialog::OnMouseMove(nFlags, point);\r
77  * }\r
78  * \endcode\r
79  */\r
80 class CWaterEffect  \r
81 {\r
82 public:\r
83         CWaterEffect();\r
84         virtual ~CWaterEffect();\r
85 \r
86 \r
87         /**\r
88          * Creates the CWaterEffect object used for a picture with a width of \a iWidth and a height of \a iHeight\r
89          * \param iWidth the width of the picture in pixels\r
90          * \param iHeight the height of the picture in pixels\r
91          */\r
92         void Create(int iWidth,int iHeight);\r
93         /**\r
94          * Renders the picture, i.e. perform the required calculations on \a pSrcImage and store the result in\r
95          * \a pTargetImage\r
96          * \param pSrcImage the image to perform the rendering on\r
97          * \param pTargetImage the resulting image\r
98          */\r
99         void Render(DWORD* pSrcImage,DWORD* pTargetImage);\r
100         /**\r
101          * Adds a 'Blob' to the picture, i.e. the effect of a drop falling in the water.\r
102          * \param x the x coordinate of the blob position\r
103          * \param y the y coordinate of the blob position\r
104          * \param radius the radius in pixels the blob (or drop) should have\r
105          * \param height the height of the blob, i.e. how deep it will enter the water\r
106          * \param page which of the two buffers to use. \r
107          * \remark since DIB's are drawn upside down the y coordinate has to be 'flipped', i.e. subtract the\r
108          * height of the picture from the real y coordinate first.\r
109          */\r
110         void Blob(int x, int y, int radius, int height, int page);\r
111 \r
112         int                     m_iDensity;     ///< The water density, higher values lead to slower water motion\r
113         int                     m_iHpage;       ///< the buffer which is in use\r
114 private:\r
115         /**\r
116          * Clears both buffers. The result is that all effects are cleared.\r
117          */\r
118         void ClearWater();\r
119         /**\r
120          * performs the calculations.\r
121          * \param npage which buffer to use\r
122          * \param density the water density\r
123          */\r
124         void CalcWater(int npage, int density);\r
125         /**\r
126          * Smooths the waves of the water so that they disappear after a while\r
127          * \param npage the buffer to use\r
128          */\r
129         void SmoothWater(int npage);\r
130 \r
131         /**\r
132          * Draws the water effect to the resulting image buffer\r
133          * \param page the internal buffer to use\r
134          * \param LightModifier how much light to use. Higher values give more 'contrast/shadows' of the waves.\r
135          * \param pSrcImage the image to use\r
136          * \param pTargetImage the resulting image\r
137          */\r
138         void DrawWater(int page, int LightModifier,DWORD* pSrcImage,DWORD* pTargetImage);\r
139         /**\r
140          * Converts the colors of the source picture (perhaps with color tables) to true color values.\r
141          */\r
142         COLORREF GetShiftedColor(COLORREF color,int shift);\r
143 \r
144         int                     m_iLightModifier;\r
145         int                     m_iWidth;\r
146         int                     m_iHeight;\r
147 \r
148         int*            m_iBuffer1;\r
149         int*            m_iBuffer2;\r
150 \r
151 };\r
152 \r