1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006,2008 - 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.
21 #define random( min, max ) (( rand() % (int)((( max ) + 1 ) - ( min ))) + ( min ))
26 * Provides a water effect on a picture. To do that the class needs
27 * the picture as an array of pixels. See CDIB class for information
29 * The formulas used in this class I found on a website: http://freespace.virgin.net/hugo.elias/graphics/x_water.htm \n
30 * An example of how to use this class and produce a water effect:
32 * //in your initialization code (e.g. OnInitDialog() )
33 * CPictureHolder tmpPic;
34 * tmpPic.CreateFromBitmap(IDB_LOGOFLIPPED);
35 * m_renderSrc.Create32BitFromPicture(&tmpPic,301,167);
36 * m_renderDest.Create32BitFromPicture(&tmpPic,301,167);
37 * m_waterEffect.Create(301,167);
39 * In a timer function / method you need to render the picture:
41 * m_waterEffect.Render((DWORD*)m_renderSrc.GetDIBits(), (DWORD*)m_renderDest.GetDIBits());
43 * CPoint ptOrigin(15,20);
44 * m_renderDest.Draw(&dc,ptOrigin);
46 * To add blobs you can do that either in a timer too
51 * r.right = r.left + m_renderSrc.GetWidth();
52 * r.bottom = r.top + m_renderSrc.GetHeight();
53 * m_waterEffect.Blob(random(r.left,r.right), random(r.top, r.bottom), 2, 200, m_waterEffect.m_iHpage);
55 * or/and in a mouse-event handler
57 * void CTestDlg::OnMouseMove(UINT nFlags, CPoint point)
62 * r.right = r.left + m_renderSrc.GetWidth();
63 * r.bottom = r.top + m_renderSrc.GetHeight();
65 * if(r.PtInRect(point) == TRUE)
67 * // dibs are drawn upside down...
69 * point.y = 167-point.y;
71 * if (nFlags & MK_LBUTTON)
72 * m_waterEffect.Blob(point.x -15,point.y,5,80,m_waterEffect.m_iHpage);
74 * m_waterEffect.Blob(point.x -15,point.y,2,30,m_waterEffect.m_iHpage);
76 * CDialog::OnMouseMove(nFlags, point);
84 virtual ~CWaterEffect();
88 * Creates the CWaterEffect object used for a picture with a width of \a iWidth and a height of \a iHeight
89 * \param iWidth the width of the picture in pixels
90 * \param iHeight the height of the picture in pixels
92 void Create(int iWidth
,int iHeight
);
94 * Renders the picture, i.e. perform the required calculations on \a pSrcImage and store the result in
96 * \param pSrcImage the image to perform the rendering on
97 * \param pTargetImage the resulting image
99 void Render(DWORD
* pSrcImage
,DWORD
* pTargetImage
);
101 * Adds a 'Blob' to the picture, i.e. the effect of a drop falling in the water.
102 * \param x the x coordinate of the blob position
103 * \param y the y coordinate of the blob position
104 * \param radius the radius in pixels the blob (or drop) should have
105 * \param height the height of the blob, i.e. how deep it will enter the water
106 * \param page which of the two buffers to use.
107 * \remark since DIB's are drawn upside down the y coordinate has to be 'flipped', i.e. subtract the
108 * height of the picture from the real y coordinate first.
110 void Blob(int x
, int y
, int radius
, int height
, int page
);
112 int m_iDensity
; ///< The water density, higher values lead to slower water motion
113 int m_iHpage
; ///< the buffer which is in use
116 * Clears both buffers. The result is that all effects are cleared.
120 * performs the calculations.
121 * \param npage which buffer to use
122 * \param density the water density
124 void CalcWater(int npage
, int density
);
126 * Smooths the waves of the water so that they disappear after a while
127 * \param npage the buffer to use
129 void SmoothWater(int npage
);
132 * Draws the water effect to the resulting image buffer
133 * \param page the internal buffer to use
134 * \param LightModifier how much light to use. Higher values give more 'contrast/shadows' of the waves.
135 * \param pSrcImage the image to use
136 * \param pTargetImage the resulting image
138 void DrawWater(int page
, int LightModifier
,DWORD
* pSrcImage
,DWORD
* pTargetImage
);
140 * Converts the colors of the source picture (perhaps with color tables) to true color values.
142 COLORREF
GetShiftedColor(COLORREF color
,int shift
);
144 int m_iLightModifier
;