Zoom into the mouse's position in the audio display

Rather than pinning the time at the center of the audio display, pin the
time at the mouse's position since that's the area the user probably
cares about. If the mouse is not over the audio display (such as if the
user is adjusting the zoom via the sliders rather than the mouse wheel),
just use the center as it used to.
This commit is contained in:
Thomas Goyne 2013-08-20 12:11:39 -07:00
parent 1f5b98b11d
commit 0b210673f9
2 changed files with 32 additions and 48 deletions

View file

@ -669,10 +669,11 @@ void AudioDisplay::SetZoomLevel(int new_zoom_level)
const double base_ms_per_pixel = 1000.0 / base_pixels_per_second;
const double new_ms_per_pixel = 100.0 * base_ms_per_pixel / factor;
if (ms_per_pixel != new_ms_per_pixel)
{
if (ms_per_pixel == new_ms_per_pixel) return;
int client_width = GetClientSize().GetWidth();
double center_time = (scroll_left + client_width / 2.0) * ms_per_pixel;
double cursor_pos = track_cursor_pos >= 0 ? track_cursor_pos - scroll_left : client_width / 2.0;
double cursor_time = (scroll_left + cursor_pos) * ms_per_pixel;
ms_per_pixel = new_ms_per_pixel;
pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel));
@ -681,9 +682,8 @@ void AudioDisplay::SetZoomLevel(int new_zoom_level)
scrollbar->ChangeLengths(pixel_audio_width, client_width);
timeline->ChangeZoom(ms_per_pixel);
ScrollTimeToCenter(center_time);
ScrollPixelToLeft(AbsoluteXFromTime(cursor_time) - cursor_pos);
Refresh();
}
}
wxString AudioDisplay::GetZoomLevelDescription(int level) const
@ -948,8 +948,8 @@ void AudioDisplay::SetDraggedObject(AudioDisplayInteractionObject *new_obj)
void AudioDisplay::SetTrackCursor(int new_pos, bool show_time)
{
if (new_pos != track_cursor_pos)
{
if (new_pos == track_cursor_pos) return;
int old_pos = track_cursor_pos;
track_cursor_pos = new_pos;
@ -971,7 +971,6 @@ void AudioDisplay::SetTrackCursor(int new_pos, bool show_time)
track_cursor_label_rect.SetSize(wxSize(0,0));
track_cursor_label.Clear();
}
}
}
void AudioDisplay::RemoveTrackCursor()

View file

@ -242,23 +242,8 @@ public:
/// @brief Scroll the audio display
/// @param pixel_position Absolute pixel to put at left edge of the audio display
///
/// This is the principal scrolling function. All other scrolling functions eventually
/// call this function to perform the actual scrolling.
void ScrollPixelToLeft(int pixel_position);
/// @brief Scroll the audio display
/// @param pixel_position Absolute pixel to put in center of the audio display
void ScrollPixelToCenter(int pixel_position) { ScrollPixelToLeft(pixel_position - GetClientRect().GetWidth()/2); }
/// @brief Scroll the audio display
/// @param ms Time in milliseconds to put at left edge of the audio display
void ScrollTimeToLeft(int ms) { ScrollPixelToLeft(AbsoluteXFromTime(ms)); }
/// @brief Scroll the audio display
/// @param ms Time in milliseconds to put in center of the audio display
void ScrollTimeToCenter(int ms) { ScrollPixelToCenter(AbsoluteXFromTime(ms)); }
/// @brief Scroll the audio display
/// @param range Time range to ensure is in view
///