43static double notchCount(
int aRotation,
int aWheelDelta )
45 if( aWheelDelta <= 0 )
61 return ACCELERATING_ZOOM_CONTROLLER::CLOCK::now();
88 const double minStep = 1.05;
91 auto timeDiff = std::chrono::duration_cast<TIMEOUT>( timestamp -
m_prevTimestamp );
96 wxString::Format(
"Rot %d, time diff: %ldms", aRotation, (
long)timeDiff.count() ) );
107 zoomScale = std::max( zoomScale, minStep );
110 zoomScale = 1.0 / zoomScale;
114 zoomScale = ( aRotation > 0 ) ? minStep : 1 / minStep;
118 if(
notchCount( aRotation, aWheelDelta ) > 1.0 )
119 zoomScale = std::pow( zoomScale,
notchCount( aRotation, aWheelDelta ) );
121 wxLogTrace(
traceZoomScroll, wxString::Format(
" Zoom factor: %f", zoomScale ) );
142 wxLogTrace(
traceZoomScroll, wxString::Format(
"Rot %d", aRotation ) );
145 const double stepCap = aWheelDelta > 0 ? std::min( aWheelDelta, 100 ) : 100;
146 const double oneStep = std::min(
std::abs(
double( aRotation ) ), stepCap );
147 const double factor = std::pow( 1.0 + oneStep *
m_scale,
notchCount( aRotation, aWheelDelta ) );
148 const double zoom_scale = aRotation > 0 ? factor : 1.0 / factor;
150 wxLogTrace(
traceZoomScroll, wxString::Format(
" Zoom factor: %f", zoom_scale ) );
A interface that provides timestamps for events.
double GetScaleForRotation(int aRotation, int aWheelDelta=0) override
Get the scale factor produced by a given mousewheel rotation.
std::chrono::time_point< CLOCK > TIME_PT
The type of the time stamps.
std::chrono::milliseconds TIMEOUT
The type of the acceleration timeout.
static constexpr TIMEOUT DEFAULT_TIMEOUT
The default timeout, after which a another scroll will not be accelerated.
TIME_PT m_prevTimestamp
The timestamp of the previous event.
TIMEOUT m_accTimeout
The timeout value.
bool m_prevRotationPositive
Previous rotation was positive.
double m_scale
A multiplier for the minimum zoom step size.
TIMESTAMP_PROVIDER * m_timestampProv
The timestamp provider to use (might be provided externally).
ACCELERATING_ZOOM_CONTROLLER(double aScale=DEFAULT_ACCELERATION_SCALE, const TIMEOUT &aAccTimeout=DEFAULT_TIMEOUT, TIMESTAMP_PROVIDER *aTimestampProv=nullptr)
std::unique_ptr< TIMESTAMP_PROVIDER > m_ownTimestampProv
Any provider owned by this class (the default one, if used).
double m_scale
The scale factor set by the constructor.
CONSTANT_ZOOM_CONTROLLER(double aScale)
double GetScaleForRotation(int aRotation, int aWheelDelta=0) override
Get the scale factor produced by a given mousewheel rotation.
static constexpr double MSW_SCALE
A suitable (magic) scale factor for Windows systems.
A very simple timestamper that uses the KIGFX::ACCELERATING_ZOOM_CONTROLLER::CLOCK to provide a times...
ACCELERATING_ZOOM_CONTROLLER::TIME_PT GetTimestamp() override
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
The Cairo implementation of the graphics abstraction layer.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
wxLogTrace helper definitions.
static double notchCount(int aRotation, int aWheelDelta)
static constexpr double MAX_MERGED_NOTCHES
ZOOM_CONTROLLER class definition.