Skip to content

Commit fa5600b

Browse files
authored
Comparer: click metric graph to seek to that frame (#8)
Add MetricCal::FrameAtX that maps a graph-area X pixel to a frame ID under the current view range, and let FrmsInfoView::OnLButtonDown use it to call SetScenes() and refresh the per-frame metric label. Combined with the recently-landed wheel zoom, the user can now zoom into a region of interest and click any point to jump straight to that frame. Double-click still resets the view, and clicks outside the graph area fall through to the default handler. Closes #8.
1 parent 467c6d1 commit fa5600b

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

Comparer/FrmsInfoView.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ BEGIN_MESSAGE_MAP(CFrmsInfoView, CView)
5555
ON_WM_ERASEBKGND()
5656
ON_WM_MOUSEWHEEL()
5757
ON_WM_LBUTTONDBLCLK()
58+
ON_WM_LBUTTONDOWN()
5859
END_MESSAGE_MAP()
5960

6061

@@ -211,3 +212,42 @@ void CFrmsInfoView::OnLButtonDblClk(UINT /*nFlags*/, CPoint point)
211212
Invalidate(FALSE);
212213
}
213214
}
215+
216+
void CFrmsInfoView::OnLButtonDown(UINT nFlags, CPoint point)
217+
{
218+
if (!mGraphRect.PtInRect(point)) {
219+
CView::OnLButtonDown(nFlags, point);
220+
return;
221+
}
222+
223+
CComparerDoc *pDoc = GetDocument();
224+
if (pDoc->mMinFrames <= 0) {
225+
CView::OnLButtonDown(nFlags, point);
226+
return;
227+
}
228+
229+
int graphX = point.x - mGraphRect.left - GRAPH_IN_MARGIN_L;
230+
long frameID = mPsnrCal->FrameAtX(graphX);
231+
if (frameID < 0) {
232+
CView::OnLButtonDown(nFlags, point);
233+
return;
234+
}
235+
236+
pDoc->KillPlayTimer();
237+
pDoc->SetScenes(frameID);
238+
239+
// Refresh the per-frame metric label shown in FrmInfoView for the new
240+
// pair of frames.
241+
IFrmCmpStrategy *compareStrategy = pDoc->mFrmCmpStrategy;
242+
if (compareStrategy) {
243+
CMainFrame *pMainFrm = static_cast<CMainFrame *>(AfxGetMainWnd());
244+
ComparerPane *paneL = &pDoc->mPane[CComparerDoc::IMG_VIEW_1];
245+
ComparerPane *paneR = &pDoc->mPane[CComparerDoc::IMG_VIEW_2];
246+
compareStrategy->CalMetrics(paneL, paneR,
247+
pMainFrm->mMetricIdx, pDoc->mFrmState);
248+
}
249+
250+
pDoc->UpdateAllViews(NULL);
251+
252+
CView::OnLButtonDown(nFlags, point);
253+
}

Comparer/FrmsInfoView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class CFrmsInfoView : public CView
6969
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
7070
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
7171
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
72+
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
7273
};
7374

7475

Comparer/MetricCal.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,29 @@ void MetricCal::ZoomAtX(short zDelta, int graphX)
193193
mViewEndFrame = mViewStartFrame + 1;
194194
}
195195

196+
long MetricCal::FrameAtX(int graphX) const
197+
{
198+
if (mStepCount == 0 || mFrameIdx == 0)
199+
return -1;
200+
int graphW = getGraphW();
201+
if (graphW <= 0)
202+
return -1;
203+
204+
if (graphX < 0) graphX = 0;
205+
if (graphX > graphW) graphX = graphW;
206+
207+
size_t viewSpan = mViewEndFrame > mViewStartFrame
208+
? mViewEndFrame - mViewStartFrame : 1;
209+
long frameID = long(mViewStartFrame)
210+
+ long((size_t(graphX) * viewSpan) / size_t(graphW));
211+
212+
// Clamp to frames that actually have parsed metrics so far.
213+
long maxFrame = long(mFrameIdx) - 1;
214+
if (frameID > maxFrame) frameID = maxFrame;
215+
if (frameID < 0) frameID = 0;
216+
return frameID;
217+
}
218+
196219
void MetricCal::CalMinMaxAccum()
197220
{
198221
size_t i;

Comparer/MetricCal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class MetricCal
6666
void ZoomAtX(short zDelta, int graphX);
6767
// Restore the X axis to cover the full parsed range.
6868
void ResetView();
69+
// Frame index at the given graph-area X pixel under the current view
70+
// range. Returns -1 if no data is available.
71+
long FrameAtX(int graphX) const;
6972

7073
void DrawCmpResult(CDC* pDC, CFont *font) const;
7174
void DrawYLabel(CDC* pDC, CRect *yLabelRect, CFont *font) const;

0 commit comments

Comments
 (0)