From 2ef7ed98c067a3ed9199b56a4af0a100612c7b06 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 1 May 2012 02:50:03 +0000 Subject: [PATCH] Update the audio scroll position at most once every 50ms when dragging markers Originally committed to SVN as r6736. --- aegisub/src/audio_display.cpp | 42 ++++++++++++++++++++++++++--------- aegisub/src/audio_display.h | 5 +++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index f3430e06f..0c25d62e3 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -591,6 +591,7 @@ AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller, agi::C Bind(wxEVT_MOTION, &AudioDisplay::OnMouseEvent, this); Bind(wxEVT_ENTER_WINDOW, &AudioDisplay::OnMouseEvent, this); Bind(wxEVT_LEAVE_WINDOW, &AudioDisplay::OnMouseEvent, this); + scroll_timer.Bind(wxEVT_TIMER, &AudioDisplay::OnScrollTimer, this); } @@ -1026,6 +1027,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) { if (!dragged_object->OnMouseEvent(event)) { + scroll_timer.Stop(); SetDraggedObject(0); SetCursor(wxNullCursor); } @@ -1234,18 +1236,17 @@ void AudioDisplay::OnSelectionChanged() 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) + if (!scroll_timer.IsRunning()) { - ScrollBy(rel_x - width / 20); - } - else if (rel_x >= width) - { - ScrollBy(rel_x - width + width / 20); + // If the dragged object is outside the visible area, start the + // scroll timer to shift it back into view + int rel_x = RelativeXFromTime(audio_marker->GetPosition()); + if (rel_x < 0 || rel_x >= GetClientSize().GetWidth()) + { + // 50ms is the default for this on Windows (hardcoded since + // wxSystemSettings doesn't expose DragScrollDelay etc.) + scroll_timer.Start(50, true); + } } } else if (OPT_GET("Audio/Auto/Scroll")->GetBool() && sel.end() != 0) @@ -1256,6 +1257,25 @@ void AudioDisplay::OnSelectionChanged() RefreshRect(scrollbar->GetBounds(), false); } +void AudioDisplay::OnScrollTimer(wxTimerEvent &event) +{ + if (!audio_marker) return; + + 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); + } +} + void AudioDisplay::OnStyleRangesChanged() { if (!controller->GetTimingController()) return; diff --git a/aegisub/src/audio_display.h b/aegisub/src/audio_display.h index 886bc3bab..8fb9ff354 100644 --- a/aegisub/src/audio_display.h +++ b/aegisub/src/audio_display.h @@ -41,6 +41,7 @@ #include #include +#include #include #endif @@ -131,6 +132,9 @@ class AudioDisplay: public wxWindow { void SetDraggedObject(AudioDisplayInteractionObject *new_obj); + /// Timer for scrolling when markers are dragged out of the displayed area + wxTimer scroll_timer; + /// Leftmost pixel in the virtual audio image being displayed int scroll_left; @@ -213,6 +217,7 @@ class AudioDisplay: public wxWindow { void OnFocus(wxFocusEvent &event); /// wxWidgets keypress event void OnKeyDown(wxKeyEvent& event); + void OnScrollTimer(wxTimerEvent &event); // AudioControllerAudioEventListener implementation void OnAudioOpen(AudioProvider *provider);