--- /dev/null
+// TortoiseIDiff - an image diff viewer in TortoiseSVN\r
+\r
+// Copyright (C) 2006-2009 - TortoiseSVN\r
+\r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// as published by the Free Software Foundation; either version 2\r
+// of the License, or (at your option) any later version.\r
+\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software Foundation,\r
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+//\r
+#pragma once\r
+#include "commctrl.h"\r
+#include "BaseWindow.h"\r
+#include "TortoiseIDiff.h"\r
+#include "Picture.h"\r
+#include "NiceTrackbar.h"\r
+\r
+#define HEADER_HEIGHT 30\r
+\r
+#define ID_ANIMATIONTIMER 100\r
+#define TIMER_ALPHASLIDER 101\r
+#define ID_ALPHATOGGLETIMER 102\r
+\r
+#define LEFTBUTTON_ID 101\r
+#define RIGHTBUTTON_ID 102\r
+#define PLAYBUTTON_ID 103\r
+#define ALPHATOGGLEBUTTON_ID 104\r
+#define BLENDALPHA_ID 105\r
+#define BLENDXOR_ID 106\r
+\r
+#define TRACKBAR_ID 101\r
+#define SLIDER_HEIGHT 30\r
+#define SLIDER_WIDTH 30\r
+\r
+\r
+#ifndef GET_X_LPARAM\r
+#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))\r
+#endif\r
+#ifndef GET_Y_LPARAM\r
+#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))\r
+#endif\r
+\r
+/**\r
+ * \ingroup TortoiseIDiff\r
+ * The image view window.\r
+ * Shows an image and provides methods to scale the image or alpha blend it\r
+ * over another image.\r
+ */\r
+class CPicWindow : public CWindow\r
+{\r
+public:\r
+ CPicWindow(HINSTANCE hInst, const WNDCLASSEX* wcx = NULL) : CWindow(hInst, wcx)\r
+ , bValid(false)\r
+ , nHScrollPos(0)\r
+ , nVScrollPos(0)\r
+ , picscale(1.0)\r
+ , transparentColor(::GetSysColor(COLOR_WINDOW))\r
+ , pSecondPic(NULL)\r
+ , blendAlpha(0.5f)\r
+ , bShowInfo(false)\r
+ , nDimensions(0)\r
+ , nCurrentDimension(1)\r
+ , nFrames(0)\r
+ , nCurrentFrame(1)\r
+ , bPlaying(false)\r
+ , pTheOtherPic(NULL)\r
+ , bLinkedPositions(true)\r
+ , bFitSizes(false)\r
+ , m_blend(BLEND_ALPHA)\r
+ , bMainPic(false)\r
+ { \r
+ SetWindowTitle(_T("Picture Window"));\r
+ m_lastTTPos.x = 0;\r
+ m_lastTTPos.y = 0;\r
+ };\r
+\r
+ enum BlendType\r
+ {\r
+ BLEND_ALPHA,\r
+ BLEND_XOR,\r
+ };\r
+ /// Registers the window class and creates the window\r
+ bool RegisterAndCreateWindow(HWND hParent);\r
+\r
+ /// Sets the image path and title to show\r
+ void SetPic(tstring path, tstring title, bool bFirst);\r
+ /// Returns the CPicture image object. Used to get an already loaded image\r
+ /// object without having to load it again.\r
+ CPicture * GetPic() {return &picture;}\r
+ /// Sets the path and title of the second image which is alpha blended over the original\r
+ void SetSecondPic(CPicture * pPicture = NULL, const tstring& sectit = _T(""), const tstring& secpath = _T(""), int hpos = 0, int vpos = 0)\r
+ {\r
+ pSecondPic = pPicture;\r
+ pictitle2 = sectit;\r
+ picpath2 = secpath;\r
+ nVSecondScrollPos = vpos;\r
+ nHSecondScrollPos = hpos;\r
+ }\r
+\r
+ void StopTimer() {KillTimer(*this, ID_ANIMATIONTIMER);}\r
+ \r
+ /// Returns the currently used alpha blending value (0.0-1.0)\r
+ float GetBlendAlpha() const { return blendAlpha; }\r
+ /// Sets the alpha blending value\r
+ void SetBlendAlpha(BlendType type, float a) \r
+ {\r
+ m_blend = type;\r
+ blendAlpha = a;\r
+ if (m_AlphaSlider.IsValid())\r
+ SendMessage(m_AlphaSlider.GetWindow(), TBM_SETPOS, (WPARAM)1, (LPARAM)(a*16.0f));\r
+ PositionTrackBar();\r
+ InvalidateRect(*this, NULL, FALSE);\r
+ }\r
+ /// Toggle the alpha blending value\r
+ void ToggleAlpha()\r
+ {\r
+ if( 0.0f != GetBlendAlpha() )\r
+ SetBlendAlpha(m_blend, 0.0f);\r
+ else\r
+ SetBlendAlpha(m_blend, 1.0f);\r
+ }\r
+\r
+ /// Set the color that this PicWindow will display behind transparent images.\r
+ void SetTransparentColor(COLORREF back) { transparentColor = back; InvalidateRect(*this, NULL, false); }\r
+\r
+ /// Resizes the image to fit into the window. Small images are not enlarged.\r
+ void FitImageInWindow();\r
+ /// center the image in the view\r
+ void CenterImage();\r
+ /// Makes both images the same size, fitting into the window\r
+ void FitSizes(bool bFit);\r
+ /// Sets the zoom factor of the image\r
+ void SetZoom(double dZoom, bool centermouse);\r
+ /// Returns the currently used zoom factor in which the image is shown.\r
+ double GetZoom() {return picscale;}\r
+ /// Zooms in (true) or out (false) in nice steps\r
+ void Zoom(bool in, bool centermouse);\r
+ /// Sets the 'Other' pic window\r
+ void SetOtherPicWindow(CPicWindow * pWnd) {pTheOtherPic = pWnd;}\r
+ /// Links/Unlinks the two pic windows\r
+ void LinkPositions(bool bLink) {bLinkedPositions = bLink;}\r
+\r
+ void ShowInfo(bool bShow = true) {bShowInfo = bShow; InvalidateRect(*this, NULL, false);}\r
+ /// Sets up the scrollbars as needed\r
+ void SetupScrollBars();\r
+\r
+ bool HasMultipleImages();\r
+\r
+ int GetHPos() {return nHScrollPos;}\r
+ int GetVPos() {return nVScrollPos;}\r
+ void SetZoomValue(double z) {picscale = z; InvalidateRect(*this, NULL, FALSE);}\r
+\r
+ /// Handles the mouse wheel\r
+ void OnMouseWheel(short fwKeys, short zDelta);\r
+protected:\r
+ /// the message handler for this window\r
+ LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\r
+ /// Draws the view title bar\r
+ void DrawViewTitle(HDC hDC, RECT * rect);\r
+ /// Creates the image buttons\r
+ bool CreateButtons();\r
+ /// Handles vertical scrolling\r
+ void OnVScroll(UINT nSBCode, UINT nPos);\r
+ /// Handles horizontal scrolling\r
+ void OnHScroll(UINT nSBCode, UINT nPos);\r
+ /// Returns the client rectangle, without the scrollbars and the view title.\r
+ /// Basically the rectangle the image can use.\r
+ void GetClientRect(RECT * pRect);\r
+ /// Returns the client rectangle, without the view title but with the scrollbars\r
+ void GetClientRectWithScrollbars(RECT * pRect);\r
+ /// the WM_PAINT function\r
+ void Paint(HWND hwnd);\r
+ /// Draw pic to hdc, with a border, scaled by scale.\r
+ void ShowPicWithBorder(HDC hdc, const RECT &bounds, CPicture &pic, double scale);\r
+ /// Positions the buttons\r
+ void PositionChildren();\r
+ /// Rounds a double to a given precision\r
+ double RoundDouble(double doValue, int nPrecision);\r
+ /// advance to the next image in the file\r
+ void NextImage();\r
+ /// go back to the previous image in the file\r
+ void PrevImage();\r
+ /// starts/stops the animation\r
+ void Animate(bool bStart);\r
+ /// Creates the trackbar (the alpha blending slider control)\r
+ void CreateTrackbar(HWND hwndParent);\r
+ /// Moves the alpha slider trackbar to the correct position\r
+ void PositionTrackBar();\r
+ /// creates the info string used in the info box and the tooltips\r
+ void BuildInfoString(TCHAR * buf, int size, bool bTooltip);\r
+\r
+ tstring picpath; ///< the path to the image we show\r
+ tstring pictitle; ///< the string to show in the image view as a title\r
+ CPicture picture; ///< the picture object of the image\r
+ bool bValid; ///< true if the picture object is valid, i.e. if the image could be loaded and can be shown\r
+ double picscale; ///< the scale factor of the image\r
+ COLORREF transparentColor; ///< the color to draw under the images\r
+ bool bFirstpaint; ///< true if the image is painted the first time. Used to initialize some stuff when the window is valid for sure.\r
+ CPicture * pSecondPic; ///< if set, this is the picture to draw transparently above the original\r
+ CPicWindow * pTheOtherPic; ///< pointer to the other picture window. Used for "linking" the two windows when scrolling/zooming/...\r
+ bool bMainPic; ///< if true, this is the first image\r
+ bool bLinkedPositions; ///< if true, the two image windows are linked together for scrolling/zooming/...\r
+ bool bFitSizes; ///< if true, the two image windows are always zoomed so they match their size\r
+ BlendType m_blend; ///< type of blending to use\r
+ tstring pictitle2; ///< the title of the second picture\r
+ tstring picpath2; ///< the path of the second picture\r
+ float blendAlpha; ///<the alpha value for transparency blending\r
+ bool bShowInfo; ///< true if the info rectangle of the image should be shown\r
+ TCHAR m_wszTip[8192];\r
+ char m_szTip[8192];\r
+ POINT m_lastTTPos;\r
+ HWND hwndTT;\r
+ // scrollbar info\r
+ int nVScrollPos; ///< vertical scroll position\r
+ int nHScrollPos; ///< horizontal scroll position\r
+ int nVSecondScrollPos; ///< vertical scroll position of second pic at the moment of enabling overlap mode\r
+ int nHSecondScrollPos; ///< horizontal scroll position of second pic at the moment of enabling overlap mode\r
+ POINT ptPanStart; ///< the point of the last mouse click\r
+ int startVScrollPos; ///< the vertical scroll position when panning starts\r
+ int startHScrollPos; ///< the horizontal scroll position when panning starts\r
+ int startVSecondScrollPos; ///< the vertical scroll position of the second pic when panning starts\r
+ int startHSecondScrollPos; ///< the horizontal scroll position of the second pic when panning starts\r
+ // image frames/dimensions\r
+ UINT nDimensions;\r
+ UINT nCurrentDimension;\r
+ UINT nFrames;\r
+ UINT nCurrentFrame;\r
+\r
+ // controls\r
+ HWND hwndLeftBtn;\r
+ HWND hwndRightBtn;\r
+ HWND hwndPlayBtn;\r
+ CNiceTrackbar m_AlphaSlider;\r
+ HWND hwndAlphaToggleBtn;\r
+ HICON hLeft;\r
+ HICON hRight;\r
+ HICON hPlay;\r
+ HICON hStop;\r
+ HICON hAlphaToggle;\r
+ bool bPlaying;\r
+ RECT m_inforect;\r
+};\r
+\r
+\r
+\r
+\r