From 418bf6f6ed74597d14c6978f963ef4e08652d156 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 25 Apr 2020 09:49:56 +0900 Subject: [PATCH] Add two dragging modes (vertical wipe and horizontal wipe) --- src/ImgDiffBuffer.hpp | 83 ++++++++++++++++++++++++++++++++++++++++++ src/ImgMergeWindow.hpp | 31 ++++++++++++++++ src/WinIMerge.cpp | 5 ++- src/WinIMerge.rc | 2 + src/WinIMergeLib.h | 2 +- src/resource.h | 8 ++-- 6 files changed, 126 insertions(+), 5 deletions(-) diff --git a/src/ImgDiffBuffer.hpp b/src/ImgDiffBuffer.hpp index daa898f..e37a73a 100644 --- a/src/ImgDiffBuffer.hpp +++ b/src/ImgDiffBuffer.hpp @@ -553,6 +553,9 @@ class CImgDiffBuffer enum OVERLAY_MODE { OVERLAY_NONE = 0, OVERLAY_XOR, OVERLAY_ALPHABLEND, OVERLAY_ALPHABLEND_ANIM }; + enum WIPE_MODE { + WIPE_NONE = 0, WIPE_VERTICAL, WIPE_HORIZONTAL + }; enum { BLINK_TIME = 800 }; enum { OVERLAY_ALPHABLEND_ANIM_TIME = 1000 }; @@ -565,6 +568,8 @@ class CImgDiffBuffer , m_insertionDeletionDetectionMode(INSERTION_DELETION_DETECTION_NONE) , m_overlayMode(OVERLAY_NONE) , m_overlayAlpha(0.3) + , m_wipeMode(WIPE_NONE) + , m_wipePosition(0) , m_diffBlockSize(8) , m_selDiffColor(Image::Rgb(0xff, 0x40, 0x40)) , m_selDiffDeletedColor(Image::Rgb(0xf0, 0xc0, 0xc0)) @@ -790,6 +795,28 @@ class CImgDiffBuffer RefreshImages(); } + WIPE_MODE GetWipeMode() const + { + return m_wipeMode; + } + + void SetWipeMode(WIPE_MODE wipeMode) + { + m_wipeMode = wipeMode; + RefreshImages(); + } + + int GetWipePosition() const + { + return m_wipePosition; + } + + void SetWipePosition(int pos) + { + m_wipePosition = pos; + RefreshImages(); + } + bool GetShowDifferences() const { return m_showDifferences; @@ -1061,6 +1088,10 @@ class CImgDiffBuffer (this->*func)(1, 2); } } + if (m_wipeMode != WIPE_NONE) + { + WipeEffect(); + } if (m_showDifferences) { bool showDiff = true; @@ -1734,6 +1765,56 @@ class CImgDiffBuffer } } + void WipeEffect() + { + const unsigned w = m_imgDiff[0].width(); + const unsigned h = m_imgDiff[0].height(); + + if (m_wipeMode == WIPE_VERTICAL) + { + auto tmp = new unsigned char[w * 4]; + for (unsigned y = m_wipePosition; y < h; ++y) + { + for (int pane = 0; pane < m_nImages - 1; ++pane) + { + unsigned char *scanline = m_imgDiff[pane].scanLine(y); + unsigned char *scanline2 = m_imgDiff[pane + 1].scanLine(y); + memcpy(tmp, scanline, w * 4); + memcpy(scanline, scanline2, w * 4); + memcpy(scanline2, tmp, w * 4); + } + } + delete tmp; + } + else if (m_wipeMode = WIPE_HORIZONTAL) + { + for (unsigned y = 0; y < h; ++y) + { + for (int pane = 0; pane < m_nImages - 1; ++pane) + { + unsigned char *scanline = m_imgDiff[pane].scanLine(y); + unsigned char *scanline2 = m_imgDiff[pane + 1].scanLine(y); + for (unsigned x = m_wipePosition; x < w; ++x) + { + unsigned char tmp[4]; + tmp[0] = scanline[x * 4 + 0]; + tmp[1] = scanline[x * 4 + 1]; + tmp[2] = scanline[x * 4 + 2]; + tmp[3] = scanline[x * 4 + 3]; + scanline[x * 4 + 0] = scanline2[x * 4 + 0]; + scanline[x * 4 + 1] = scanline2[x * 4 + 1]; + scanline[x * 4 + 2] = scanline2[x * 4 + 2]; + scanline[x * 4 + 3] = scanline2[x * 4 + 3]; + scanline2[x * 4 + 0] = tmp[0]; + scanline2[x * 4 + 1] = tmp[1]; + scanline2[x * 4 + 2] = tmp[2]; + scanline2[x * 4 + 3] = tmp[3]; + } + } + } + } + } + void CopyPreprocessedImageToDiffImage(int dst) { unsigned w = m_imgPreprocessed[dst].width(); @@ -2020,6 +2101,8 @@ class CImgDiffBuffer INSERTION_DELETION_DETECTION_MODE m_insertionDeletionDetectionMode; OVERLAY_MODE m_overlayMode; double m_overlayAlpha; + WIPE_MODE m_wipeMode; + int m_wipePosition; unsigned m_diffBlockSize; Image::Color m_selDiffColor; Image::Color m_selDiffDeletedColor; diff --git a/src/ImgMergeWindow.hpp b/src/ImgMergeWindow.hpp index 7a3070f..5321af7 100644 --- a/src/ImgMergeWindow.hpp +++ b/src/ImgMergeWindow.hpp @@ -1163,6 +1163,17 @@ class CImgMergeWindow : public IImgMergeWindow pImgWnd->m_ptPrev.x = INT_MIN; pImgWnd->m_ptPrev.y = INT_MIN; SetCapture(hwnd); + POINT pt = pImgWnd->GetCursorPos(evt.pane); + if (pImgWnd->m_draggingMode == DRAGGING_MODE::VERTICAL_WIPE) + { + pImgWnd->m_buffer.SetWipeMode(CImgDiffBuffer::WIPE_VERTICAL); + pImgWnd->m_buffer.SetWipePosition(pt.x); + } + else if (pImgWnd->m_draggingMode == DRAGGING_MODE::HORIZONTAL_WIPE) + { + pImgWnd->m_buffer.SetWipeMode(CImgDiffBuffer::WIPE_HORIZONTAL); + pImgWnd->m_buffer.SetWipePosition(pt.x); + } break; } case WM_LBUTTONUP: @@ -1179,6 +1190,12 @@ class CImgMergeWindow : public IImgMergeWindow pImgWnd->m_imgWindow[evt.pane].DrawFocusRectangle(offsetX, offsetY, pImgWnd->GetImageWidth(evt.pane), pImgWnd->GetImageHeight(evt.pane)); pImgWnd->AddImageOffset(evt.pane, static_cast((evt.x - pImgWnd->m_ptOrg.x) / zoom), static_cast((evt.y - pImgWnd->m_ptOrg.y) / zoom)); } + else if (pImgWnd->m_draggingMode == DRAGGING_MODE::VERTICAL_WIPE || + pImgWnd->m_draggingMode == DRAGGING_MODE::HORIZONTAL_WIPE) + { + pImgWnd->m_buffer.SetWipeMode(CImgDiffBuffer::WIPE_NONE); + pImgWnd->Invalidate(); + } } break; case WM_MOUSEMOVE: @@ -1224,6 +1241,20 @@ class CImgMergeWindow : public IImgMergeWindow pImgWnd->m_ptPrev.x = evt.x; pImgWnd->m_ptPrev.y = evt.y; } + else if (pImgWnd->m_draggingMode == DRAGGING_MODE::VERTICAL_WIPE) + { + POINT pt = pImgWnd->GetCursorPos(evt.pane); + pImgWnd->m_buffer.SetWipePosition(pt.y); + pImgWnd->Invalidate(); + SetCursor(LoadCursor(NULL, IDC_SIZENS)); + } + else if (pImgWnd->m_draggingMode == DRAGGING_MODE::HORIZONTAL_WIPE) + { + POINT pt = pImgWnd->GetCursorPos(evt.pane); + pImgWnd->m_buffer.SetWipePosition(pt.x); + pImgWnd->Invalidate(); + SetCursor(LoadCursor(NULL, IDC_SIZEWE)); + } } break; } diff --git a/src/WinIMerge.cpp b/src/WinIMerge.cpp index 57722b0..1537018 100644 --- a/src/WinIMerge.cpp +++ b/src/WinIMerge.cpp @@ -204,7 +204,7 @@ void UpdateMenuState(HWND hWnd) m_pImgMergeWindow->GetInsertionDeletionDetectionMode() + ID_VIEW_INSERTIONDELETIONDETECTION_NONE, MF_BYCOMMAND); CheckMenuRadioItem(hMenu, ID_VIEW_OVERLAY_NONE, ID_VIEW_OVERLAY_ALPHABLEND, m_pImgMergeWindow->GetOverlayMode() + ID_VIEW_OVERLAY_NONE, MF_BYCOMMAND); - CheckMenuRadioItem(hMenu, ID_VIEW_DRAGGINGMODE_NONE, ID_VIEW_DRAGGINGMODE_ADJUST_OFFSET, + CheckMenuRadioItem(hMenu, ID_VIEW_DRAGGINGMODE_NONE, ID_VIEW_DRAGGINGMODE_HORIZONTAL_WIPE, m_pImgMergeWindow->GetDraggingMode() + ID_VIEW_DRAGGINGMODE_NONE, MF_BYCOMMAND); int blockSize = m_pImgMergeWindow->GetDiffBlockSize(); int id = ID_VIEW_DIFFBLOCKSIZE_1; @@ -573,7 +573,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_VIEW_DRAGGINGMODE_NONE: case ID_VIEW_DRAGGINGMODE_MOVE: case ID_VIEW_DRAGGINGMODE_ADJUST_OFFSET: + case ID_VIEW_DRAGGINGMODE_VERTICAL_WIPE: + case ID_VIEW_DRAGGINGMODE_HORIZONTAL_WIPE: m_pImgMergeWindow->SetDraggingMode(static_cast(wmId - ID_VIEW_DRAGGINGMODE_NONE)); + UpdateMenuState(hWnd); break; case ID_VIEW_USEBACKCOLOR: { diff --git a/src/WinIMerge.rc b/src/WinIMerge.rc index e440794..f54cefd 100644 --- a/src/WinIMerge.rc +++ b/src/WinIMerge.rc @@ -148,6 +148,8 @@ BEGIN MENUITEM "&None", ID_VIEW_DRAGGINGMODE_NONE MENUITEM "&Move", ID_VIEW_DRAGGINGMODE_MOVE MENUITEM "&Adjust Offset", ID_VIEW_DRAGGINGMODE_ADJUST_OFFSET + MENUITEM "&Vertical Wipe", ID_VIEW_DRAGGINGMODE_VERTICAL_WIPE + MENUITEM "&Horizontal Wipe", ID_VIEW_DRAGGINGMODE_HORIZONTAL_WIPE END MENUITEM "Split &Horizontally", ID_VIEW_SPLITHORIZONTALLY MENUITEM "&Set Background Color", ID_VIEW_USEBACKCOLOR diff --git a/src/WinIMergeLib.h b/src/WinIMergeLib.h index b5cd03a..ec86514 100644 --- a/src/WinIMergeLib.h +++ b/src/WinIMergeLib.h @@ -36,7 +36,7 @@ struct IImgMergeWindow REFRESH, SCROLLTODIFF, OPEN }; enum DRAGGING_MODE { - NONE = 0, MOVE, ADJUST_OFFSET + NONE = 0, MOVE, ADJUST_OFFSET, VERTICAL_WIPE, HORIZONTAL_WIPE }; struct Event { diff --git a/src/resource.h b/src/resource.h index 5810cf4..d4e70de 100644 --- a/src/resource.h +++ b/src/resource.h @@ -119,9 +119,11 @@ #define ID_VIEW_DRAGGINGMODE_NONE 32845 #define ID_VIEW_DRAGGINGMODE_MOVE 32846 #define ID_VIEW_DRAGGINGMODE_ADJUST_OFFSET 32847 -#define ID_VIEW_INSERTIONDELETIONDETECTION_NONE 32848 -#define ID_VIEW_INSERTIONDELETIONDETECTION_VERTICAL 32849 -#define ID_VIEW_INSERTIONDELETIONDETECTION_HORIZONTAL 32850 +#define ID_VIEW_DRAGGINGMODE_VERTICAL_WIPE 32848 +#define ID_VIEW_DRAGGINGMODE_HORIZONTAL_WIPE 32849 +#define ID_VIEW_INSERTIONDELETIONDETECTION_NONE 32850 +#define ID_VIEW_INSERTIONDELETIONDETECTION_VERTICAL 32851 +#define ID_VIEW_INSERTIONDELETIONDETECTION_HORIZONTAL 32852 #define ID_VIEW_VECTORIMAGESCALING_25 32860 #define ID_VIEW_VECTORIMAGESCALING_50 32861 #define ID_VIEW_VECTORIMAGESCALING_100 32862