Skip to content

Commit

Permalink
Make it possible to change the blink interval and overlay animation i…
Browse files Browse the repository at this point in the history
…nterval.
  • Loading branch information
sdottaka committed Jul 23, 2024
1 parent 05b9c5d commit bb2f4cd
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 35 deletions.
63 changes: 50 additions & 13 deletions src/WinIMerge/WinIMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ wchar_t m_szTitle[256] = L"WinIMerge";
wchar_t m_szWindowClass[256] = L"WinIMergeClass";
IImgMergeWindow *m_pImgMergeWindow = NULL;
IImgToolWindow *m_pImgToolWindow = NULL;
static const int INTERVALS[] = { 200, 400, 600, 800, 1000, 1200, 1500, 2000, 3000, 4000 };

#define IMAGES_FILE_FILTER_WILDCARDS L"*.3fr;*.ari;*.arw;*.avci;*.avcs;*.avif;*.avifs;*.bay;*.bmp;*.cap;*.cr2;*.cr3;*.crw;*.cur;*.dcr;*.dcs;*.dds;*.dib;*.dng;*.drf;*.eip;*.erf;*.exif;*.fff;*.gif;*.heic;*.heics;*.heif;*.heifs;*.hif;*.ico;*.icon;*.iiq;*.jfif;*.jpe;*.jpeg;*.jpg;*.jxl;*.jxr;*.k25;*.kdc;*.mef;*.mos;*.mrw;*.nef;*.nrw;*.orf;*.ori;*.pef;*.png;*.ptx;*.pxn;*.raf;*.raw;*.rle;*.rw2;*.rwl;*.sr2;*.srf;*.srw;*.tif;*.tiff;*.wdp;*.webp;*.x3f;*.tga;*.psd;*.svg;*.emf;*.pdf"
static wchar_t const ImagesFileFilter[] = L"Images (" IMAGES_FILE_FILTER_WILDCARDS L")\0" IMAGES_FILE_FILTER_WILDCARDS L"\0";
Expand Down Expand Up @@ -208,6 +209,7 @@ void UpdateMenuState(HWND hWnd)
{
HMENU hMenu = GetMenu(hWnd);
CheckMenuItem(hMenu, ID_VIEW_VIEWDIFFERENCES, m_pImgMergeWindow->GetShowDifferences() ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(hMenu, ID_VIEW_BLINKDIFFERENCES, m_pImgMergeWindow->GetBlinkDifferences() ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(hMenu, ID_VIEW_SPLITHORIZONTALLY, m_pImgMergeWindow->GetHorizontalSplit() ? MF_CHECKED : MF_UNCHECKED);
CheckMenuRadioItem(hMenu, ID_VIEW_INSERTIONDELETIONDETECTION_NONE, ID_VIEW_INSERTIONDELETIONDETECTION_HORIZONTAL,
m_pImgMergeWindow->GetInsertionDeletionDetectionMode() + ID_VIEW_INSERTIONDELETIONDETECTION_NONE, MF_BYCOMMAND);
Expand Down Expand Up @@ -438,6 +440,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
MoveWindow(m_hwndStatusBar, rc.left, rc.bottom, rc.right, rc.bottom + rcStatusBar.bottom, TRUE);
break;
}
case WM_INITMENUPOPUP:
UpdateMenuState(hWnd);
break;
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
Expand Down Expand Up @@ -557,32 +562,38 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_VIEW_ZOOM_50:
case ID_VIEW_ZOOM_25:
m_pImgMergeWindow->SetZoom(pow(2.0, (wmId - ID_VIEW_ZOOM_100)));
m_pImgToolWindow->Sync();
break;
case ID_VIEW_ZOOMIN:
m_pImgMergeWindow->SetZoom(m_pImgMergeWindow->GetZoom() + 0.1);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_ZOOMOUT:
m_pImgMergeWindow->SetZoom(m_pImgMergeWindow->GetZoom() - 0.1);
break;
case ID_VIEW_OVERLAY_NONE:
m_pImgMergeWindow->SetOverlayMode(IImgMergeWindow::OVERLAY_NONE);
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_OVERLAY_ALPHABLEND:
m_pImgMergeWindow->SetOverlayMode(IImgMergeWindow::OVERLAY_ALPHABLEND);
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_OVERLAY_ALPHABLEND_ANIM:
m_pImgMergeWindow->SetOverlayMode(IImgMergeWindow::OVERLAY_ALPHABLEND_ANIM);
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_OVERLAY_XOR:
m_pImgMergeWindow->SetOverlayMode(IImgMergeWindow::OVERLAY_XOR);
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_VIEWDIFFERENCES:
m_pImgMergeWindow->SetShowDifferences(!m_pImgMergeWindow->GetShowDifferences());
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_BLINKDIFFERENCES:
m_pImgMergeWindow->SetBlinkDifferences(!m_pImgMergeWindow->GetBlinkDifferences());
m_pImgToolWindow->Sync();
break;
case ID_VIEW_DIFFBLOCKSIZE_1:
case ID_VIEW_DIFFBLOCKSIZE_2:
Expand All @@ -591,11 +602,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_VIEW_DIFFBLOCKSIZE_16:
case ID_VIEW_DIFFBLOCKSIZE_32:
m_pImgMergeWindow->SetDiffBlockSize(1 << (wmId - ID_VIEW_DIFFBLOCKSIZE_1));
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_THRESHOLD_0:
m_pImgMergeWindow->SetColorDistanceThreshold(0);
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_THRESHOLD_2:
case ID_VIEW_THRESHOLD_4:
Expand All @@ -604,25 +615,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_VIEW_THRESHOLD_32:
case ID_VIEW_THRESHOLD_64:
m_pImgMergeWindow->SetColorDistanceThreshold((1 << (wmId - ID_VIEW_THRESHOLD_2)) * 2.0);
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_INSERTIONDELETIONDETECTION_NONE:
case ID_VIEW_INSERTIONDELETIONDETECTION_VERTICAL:
case ID_VIEW_INSERTIONDELETIONDETECTION_HORIZONTAL:
m_pImgMergeWindow->SetInsertionDeletionDetectionMode(static_cast<IImgMergeWindow::INSERTION_DELETION_DETECTION_MODE>(wmId - ID_VIEW_INSERTIONDELETIONDETECTION_NONE));
UpdateMenuState(hWnd);
m_pImgToolWindow->Sync();
break;
case ID_VIEW_DIFF_ALGORITHM_MYERS:
case ID_VIEW_DIFF_ALGORITHM_MINIMAL:
case ID_VIEW_DIFF_ALGORITHM_PATIENCE:
case ID_VIEW_DIFF_ALGORITHM_HISTOGRAM:
case ID_VIEW_DIFF_ALGORITHM_NONE:
m_pImgMergeWindow->SetDiffAlgorithm(static_cast<IImgMergeWindow::DIFF_ALGORITHM>(wmId - ID_VIEW_DIFF_ALGORITHM_MYERS));
UpdateMenuState(hWnd);
break;
case ID_VIEW_SPLITHORIZONTALLY:
m_pImgMergeWindow->SetHorizontalSplit(!m_pImgMergeWindow->GetHorizontalSplit());
UpdateMenuState(hWnd);
break;
case ID_VIEW_PAGE_NEXTPAGE:
{
Expand All @@ -643,7 +652,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_VIEW_DRAGGINGMODE_HORIZONTAL_WIPE:
case ID_VIEW_DRAGGINGMODE_RECTANGLE_SELECT:
m_pImgMergeWindow->SetDraggingMode(static_cast<IImgMergeWindow::DRAGGING_MODE>(wmId - ID_VIEW_DRAGGINGMODE_NONE));
UpdateMenuState(hWnd);
break;
case ID_VIEW_USEBACKCOLOR:
{
Expand All @@ -669,7 +677,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
m_pImgMergeWindow->SetUseBackColor(useBackColor);
}
UpdateMenuState(hWnd);
break;
}
case ID_VIEW_VECTORIMAGESCALING_400:
Expand All @@ -679,6 +686,36 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_VIEW_VECTORIMAGESCALING_25:
m_pImgMergeWindow->SetVectorImageZoomRatio(static_cast<float>(pow(2.0, (wmId - ID_VIEW_VECTORIMAGESCALING_100))));
break;
case ID_VIEW_BLINKINTERVAL_200:
case ID_VIEW_BLINKINTERVAL_400:
case ID_VIEW_BLINKINTERVAL_600:
case ID_VIEW_BLINKINTERVAL_800:
case ID_VIEW_BLINKINTERVAL_1000:
case ID_VIEW_BLINKINTERVAL_1200:
case ID_VIEW_BLINKINTERVAL_1500:
case ID_VIEW_BLINKINTERVAL_2000:
case ID_VIEW_BLINKINTERVAL_3000:
case ID_VIEW_BLINKINTERVAL_4000:
{
m_pImgMergeWindow->SetBlinkInterval(INTERVALS[wmId - ID_VIEW_BLINKINTERVAL_200]);
m_pImgToolWindow->Sync();
break;
}
case ID_VIEW_OVERLAYANIMINTERVAL_200:
case ID_VIEW_OVERLAYANIMINTERVAL_400:
case ID_VIEW_OVERLAYANIMINTERVAL_600:
case ID_VIEW_OVERLAYANIMINTERVAL_800:
case ID_VIEW_OVERLAYANIMINTERVAL_1000:
case ID_VIEW_OVERLAYANIMINTERVAL_1200:
case ID_VIEW_OVERLAYANIMINTERVAL_1500:
case ID_VIEW_OVERLAYANIMINTERVAL_2000:
case ID_VIEW_OVERLAYANIMINTERVAL_3000:
case ID_VIEW_OVERLAYANIMINTERVAL_4000:
{
m_pImgMergeWindow->SetOverlayAnimationInterval(INTERVALS[wmId - ID_VIEW_OVERLAYANIMINTERVAL_200]);
m_pImgToolWindow->Sync();
break;
}
case ID_VIEW_EXTRACTTEXT:
{
int pane = m_pImgMergeWindow->GetActivePane();
Expand Down
46 changes: 38 additions & 8 deletions src/WinIMerge/WinIMerge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ BEGIN
POPUP "&View"
BEGIN
MENUITEM "View &Differences", ID_VIEW_VIEWDIFFERENCES
MENUITEM "&Blink Differences", ID_VIEW_BLINKDIFFERENCES
POPUP "Diff &Block Size"
BEGIN
MENUITEM "&1", ID_VIEW_DIFFBLOCKSIZE_1
Expand All @@ -122,14 +123,14 @@ BEGIN
MENUITEM "&None", ID_VIEW_INSERTIONDELETIONDETECTION_NONE
MENUITEM "&Vertical", ID_VIEW_INSERTIONDELETIONDETECTION_VERTICAL
MENUITEM "&Horizontal", ID_VIEW_INSERTIONDELETIONDETECTION_HORIZONTAL
POPUP "Diff Algorithm"
BEGIN
MENUITEM "&Myers", ID_VIEW_DIFF_ALGORITHM_MYERS
MENUITEM "&Minimal", ID_VIEW_DIFF_ALGORITHM_MINIMAL
MENUITEM "&Patience", ID_VIEW_DIFF_ALGORITHM_PATIENCE
MENUITEM "&Histogram", ID_VIEW_DIFF_ALGORITHM_HISTOGRAM
MENUITEM "&None", ID_VIEW_DIFF_ALGORITHM_NONE
END
POPUP "Diff Algorithm"
BEGIN
MENUITEM "&Myers", ID_VIEW_DIFF_ALGORITHM_MYERS
MENUITEM "&Minimal", ID_VIEW_DIFF_ALGORITHM_MINIMAL
MENUITEM "&Patience", ID_VIEW_DIFF_ALGORITHM_PATIENCE
MENUITEM "&Histogram", ID_VIEW_DIFF_ALGORITHM_HISTOGRAM
MENUITEM "&None", ID_VIEW_DIFF_ALGORITHM_NONE
END
END
MENUITEM SEPARATOR
MENUITEM "&Prev Page", ID_VIEW_PAGE_PREVPAGE
Expand Down Expand Up @@ -180,6 +181,35 @@ BEGIN
MENUITEM "50%", ID_VIEW_VECTORIMAGESCALING_50
MENUITEM "25%", ID_VIEW_VECTORIMAGESCALING_25
END
POPUP "&Animation Settings"
BEGIN
POPUP "&Blink interval"
BEGIN
MENUITEM "200[ms]", ID_VIEW_BLINKINTERVAL_200
MENUITEM "400[ms]", ID_VIEW_BLINKINTERVAL_400
MENUITEM "600[ms]", ID_VIEW_BLINKINTERVAL_600
MENUITEM "800[ms]", ID_VIEW_BLINKINTERVAL_800
MENUITEM "1000[ms]", ID_VIEW_BLINKINTERVAL_1000
MENUITEM "1200[ms]", ID_VIEW_BLINKINTERVAL_1200
MENUITEM "1500[ms]", ID_VIEW_BLINKINTERVAL_1500
MENUITEM "2000[ms]", ID_VIEW_BLINKINTERVAL_2000
MENUITEM "3000[ms]", ID_VIEW_BLINKINTERVAL_3000
MENUITEM "4000[ms]", ID_VIEW_BLINKINTERVAL_4000
END
POPUP "&Overlay animation interval"
BEGIN
MENUITEM "200[ms]", ID_VIEW_OVERLAYANIMINTERVAL_200
MENUITEM "400[ms]", ID_VIEW_OVERLAYANIMINTERVAL_400
MENUITEM "600[ms]", ID_VIEW_OVERLAYANIMINTERVAL_600
MENUITEM "800[ms]", ID_VIEW_OVERLAYANIMINTERVAL_800
MENUITEM "1000[ms]", ID_VIEW_OVERLAYANIMINTERVAL_1000
MENUITEM "1200[ms]", ID_VIEW_OVERLAYANIMINTERVAL_1200
MENUITEM "1500[ms]", ID_VIEW_OVERLAYANIMINTERVAL_1500
MENUITEM "2000[ms]", ID_VIEW_OVERLAYANIMINTERVAL_2000
MENUITEM "3000[ms]", ID_VIEW_OVERLAYANIMINTERVAL_3000
MENUITEM "4000[ms]", ID_VIEW_OVERLAYANIMINTERVAL_4000
END
END
MENUITEM SEPARATOR
MENUITEM "Extract &Text", ID_VIEW_EXTRACTTEXT
MENUITEM "Show &Metadata", ID_VIEW_SHOWMETADATA
Expand Down
21 changes: 21 additions & 0 deletions src/WinIMerge/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@
#define ID_VIEW_VECTORIMAGESCALING_400 32864
#define ID_VIEW_EXTRACTTEXT 32870
#define ID_VIEW_SHOWMETADATA 32871
#define ID_VIEW_BLINKINTERVAL_200 32872
#define ID_VIEW_BLINKINTERVAL_400 32873
#define ID_VIEW_BLINKINTERVAL_600 32874
#define ID_VIEW_BLINKINTERVAL_800 32875
#define ID_VIEW_BLINKINTERVAL_1000 32876
#define ID_VIEW_BLINKINTERVAL_1200 32877
#define ID_VIEW_BLINKINTERVAL_1500 32878
#define ID_VIEW_BLINKINTERVAL_2000 32879
#define ID_VIEW_BLINKINTERVAL_3000 32880
#define ID_VIEW_BLINKINTERVAL_4000 32881
#define ID_VIEW_OVERLAYANIMINTERVAL_200 32882
#define ID_VIEW_OVERLAYANIMINTERVAL_400 32883
#define ID_VIEW_OVERLAYANIMINTERVAL_600 32884
#define ID_VIEW_OVERLAYANIMINTERVAL_800 32885
#define ID_VIEW_OVERLAYANIMINTERVAL_1000 32886
#define ID_VIEW_OVERLAYANIMINTERVAL_1200 32887
#define ID_VIEW_OVERLAYANIMINTERVAL_1500 32888
#define ID_VIEW_OVERLAYANIMINTERVAL_2000 32889
#define ID_VIEW_OVERLAYANIMINTERVAL_3000 32890
#define ID_VIEW_OVERLAYANIMINTERVAL_4000 32891
#define ID_VIEW_BLINKDIFFERENCES 32892
#define IDC_STATIC -1

// Next default values for new objects
Expand Down
24 changes: 14 additions & 10 deletions src/WinIMergeLib/ImgDiffBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ class CImgDiffBuffer
MYERS_DIFF, MINIMAL_DIFF, PATIENCE_DIFF, HISTOGRAM_DIFF, NONE_DIFF
};

enum { BLINK_TIME = 800 };
enum { OVERLAY_ALPHABLEND_ANIM_TIME = 1000 };
enum { BLINK_INTERVAL = 800 };
enum { OVERLAY_ANIMATION_INTERVAL = 1000 };

CImgDiffBuffer() :
m_nImages(0)
Expand All @@ -516,6 +516,8 @@ class CImgDiffBuffer
, m_verticalFlip{}
, m_temporarilyTransformed(false)
, m_diffAlgorithm(MYERS_DIFF)
, m_blinkInterval(BLINK_INTERVAL)
, m_overlayAnimationInterval(OVERLAY_ANIMATION_INTERVAL)
{
for (int i = 0; i < 3; ++i)
m_currentPage[i] = 0;
Expand Down Expand Up @@ -1145,7 +1147,7 @@ class CImgDiffBuffer
{
auto now = std::chrono::system_clock::now();
auto tse = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
if ((tse.count() % BLINK_TIME) < BLINK_TIME / 2)
if ((tse.count() % m_blinkInterval) < m_blinkInterval / 2)
{
showDiff = false;
}
Expand Down Expand Up @@ -1970,14 +1972,14 @@ class CImgDiffBuffer
{
auto now = std::chrono::system_clock::now();
auto tse = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
double t = static_cast<double>(tse.count() % OVERLAY_ALPHABLEND_ANIM_TIME);
if (t < OVERLAY_ALPHABLEND_ANIM_TIME * 2 / 10)
overlayAlpha = t / (OVERLAY_ALPHABLEND_ANIM_TIME * 2 / 10);
else if (t < OVERLAY_ALPHABLEND_ANIM_TIME * 5 / 10)
double t = static_cast<double>(tse.count() % m_overlayAnimationInterval);
if (t < m_overlayAnimationInterval * 2 / 10)
overlayAlpha = t / (m_overlayAnimationInterval * 2 / 10);
else if (t < m_overlayAnimationInterval * 5 / 10)
overlayAlpha = 1.0;
else if (t < OVERLAY_ALPHABLEND_ANIM_TIME * 7 / 10)
overlayAlpha = ((OVERLAY_ALPHABLEND_ANIM_TIME * 2 / 10) - (t - (OVERLAY_ALPHABLEND_ANIM_TIME * 5 / 10)))
/ (OVERLAY_ALPHABLEND_ANIM_TIME * 2 / 10);
else if (t < m_overlayAnimationInterval * 7 / 10)
overlayAlpha = ((m_overlayAnimationInterval * 2 / 10) - (t - (m_overlayAnimationInterval * 5 / 10)))
/ (m_overlayAnimationInterval * 2 / 10);
else
overlayAlpha = 0.0;
}
Expand Down Expand Up @@ -2275,4 +2277,6 @@ class CImgDiffBuffer
std::vector<LineDiffInfo> m_lineDiffInfos;
bool m_temporarilyTransformed;
DIFF_ALGORITHM m_diffAlgorithm;
int m_blinkInterval;
int m_overlayAnimationInterval;
};
21 changes: 21 additions & 0 deletions src/WinIMergeLib/ImgMergeBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,27 @@ class CImgMergeBuffer : public CImgDiffBuffer
return !m_imgConverter[pane].isValid() && m_imgOrig[pane].isSaveSupported();
}

int GetBlinkInterval() const
{
return m_blinkInterval;
}

void SetBlinkInterval(int interval)
{
m_blinkInterval = interval;
}

int GetOverlayAnimationInterval() const
{
return m_overlayAnimationInterval;
}

void SetOverlayAnimationInterval(int interval)
{
m_overlayAnimationInterval = interval;
}


bool SaveImage(int pane)
{
if (pane < 0 || pane >= m_nImages)
Expand Down
26 changes: 22 additions & 4 deletions src/WinIMergeLib/ImgMergeWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ namespace
class CImgMergeWindow : public IImgMergeWindow
{
static constexpr int TIMER_INTERVAL = 25;
static constexpr int TIMER_INTERVAL_ANIM = 50;
static constexpr int TIMER_INTERVAL_BLINK = 400;

struct EventListenerInfo
{
Expand Down Expand Up @@ -1188,6 +1186,26 @@ class CImgMergeWindow : public IImgMergeWindow
return m_buffer.IsSaveSupported(pane);
}

int GetBlinkInterval() const override
{
return m_buffer.GetBlinkInterval();
}

void SetBlinkInterval(int interval) override
{
m_buffer.SetBlinkInterval(interval);
}

int GetOverlayAnimationInterval() const override
{
return m_buffer.GetOverlayAnimationInterval();
}

void SetOverlayAnimationInterval(int interval) override
{
m_buffer.SetOverlayAnimationInterval(interval);
}

private:

ATOM MyRegisterClass(HINSTANCE hInstance)
Expand Down Expand Up @@ -1476,8 +1494,8 @@ class CImgMergeWindow : public IImgMergeWindow
}
const auto actualCycle = tse - m_timerPrev;
const auto idealCycle =
std::chrono::milliseconds((m_buffer.GetOverlayMode() == OVERLAY_ALPHABLEND_ANIM) ? TIMER_INTERVAL_ANIM : TIMER_INTERVAL_BLINK);
m_timerNext = tse + ((m_timerNext.count() == 0 || actualCycle < idealCycle) ? idealCycle : actualCycle);
std::chrono::milliseconds((wParam == 2) ? m_buffer.GetOverlayAnimationInterval() / 20 : m_buffer.GetBlinkInterval() / 4);
m_timerNext = tse +((m_timerNext.count() == 0 || actualCycle < idealCycle) ? idealCycle : actualCycle);
}
m_timerPrev = tse;
break;
Expand Down
Loading

0 comments on commit bb2f4cd

Please sign in to comment.