From c84c9fe6b86055b6f49eec472c9a47bf2767ca70 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 7 Mar 2012 22:41:03 +0000 Subject: [PATCH] Fix issues with audio auto scrolling and lines longer than the display Clicking on the audio display (to change line timing) now never scrolls the display, rather than jumping around if the line is too long to fit on the display. Dragged markers are now always kept visible in the display, even if auto scroll is off. Originally committed to SVN as r6541. --- aegisub/src/audio_display.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index a0f685463..c23199d3d 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -502,6 +502,9 @@ public: // We lose the marker drag if the button used to initiate it goes up return !event.ButtonUp(button_used); } + + /// Get the position in milliseconds of this group of markers + int GetPosition() const { return markers.front()->GetPosition(); } }; class AudioStyleRangeMerger : public AudioRenderingStyleRanges { @@ -1090,6 +1093,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) SetCursor(wxNullCursor); } + int old_scroll_pos = scroll_left; if (event.LeftDown() || event.RightDown()) { int timepos = TimeFromRelativeX(mousepos.x); @@ -1097,6 +1101,9 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) timing->OnLeftClick(timepos, event.CmdDown(), drag_sensitivity, snap_sensitivity) : timing->OnRightClick(timepos, event.CmdDown(), drag_sensitivity, snap_sensitivity); + // Clicking should never result in the audio display scrolling + ScrollPixelToLeft(old_scroll_pos); + if (markers.size()) { RemoveTrackCursor(); @@ -1222,7 +1229,23 @@ void AudioDisplay::OnSelectionChanged() TimeRange sel(controller->GetPrimaryPlaybackRange()); scrollbar->SetSelection(AbsoluteXFromTime(sel.begin()), AbsoluteXFromTime(sel.length())); - if (OPT_GET("Audio/Auto/Scroll")->GetBool()) + if (audio_marker) + { + int rel_x = RelativeXFromTime(audio_marker->GetPosition()); + int width = GetClientSize().GetWidth(); + + // If the dragged object is outside the visible area, scroll it into + // view with a 5% margin + if (rel_x < 0) + { + ScrollBy(rel_x - width / 20); + } + else if (rel_x >= width) + { + ScrollBy(rel_x - width + width / 20); + } + } + else if (OPT_GET("Audio/Auto/Scroll")->GetBool()) { ScrollTimeRangeInView(sel); }