1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 16:41:14 +02:00

ScrollIntoView out of TrackPanel, into ProjectWindow

This commit is contained in:
Paul Licameli 2019-06-08 09:02:17 -04:00
parent b0d03d09a2
commit 52ff705b0d
9 changed files with 52 additions and 52 deletions

View File

@ -935,6 +935,28 @@ const int sbarHjump = 30; //STM: This is how far the thumb jumps when the
#include "AllThemeResources.h" #include "AllThemeResources.h"
#endif #endif
// Make sure selection edge is in view
void ProjectWindow::ScrollIntoView(double pos)
{
auto &trackPanel = TrackPanel::Get( mProject );
auto &viewInfo = ViewInfo::Get( mProject );
auto w = viewInfo.GetTracksUsableWidth();
int pixel = viewInfo.TimeToPosition(pos);
if (pixel < 0 || pixel >= w)
{
TP_ScrollWindow
(viewInfo.OffsetTimeByPixels(pos, -(w / 2)));
trackPanel.Refresh(false);
}
}
void ProjectWindow::ScrollIntoView(int x)
{
auto &viewInfo = ViewInfo::Get( mProject );
ScrollIntoView(viewInfo.PositionToTime(x, viewInfo.GetLeftOffset()));
}
/// ///
/// This method handles general left-scrolling, either for drag-scrolling /// This method handles general left-scrolling, either for drag-scrolling
/// or when the scrollbar is clicked to the left of the thumb /// or when the scrollbar is clicked to the left of the thumb
@ -1717,7 +1739,6 @@ void ProjectWindow::SkipEnd(bool shift)
{ {
auto &project = mProject; auto &project = mProject;
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
double len = tracks.GetEndTime(); double len = tracks.GetEndTime();
@ -1726,8 +1747,7 @@ void ProjectWindow::SkipEnd(bool shift)
viewInfo.selectedRegion.setT0(len); viewInfo.selectedRegion.setT0(len);
// Make sure the end of the track is visible // Make sure the end of the track is visible
trackPanel.ScrollIntoView(len); ScrollIntoView(len);
trackPanel.Refresh(false);
} }
void ProjectWindow::TP_DisplaySelection() void ProjectWindow::TP_DisplaySelection()
@ -1832,7 +1852,6 @@ void ProjectWindow::PlaybackScroller::OnTimer(wxCommandEvent &event)
void ProjectWindow::ZoomInByFactor( double ZoomFactor ) void ProjectWindow::ZoomInByFactor( double ZoomFactor )
{ {
auto &project = mProject; auto &project = mProject;
auto &trackPanel = TrackPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
auto gAudioIO = AudioIOBase::Get(); auto gAudioIO = AudioIOBase::Get();
@ -1842,8 +1861,7 @@ void ProjectWindow::ZoomInByFactor( double ZoomFactor )
ProjectAudioIO::Get( project ).GetAudioIOToken()) && ProjectAudioIO::Get( project ).GetAudioIOToken()) &&
!gAudioIO->IsPaused()){ !gAudioIO->IsPaused()){
ZoomBy(ZoomFactor); ZoomBy(ZoomFactor);
trackPanel.ScrollIntoView(gAudioIO->GetStreamTime()); ScrollIntoView(gAudioIO->GetStreamTime());
trackPanel.Refresh(false);
return; return;
} }

View File

@ -102,6 +102,9 @@ public:
wxScrollBar &GetVerticalScrollBar() { return *mVsbar; } wxScrollBar &GetVerticalScrollBar() { return *mVsbar; }
void ScrollIntoView(double pos);
void ScrollIntoView(int x);
void OnScrollLeft(); void OnScrollLeft();
void OnScrollRight(); void OnScrollRight();

View File

@ -971,25 +971,6 @@ void TrackPanel::UpdateVRulerSize()
Refresh(false); Refresh(false);
} }
// Make sure selection edge is in view
void TrackPanel::ScrollIntoView(double pos)
{
auto w = mViewInfo->GetTracksUsableWidth();
int pixel = mViewInfo->TimeToPosition(pos);
if (pixel < 0 || pixel >= w)
{
mListener->TP_ScrollWindow
(mViewInfo->OffsetTimeByPixels(pos, -(w / 2)));
Refresh(false);
}
}
void TrackPanel::ScrollIntoView(int x)
{
ScrollIntoView(mViewInfo->PositionToTime(x, mViewInfo->GetLeftOffset()));
}
void TrackPanel::OnTrackMenu(Track *t) void TrackPanel::OnTrackMenu(Track *t)
{ {
CellularPanel::DoContextMenu( t ? &TrackView::Get( *t ) : nullptr ); CellularPanel::DoContextMenu( t ? &TrackView::Get( *t ) : nullptr );

View File

@ -117,9 +117,6 @@ class AUDACITY_DLL_API TrackPanel final
void HandlePageDownKey(); void HandlePageDownKey();
AudacityProject * GetProject() const override; AudacityProject * GetProject() const override;
void ScrollIntoView(double pos);
void ScrollIntoView(int x);
void OnTrackMenu(Track *t = NULL); void OnTrackMenu(Track *t = NULL);
void VerticalScroll( float fracPosition); void VerticalScroll( float fracPosition);

View File

@ -2,6 +2,7 @@
#include "../ProjectHistory.h" #include "../ProjectHistory.h"
#include "../ProjectSettings.h" #include "../ProjectSettings.h"
#include "../TrackPanel.h" #include "../TrackPanel.h"
#include "../ProjectWindow.h"
#include "../UndoManager.h" #include "../UndoManager.h"
#include "../WaveClip.h" #include "../WaveClip.h"
#include "../ViewInfo.h" #include "../ViewInfo.h"
@ -561,6 +562,7 @@ void DoSelectClip(AudacityProject &project, bool next)
{ {
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &trackPanel = TrackPanel::Get( project ); auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project );
std::vector<FoundClip> results; std::vector<FoundClip> results;
FindClips(project, selectedRegion.t0(), FindClips(project, selectedRegion.t0(),
@ -573,7 +575,7 @@ void DoSelectClip(AudacityProject &project, bool next)
double t1 = results[0].endTime; double t1 = results[0].endTime;
selectedRegion.setTimes(t0, t1); selectedRegion.setTimes(t0, t1);
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
trackPanel.ScrollIntoView(selectedRegion.t0()); window.ScrollIntoView(selectedRegion.t0());
// create and send message to screen reader // create and send message to screen reader
wxString message; wxString message;
@ -607,6 +609,7 @@ void DoCursorClipBoundary
{ {
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &trackPanel = TrackPanel::Get( project ); auto &trackPanel = TrackPanel::Get( project );
auto &window = ProjectWindow::Get( project );
std::vector<FoundClipBoundary> results; std::vector<FoundClipBoundary> results;
FindClipBoundaries(project, next ? selectedRegion.t1() : FindClipBoundaries(project, next ? selectedRegion.t1() :
@ -618,7 +621,7 @@ void DoCursorClipBoundary
double time = results[0].time; double time = results[0].time;
selectedRegion.setTimes(time, time); selectedRegion.setTimes(time, time);
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
trackPanel.ScrollIntoView(selectedRegion.t0()); window.ScrollIntoView(selectedRegion.t0());
wxString message = ClipBoundaryMessage(results); wxString message = ClipBoundaryMessage(results);
trackPanel.MessageForScreenReader(message); trackPanel.MessageForScreenReader(message);
@ -691,6 +694,7 @@ void DoClipLeftOrRight
(AudacityProject &project, bool right, bool keyUp ) (AudacityProject &project, bool right, bool keyUp )
{ {
auto &undoManager = UndoManager::Get( project ); auto &undoManager = UndoManager::Get( project );
auto &window = ProjectWindow::Get( project );
if (keyUp) { if (keyUp) {
undoManager.StopConsolidating(); undoManager.StopConsolidating();
@ -707,7 +711,7 @@ void DoClipLeftOrRight
auto amount = DoClipMove( viewInfo, trackPanel.GetFocusedTrack(), auto amount = DoClipMove( viewInfo, trackPanel.GetFocusedTrack(),
tracks, isSyncLocked, right ); tracks, isSyncLocked, right );
trackPanel.ScrollIntoView(selectedRegion.t0()); window.ScrollIntoView(selectedRegion.t0());
if (amount != 0.0) { if (amount != 0.0) {
wxString message = right? _("Time shifted clips to the right") : wxString message = right? _("Time shifted clips to the right") :

View File

@ -41,7 +41,6 @@ void FinishCopy
bool DoPasteText(AudacityProject &project) bool DoPasteText(AudacityProject &project)
{ {
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project ); auto &window = ProjectWindow::Get( project );
@ -61,7 +60,7 @@ bool DoPasteText(AudacityProject &project)
// Make sure caret is in view // Make sure caret is in view
int x; int x;
if (view.CalcCursorX( project, &x )) { if (view.CalcCursorX( project, &x )) {
trackPanel.ScrollIntoView(x); window.ScrollIntoView(x);
} }
return true; return true;

View File

@ -273,7 +273,7 @@ void MoveWhenAudioInactive
} }
// Make sure NEW position is in view // Make sure NEW position is in view
trackPanel.ScrollIntoView(viewInfo.selectedRegion.t1()); window.ScrollIntoView(viewInfo.selectedRegion.t1());
return; return;
} }
@ -282,9 +282,9 @@ void SeekWhenAudioInactive
SelectionOperation operation) SelectionOperation operation)
{ {
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
const auto &settings = ProjectSettings::Get( project ); const auto &settings = ProjectSettings::Get( project );
auto &window = ProjectWindow::Get( project );
if( operation == CURSOR_MOVE ) if( operation == CURSOR_MOVE )
{ {
@ -318,9 +318,8 @@ SelectionOperation operation)
else else
viewInfo.selectedRegion.setT1( newT ); viewInfo.selectedRegion.setT1( newT );
// Ensure it is visible, and refresh. // Ensure it is visible
trackPanel.ScrollIntoView(newT); window.ScrollIntoView(newT);
trackPanel.Refresh(false);
} }
// Handle small cursor and play head movements // Handle small cursor and play head movements
@ -381,8 +380,8 @@ void DoCursorMove(
void DoBoundaryMove(AudacityProject &project, int step, SeekInfo &info) void DoBoundaryMove(AudacityProject &project, int step, SeekInfo &info)
{ {
auto &viewInfo = ViewInfo::Get( project ); auto &viewInfo = ViewInfo::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
auto &window = ProjectWindow::Get( project );
// step is negative, then is moving left. step positive, moving right. // step is negative, then is moving left. step positive, moving right.
// Move the left/right selection boundary, to expand the selection // Move the left/right selection boundary, to expand the selection
@ -434,9 +433,8 @@ void DoBoundaryMove(AudacityProject &project, int step, SeekInfo &info)
else else
viewInfo.selectedRegion.setT1( newT ); viewInfo.selectedRegion.setT1( newT );
// Ensure it is visible, and refresh. // Ensure it is visible
trackPanel.ScrollIntoView(newT); window.ScrollIntoView(newT);
trackPanel.Refresh(false);
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
} }
@ -834,31 +832,31 @@ void OnSelContractRight(const CommandContext &context)
void OnCursorSelStart(const CommandContext &context) void OnCursorSelStart(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
selectedRegion.collapseToT0(); selectedRegion.collapseToT0();
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
trackPanel.ScrollIntoView(selectedRegion.t0()); window.ScrollIntoView(selectedRegion.t0());
} }
void OnCursorSelEnd(const CommandContext &context) void OnCursorSelEnd(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
selectedRegion.collapseToT1(); selectedRegion.collapseToT1();
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
trackPanel.ScrollIntoView(selectedRegion.t1()); window.ScrollIntoView(selectedRegion.t1());
} }
void OnCursorTrackStart(const CommandContext &context) void OnCursorTrackStart(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
double kWayOverToRight = std::numeric_limits<double>::max(); double kWayOverToRight = std::numeric_limits<double>::max();
@ -876,15 +874,15 @@ void OnCursorTrackStart(const CommandContext &context)
selectedRegion.setTimes(minOffset, minOffset); selectedRegion.setTimes(minOffset, minOffset);
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
trackPanel.ScrollIntoView(selectedRegion.t0()); window.ScrollIntoView(selectedRegion.t0());
} }
void OnCursorTrackEnd(const CommandContext &context) void OnCursorTrackEnd(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &window = ProjectWindow::Get( project );
double kWayOverToLeft = std::numeric_limits<double>::lowest(); double kWayOverToLeft = std::numeric_limits<double>::lowest();
@ -902,7 +900,7 @@ void OnCursorTrackEnd(const CommandContext &context)
selectedRegion.setTimes(maxEndOffset, maxEndOffset); selectedRegion.setTimes(maxEndOffset, maxEndOffset);
ProjectHistory::Get( project ).ModifyState(false); ProjectHistory::Get( project ).ModifyState(false);
trackPanel.ScrollIntoView(selectedRegion.t1()); window.ScrollIntoView(selectedRegion.t1());
} }
void OnSkipStart(const CommandContext &context) void OnSkipStart(const CommandContext &context)

View File

@ -173,7 +173,7 @@ void DoMoveToLabel(AudacityProject &project, bool next)
} }
else { else {
selectedRegion = label->selectedRegion; selectedRegion = label->selectedRegion;
trackPanel.ScrollIntoView(selectedRegion.t0()); window.ScrollIntoView(selectedRegion.t0());
window.RedrawProject(); window.RedrawProject();
} }

View File

@ -1302,7 +1302,7 @@ unsigned LabelTrackView::KeyDown(
// Make sure caret is in view // Make sure caret is in view
int x; int x;
if (CalcCursorX( *project, &x )) if (CalcCursorX( *project, &x ))
TrackPanel::Get( *project ).ScrollIntoView(x); ProjectWindow::Get( *project ).ScrollIntoView(x);
// If selection modified, refresh // If selection modified, refresh
// Otherwise, refresh track display if the keystroke was handled // Otherwise, refresh track display if the keystroke was handled