forked from mia/Aegisub
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:
parent
1f5b98b11d
commit
0b210673f9
2 changed files with 32 additions and 48 deletions
|
@ -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 new_ms_per_pixel = 100.0 * base_ms_per_pixel / factor;
|
||||
|
||||
if (ms_per_pixel != new_ms_per_pixel)
|
||||
{
|
||||
int client_width = GetClientSize().GetWidth();
|
||||
double center_time = (scroll_left + client_width / 2.0) * ms_per_pixel;
|
||||
if (ms_per_pixel == new_ms_per_pixel) return;
|
||||
|
||||
ms_per_pixel = new_ms_per_pixel;
|
||||
pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel));
|
||||
int client_width = GetClientSize().GetWidth();
|
||||
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);
|
||||
scrollbar->ChangeLengths(pixel_audio_width, client_width);
|
||||
timeline->ChangeZoom(ms_per_pixel);
|
||||
ms_per_pixel = new_ms_per_pixel;
|
||||
pixel_audio_width = std::max(1, int(controller->GetDuration() / ms_per_pixel));
|
||||
|
||||
ScrollTimeToCenter(center_time);
|
||||
Refresh();
|
||||
}
|
||||
audio_renderer->SetMillisecondsPerPixel(ms_per_pixel);
|
||||
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
|
||||
|
@ -948,29 +948,28 @@ 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;
|
||||
|
||||
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;
|
||||
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
|
||||
AssTime new_label_time = TimeFromAbsoluteX(track_cursor_pos);
|
||||
track_cursor_label = to_wx(new_label_time.GetAssFormated());
|
||||
track_cursor_label_rect.x += new_pos - old_pos;
|
||||
RefreshRect(track_cursor_label_rect, false);
|
||||
|
||||
if (show_time)
|
||||
{
|
||||
AssTime new_label_time = TimeFromAbsoluteX(track_cursor_pos);
|
||||
track_cursor_label = to_wx(new_label_time.GetAssFormated());
|
||||
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();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
track_cursor_label_rect.SetSize(wxSize(0,0));
|
||||
track_cursor_label.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue