Skip to content

Commit 8ef41f7

Browse files
committed
Comparer: handle Space play/pause from the timeline view (#11)
1 parent d3f8321 commit 8ef41f7

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

Comparer/ComparerDoc.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,20 @@ void CComparerDoc::KillPlayTimer()
682682
mIsPlaying = false;
683683
}
684684

685+
void CComparerDoc::TogglePlay()
686+
{
687+
if (mIsPlaying) {
688+
KillPlayTimer();
689+
return;
690+
}
691+
692+
CMainFrame *pMainFrm = static_cast<CMainFrame *>(AfxGetMainWnd());
693+
mIsPlaying = true;
694+
pMainFrm->SetTimer(CTI_ID_PLAY, ROUND2I((1000 / mFps) - FPS_ADJUSTMENT), NULL);
695+
if (!NextScenes())
696+
SetScenes(0);
697+
}
698+
685699
void CComparerDoc::MarkImgViewProcessing()
686700
{
687701
CMainFrame* pMainFrm = static_cast<CMainFrame*>(AfxGetMainWnd());

Comparer/ComparerDoc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class CComparerDoc : public CDocument
101101
}
102102
std::vector<ComparerPane*> GetOtherPanes(ComparerPane* pane);
103103
void KillPlayTimer();
104+
void TogglePlay();
104105
bool OffsetScenes(long offset);
105106
void MarkImgViewProcessing();
106107
bool CheckImgViewProcessing();

Comparer/ComparerView.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,6 @@ void CComparerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
802802
if (nChar != VK_SPACE && isProcessing)
803803
return;
804804

805-
CMainFrame *pMainFrm = static_cast<CMainFrame *>(AfxGetMainWnd());
806-
807805
switch (nChar) {
808806
case VK_RIGHT:
809807
pDoc->OffsetScenes(1);
@@ -812,15 +810,7 @@ void CComparerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
812810
pDoc->OffsetScenes(-1);
813811
break;
814812
case VK_SPACE:
815-
if (!pDoc->mIsPlaying) {
816-
pDoc->mIsPlaying = true;
817-
pMainFrm->SetTimer(CTI_ID_PLAY, ROUND2I((1000 / pDoc->mFps) - FPS_ADJUSTMENT), NULL);
818-
bool changed = pDoc->NextScenes();
819-
if (!changed)
820-
pDoc->SetScenes(0);
821-
} else {
822-
pDoc->KillPlayTimer();
823-
}
813+
pDoc->TogglePlay();
824814
break;
825815
case 'H': // Toggle hexadecimal pixel values.
826816
pDoc->mHexMode = !pDoc->mHexMode;

Comparer/PosInfoView.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ BEGIN_MESSAGE_MAP(CPosInfoView, CScrollView)
5151
ON_WM_DESTROY()
5252
ON_WM_MOUSEWHEEL()
5353
ON_WM_VSCROLL()
54+
ON_WM_KEYDOWN()
5455
END_MESSAGE_MAP()
5556

5657

@@ -351,3 +352,16 @@ void CPosInfoView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
351352

352353
CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
353354
}
355+
356+
void CPosInfoView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
357+
{
358+
// The timeline owns focus after a seek click, so route play/pause here too.
359+
if (nChar == VK_SPACE) {
360+
CComparerDoc* pDoc = GetDocument();
361+
pDoc->TogglePlay();
362+
pDoc->UpdateAllViews(NULL);
363+
return;
364+
}
365+
366+
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
367+
}

Comparer/PosInfoView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class CPosInfoView : public CScrollView
6161
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
6262
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
6363
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
64+
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
6465
};
6566

6667

0 commit comments

Comments
 (0)