Support negative log filter syntax (starts with an exclamation mark)
[TortoiseGit.git] / src / TortoiseIDiff / PicWindow.h
blob672ac735a3cfca78a4a9fce426b8c5ac4e16fd1e
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;
116 enum BlendType
118 BLEND_ALPHA,
119 BLEND_XOR,
121 /// Registers the window class and creates the window
122 bool RegisterAndCreateWindow(HWND hParent);
124 /// Sets the image path and title to show
125 void SetPic(tstring path, tstring title, bool bFirst);
126 /// Returns the CPicture image object. Used to get an already loaded image
127 /// object without having to load it again.
128 CPicture * GetPic() {return &picture;}
129 /// Sets the path and title of the second image which is alpha blended over the original
130 void SetSecondPic(CPicture * pPicture = NULL, const tstring& sectit = _T(""), const tstring& secpath = _T(""), int hpos = 0, int vpos = 0)
132 pSecondPic = pPicture;
133 pictitle2 = sectit;
134 picpath2 = secpath;
135 nVSecondScrollPos = vpos;
136 nHSecondScrollPos = hpos;
139 void StopTimer() {KillTimer(*this, ID_ANIMATIONTIMER);}
141 /// Returns the currently used alpha blending value (0.0-1.0)
142 float GetBlendAlpha() const { return blendAlpha; }
143 /// Sets the alpha blending value
144 void SetBlendAlpha(BlendType type, float a)
146 m_blend = type;
147 blendAlpha = a;
148 if (m_AlphaSlider.IsValid())
149 SendMessage(m_AlphaSlider.GetWindow(), TBM_SETPOS, (WPARAM)1, (LPARAM)(a*16.0f));
150 PositionTrackBar();
151 InvalidateRect(*this, NULL, FALSE);
153 /// Toggle the alpha blending value
154 void ToggleAlpha()
156 if( 0.0f != GetBlendAlpha() )
157 SetBlendAlpha(m_blend, 0.0f);
158 else
159 SetBlendAlpha(m_blend, 1.0f);
162 /// Set the color that this PicWindow will display behind transparent images.
163 void SetTransparentColor(COLORREF back) { transparentColor = back; InvalidateRect(*this, NULL, false); }
165 /// Resizes the image to fit into the window. Small images are not enlarged.
166 void FitImageInWindow();
167 /// center the image in the view
168 void CenterImage();
169 /// forces the widths of the images to be the same
170 void FitWidths(bool bFit);
171 /// forces the heights of the images to be the same
172 void FitHeights(bool bFit);
173 /// Sets the zoom factor of the image
174 void SetZoom(int Zoom, bool centermouse, bool inzoom = false);
175 /// Returns the currently used zoom factor in which the image is shown.
176 int GetZoom() {return picscale;}
177 /// Zooms in (true) or out (false) in nice steps
178 void Zoom(bool in, bool centermouse);
179 /// Sets the 'Other' pic window
180 void SetOtherPicWindow(CPicWindow * pWnd) {pTheOtherPic = pWnd;}
181 /// Links/Unlinks the two pic windows
182 void LinkPositions(bool bLink) {bLinkedPositions = bLink;}
183 /// Sets the overlay mode info
184 void SetOverlapMode(bool b) {bOverlap = b;}
186 void ShowInfo(bool bShow = true) {bShowInfo = bShow; InvalidateRect(*this, NULL, false);}
187 /// Sets up the scrollbars as needed
188 void SetupScrollBars();
190 bool HasMultipleImages();
192 int GetHPos() {return nHScrollPos;}
193 int GetVPos() {return nVScrollPos;}
194 void SetZoomValue(int z) {picscale = z; InvalidateRect(*this, NULL, FALSE);}
196 void SetSelectionMode(bool bSelect = true) { bSelectionMode = bSelect; }
197 /// Handles the mouse wheel
198 void OnMouseWheel(short fwKeys, short zDelta);
199 protected:
200 /// the message handler for this window
201 LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
202 /// Draws the view title bar
203 void DrawViewTitle(HDC hDC, RECT * rect);
204 /// Creates the image buttons
205 bool CreateButtons();
206 /// Handles vertical scrolling
207 void OnVScroll(UINT nSBCode, UINT nPos);
208 /// Handles horizontal scrolling
209 void OnHScroll(UINT nSBCode, UINT nPos);
210 /// Returns the client rectangle, without the scrollbars and the view title.
211 /// Basically the rectangle the image can use.
212 void GetClientRect(RECT * pRect);
213 /// Returns the client rectangle, without the view title but with the scrollbars
214 void GetClientRectWithScrollbars(RECT * pRect);
215 /// the WM_PAINT function
216 void Paint(HWND hwnd);
217 /// Draw pic to hdc, with a border, scaled by scale.
218 void ShowPicWithBorder(HDC hdc, const RECT &bounds, CPicture &pic, int scale);
219 /// Positions the buttons
220 void PositionChildren();
221 /// advance to the next image in the file
222 void NextImage();
223 /// go back to the previous image in the file
224 void PrevImage();
225 /// starts/stops the animation
226 void Animate(bool bStart);
227 /// Creates the trackbar (the alpha blending slider control)
228 void CreateTrackbar(HWND hwndParent);
229 /// Moves the alpha slider trackbar to the correct position
230 void PositionTrackBar();
231 /// creates the info string used in the info box and the tooltips
232 void BuildInfoString(TCHAR * buf, int size, bool bTooltip);
233 /// adjusts the zoom to fit the specified width
234 void SetZoomToWidth(long width);
235 /// adjusts the zoom to fit the specified height
236 void SetZoomToHeight(long height);
239 tstring picpath; ///< the path to the image we show
240 tstring pictitle; ///< the string to show in the image view as a title
241 CPicture picture; ///< the picture object of the image
242 bool bValid; ///< true if the picture object is valid, i.e. if the image could be loaded and can be shown
243 int picscale; ///< the scale factor of the image in percent
244 COLORREF transparentColor; ///< the color to draw under the images
245 bool bFirstpaint; ///< true if the image is painted the first time. Used to initialize some stuff when the window is valid for sure.
246 CPicture * pSecondPic; ///< if set, this is the picture to draw transparently above the original
247 CPicWindow * pTheOtherPic; ///< pointer to the other picture window. Used for "linking" the two windows when scrolling/zooming/...
248 bool bMainPic; ///< if true, this is the first image
249 bool bLinkedPositions; ///< if true, the two image windows are linked together for scrolling/zooming/...
250 bool bFitWidths; ///< if true, the two image windows are shown with the same width
251 bool bFitHeights; ///< if true, the two image windows are shown with the same height
252 bool bOverlap; ///< true if the overlay mode is active
253 bool bDragging; ///< indicates an ongoing dragging operation
254 BlendType m_blend; ///< type of blending to use
255 tstring pictitle2; ///< the title of the second picture
256 tstring picpath2; ///< the path of the second picture
257 float blendAlpha; ///<the alpha value for transparency blending
258 bool bShowInfo; ///< true if the info rectangle of the image should be shown
259 TCHAR m_wszTip[8192];
260 char m_szTip[8192];
261 POINT m_lastTTPos;
262 HWND hwndTT;
263 bool bSelectionMode; ///< true if TortoiseIDiff is in selection mode, used to resolve conflicts
264 // scrollbar info
265 int nVScrollPos; ///< vertical scroll position
266 int nHScrollPos; ///< horizontal scroll position
267 int nVSecondScrollPos; ///< vertical scroll position of second pic at the moment of enabling overlap mode
268 int nHSecondScrollPos; ///< horizontal scroll position of second pic at the moment of enabling overlap mode
269 POINT ptPanStart; ///< the point of the last mouse click
270 int startVScrollPos; ///< the vertical scroll position when panning starts
271 int startHScrollPos; ///< the horizontal scroll position when panning starts
272 int startVSecondScrollPos; ///< the vertical scroll position of the second pic when panning starts
273 int startHSecondScrollPos; ///< the horizontal scroll position of the second pic when panning starts
274 // image frames/dimensions
275 UINT nDimensions;
276 UINT nCurrentDimension;
277 UINT nFrames;
278 UINT nCurrentFrame;
280 // controls
281 HWND hwndLeftBtn;
282 HWND hwndRightBtn;
283 HWND hwndPlayBtn;
284 HWND hwndSelectBtn;
285 CNiceTrackbar m_AlphaSlider;
286 HWND hwndAlphaToggleBtn;
287 HICON hLeft;
288 HICON hRight;
289 HICON hPlay;
290 HICON hStop;
291 HICON hAlphaToggle;
292 bool bPlaying;
293 RECT m_inforect;
295 // linked image sizes/positions
296 long m_linkedWidth;
297 long m_linkedHeight;