Skip to content

Commit

Permalink
The seekbar thumb now follows the mouse pointer when dragging and onl…
Browse files Browse the repository at this point in the history
…y jumps to final seek position after drag ends. Previously it would jump to the actual seek points during the drag. This could give a jumpy experience for files with large keyframe gaps or short durations.
  • Loading branch information
clsid2 committed Nov 21, 2021
1 parent a5fc3da commit 5705b1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/mpc-hc/PlayerSeekBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CPlayerSeekBar::CPlayerSeekBar(CMainFrame* pMainFrame)
, m_rtStart(0)
, m_rtStop(0)
, m_rtPos(0)
, m_rtPosDraw(0)
, m_bEnabled(false)
, m_bHasDuration(false)
, m_rtHoverPos(0)
Expand Down Expand Up @@ -138,14 +139,15 @@ CSize CPlayerSeekBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
void CPlayerSeekBar::MoveThumb(const CPoint& point)
{
if (m_bHasDuration) {
REFERENCE_TIME rtPos = PositionFromClientPoint(point);
REFERENCE_TIME rtPosDraw = PositionFromClientPoint(point);
REFERENCE_TIME rtPos = rtPosDraw;
const CAppSettings& s = AfxGetAppSettings();
REFERENCE_TIME duration = m_rtStop - m_rtStart;
if (duration >= 600000000LL && s.bFastSeek && (GetKeyState(VK_SHIFT) >= 0)) {
REFERENCE_TIME rtMaxDiff = s.bAllowInaccurateFastseek ? 200000000LL : std::min(100000000LL, duration / 30);
rtPos = m_pMainFrame->GetClosestKeyFrame(rtPos, rtMaxDiff, rtMaxDiff);
}
SyncThumbToVideo(rtPos);
SyncThumbToVideo(rtPos, rtPosDraw);
}
}

Expand Down Expand Up @@ -196,9 +198,10 @@ REFERENCE_TIME CPlayerSeekBar::PositionFromClientPoint(const CPoint& point) cons
return rtRet;
}

void CPlayerSeekBar::SyncThumbToVideo(REFERENCE_TIME rtPos)
void CPlayerSeekBar::SyncThumbToVideo(REFERENCE_TIME rtPos, REFERENCE_TIME rtPosDraw)
{
m_rtPos = rtPos;
m_rtPosDraw = rtPosDraw;
if (m_bHasDuration) {
CRect newThumbRect(GetThumbRect());
bool bSetTaskbar = (rtPos <= 0);
Expand Down Expand Up @@ -284,7 +287,7 @@ CRect CPlayerSeekBar::GetChannelRect() const
CRect CPlayerSeekBar::GetThumbRect() const
{
const CRect channelRect(GetChannelRect());
const long x = channelRect.left + ChannelPointFromPosition(m_rtPos);
const long x = channelRect.left + ChannelPointFromPosition(m_rtPosDraw);
CSize s;
s.cy = m_pMainFrame->m_dpi.ScaleFloorY(SEEK_DRAGGER_OVERLAP);
s.cx = m_pMainFrame->m_dpi.TransposeScaledY(channelRect.Height()) / 2 + s.cy;
Expand Down Expand Up @@ -332,7 +335,7 @@ void CPlayerSeekBar::UpdateTooltip(const CPoint& point)
break;
case TOOLTIP_VISIBLE:
// Update the tooltip if needed
ASSERT(!m_bIgnoreLastTooltipPoint);
ASSERT(!m_bIgnoreLastTooltipPoint || !m_pMainFrame->CanPreviewUse()); // ??
if (point != m_tooltipPoint) {
m_tooltipPoint = point;
if (!m_pMainFrame->CanPreviewUse()) {
Expand Down Expand Up @@ -513,7 +516,7 @@ void CPlayerSeekBar::SetPos(REFERENCE_TIME rtPos)
return;
}

SyncThumbToVideo(rtPos);
SyncThumbToVideo(rtPos, rtPos);
}

bool CPlayerSeekBar::HasDuration() const
Expand Down
4 changes: 2 additions & 2 deletions src/mpc-hc/PlayerSeekBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CPlayerSeekBar : public CDialogBar
enum { TIMER_SHOWHIDE_TOOLTIP = 1 };

CMainFrame* m_pMainFrame;
REFERENCE_TIME m_rtStart, m_rtStop, m_rtPos;
REFERENCE_TIME m_rtStart, m_rtStop, m_rtPos, m_rtPosDraw;
REFERENCE_TIME m_pos_preview = 0;
LONG m_last_pointx_preview = 0;

Expand Down Expand Up @@ -81,7 +81,7 @@ class CPlayerSeekBar : public CDialogBar
void CheckScrollDistance(CPoint point, REFERENCE_TIME minimum_duration_change);
long ChannelPointFromPosition(REFERENCE_TIME rtPos) const;
REFERENCE_TIME PositionFromClientPoint(const CPoint& point) const;
void SyncThumbToVideo(REFERENCE_TIME rtPos);
void SyncThumbToVideo(REFERENCE_TIME rtPos, REFERENCE_TIME rtPosDraw);

void CreateThumb(bool bEnabled, CDC& parentDC);
CRect GetChannelRect() const;
Expand Down

0 comments on commit 5705b1e

Please sign in to comment.