Add an option to the TortoiseGitMerge settings dialog to specify the number of contex...
[TortoiseGit.git] / src / TortoiseIDiff / PicWindow.h
blob1bce9c7aaeee41950cc1090125d3837a3d34edc0
1 // TortoiseIDiff - an image diff viewer in TortoiseSVN
3 // Copyright (C) 2006-2010, 2012-2013 - 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.
19 #pragma once
20 #include <CommCtrl.h>
21 #include "BaseWindow.h"
22 #include "TortoiseIDiff.h"
23 #include "Picture.h"
24 #include "NiceTrackbar.h"
26 #define HEADER_HEIGHT 30
28 #define ID_ANIMATIONTIMER 100
29 #define TIMER_ALPHASLIDER 101
30 #define ID_ALPHATOGGLETIMER 102
32 #define LEFTBUTTON_ID 101
33 #define RIGHTBUTTON_ID 102
34 #define PLAYBUTTON_ID 103
35 #define ALPHATOGGLEBUTTON_ID 104
36 #define BLENDALPHA_ID 105
37 #define BLENDXOR_ID 106
38 #define SELECTBUTTON_ID 107
40 #define TRACKBAR_ID 101
41 #define SLIDER_HEIGHT 30
42 #define SLIDER_WIDTH 30
45 #ifndef GET_X_LPARAM
46 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
47 #endif
48 #ifndef GET_Y_LPARAM
49 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
50 #endif
52 /**
53 * \ingroup TortoiseIDiff
54 * The image view window.
55 * Shows an image and provides methods to scale the image or alpha blend it
56 * over another image.
58 class CPicWindow : public CWindow
60 private:
61 CPicWindow() : CWindow(NULL) {}
62 public:
63 CPicWindow(HINSTANCE hInst, const WNDCLASSEX* wcx = NULL) : CWindow(hInst, wcx)
64 , bValid(false)
65 , nHScrollPos(0)
66 , nVScrollPos(0)
67 , picscale(100)
68 , transparentColor(::GetSysColor(COLOR_WINDOW))
69 , pSecondPic(NULL)
70 , blendAlpha(0.5f)
71 , bShowInfo(false)
72 , nDimensions(0)
73 , nCurrentDimension(1)
74 , nFrames(0)
75 , nCurrentFrame(1)
76 , bPlaying(false)
77 , pTheOtherPic(NULL)
78 , bLinkedPositions(true)
79 , bFitWidths(false)
80 , bFitHeights(false)
81 , bOverlap(false)
82 , m_blend(BLEND_ALPHA)
83 , bMainPic(false)
84 , bFirstpaint(false)
85 , nVSecondScrollPos(0)
86 , nHSecondScrollPos(0)
87 , startVScrollPos(0)
88 , startHScrollPos(0)
89 , startVSecondScrollPos(0)
90 , startHSecondScrollPos(0)
91 , hwndTT(0)
92 , hwndLeftBtn(0)
93 , hwndRightBtn(0)
94 , hwndPlayBtn(0)
95 , hwndSelectBtn(0)
96 , hwndAlphaToggleBtn(0)
97 , hLeft(0)
98 , hRight(0)
99 , hPlay(0)
100 , hStop(0)
101 , hAlphaToggle(0)
102 , m_linkedWidth(0)
103 , m_linkedHeight(0)
104 , bDragging(false)
105 , bSelectionMode(false)
107 SetWindowTitle(_T("Picture Window"));
108 m_lastTTPos.x = 0;
109 m_lastTTPos.y = 0;
110 m_wszTip[0] = 0;
111 m_szTip[0] = 0;
112 ptPanStart.x = -1;
113 ptPanStart.y = -1;
114 m_inforect.left = 0;
115 m_inforect.right = 0;
116 m_inforect.bottom = 0;
117 m_inforect.top = 0;
120 enum BlendType
122 BLEND_ALPHA,
123 BLEND_XOR,
125 /// Registers the window class and creates the window
126 bool RegisterAndCreateWindow(HWND hParent);
128 /// Sets the image path and title to show
129 void SetPic(tstring path, tstring title, bool bFirst);
130 /// Returns the CPicture image object. Used to get an already loaded image
131 /// object without having to load it again.
132 CPicture * GetPic() {return &picture;}
133 /// Sets the path and title of the second image which is alpha blended over the original
134 void SetSecondPic(CPicture * pPicture = NULL, const tstring& sectit = _T(""), const tstring& secpath = _T(""), int hpos = 0, int vpos = 0)
136 pSecondPic = pPicture;
137 pictitle2 = sectit;
138 picpath2 = secpath;
139 nVSecondScrollPos = vpos;
140 nHSecondScrollPos = hpos;
143 void StopTimer() {KillTimer(*this, ID_ANIMATIONTIMER);}
145 /// Returns the currently used alpha blending value (0.0-1.0)
146 float GetBlendAlpha() const { return blendAlpha; }
147 /// Sets the alpha blending value
148 void SetBlendAlpha(BlendType type, float a)
150 m_blend = type;
151 blendAlpha = a;
152 if (m_AlphaSlider.IsValid())
153 SendMessage(m_AlphaSlider.GetWindow(), TBM_SETPOS, (WPARAM)1, (LPARAM)(a*16.0f));
154 PositionTrackBar();
155 InvalidateRect(*this, NULL, FALSE);
157 /// Toggle the alpha blending value
158 void ToggleAlpha()
160 if( 0.0f != GetBlendAlpha() )
161 SetBlendAlpha(m_blend, 0.0f);
162 else
163 SetBlendAlpha(m_blend, 1.0f);
166 /// Set the color that this PicWindow will display behind transparent images.
167 void SetTransparentColor(COLORREF back) { transparentColor = back; InvalidateRect(*this, NULL, false); }
169 /// Resizes the image to fit into the window. Small images are not enlarged.
170 void FitImageInWindow();
171 /// center the image in the view
172 void CenterImage();
173 /// forces the widths of the images to be the same
174 void FitWidths(bool bFit);
175 /// forces the heights of the images to be the same
176 void FitHeights(bool bFit);
177 /// Sets the zoom factor of the image
178 void SetZoom(int Zoom, bool centermouse, bool inzoom = false);
179 /// Returns the currently used zoom factor in which the image is shown.
180 int GetZoom() {return picscale;}
181 /// Zooms in (true) or out (false) in nice steps
182 void Zoom(bool in, bool centermouse);
183 /// Sets the 'Other' pic window
184 void SetOtherPicWindow(CPicWindow * pWnd) {pTheOtherPic = pWnd;}
185 /// Links/Unlinks the two pic windows
186 void LinkPositions(bool bLink) {bLinkedPositions = bLink;}
187 /// Sets the overlay mode info
188 void SetOverlapMode(bool b) {bOverlap = b;}
190 void ShowInfo(bool bShow = true) {bShowInfo = bShow; InvalidateRect(*this, NULL, false);}
191 /// Sets up the scrollbars as needed
192 void SetupScrollBars();
194 bool HasMultipleImages();
196 int GetHPos() {return nHScrollPos;}
197 int GetVPos() {return nVScrollPos;}
198 void SetZoomValue(int z) {picscale = z; InvalidateRect(*this, NULL, FALSE);}
200 void SetSelectionMode(bool bSelect = true) { bSelectionMode = bSelect; }
201 /// Handles the mouse wheel
202 void OnMouseWheel(short fwKeys, short zDelta);
203 protected:
204 /// the message handler for this window
205 LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
206 /// Draws the view title bar
207 void DrawViewTitle(HDC hDC, RECT * rect);
208 /// Creates the image buttons
209 bool CreateButtons();
210 /// Handles vertical scrolling
211 void OnVScroll(UINT nSBCode, UINT nPos);
212 /// Handles horizontal scrolling
213 void OnHScroll(UINT nSBCode, UINT nPos);
214 /// Returns the client rectangle, without the scrollbars and the view title.
215 /// Basically the rectangle the image can use.
216 void GetClientRect(RECT * pRect);
217 /// Returns the client rectangle, without the view title but with the scrollbars
218 void GetClientRectWithScrollbars(RECT * pRect);
219 /// the WM_PAINT function
220 void Paint(HWND hwnd);
221 /// Draw pic to hdc, with a border, scaled by scale.
222 void ShowPicWithBorder(HDC hdc, const RECT &bounds, CPicture &pic, int scale);
223 /// Positions the buttons
224 void PositionChildren();
225 /// advance to the next image in the file
226 void NextImage();
227 /// go back to the previous image in the file
228 void PrevImage();
229 /// starts/stops the animation
230 void Animate(bool bStart);
231 /// Creates the trackbar (the alpha blending slider control)
232 void CreateTrackbar(HWND hwndParent);
233 /// Moves the alpha slider trackbar to the correct position
234 void PositionTrackBar();
235 /// creates the info string used in the info box and the tooltips
236 void BuildInfoString(TCHAR * buf, int size, bool bTooltip);
237 /// adjusts the zoom to fit the specified width
238 void SetZoomToWidth(long width);
239 /// adjusts the zoom to fit the specified height
240 void SetZoomToHeight(long height);
243 tstring picpath; ///< the path to the image we show
244 tstring pictitle; ///< the string to show in the image view as a title
245 CPicture picture; ///< the picture object of the image
246 bool bValid; ///< true if the picture object is valid, i.e. if the image could be loaded and can be shown
247 int picscale; ///< the scale factor of the image in percent
248 COLORREF transparentColor; ///< the color to draw under the images
249 bool bFirstpaint; ///< true if the image is painted the first time. Used to initialize some stuff when the window is valid for sure.
250 CPicture * pSecondPic; ///< if set, this is the picture to draw transparently above the original
251 CPicWindow * pTheOtherPic; ///< pointer to the other picture window. Used for "linking" the two windows when scrolling/zooming/...
252 bool bMainPic; ///< if true, this is the first image
253 bool bLinkedPositions; ///< if true, the two image windows are linked together for scrolling/zooming/...
254 bool bFitWidths; ///< if true, the two image windows are shown with the same width
255 bool bFitHeights; ///< if true, the two image windows are shown with the same height
256 bool bOverlap; ///< true if the overlay mode is active
257 bool bDragging; ///< indicates an ongoing dragging operation
258 BlendType m_blend; ///< type of blending to use
259 tstring pictitle2; ///< the title of the second picture
260 tstring picpath2; ///< the path of the second picture
261 float blendAlpha; ///<the alpha value for transparency blending
262 bool bShowInfo; ///< true if the info rectangle of the image should be shown
263 TCHAR m_wszTip[8192];
264 char m_szTip[8192];
265 POINT m_lastTTPos;
266 HWND hwndTT;
267 bool bSelectionMode; ///< true if TortoiseIDiff is in selection mode, used to resolve conflicts
268 // scrollbar info
269 int nVScrollPos; ///< vertical scroll position
270 int nHScrollPos; ///< horizontal scroll position
271 int nVSecondScrollPos; ///< vertical scroll position of second pic at the moment of enabling overlap mode
272 int nHSecondScrollPos; ///< horizontal scroll position of second pic at the moment of enabling overlap mode
273 POINT ptPanStart; ///< the point of the last mouse click
274 int startVScrollPos; ///< the vertical scroll position when panning starts
275 int startHScrollPos; ///< the horizontal scroll position when panning starts
276 int startVSecondScrollPos; ///< the vertical scroll position of the second pic when panning starts
277 int startHSecondScrollPos; ///< the horizontal scroll position of the second pic when panning starts
278 // image frames/dimensions
279 UINT nDimensions;
280 UINT nCurrentDimension;
281 UINT nFrames;
282 UINT nCurrentFrame;
284 // controls
285 HWND hwndLeftBtn;
286 HWND hwndRightBtn;
287 HWND hwndPlayBtn;
288 HWND hwndSelectBtn;
289 CNiceTrackbar m_AlphaSlider;
290 HWND hwndAlphaToggleBtn;
291 HICON hLeft;
292 HICON hRight;
293 HICON hPlay;
294 HICON hStop;
295 HICON hAlphaToggle;
296 bool bPlaying;
297 RECT m_inforect;
299 // linked image sizes/positions
300 long m_linkedWidth;
301 long m_linkedHeight;