Updated accelerating zoom controller to use default (non-accelerated)

zoom if changing direction.

Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
This commit is contained in:
Bevan Weiss 2022-11-04 16:28:32 +00:00 committed by Seth Hillbrand
parent 8444339681
commit 4f634d7df7
3 changed files with 14 additions and 9 deletions

View File

@ -66,7 +66,7 @@ ACCELERATING_ZOOM_CONTROLLER::ACCELERATING_ZOOM_CONTROLLER(
m_timestampProv = m_ownTimestampProv.get(); m_timestampProv = m_ownTimestampProv.get();
} }
m_lastTimestamp = m_timestampProv->GetTimestamp(); m_prevTimestamp = m_timestampProv->GetTimestamp();
} }
@ -76,9 +76,9 @@ double ACCELERATING_ZOOM_CONTROLLER::GetScaleForRotation( int aRotation )
const double minStep = 1.05; const double minStep = 1.05;
const auto timestamp = m_timestampProv->GetTimestamp(); const auto timestamp = m_timestampProv->GetTimestamp();
auto timeDiff = std::chrono::duration_cast<TIMEOUT>( timestamp - m_lastTimestamp ); auto timeDiff = std::chrono::duration_cast<TIMEOUT>( timestamp - m_prevTimestamp );
m_lastTimestamp = timestamp; m_prevTimestamp = timestamp;
wxLogTrace( traceZoomScroll, wxLogTrace( traceZoomScroll,
wxString::Format( "Rot %d, time diff: %ldms", aRotation, (long)timeDiff.count() ) ); wxString::Format( "Rot %d, time diff: %ldms", aRotation, (long)timeDiff.count() ) );
@ -86,7 +86,8 @@ double ACCELERATING_ZOOM_CONTROLLER::GetScaleForRotation( int aRotation )
double zoomScale; double zoomScale;
// Set scaling speed depending on scroll wheel event interval // Set scaling speed depending on scroll wheel event interval
if( timeDiff < m_accTimeout ) if( timeDiff < m_accTimeout
&& ( (aRotation > 0) == m_prevRotationPositive ) )
{ {
zoomScale = ( 2.05 * m_scale / 5.0 ) - timeDiff / m_accTimeout; zoomScale = ( 2.05 * m_scale / 5.0 ) - timeDiff / m_accTimeout;
@ -100,6 +101,7 @@ double ACCELERATING_ZOOM_CONTROLLER::GetScaleForRotation( int aRotation )
{ {
zoomScale = ( aRotation > 0 ) ? minStep : 1 / minStep; zoomScale = ( aRotation > 0 ) ? minStep : 1 / minStep;
} }
m_prevRotationPositive = aRotation > 0;
wxLogTrace( traceZoomScroll, wxString::Format( " Zoom factor: %f", zoomScale ) ); wxLogTrace( traceZoomScroll, wxString::Format( " Zoom factor: %f", zoomScale ) );

View File

@ -120,12 +120,15 @@ private:
///< Any provider owned by this class (the default one, if used). ///< Any provider owned by this class (the default one, if used).
std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv; std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
///< The timestamp of the last event. ///< The timestamp of the previous event.
TIME_PT m_lastTimestamp; TIME_PT m_prevTimestamp;
///< The timeout value. ///< The timeout value.
TIMEOUT m_accTimeout; TIMEOUT m_accTimeout;
/// Previous rotation was positive.
bool m_prevRotationPositive = false;
/// A multiplier for the minimum zoom step size /// A multiplier for the minimum zoom step size
double m_scale; double m_scale;
}; };

View File

@ -116,9 +116,9 @@ struct ACCEL_ZOOM_CASE
static const std::vector<ACCEL_ZOOM_CASE> accel_cases = { static const std::vector<ACCEL_ZOOM_CASE> accel_cases = {
// Scrolls widely spaced, just go up and down by a constant factor // Scrolls widely spaced, just go up and down by a constant factor
{ 500, { 0, 1000, 2000, 3000 }, { 120, 120, -120 }, { 1.05, 1.05, 1 / 1.05 } }, { 500, { 0, 1000, 2000, 3000, 4000 }, { 120, 120, -120, -120 }, { 1.05, 1.05, 1 / 1.05, 1 / 1.05 } },
// Close scrolls - acceleration on the latter // Close scrolls - acceleration, apart from when changing direction
{ 500, { 0, 1000, 1100 }, { 120, 120 }, { 1.05, 2.05 } }, { 500, { 0, 1000, 1100, 1200, 1300, 1400 }, { 120, 120, -120, -120, 120 }, { 1.05, 2.05, 1 / 1.05, 1 / 2.05, 1.05 } },
}; };