Skip to content

Commit

Permalink
Add two dragging modes (vertical wipe and horizontal wipe)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Apr 25, 2020
1 parent 2fa55a2 commit 418bf6f
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 5 deletions.
83 changes: 83 additions & 0 deletions src/ImgDiffBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1061,6 +1088,10 @@ class CImgDiffBuffer
(this->*func)(1, 2);
}
}
if (m_wipeMode != WIPE_NONE)
{
WipeEffect();
}
if (m_showDifferences)
{
bool showDiff = true;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions src/ImgMergeWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<int>((evt.x - pImgWnd->m_ptOrg.x) / zoom), static_cast<int>((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:
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/WinIMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IImgMergeWindow::DRAGGING_MODE>(wmId - ID_VIEW_DRAGGINGMODE_NONE));
UpdateMenuState(hWnd);
break;
case ID_VIEW_USEBACKCOLOR:
{
Expand Down
2 changes: 2 additions & 0 deletions src/WinIMerge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/WinIMergeLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 5 additions & 3 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 418bf6f

Please sign in to comment.