Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Comparer/FrmsInfoView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ BEGIN_MESSAGE_MAP(CFrmsInfoView, CView)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_MOUSEWHEEL()
ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()


Expand Down Expand Up @@ -185,3 +187,27 @@ BOOL CFrmsInfoView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}

BOOL CFrmsInfoView::OnMouseWheel(UINT /*nFlags*/, short zDelta, CPoint pt)
{
// pt is in screen coordinates; convert to client coordinates so we can
// check the cursor against the graph area.
CPoint client = pt;
ScreenToClient(&client);
if (!mGraphRect.PtInRect(client))
return FALSE;

int graphX = client.x - mGraphRect.left - GRAPH_IN_MARGIN_L;
mPsnrCal->ZoomAtX(zDelta, graphX);
Invalidate(FALSE);
return TRUE;
}

void CFrmsInfoView::OnLButtonDblClk(UINT /*nFlags*/, CPoint point)
{
// Double-click anywhere on the graph restores the full-range view.
if (mGraphRect.PtInRect(point)) {
mPsnrCal->ResetView();
Invalidate(FALSE);
}
}
2 changes: 2 additions & 0 deletions Comparer/FrmsInfoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class CFrmsInfoView : public CView
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
};


70 changes: 68 additions & 2 deletions Comparer/MetricCal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ MetricCal::MetricCal()
, mFileScanThread(NULL)
, mStepCount(0)
, mFrameIdx(0)
, mViewStartFrame(0)
, mViewEndFrame(0)
, mAvgFont(new Font(&FontFamily(Q1UI_FONT_TEXT), 9))
, mMetricIdx(METRIC_PSNR_IDX)
{
Expand Down Expand Up @@ -90,7 +92,16 @@ void MetricCal::Setup(CRect *graphRect, int metricIdx)
{
mGraphRect = *graphRect;

mStepW = getGraphW() / int(mStepCount + 1);
// Clamp the view range to the current parsed run. Zoom may have left the
// range outside the new bounds after a fresh load or scan progress.
if (mViewEndFrame == 0 || mViewEndFrame > mStepCount)
mViewEndFrame = mStepCount;
if (mViewStartFrame >= mViewEndFrame)
mViewStartFrame = 0;

size_t viewSpan = mViewEndFrame > mViewStartFrame
? mViewEndFrame - mViewStartFrame : 1;
mStepW = getGraphW() / int(viewSpan + 1);
mStepW = max(mStepW, MIN_X_AXIS_STEP_W);

mShowID.clear();
Expand Down Expand Up @@ -126,9 +137,62 @@ void MetricCal::Update(const FileScanThread *fileScanThread, size_t stepCount)
mFileScanThread = fileScanThread;
mStepCount = stepCount;

ResetView();
Init();
}

void MetricCal::ResetView()
{
mViewStartFrame = 0;
mViewEndFrame = mStepCount;
}

void MetricCal::ZoomAtX(short zDelta, int graphX)
{
if (mStepCount == 0)
return;

int graphW = getGraphW();
if (graphW <= 0)
return;

if (graphX < 0) graphX = 0;
if (graphX > graphW) graphX = graphW;

// Anchor: the frame currently sitting under the cursor pixel.
double span = double(mViewEndFrame - mViewStartFrame);
if (span <= 0.0)
span = double(mStepCount);
double cursorFrame = double(mViewStartFrame) + (double(graphX) / graphW) * span;

// One wheel notch (WHEEL_DELTA == 120) zooms by ~25%.
const double kStep = 1.25;
double notches = double(zDelta) / 120.0;
double factor = pow(kStep, -notches); // zDelta > 0 -> zoom in -> smaller span
double newSpan = span * factor;

// Show at least 10 frames; don't zoom past the full parsed range.
const double kMinSpan = 10.0;
if (newSpan < kMinSpan)
newSpan = kMinSpan;
if (newSpan > double(mStepCount))
newSpan = double(mStepCount);

double newStart = cursorFrame - (double(graphX) / graphW) * newSpan;
double newEnd = newStart + newSpan;
if (newStart < 0.0) { newEnd -= newStart; newStart = 0.0; }
if (newEnd > double(mStepCount)) {
newStart -= newEnd - double(mStepCount);
newEnd = double(mStepCount);
if (newStart < 0.0) newStart = 0.0;
}

mViewStartFrame = static_cast<size_t>(newStart);
mViewEndFrame = static_cast<size_t>(newEnd);
if (mViewEndFrame <= mViewStartFrame)
mViewEndFrame = mViewStartFrame + 1;
}

void MetricCal::CalMinMaxAccum()
{
size_t i;
Expand Down Expand Up @@ -175,9 +239,11 @@ size_t MetricCal::CalculateCoords(CRect *graphRect, int metricIdx)

size_t prevID = -1;
int graphW = getGraphW();
size_t viewSpan = mViewEndFrame > mViewStartFrame
? mViewEndFrame - mViewStartFrame : 1;

for (int i = 0; i < graphW; i += mStepW) {
size_t frameID = (i * mStepCount) / graphW;
size_t frameID = mViewStartFrame + (size_t(i) * viewSpan) / graphW;

if (frameID >= mFrameIdx)
break;
Expand Down
12 changes: 12 additions & 0 deletions Comparer/MetricCal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class MetricCal
size_t mStepCount;
size_t mFrameIdx;

// Frame range currently visible on the X axis. Default covers the whole
// parsed run; mouse wheel zoom narrows it around the cursor frame.
size_t mViewStartFrame;
size_t mViewEndFrame;

list<size_t> mShowID;
list<double> mShowVal[QPLANES];

Expand Down Expand Up @@ -55,6 +60,13 @@ class MetricCal
void Update(const FileScanThread *fileScanThread, size_t stepCount);
size_t CalculateCoords(CRect *graphRect, int metricIdx);

// Zoom the X axis around the frame at |graphX|. |graphX| is in graph-area
// pixels (0 == left edge of the drawable graph). zDelta uses the standard
// WHEEL_DELTA sign convention.
void ZoomAtX(short zDelta, int graphX);
// Restore the X axis to cover the full parsed range.
void ResetView();

void DrawCmpResult(CDC* pDC, CFont *font) const;
void DrawYLabel(CDC* pDC, CRect *yLabelRect, CFont *font) const;
void DrawXLabel(CDC* pDC, int hClient, CFont *font) const;
Expand Down