1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-19 22:27:43 +02:00

Make TrackInfo a namespace, not a class...

... Its functions take a pointer to TrackPanel when necessary, just to do the
reparenting of the global slider instances
This commit is contained in:
Paul Licameli 2018-11-04 10:37:27 -05:00
parent b5d4a828d1
commit 38005054f4
2 changed files with 81 additions and 113 deletions

View File

@ -37,19 +37,20 @@
*//*****************************************************************//**
\class TrackInfo
\namespace TrackInfo
\brief
The TrackInfo is shown to the side of a track
Functions for drawing the track control panel, which is shown to the side
of a track
It has the menus, pan and gain controls displayed in it.
So "Info" is somewhat a misnomer. Should possibly be "TrackControls".
In its current implementation TrackInfo is not derived from a
wxWindow. Following the original coding style, it has
been coded as a 'flyweight' class, which is passed
state as needed, except for the array of gains and pans.
It maintains global slider widget instances that are reparented and
repositioned as needed for drawing and interaction with the user,
interoperating with the custom panel subdivision implemented in CellularPanel
and avoiding wxWidgets sizers
If we'd instead coded it as a wxWindow, we would have an instance
of this class for each instance displayed.
of this class for each track displayed.
*//**************************************************************//**
@ -206,7 +207,6 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
AdornedRulerPanel * ruler)
: CellularPanel(parent, id, pos, size, viewInfo,
wxWANTS_CHARS | wxNO_BORDER),
mTrackInfo(this),
mListener(listener),
mTracks(tracks),
mRuler(ruler),
@ -217,6 +217,9 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
#pragma warning( default: 4355 )
#endif
{
TrackInfo::ReCreateSliders( this );
TrackInfo::UpdatePrefs( this );
SetLayoutDirection(wxLayout_LeftToRight);
SetLabel(_("Track Panel"));
SetName(_("Track Panel"));
@ -312,14 +315,14 @@ void TrackPanel::UpdatePrefs()
// frequences may have been changed.
UpdateVRulers();
mTrackInfo.UpdatePrefs();
TrackInfo::UpdatePrefs( this );
Refresh();
}
void TrackPanel::ApplyUpdatedTheme()
{
mTrackInfo.ReCreateSliders();
TrackInfo::ReCreateSliders( this );
}
@ -1628,7 +1631,7 @@ void TrackPanel::DrawOutside
int labelw = GetLabelWidth();
int vrul = GetVRulerOffset();
mTrackInfo.DrawBackground( dc, rect, t->GetSelected(), vrul );
TrackInfo::DrawBackground( dc, rect, t->GetSelected(), vrul );
// Vaughan, 2010-08-24: No longer doing this.
// Draw sync-lock tiles in ruler area.
@ -2237,24 +2240,27 @@ void TrackPanel::SetFocusedTrack( Track *t )
/**********************************************************************
TrackInfo code is destined to move out of this file.
Code should become a lot cleaner when we have sizers.
**********************************************************************/
TrackInfo::TrackInfo(TrackPanel * pParentIn)
{
pParent = pParentIn;
namespace {
ReCreateSliders();
wxFont gFont;
std::unique_ptr<LWSlider>
gGainCaptured
, gPanCaptured
, gGain
, gPan
#ifdef EXPERIMENTAL_MIDI_OUT
, gVelocityCaptured
, gVelocity
#endif
;
UpdatePrefs();
}
TrackInfo::~TrackInfo()
{
}
void TrackInfo::ReCreateSliders(){
void TrackInfo::ReCreateSliders( wxWindow *pParent ){
const wxPoint point{ 0, 0 };
wxRect sliderRect;
GetGainRect(point, sliderRect);
@ -2307,7 +2313,7 @@ void TrackInfo::ReCreateSliders(){
}
int TrackInfo::GetTrackInfoWidth() const
int TrackInfo::GetTrackInfoWidth()
{
return kTrackInfoWidth;
}
@ -2487,8 +2493,6 @@ void TrackInfo::GetMidiControlsRect(const wxRect & rect, wxRect & dest)
}
#endif
wxFont TrackInfo::gFont;
/// \todo Probably should move to 'Utils.cpp'.
void TrackInfo::SetTrackInfoFont(wxDC * dc)
{
@ -2552,7 +2556,7 @@ void TrackInfo::DrawBordersWithin
// Paint the whole given rectangle some fill color
void TrackInfo::DrawBackground(
wxDC * dc, const wxRect & rect, bool bSelected, const int vrul) const
wxDC * dc, const wxRect & rect, bool bSelected, const int vrul)
{
// fill in label
wxRect fill = rect;
@ -2608,17 +2612,6 @@ unsigned TrackInfo::DefaultWaveTrackHeight()
return DefaultTrackHeight( waveTrackTCPLines );
}
std::unique_ptr<LWSlider>
TrackInfo::gGainCaptured
, TrackInfo::gPanCaptured
, TrackInfo::gGain
, TrackInfo::gPan
#ifdef EXPERIMENTAL_MIDI_OUT
, TrackInfo::gVelocityCaptured
, TrackInfo::gVelocity
#endif
;
LWSlider * TrackInfo::GainSlider
(const wxRect &sliderRect, const WaveTrack *t, bool captured, wxWindow *pParent)
{
@ -2669,7 +2662,7 @@ LWSlider * TrackInfo::VelocitySlider
}
#endif
void TrackInfo::UpdatePrefs()
void TrackInfo::UpdatePrefs( wxWindow *pParent )
{
// Calculation of best font size depends on language, so it should be redone in case
// the language preference changed.

View File

@ -64,171 +64,152 @@ enum {
};
class AUDACITY_DLL_API TrackInfo
namespace TrackInfo
{
public:
TrackInfo(TrackPanel * pParentIn);
~TrackInfo();
void ReCreateSliders();
void ReCreateSliders( wxWindow *pParent );
static unsigned MinimumTrackHeight();
unsigned MinimumTrackHeight();
struct TCPLine;
static void DrawItems
void DrawItems
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track &track );
static void DrawItems
void DrawItems
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack,
const std::vector<TCPLine> &topLines,
const std::vector<TCPLine> &bottomLines );
static void CloseTitleDrawFunction
void CloseTitleDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void MinimizeSyncLockDrawFunction
void MinimizeSyncLockDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void MidiControlsDrawFunction
void MidiControlsDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
template<typename TrackClass>
static void SliderDrawFunction
void SliderDrawFunction
( LWSlider *(*Selector)
(const wxRect &sliderRect, const TrackClass *t, bool captured,
wxWindow*),
wxDC *dc, const wxRect &rect, const Track *pTrack,
bool captured, bool highlight );
static void PanSliderDrawFunction
void PanSliderDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void GainSliderDrawFunction
void GainSliderDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
#ifdef EXPERIMENTAL_MIDI_OUT
static void VelocitySliderDrawFunction
void VelocitySliderDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
#endif
static void MuteOrSoloDrawFunction
void MuteOrSoloDrawFunction
( wxDC *dc, const wxRect &rect, const Track *pTrack, bool down,
bool captured, bool solo, bool hit );
static void WideMuteDrawFunction
void WideMuteDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void WideSoloDrawFunction
void WideSoloDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void MuteAndSoloDrawFunction
void MuteAndSoloDrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void StatusDrawFunction
void StatusDrawFunction
( const wxString &string, wxDC *dc, const wxRect &rect );
static void Status1DrawFunction
void Status1DrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
static void Status2DrawFunction
void Status2DrawFunction
( TrackPanelDrawingContext &context,
const wxRect &rect, const Track *pTrack );
public:
int GetTrackInfoWidth() const;
static void SetTrackInfoFont(wxDC *dc);
int GetTrackInfoWidth();
void SetTrackInfoFont(wxDC *dc);
void DrawBackground(
wxDC * dc, const wxRect & rect, bool bSelected, const int vrul ) const;
wxDC * dc, const wxRect & rect, bool bSelected, const int vrul );
// void DrawBordersWithin(
// wxDC * dc, const wxRect & rect, const Track &track ) const;
static void GetCloseBoxHorizontalBounds( const wxRect & rect, wxRect &dest );
static void GetCloseBoxRect(const wxRect & rect, wxRect &dest);
void GetCloseBoxHorizontalBounds( const wxRect & rect, wxRect &dest );
void GetCloseBoxRect(const wxRect & rect, wxRect &dest);
static void GetTitleBarHorizontalBounds( const wxRect & rect, wxRect &dest );
static void GetTitleBarRect(const wxRect & rect, wxRect &dest);
void GetTitleBarHorizontalBounds( const wxRect & rect, wxRect &dest );
void GetTitleBarRect(const wxRect & rect, wxRect &dest);
static void GetNarrowMuteHorizontalBounds
void GetNarrowMuteHorizontalBounds
( const wxRect & rect, wxRect &dest );
static void GetNarrowSoloHorizontalBounds
void GetNarrowSoloHorizontalBounds
( const wxRect & rect, wxRect &dest );
static void GetWideMuteSoloHorizontalBounds
void GetWideMuteSoloHorizontalBounds
( const wxRect & rect, wxRect &dest );
static void GetMuteSoloRect
void GetMuteSoloRect
(const wxRect & rect, wxRect &dest, bool solo, bool bHasSoloButton,
const Track *pTrack);
static void GetSliderHorizontalBounds( const wxPoint &topleft, wxRect &dest );
void GetSliderHorizontalBounds( const wxPoint &topleft, wxRect &dest );
static void GetGainRect(const wxPoint & topLeft, wxRect &dest);
void GetGainRect(const wxPoint & topLeft, wxRect &dest);
static void GetPanRect(const wxPoint & topLeft, wxRect &dest);
void GetPanRect(const wxPoint & topLeft, wxRect &dest);
#ifdef EXPERIMENTAL_MIDI_OUT
static void GetVelocityRect(const wxPoint & topLeft, wxRect &dest);
void GetVelocityRect(const wxPoint & topLeft, wxRect &dest);
#endif
static void GetMinimizeHorizontalBounds( const wxRect &rect, wxRect &dest );
static void GetMinimizeRect(const wxRect & rect, wxRect &dest);
void GetMinimizeHorizontalBounds( const wxRect &rect, wxRect &dest );
void GetMinimizeRect(const wxRect & rect, wxRect &dest);
static void GetSyncLockHorizontalBounds( const wxRect &rect, wxRect &dest );
static void GetSyncLockIconRect(const wxRect & rect, wxRect &dest);
void GetSyncLockHorizontalBounds( const wxRect &rect, wxRect &dest );
void GetSyncLockIconRect(const wxRect & rect, wxRect &dest);
#ifdef USE_MIDI
static void GetMidiControlsHorizontalBounds
void GetMidiControlsHorizontalBounds
( const wxRect &rect, wxRect &dest );
static void GetMidiControlsRect(const wxRect & rect, wxRect &dest);
void GetMidiControlsRect(const wxRect & rect, wxRect &dest);
#endif
static bool HideTopItem( const wxRect &rect, const wxRect &subRect,
bool HideTopItem( const wxRect &rect, const wxRect &subRect,
int allowance = 0 );
static unsigned DefaultNoteTrackHeight();
static unsigned DefaultWaveTrackHeight();
unsigned DefaultNoteTrackHeight();
unsigned DefaultWaveTrackHeight();
static LWSlider * GainSlider
LWSlider * GainSlider
(const wxRect &sliderRect, const WaveTrack *t, bool captured,
wxWindow *pParent);
static LWSlider * PanSlider
LWSlider * PanSlider
(const wxRect &sliderRect, const WaveTrack *t, bool captured,
wxWindow *pParent);
#ifdef EXPERIMENTAL_MIDI_OUT
static LWSlider * VelocitySlider
LWSlider * VelocitySlider
(const wxRect &sliderRect, const NoteTrack *t, bool captured,
wxWindow *pParent);
#endif
private:
void UpdatePrefs();
TrackPanel * pParent;
static wxFont gFont;
// These are on separate lines to work around an MSVC 2013 compiler bug.
static std::unique_ptr<LWSlider> gGainCaptured;
static std::unique_ptr<LWSlider> gPanCaptured;
static std::unique_ptr<LWSlider> gGain;
static std::unique_ptr<LWSlider> gPan;
#ifdef EXPERIMENTAL_MIDI_OUT
static std::unique_ptr<LWSlider> gVelocityCaptured;
static std::unique_ptr<LWSlider> gVelocity;
#endif
friend class TrackPanel;
void UpdatePrefs( wxWindow *pParent );
};
@ -341,10 +322,11 @@ protected:
std::shared_ptr<TrackPanelNode> Root() override;
int GetVRulerWidth() const;
int GetVRulerOffset() const { return mTrackInfo.GetTrackInfoWidth(); }
int GetVRulerOffset() const { return TrackInfo::GetTrackInfoWidth(); }
public:
int GetLabelWidth() const { return mTrackInfo.GetTrackInfoWidth() + GetVRulerWidth(); }
int GetLabelWidth() const
{ return TrackInfo::GetTrackInfoWidth() + GetVRulerWidth(); }
// JKC Nov-2011: These four functions only used from within a dll such as mod-track-panel
// They work around some messy problems with constructors.
@ -397,10 +379,6 @@ public:
// Accessors...
static bool HasSoloButton(){ return gSoloPref!=wxT("None");}
protected:
TrackInfo mTrackInfo;
public:
LWSlider *GainSlider( const WaveTrack *wt );
@ -409,9 +387,6 @@ public:
LWSlider *VelocitySlider( const NoteTrack *nt );
#endif
TrackInfo *GetTrackInfo() { return &mTrackInfo; }
const TrackInfo *GetTrackInfo() const { return &mTrackInfo; }
protected:
TrackPanelListener *mListener;