forked from mia/Aegisub
Update the audio scroll position at most once every 50ms when dragging markers
Originally committed to SVN as r6736.
This commit is contained in:
parent
1558aa2dad
commit
2ef7ed98c0
2 changed files with 36 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/timer.h>
|
||||
#include <wx/window.h>
|
||||
#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);
|
||||
|
|
Loading…
Reference in a new issue