mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 08:39:46 +02:00
Support mice with high-precision scroll wheels
fixes P2: Ctrl+Mouse Wheel causes Crash (hang)
This commit is contained in:
parent
5e3b227f5b
commit
b51db1586b
@ -443,7 +443,8 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
|
||||
mBacking(NULL),
|
||||
mRefreshBacking(false),
|
||||
mAutoScrolling(false),
|
||||
vrulerSize(36,0)
|
||||
vrulerSize(36,0),
|
||||
mVertScrollRemainder(0)
|
||||
#ifndef __WXGTK__ //Get rid if this pragma for gtk
|
||||
#pragma warning( default: 4355 )
|
||||
#endif
|
||||
@ -4144,8 +4145,8 @@ void TrackPanel::HandleResize(wxMouseEvent & event)
|
||||
/// Handle mouse wheel rotation (for zoom in/out and vertical scrolling)
|
||||
void TrackPanel::HandleWheelRotation(wxMouseEvent & event)
|
||||
{
|
||||
int steps = event.m_wheelRotation /
|
||||
(event.m_wheelDelta > 0 ? event.m_wheelDelta : 120);
|
||||
double steps = event.m_wheelRotation /
|
||||
(event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
|
||||
|
||||
if (event.ShiftDown())
|
||||
{
|
||||
@ -4160,10 +4161,7 @@ void TrackPanel::HandleWheelRotation(wxMouseEvent & event)
|
||||
int trackLeftEdge = GetLeftOffset();
|
||||
|
||||
double center_h = PositionToTime(event.m_x, trackLeftEdge);
|
||||
if (steps < 0)
|
||||
mViewInfo->zoom = wxMax(mViewInfo->zoom / (2.0 * -steps), gMinZoom);
|
||||
else
|
||||
mViewInfo->zoom = wxMin(mViewInfo->zoom * (2.0 * steps), gMaxZoom);
|
||||
mViewInfo->zoom = wxMin(mViewInfo->zoom * pow(2.0, steps), gMaxZoom);
|
||||
|
||||
double new_center_h = PositionToTime(event.m_x, trackLeftEdge);
|
||||
mViewInfo->h += (center_h - new_center_h);
|
||||
@ -4173,7 +4171,10 @@ void TrackPanel::HandleWheelRotation(wxMouseEvent & event)
|
||||
} else
|
||||
{
|
||||
// MM: Zoom up/down when used without modifier keys
|
||||
mListener->TP_ScrollUpDown(-steps * 4);
|
||||
double lines = steps * 4 + mVertScrollRemainder;
|
||||
mVertScrollRemainder = lines - floor(lines);
|
||||
lines = floor(lines);
|
||||
mListener->TP_ScrollUpDown((int)-lines);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -578,6 +578,9 @@ private:
|
||||
|
||||
wxString mSoloPref;
|
||||
|
||||
// Keeps track of extra fractional vertical scroll steps
|
||||
double mVertScrollRemainder;
|
||||
|
||||
private:
|
||||
|
||||
// The screenshot class needs to access internals
|
||||
|
@ -1036,19 +1036,18 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
|
||||
}
|
||||
else if( event.m_wheelRotation != 0 )
|
||||
{
|
||||
|
||||
//Calculate the number of steps in a given direction this event
|
||||
//represents (allows for two or more clicks on a single event.)
|
||||
int steps = event.m_wheelRotation /
|
||||
(event.m_wheelDelta > 0 ? event.m_wheelDelta : 120);
|
||||
double steps = event.m_wheelRotation /
|
||||
(event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
|
||||
|
||||
if( steps < 0 )
|
||||
if( steps < 0.0 )
|
||||
{
|
||||
Decrease( -steps );
|
||||
Decrease( (float)-steps );
|
||||
}
|
||||
else
|
||||
{
|
||||
Increase( steps );
|
||||
Increase( (float)steps );
|
||||
}
|
||||
SendUpdate( mCurrentValue );
|
||||
}
|
||||
|
@ -982,15 +982,18 @@ void TimeTextCtrl::OnMouse(wxMouseEvent &event)
|
||||
OnContext(e);
|
||||
}
|
||||
else if( event.m_wheelRotation != 0 ) {
|
||||
int steps = event.m_wheelRotation /
|
||||
(event.m_wheelDelta > 0 ? event.m_wheelDelta : 120);
|
||||
double steps = event.m_wheelRotation /
|
||||
(event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0) +
|
||||
mScrollRemainder;
|
||||
mScrollRemainder = steps - floor(steps);
|
||||
steps = floor(steps);
|
||||
|
||||
if (steps < 0) {
|
||||
Decrease(-steps);
|
||||
if (steps < 0.0) {
|
||||
Decrease((int)-steps);
|
||||
Updated();
|
||||
}
|
||||
else {
|
||||
Increase(steps);
|
||||
Increase((int)steps);
|
||||
Updated();
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,9 @@ private:
|
||||
double mScalingFactor;
|
||||
bool mNtscDrop;
|
||||
|
||||
// Keeps track of extra fractional scrollwheel steps
|
||||
double mScrollRemainder;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user