Skip to content

Commit

Permalink
Define Viewport::Redraw to break more dependency on ProjectWindow.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Nov 7, 2023
1 parent d3903bd commit 9f14237
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/AudacityApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ It handles initialization and termination by subclassing wxApp.
#include "Track.h"
#include "prefs/PrefsDialog.h"
#include "Theme.h"
#include "Viewport.h"
#include "PlatformCompatibility.h"
#include "AutoRecoveryDialog.h"
#include "SplashDialog.h"
Expand Down Expand Up @@ -1196,8 +1197,7 @@ bool AudacityApp::OnExceptionInMainLoop()

// Forget pending changes in the TrackList
TrackList::Get( *pProject ).ClearPendingTracks();

ProjectWindow::Get( *pProject ).RedrawProject();
Viewport::Get(*pProject).Redraw();
}

// Give the user an alert
Expand Down
4 changes: 2 additions & 2 deletions src/LabelDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include "LabelTrack.h"
#include "Prefs.h"
#include "Project.h"
#include "ProjectWindow.h"
#include "SelectFile.h"
#include "ViewInfo.h"
#include "Viewport.h"
#include "tracks/labeltrack/ui/LabelTrackView.h"
#include "AudacityMessageBox.h"
#include "AudacityTextEntryDialog.h"
Expand Down Expand Up @@ -749,7 +749,7 @@ void LabelDialog::OnSelectCell(wxGridEvent &event)
RowData &rd = mData[event.GetRow()];
mViewInfo->selectedRegion = rd.selectedRegion;

ProjectWindow::Get( mProject ).RedrawProject();
Viewport::Get(mProject).Redraw();
}

event.Skip();
Expand Down
5 changes: 3 additions & 2 deletions src/MixerBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "TrackPanel.h"
#include "TrackUtilities.h"
#include "UndoManager.h"
#include "Viewport.h"
#include "WaveTrack.h"

#include "widgets/AButton.h"
Expand Down Expand Up @@ -793,7 +794,7 @@ void MixerTrackCluster::OnButton_Mute(wxCommandEvent& WXUNUSED(event))

// Update the TrackPanel correspondingly.
if (TracksBehaviorsSolo.ReadEnum() == SoloBehaviorSimple)
ProjectWindow::Get( *mProject ).RedrawProject();
Viewport::Get(*mProject).Redraw();
else
// Update only the changed track.
TrackPanel::Get( *mProject ).RefreshTrack(mTrack.get());
Expand All @@ -808,7 +809,7 @@ void MixerTrackCluster::OnButton_Solo(wxCommandEvent& WXUNUSED(event))

// Update the TrackPanel correspondingly.
// Bug 509: Must repaint all, as many tracks can change with one Solo change.
ProjectWindow::Get( *mProject ).RedrawProject();
Viewport::Get(*mProject).Redraw();
}


Expand Down
6 changes: 4 additions & 2 deletions src/ProjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ Paul Licameli split from AudacityProject.cpp
#include "ProjectFileManager.h"
#include "ProjectHistory.h"
#include "ProjectSelectionManager.h"
#include "ProjectWindows.h"
#include "ProjectRate.h"
#include "ProjectSettings.h"
#include "ProjectStatus.h"
#include "ProjectWindow.h"
#include "ProjectWindows.h"
#include "SelectUtilities.h"
#include "TrackPanel.h"
#include "TrackUtilities.h"
#include "UndoManager.h"
#include "Viewport.h"
#include "WaveTrack.h"
#include "wxFileNameWrapper.h"
#include "Import.h"
Expand Down Expand Up @@ -416,6 +417,7 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
const auto &settings = ProjectSettings::Get( project );
auto &projectAudioIO = ProjectAudioIO::Get( project );
auto &tracks = TrackList::Get( project );
auto &viewport = Viewport::Get(project);
auto &window = ProjectWindow::Get( project );
auto gAudioIO = AudioIO::Get();

Expand Down Expand Up @@ -450,7 +452,7 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
ProjectAudioManager::Get( project ).Stop();

projectAudioIO.SetAudioIOToken(0);
window.RedrawProject();
viewport.Redraw();
}
else if (gAudioIO->IsMonitoring()) {
gAudioIO->StopStream();
Expand Down
23 changes: 0 additions & 23 deletions src/ProjectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,29 +660,6 @@ void ProjectWindow::ApplyUpdatedTheme()
ClearBackground();// For wxGTK.
}

void ProjectWindow::RedrawProject()
{
auto pThis = wxWeakRef<ProjectWindow>(this);
CallAfter( [pThis]{

if (!pThis)
return;
if (pThis->IsBeingDeleted())
return;

auto pProject = pThis->FindProject();
if (!pProject)
return;

auto &project = *pProject;
auto &tracks = TrackList::Get( project );
auto &trackPanel = GetProjectPanel( project );
Viewport::Get(project).UpdateScrollbarsForTracks();
trackPanel.Refresh(false);

});
}

void ProjectWindow::OnThemeChange(ThemeChangeMessage message)
{
auto pProject = FindProject();
Expand Down
2 changes: 0 additions & 2 deletions src/ProjectWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class AUDACITY_DLL_API ProjectWindow final : public ProjectWindowBase
void SetNormalizedWindowState(wxRect pSizeAndLocation) { mNormalizedWindowState = pSizeAndLocation; }
wxRect GetNormalizedWindowState() const { return mNormalizedWindowState; }

void RedrawProject();

void ApplyUpdatedTheme();

Expand Down Expand Up @@ -162,7 +161,6 @@ class AUDACITY_DLL_API ProjectWindow final : public ProjectWindowBase
void RefreshTPTrack(Track* pTrk, bool refreshbacking = true) /* not override */;

private:

void OnThemeChange(struct ThemeChangeMessage);

// PrefsListener implementation
Expand Down
19 changes: 11 additions & 8 deletions src/Screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ It forwards the actual work of doing the commands to the ScreenshotCommand.
#include "prefs/GUISettings.h" // for RTL_WORKAROUND
#include "Project.h"
#include "ProjectStatus.h"
#include "ProjectWindow.h"
#include "ProjectWindows.h"
#include "Prefs.h"
#include "toolbars/ToolManager.h"
#include "tracks/ui/ChannelView.h"
#include "HelpSystem.h"

#include "ViewInfo.h"
#include "Viewport.h"
#include "WaveTrack.h"

class OldStyleCommandType;
Expand Down Expand Up @@ -725,12 +725,13 @@ void ScreenshotBigDialog::OnCaptureSomething(wxCommandEvent & event)

void ScreenshotBigDialog::TimeZoom(double seconds)
{
auto &viewInfo = ViewInfo::Get( mContext.project );
auto &window = ProjectWindow::Get( mContext.project );
auto &project = mContext.project;
auto &viewInfo = ViewInfo::Get(project);
auto &window = GetProjectFrame(project);
int width, height;
window.GetClientSize(&width, &height);
viewInfo.SetZoom((0.75 * width) / seconds);
window.RedrawProject();
Viewport::Get(project).Redraw();
}

void ScreenshotBigDialog::OnOneSec(wxCommandEvent & WXUNUSED(event))
Expand Down Expand Up @@ -767,27 +768,29 @@ void ScreenshotBigDialog::SizeTracks(int h)
// If there should be more-than-stereo tracks, this makes
// each channel as high as for a stereo channel

auto &tracks = TrackList::Get( mContext.project );
auto &project = mContext.project;
auto &tracks = TrackList::Get(project);
for (auto t : tracks.Any<WaveTrack>()) {
auto channels = t->Channels();
auto nChannels = channels.size();
auto height = nChannels == 1 ? 2 * h : h;
for (auto pChannel : channels)
ChannelView::Get(*pChannel).SetExpandedHeight(height);
}
ProjectWindow::Get( mContext.project ).RedrawProject();
Viewport::Get(project).Redraw();
}

void ScreenshotBigDialog::OnShortTracks(wxCommandEvent & WXUNUSED(event))
{
for (auto t : TrackList::Get(mContext.project).Any<WaveTrack>()) {
auto &project = mContext.project;
for (auto t : TrackList::Get(project).Any<WaveTrack>()) {
for (auto pChannel : t->Channels()) {
auto &view = ChannelView::Get(*pChannel);
view.SetExpandedHeight(view.GetMinimizedHeight());
}
}

ProjectWindow::Get( mContext.project ).RedrawProject();
Viewport::Get(project).Redraw();
}

void ScreenshotBigDialog::OnMedTracks(wxCommandEvent & WXUNUSED(event))
Expand Down
4 changes: 3 additions & 1 deletion src/TrackPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ is time to refresh some aspect of the screen.
#include "TrackArtist.h"
#include "TrackPanelAx.h"
#include "TrackPanelResizerCell.h"
#include "Viewport.h"
#include "WaveTrack.h"

#include "FrameStatistics.h"
Expand Down Expand Up @@ -414,6 +415,7 @@ void TrackPanel::OnTimer(wxTimerEvent& )

AudacityProject *const p = GetProject();
auto &window = ProjectWindow::Get( *p );
auto &viewport = Viewport::Get(*p);

auto &projectAudioIO = ProjectAudioIO::Get( *p );
auto gAudioIO = AudioIO::Get();
Expand All @@ -433,7 +435,7 @@ void TrackPanel::OnTimer(wxTimerEvent& )
!gAudioIO->IsAudioTokenActive(projectAudioIO.GetAudioIOToken()))
{
projectAudioIO.SetAudioIOToken(0);
window.RedrawProject();
viewport.Redraw();
}
if (mLastDrawnSelectedRegion != mViewInfo->selectedRegion) {
UpdateSelectionDisplay();
Expand Down
8 changes: 5 additions & 3 deletions src/commands/CommandDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include "CommandManager.h"
#include "PluginManager.h"
#include "ProjectAudioManager.h"
#include "ProjectWindow.h"
#include "ProjectWindows.h"
#include "Viewport.h"
#include "../effects/EffectManager.h"
#include "../effects/EffectUI.h"
#include <wx/log.h>
#include <wx/frame.h>

bool CommandDispatch::HandleTextualCommand( CommandManager &commandManager,
const CommandID & Str,
Expand Down Expand Up @@ -57,7 +59,7 @@ bool CommandDispatch::DoAudacityCommand(
const PluginID & ID, const CommandContext & context, unsigned flags )
{
auto &project = context.project;
auto &window = ProjectWindow::Get( project );
auto &window = GetProjectFrame(project);
const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
if (!plug)
return false;
Expand Down Expand Up @@ -88,7 +90,7 @@ bool CommandDispatch::DoAudacityCommand(
PushState(longDesc, shortDesc);
}
*/
window.RedrawProject();
Viewport::Get(project).Redraw();
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

#include "../ActiveProject.h"
#include "Project.h"
#include "../ProjectWindow.h"
#include "AppCommandEvent.h"
#include "ScriptCommandRelay.h"
#include "../commands/CommandContext.h"
#include "../commands/Command.h"
#include "Viewport.h"

CommandHandler::CommandHandler()
{
Expand All @@ -51,6 +51,6 @@ void CommandHandler::OnReceiveCommand(AppCommandEvent &event)
wxUnusedVar(result);

// Redraw the project
ProjectWindow::Get( context.project ).RedrawProject();
Viewport::Get(context.project).Redraw();
}
}
9 changes: 5 additions & 4 deletions src/effects/EffectUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
#include "ProjectAudioIO.h"
#include "ProjectHistory.h"
#include "../ProjectWindowBase.h"
#include "../ProjectWindows.h"
#include "TrackFocus.h"
#include "RealtimeEffectList.h"
#include "RealtimeEffectManager.h"
#include "RealtimeEffectState.h"
#include "Theme.h"
#include "Viewport.h"
#include "wxWidgetsWindowPlacement.h"

static PluginID GetID(EffectPlugin &effect)
Expand Down Expand Up @@ -1131,7 +1133,6 @@ DialogFactoryResults EffectUI::DialogFactory(wxWindow &parent,

#include "PluginManager.h"
#include "ProjectRate.h"
#include "../ProjectWindow.h"
#include "../SelectUtilities.h"
#include "WaveTrack.h"
#include "../commands/CommandManager.h"
Expand All @@ -1152,7 +1153,7 @@ DialogFactoryResults EffectUI::DialogFactory(wxWindow &parent,
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
auto &commandManager = CommandManager::Get( project );
auto &viewport = Viewport::Get(project);
auto &window = ProjectWindow::Get( project );
auto &window = GetProjectFrame(project);

const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);

Expand Down Expand Up @@ -1311,8 +1312,8 @@ DialogFactoryResults EffectUI::DialogFactory(wxWindow &parent,
viewport.ZoomFitHorizontally();
}

// PRL: RedrawProject explicitly because sometimes history push is skipped
window.RedrawProject();
// PRL: Redraw explicitly because sometimes history push is skipped
viewport.Redraw();

if (focus != nullptr && focus->GetParent()==parent) {
focus->SetFocus();
Expand Down
8 changes: 3 additions & 5 deletions src/menus/TransportMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
#include "../CommonCommandFlags.h"
#include "DeviceManager.h"
#include "../LabelTrack.h"
#include "../Menus.h"
#include "Prefs.h"
#include "Project.h"
#include "ProjectAudioIO.h"
#include "../ProjectAudioManager.h"
#include "ProjectHistory.h"
#include "../ProjectSettings.h"
#include "../ProjectWindows.h"
#include "../ProjectWindow.h"
#include "../SelectUtilities.h"
#include "../SoundActivatedRecord.h"
#include "TrackFocus.h"
Expand All @@ -21,6 +19,7 @@
#include "../prefs/TracksPrefs.h"
#include "WaveTrack.h"
#include "ViewInfo.h"
#include "Viewport.h"
#include "../commands/CommandContext.h"
#include "../commands/CommandManager.h"
#include "../toolbars/ControlToolBar.h"
Expand Down Expand Up @@ -75,7 +74,6 @@ void DoMoveToLabel(AudacityProject &project, bool next)
auto &tracks = TrackList::Get( project );
auto &trackFocus = TrackFocus::Get( project );
auto &viewport = Viewport::Get(project);
auto &window = ProjectWindow::Get( project );
auto &projectAudioManager = ProjectAudioManager::Get(project);

// Find the number of label tracks, and ptr to last track found
Expand Down Expand Up @@ -111,13 +109,13 @@ void DoMoveToLabel(AudacityProject &project, bool next)
if (ProjectAudioIO::Get( project ).IsAudioActive()) {
TransportUtilities::DoStopPlaying(project);
selectedRegion = label->selectedRegion;
window.RedrawProject();
viewport.Redraw();
TransportUtilities::DoStartPlaying(project, newDefault);
}
else {
selectedRegion = label->selectedRegion;
viewport.ScrollIntoView(selectedRegion.t0());
window.RedrawProject();
viewport.Redraw();
}
/* i18n-hint:
String is replaced by the name of a label,
Expand Down
4 changes: 2 additions & 2 deletions src/toolbars/ToolsToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
#include "ImageManipulation.h"
#include "Project.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../tracks/ui/Scrubbing.h"
#include "Viewport.h"

#include "../widgets/AButton.h"

Expand Down Expand Up @@ -228,7 +228,7 @@ void ToolsToolBar::OnToolChanged(wxCommandEvent &evt)
if (evt.GetInt() != ProjectSettings::ChangedTool)
return;
DoToolChanged();
ProjectWindow::Get( mProject ).RedrawProject();
Viewport::Get(mProject).Redraw();
}

void ToolsToolBar::DoToolChanged()
Expand Down
Loading

0 comments on commit 9f14237

Please sign in to comment.