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,21 +669,21 @@ void AudioDisplay::SetZoomLevel(int new_zoom_level)
const double base_ms_per_pixel = 1000.0 / base_pixels_per_second; 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; 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;
ms_per_pixel = new_ms_per_pixel; int client_width = GetClientSize().GetWidth();
pixel_audio_width = std::max(1, int(controller->GetDuration() / 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;
audio_renderer->SetMillisecondsPerPixel(ms_per_pixel); ms_per_pixel = new_ms_per_pixel;
scrollbar->ChangeLengths(pixel_audio_width, client_width); pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel));
timeline->ChangeZoom(ms_per_pixel);
ScrollTimeToCenter(center_time); audio_renderer->SetMillisecondsPerPixel(ms_per_pixel);
Refresh(); scrollbar->ChangeLengths(pixel_audio_width, client_width);
} timeline->ChangeZoom(ms_per_pixel);
ScrollPixelToLeft(AbsoluteXFromTime(cursor_time) - cursor_pos);
Refresh();
} }
wxString AudioDisplay::GetZoomLevelDescription(int level) const wxString AudioDisplay::GetZoomLevelDescription(int level) const
@ -948,29 +948,28 @@ void AudioDisplay::SetDraggedObject(AudioDisplayInteractionObject *new_obj)
void AudioDisplay::SetTrackCursor(int new_pos, bool show_time) 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;
RefreshRect(wxRect(old_pos - scroll_left - 0, audio_top, 1, audio_height), false);
RefreshRect(wxRect(new_pos - scroll_left - 0, audio_top, 1, audio_height), false);
// Make sure the old label gets cleared away
RefreshRect(track_cursor_label_rect, false);
if (show_time)
{ {
int old_pos = track_cursor_pos; AssTime new_label_time = TimeFromAbsoluteX(track_cursor_pos);
track_cursor_pos = new_pos; track_cursor_label = to_wx(new_label_time.GetAssFormated());
track_cursor_label_rect.x += new_pos - old_pos;
RefreshRect(wxRect(old_pos - scroll_left - 0, audio_top, 1, audio_height), false);
RefreshRect(wxRect(new_pos - scroll_left - 0, audio_top, 1, audio_height), false);
// Make sure the old label gets cleared away
RefreshRect(track_cursor_label_rect, false); RefreshRect(track_cursor_label_rect, false);
}
if (show_time) else
{ {
AssTime new_label_time = TimeFromAbsoluteX(track_cursor_pos); track_cursor_label_rect.SetSize(wxSize(0,0));
track_cursor_label = to_wx(new_label_time.GetAssFormated()); track_cursor_label.Clear();
track_cursor_label_rect.x += new_pos - old_pos;
RefreshRect(track_cursor_label_rect, false);
}
else
{
track_cursor_label_rect.SetSize(wxSize(0,0));
track_cursor_label.Clear();
}
} }
} }

View file

@ -242,23 +242,8 @@ public:
/// @brief Scroll the audio display /// @brief Scroll the audio display
/// @param pixel_position Absolute pixel to put at left edge of 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); 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 /// @brief Scroll the audio display
/// @param range Time range to ensure is in view /// @param range Time range to ensure is in view
/// ///