diff --git a/locale/POTFILES.in b/locale/POTFILES.in index 2319a4c65..40ff2dcc2 100644 --- a/locale/POTFILES.in +++ b/locale/POTFILES.in @@ -252,6 +252,7 @@ src/TrackPanel.h src/TrackPanelAx.cpp src/TrackPanelAx.h src/TrackPanelCell.h +src/TrackPanelDrawable.h src/TrackPanelDrawingContext.h src/TrackPanelListener.h src/TrackPanelMouseEvent.h diff --git a/mac/Audacity.xcodeproj/project.pbxproj b/mac/Audacity.xcodeproj/project.pbxproj index 4a5a7dd80..e7a89e545 100644 --- a/mac/Audacity.xcodeproj/project.pbxproj +++ b/mac/Audacity.xcodeproj/project.pbxproj @@ -3238,6 +3238,7 @@ 5E19D64C217D51190024D0B1 /* PluginMenus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PluginMenus.cpp; path = menus/PluginMenus.cpp; sourceTree = ""; }; 5E19F59722A9665500E3F88E /* AutoRecoveryDialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutoRecoveryDialog.cpp; sourceTree = ""; }; 5E19F59822A9665500E3F88E /* AutoRecoveryDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoRecoveryDialog.h; sourceTree = ""; }; + 5E1C3F4D218F7604002CD087 /* TrackPanelDrawable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackPanelDrawable.h; sourceTree = ""; }; 5E2A19921EED688500217B58 /* SelectionState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectionState.cpp; sourceTree = ""; }; 5E2A19931EED688500217B58 /* SelectionState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionState.h; sourceTree = ""; }; 5E2B3E6022BF9621005042E1 /* RealtimeEffectManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RealtimeEffectManager.cpp; sourceTree = ""; }; @@ -4607,6 +4608,7 @@ 1790B0ED09883BFD008A330A /* TrackPanel.h */, 1790B0EF09883BFD008A330A /* TrackPanelAx.h */, 5E74D2D91CC4427B00D88B0B /* TrackPanelCell.h */, + 5E1C3F4D218F7604002CD087 /* TrackPanelDrawable.h */, 5E52335F1EFDD57D001E4BB8 /* TrackPanelDrawingContext.h */, 2803C8B619F35AA000278526 /* TrackPanelListener.h */, 5E15123A1DB000C000702E29 /* TrackPanelMouseEvent.h */, diff --git a/src/CellularPanel.cpp b/src/CellularPanel.cpp index c7c980295..b99481ef6 100644 --- a/src/CellularPanel.cpp +++ b/src/CellularPanel.cpp @@ -1122,3 +1122,32 @@ std::shared_ptr CellularPanel::LastCell() const auto &state = *mState; return state.mLastCell.lock(); } + +void CellularPanel::Draw( TrackPanelDrawingContext &context, unsigned nPasses ) +{ + const auto panelRect = GetClientRect(); + auto lastCell = LastCell(); + for ( unsigned iPass = 0; iPass < nPasses; ++iPass ) { + + VisitPostorder( [&]( const wxRect &rect, TrackPanelNode &node ) { + + // Draw the node + const auto newRect = node.DrawingArea( rect, panelRect, iPass ); + if ( newRect.Intersects( panelRect ) ) + node.Draw( context, newRect, iPass ); + + // Draw the current handle if it is associated with the node + if ( &node == lastCell.get() ) { + auto target = Target(); + if ( target ) { + const auto targetRect = + target->DrawingArea( rect, panelRect, iPass ); + if ( targetRect.Intersects( panelRect ) ) + target->Draw( context, targetRect, iPass ); + } + } + + } ); // nodes + + } // passes +} diff --git a/src/CellularPanel.h b/src/CellularPanel.h index e02969591..97aff138a 100644 --- a/src/CellularPanel.h +++ b/src/CellularPanel.h @@ -17,6 +17,7 @@ class ViewInfo; class AudacityProject; class TrackPanelCell; +struct TrackPanelDrawingContext; class TrackPanelGroup; class TrackPanelNode; struct TrackPanelMouseEvent; @@ -107,6 +108,12 @@ public: wxCoord MostRecentXCoord() const; void HandleCursorForPresentMouseState(bool doHit = true); + + // Visit the Draw functions of all cells that intersect the panel area, + // and of handles associated with such cells, + // and of all groups of cells, + // repeatedly with a pass count from 0 to nPasses - 1 + void Draw( TrackPanelDrawingContext &context, unsigned nPasses ); protected: bool HasEscape(); diff --git a/src/Makefile.am b/src/Makefile.am index fbd67bf54..0e69fe670 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -298,6 +298,7 @@ audacity_SOURCES = \ TrackPanelAx.cpp \ TrackPanelAx.h \ TrackPanelCell.h \ + TrackPanelDrawable.h \ TrackPanelDrawingContext.h \ TrackPanelListener.h \ TrackPanelMouseEvent.h \ diff --git a/src/Makefile.in b/src/Makefile.in index a5a3ca453..ac4c3b1b0 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -345,26 +345,26 @@ am__audacity_SOURCES_DIST = BlockFile.cpp BlockFile.h DirManager.cpp \ TimeTrack.h Track.cpp Track.h TrackArtist.cpp TrackArtist.h \ TrackInfo.cpp TrackInfo.h TrackPanel.cpp TrackPanel.h \ TrackPanelAx.cpp TrackPanelAx.h TrackPanelCell.h \ - TrackPanelDrawingContext.h TrackPanelListener.h \ - TrackPanelMouseEvent.h TrackPanelResizeHandle.cpp \ - TrackPanelResizeHandle.h TrackPanelResizerCell.cpp \ - TrackPanelResizerCell.h TrackUtilities.cpp TrackUtilities.h \ - TranslatableStringArray.h UIHandle.h UIHandle.cpp \ - UndoManager.cpp UndoManager.h UserException.cpp \ - UserException.h ViewInfo.cpp ViewInfo.h VoiceKey.cpp \ - VoiceKey.h WaveClip.cpp WaveClip.h WaveTrack.cpp WaveTrack.h \ - WaveTrackLocation.h WrappedType.cpp WrappedType.h ZoomInfo.cpp \ - ZoomInfo.h wxFileNameWrapper.h commands/AppCommandEvent.cpp \ - commands/AppCommandEvent.h commands/AudacityCommand.cpp \ - commands/AudacityCommand.h commands/BatchEvalCommand.cpp \ - commands/BatchEvalCommand.h commands/Command.cpp \ - commands/Command.h commands/CommandBuilder.cpp \ - commands/CommandBuilder.h commands/CommandContext.cpp \ - commands/CommandContext.h commands/CommandDirectory.cpp \ - commands/CommandDirectory.h commands/CommandFlag.h \ - commands/CommandFunctors.h commands/CommandHandler.cpp \ - commands/CommandHandler.h commands/CommandManager.cpp \ - commands/CommandManager.h \ + TrackPanelDrawable.h TrackPanelDrawingContext.h \ + TrackPanelListener.h TrackPanelMouseEvent.h \ + TrackPanelResizeHandle.cpp TrackPanelResizeHandle.h \ + TrackPanelResizerCell.cpp TrackPanelResizerCell.h \ + TrackUtilities.cpp TrackUtilities.h TranslatableStringArray.h \ + UIHandle.h UIHandle.cpp UndoManager.cpp UndoManager.h \ + UserException.cpp UserException.h ViewInfo.cpp ViewInfo.h \ + VoiceKey.cpp VoiceKey.h WaveClip.cpp WaveClip.h WaveTrack.cpp \ + WaveTrack.h WaveTrackLocation.h WrappedType.cpp WrappedType.h \ + ZoomInfo.cpp ZoomInfo.h wxFileNameWrapper.h \ + commands/AppCommandEvent.cpp commands/AppCommandEvent.h \ + commands/AudacityCommand.cpp commands/AudacityCommand.h \ + commands/BatchEvalCommand.cpp commands/BatchEvalCommand.h \ + commands/Command.cpp commands/Command.h \ + commands/CommandBuilder.cpp commands/CommandBuilder.h \ + commands/CommandContext.cpp commands/CommandContext.h \ + commands/CommandDirectory.cpp commands/CommandDirectory.h \ + commands/CommandFlag.h commands/CommandFunctors.h \ + commands/CommandHandler.cpp commands/CommandHandler.h \ + commands/CommandManager.cpp commands/CommandManager.h \ commands/CommandManagerWindowClasses.h commands/CommandMisc.h \ commands/CommandSignature.cpp commands/CommandSignature.h \ commands/CommandTargets.h commands/CommandType.cpp \ @@ -1449,26 +1449,26 @@ audacity_SOURCES = $(libaudacity_la_SOURCES) AboutDialog.cpp \ TimeTrack.h Track.cpp Track.h TrackArtist.cpp TrackArtist.h \ TrackInfo.cpp TrackInfo.h TrackPanel.cpp TrackPanel.h \ TrackPanelAx.cpp TrackPanelAx.h TrackPanelCell.h \ - TrackPanelDrawingContext.h TrackPanelListener.h \ - TrackPanelMouseEvent.h TrackPanelResizeHandle.cpp \ - TrackPanelResizeHandle.h TrackPanelResizerCell.cpp \ - TrackPanelResizerCell.h TrackUtilities.cpp TrackUtilities.h \ - TranslatableStringArray.h UIHandle.h UIHandle.cpp \ - UndoManager.cpp UndoManager.h UserException.cpp \ - UserException.h ViewInfo.cpp ViewInfo.h VoiceKey.cpp \ - VoiceKey.h WaveClip.cpp WaveClip.h WaveTrack.cpp WaveTrack.h \ - WaveTrackLocation.h WrappedType.cpp WrappedType.h ZoomInfo.cpp \ - ZoomInfo.h wxFileNameWrapper.h commands/AppCommandEvent.cpp \ - commands/AppCommandEvent.h commands/AudacityCommand.cpp \ - commands/AudacityCommand.h commands/BatchEvalCommand.cpp \ - commands/BatchEvalCommand.h commands/Command.cpp \ - commands/Command.h commands/CommandBuilder.cpp \ - commands/CommandBuilder.h commands/CommandContext.cpp \ - commands/CommandContext.h commands/CommandDirectory.cpp \ - commands/CommandDirectory.h commands/CommandFlag.h \ - commands/CommandFunctors.h commands/CommandHandler.cpp \ - commands/CommandHandler.h commands/CommandManager.cpp \ - commands/CommandManager.h \ + TrackPanelDrawable.h TrackPanelDrawingContext.h \ + TrackPanelListener.h TrackPanelMouseEvent.h \ + TrackPanelResizeHandle.cpp TrackPanelResizeHandle.h \ + TrackPanelResizerCell.cpp TrackPanelResizerCell.h \ + TrackUtilities.cpp TrackUtilities.h TranslatableStringArray.h \ + UIHandle.h UIHandle.cpp UndoManager.cpp UndoManager.h \ + UserException.cpp UserException.h ViewInfo.cpp ViewInfo.h \ + VoiceKey.cpp VoiceKey.h WaveClip.cpp WaveClip.h WaveTrack.cpp \ + WaveTrack.h WaveTrackLocation.h WrappedType.cpp WrappedType.h \ + ZoomInfo.cpp ZoomInfo.h wxFileNameWrapper.h \ + commands/AppCommandEvent.cpp commands/AppCommandEvent.h \ + commands/AudacityCommand.cpp commands/AudacityCommand.h \ + commands/BatchEvalCommand.cpp commands/BatchEvalCommand.h \ + commands/Command.cpp commands/Command.h \ + commands/CommandBuilder.cpp commands/CommandBuilder.h \ + commands/CommandContext.cpp commands/CommandContext.h \ + commands/CommandDirectory.cpp commands/CommandDirectory.h \ + commands/CommandFlag.h commands/CommandFunctors.h \ + commands/CommandHandler.cpp commands/CommandHandler.h \ + commands/CommandManager.cpp commands/CommandManager.h \ commands/CommandManagerWindowClasses.h commands/CommandMisc.h \ commands/CommandSignature.cpp commands/CommandSignature.h \ commands/CommandTargets.h commands/CommandType.cpp \ diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 92a13c289..845352ef6 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1666,6 +1666,21 @@ void TrackPanel::OnTrackFocusChange( wxCommandEvent &event ) } } +TrackPanelDrawable::~TrackPanelDrawable() +{ +} + +void TrackPanelDrawable::Draw( + TrackPanelDrawingContext &, const wxRect &, unsigned ) +{ +} + +wxRect TrackPanelDrawable::DrawingArea( + const wxRect &rect, const wxRect &, unsigned ) +{ + return rect; +} + TrackPanelNode::TrackPanelNode() { } diff --git a/src/TrackPanelCell.h b/src/TrackPanelCell.h index 09199c37c..ff22e887b 100644 --- a/src/TrackPanelCell.h +++ b/src/TrackPanelCell.h @@ -14,9 +14,11 @@ Paul Licameli #include "Audacity.h" #include "MemoryX.h" +#include "TrackPanelDrawable.h" // to inherit class AudacityProject; struct HitTestPreview; +struct TrackPanelDrawingContext; struct TrackPanelMouseEvent; struct TrackPanelMouseState; class ViewInfo; @@ -31,9 +33,9 @@ using UIHandlePtr = std::shared_ptr; #include /// \brief The TrackPanel is built up of nodes, subtrees of the CellularPanel's area -/// This class itself has almost nothing in it. Other classes derived from it -/// build up the capabilities. +/// Common base class for TrackPanelCell (leaf) and TrackPanelGroup (nonleaf) class AUDACITY_DLL_API /* not final */ TrackPanelNode + : public TrackPanelDrawable { public: TrackPanelNode(); diff --git a/src/TrackPanelDrawable.h b/src/TrackPanelDrawable.h new file mode 100644 index 000000000..0eaf3f481 --- /dev/null +++ b/src/TrackPanelDrawable.h @@ -0,0 +1,51 @@ +/********************************************************************** + +Audacity: A Digital Audio Editor + +TrackPanelDrawable.h + +Paul Licameli + +**********************************************************************/ + +#ifndef __AUDACITY_TRACK_PANEL_DRAWABLE__ +#define __AUDACITY_TRACK_PANEL_DRAWABLE__ + +struct TrackPanelDrawingContext; +struct wxRect; + +/// \brief Drawing interface common to cells, groups of cells, and temporary handles in CellularPanel +class TrackPanelDrawable { +public: + virtual ~TrackPanelDrawable() = 0; + + // Drawing functions of the subdivision are visited repeatedly in one + // painting if their areas (as computed by DrawingArea) intersect the + // panel area, and depending on iPass may overpaint results of previous + // passes. + // Drawing function is given the rectangle computed by DrawingArea. + // iPass counts zero-based up to some limit given to CellularPanel::Draw. + // Default implementation does nothing. + virtual void Draw( + TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass ); + + // For drawing purposes, a cell might require a bigger rectangle than for + // hit-test purposes, spilling over into other parts of the partition of the + // panel area. + // Default implementation returns rect unchanged. + virtual wxRect DrawingArea( + const wxRect &rect, const wxRect &panelRect, unsigned iPass ); + + // Utilities for implementing DrawingArea: + static inline wxRect MaximizeWidth( + const wxRect &rect, const wxRect &panelRect ) { + return { panelRect.x, rect.y, panelRect.width, rect.height }; + } + + static inline wxRect MaximizeHeight( + const wxRect &rect, const wxRect &panelRect ) { + return { rect.x, panelRect.y, rect.width, panelRect.height }; + } +}; + +#endif diff --git a/src/UIHandle.h b/src/UIHandle.h index ff8074962..45026d9b1 100644 --- a/src/UIHandle.h +++ b/src/UIHandle.h @@ -13,6 +13,7 @@ Paul Licameli #include #include "MemoryX.h" +#include "TrackPanelDrawable.h" // to inherit class wxDC; class wxRect; @@ -27,10 +28,11 @@ struct TrackPanelMouseState; #include "MemoryX.h" +/// \brief Short-lived drawing and event-handling object associated with a TrackPanelCell // A TrackPanelCell reports a handle object of some subclass, in response to a // hit test at a mouse position; then this handle processes certain events, // and maintains necessary state through click-drag-release event sequences. -class UIHandle /* not final */ +class UIHandle /* not final */ : public TrackPanelDrawable { public: // See RefreshCode.h for bit flags: diff --git a/win/Projects/Audacity/Audacity.vcxproj b/win/Projects/Audacity/Audacity.vcxproj index 829c20a80..2b58c0d42 100755 --- a/win/Projects/Audacity/Audacity.vcxproj +++ b/win/Projects/Audacity/Audacity.vcxproj @@ -582,6 +582,7 @@ + diff --git a/win/Projects/Audacity/Audacity.vcxproj.filters b/win/Projects/Audacity/Audacity.vcxproj.filters index 896eae286..7f09a7f69 100755 --- a/win/Projects/Audacity/Audacity.vcxproj.filters +++ b/win/Projects/Audacity/Audacity.vcxproj.filters @@ -2404,6 +2404,9 @@ src\tracks\ui + + src +