1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-03 17:19:43 +02:00

Implement scrolling of vertical ruler (without zooming) for wheel (no keys)

This commit is contained in:
Paul Licameli 2015-08-27 12:52:27 -04:00
parent 2217d1646e
commit 638b98b0a3

View File

@ -6265,8 +6265,12 @@ void TrackPanel::HandleWheelRotation(wxMouseEvent & event)
void TrackPanel::HandleWheelRotationInVRuler
(wxMouseEvent &event, Track *pTrack, const wxRect &rect)
{
double steps = event.m_wheelRotation /
(event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0);
if (pTrack->GetKind() == Track::Wave) {
WaveTrack *const wt = static_cast<WaveTrack*>(pTrack);
WaveTrack *const partner = static_cast<WaveTrack*>(wt->GetLink());
const bool isDB =
wt->GetDisplay() == WaveTrack::Waveform &&
wt->GetWaveformSettings().scaleType == WaveformSettings::stLogarithmic;
@ -6282,7 +6286,6 @@ void TrackPanel::HandleWheelRotationInVRuler
else
settings.NextHigherDBRange();
WaveTrack *const partner = static_cast<WaveTrack*>(wt->GetLink());
if (partner) {
WaveformSettings &settings = partner->GetIndependentWaveformSettings();
if (event.m_wheelRotation < 0)
@ -6301,6 +6304,65 @@ void TrackPanel::HandleWheelRotationInVRuler
wt, false, (event.m_wheelRotation < 0),
true);
}
else if (!(event.CmdDown() || event.ShiftDown())) {
// Scroll some fixed number of pixels, independent of zoom level or track height:
static const float movement = 10.0f;
const int height = wt->GetHeight() - (kTopMargin + kBottomMargin);
const bool spectral = (wt->GetDisplay() == WaveTrack::Spectrum);
if (spectral) {
const float delta = steps * movement / height;
SpectrogramSettings &settings = wt->GetIndependentSpectrogramSettings();
const bool isLinear = settings.scaleType == SpectrogramSettings::stLinear;
const double rate = wt->GetRate();
const float maxFreq = float(rate) / 2.0f;
const NumberScale numberScale(settings.GetScale(rate, false));
float newTop =
std::min(maxFreq, numberScale.PositionToValue(1.0f + delta));
const float newBottom =
std::max((isLinear ? 0.0f : 1.0f),
numberScale.PositionToValue(numberScale.ValueToPosition(newTop) - 1.0f));
newTop =
std::min(maxFreq,
numberScale.PositionToValue(numberScale.ValueToPosition(newBottom) + 1.0f));
if (isLinear) {
settings.SetMinFreq(newBottom);
settings.SetMaxFreq(newTop);
}
else {
settings.SetLogMinFreq(newBottom);
settings.SetLogMaxFreq(newTop);
}
if (partner) {
SpectrogramSettings &partnerSettings = partner->GetIndependentSpectrogramSettings();
if (isLinear) {
partnerSettings.SetMinFreq(newBottom);
partnerSettings.SetMaxFreq(newTop);
}
else {
partnerSettings.SetLogMinFreq(newBottom);
partnerSettings.SetLogMaxFreq(newTop);
}
}
}
else {
float topLimit = 2.0;
if (isDB) {
const float dBRange = wt->GetWaveformSettings().dBRange;
topLimit = (LINEAR_TO_DB(topLimit) + dBRange) / dBRange;
}
const float bottomLimit = -topLimit;
float top, bottom;
wt->GetDisplayBounds(&bottom, &top);
const float range = top - bottom;
const float delta = range * steps * movement / height;
float newTop = std::min(topLimit, top + delta);
const float newBottom = std::max(bottomLimit, newTop - range);
newTop = std::min(topLimit, newBottom + range);
wt->SetDisplayBounds(newBottom, newTop);
if (partner)
partner->SetDisplayBounds(newBottom, newTop);
}
}
else
return;