Audacity 3.2.0
Classes | Enumerations | Functions | Variables
anonymous_namespace{TrackPanel.cpp} Namespace Reference

Classes

struct  ChannelStack
 
struct  EmptyCell
 
class  EmptyPanelRect
 
struct  HorizontalGroup
 
struct  LabeledChannelGroup
 
struct  MainGroup
 
struct  ResizingChannelGroup
 
struct  Subgroup
 
struct  VRulerAndChannel
 
struct  VRulersAndChannels
 

Enumerations

enum  : int {
  DisplaceX = 7 , DisplaceY = 1 , MarginX = 8 , MarginY = 2 ,
  MarginsX = 2 * MarginX , MarginsY = 2 * MarginY
}
 

Functions

std::shared_ptr< TrackFindTrack (TrackPanelCell *pCell)
 
std::vector< int > FindAdjustedChannelHeights (Track &t)
 
TrackGetTrack (Channel &channel)
 
const TrackGetTrack (const Channel &channel)
 
void GetTrackNameExtent (wxDC &dc, const Channel &channel, wxCoord *pW, wxCoord *pH)
 
wxRect GetTrackNameRect (int leftOffset, const wxRect &trackRect, wxCoord textWidth, wxCoord textHeight)
 
void DrawTrackName (int leftOffset, TrackPanelDrawingContext &context, const Channel &channel, const wxRect &rect)
 

Variables

AttachedWindows::RegisteredFactory sKey
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : int
Enumerator
DisplaceX 
DisplaceY 
MarginX 
MarginY 
MarginsX 
MarginsY 

Definition at line 1030 of file TrackPanel.cpp.

1030 : int {
1031 // Displacement of the rectangle from upper left corner
1032 DisplaceX = 7, DisplaceY = 1,
1033 // Size of margins about the text extent that determine the rectangle size
1034 MarginX = 8, MarginY = 2,
1035 // Derived constants
1036 MarginsX = 2 * MarginX, MarginsY = 2 * MarginY,
1037 };

Function Documentation

◆ DrawTrackName()

void anonymous_namespace{TrackPanel.cpp}::DrawTrackName ( int  leftOffset,
TrackPanelDrawingContext context,
const Channel channel,
const wxRect &  rect 
)

Definition at line 1074 of file TrackPanel.cpp.

1076{
1077 if (!TrackArtist::Get(context)->mbShowTrackNameInTrack)
1078 return;
1079 auto &track = *GetTrack(channel).SubstitutePendingChangedTrack();
1080 auto name = track.GetName();
1081 if (name.IsEmpty())
1082 return;
1083 if (!track.IsLeader())
1084 return;
1085 auto &dc = context.dc;
1086 wxBrush Brush;
1087 wxCoord textWidth, textHeight;
1088 GetTrackNameExtent(dc, channel, &textWidth, &textHeight);
1089
1090 // Logic for name background translucency (aka 'shields')
1091 // Tracks less than kOpaqueHeight high will have opaque shields.
1092 // Tracks more than kTranslucentHeight will have maximum translucency for shields.
1093 const int kOpaqueHeight = 44;
1094 const int kTranslucentHeight = 124;
1095
1096 // PRL: to do: reexamine this strange use of ChannelView::GetHeight,
1097 // ultimately to compute an opacity
1098 int h = ChannelView::Get(channel).GetHeight();
1099
1100 // f codes the opacity as a number between 0.0 and 1.0
1101 float f = wxClip((h-kOpaqueHeight)/(float)(kTranslucentHeight-kOpaqueHeight),0.0,1.0);
1102 // kOpaque is the shield's alpha for tracks that are not tall
1103 // kTranslucent is the shield's alpha for tracks that are tall.
1104 const int kOpaque = 255;
1105 const int kTranslucent = 140;
1106 // 0.0 maps to full opacity, 1.0 maps to full translucency.
1107 int opacity = 255 - (255-140)*f;
1108
1109 const auto nameRect =
1110 GetTrackNameRect( leftOffset, rect, textWidth, textHeight );
1111
1112#ifdef __WXMAC__
1113 // Mac dc is a graphics dc already.
1114 AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, opacity );
1115 dc.DrawRoundedRectangle( nameRect, 8.0 );
1116#else
1117 // This little dance with wxImage in order to draw to a graphic dc
1118 // which we can then paste as a translucent bitmap onto the real dc.
1119 enum : int {
1120 SecondMarginX = 1, SecondMarginY = 1,
1121 SecondMarginsX = 2 * SecondMarginX, SecondMarginsY = 2 * SecondMarginY,
1122 };
1123 wxImage image(
1124 textWidth + MarginsX + SecondMarginsX,
1125 textHeight + MarginsY + SecondMarginsY );
1126 image.InitAlpha();
1127 unsigned char *alpha=image.GetAlpha();
1128 memset(alpha, wxIMAGE_ALPHA_TRANSPARENT, image.GetWidth()*image.GetHeight());
1129
1130 {
1131 std::unique_ptr< wxGraphicsContext >
1132 pGc{ wxGraphicsContext::Create(image) };
1133 auto &gc = *pGc;
1134 // This is to a gc, not a dc.
1135 AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, opacity );
1136 // Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing.
1137 gc.DrawRoundedRectangle(
1138 SecondMarginX, SecondMarginY,
1139 textWidth + MarginsX, textHeight + MarginsY, 8.0 );
1140 // destructor of gc updates the wxImage.
1141 }
1142 wxBitmap bitmap( image );
1143 dc.DrawBitmap( bitmap,
1144 nameRect.x - SecondMarginX, nameRect.y - SecondMarginY );
1145#endif
1146 dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
1147 dc.DrawText(track.GetName(),
1148 nameRect.x + MarginX,
1149 nameRect.y + MarginY);
1150}
wxImage(22, 22)
const TranslatableString name
Definition: Distortion.cpp:76
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:372
static ChannelView & Get(Channel &channel)
int GetHeight() const
wxColour & Colour(int iIndex)
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
std::shared_ptr< Track > SubstitutePendingChangedTrack()
Definition: Track.cpp:1164
const Track & GetTrack(const Channel &channel)
void GetTrackNameExtent(wxDC &dc, const Channel &channel, wxCoord *pW, wxCoord *pH)
wxRect GetTrackNameRect(int leftOffset, const wxRect &trackRect, wxCoord textWidth, wxCoord textHeight)

References ThemeBase::Colour(), TrackPanelDrawingContext::dc, ChannelView::Get(), TrackArtist::Get(), ChannelView::GetHeight(), GetTrack(), GetTrackNameExtent(), GetTrackNameRect(), MarginsX, MarginsY, MarginX, MarginY, name, Track::SubstitutePendingChangedTrack(), theTheme, AColor::UseThemeColour(), and wxImage().

Referenced by anonymous_namespace{TrackPanel.cpp}::VRulersAndChannels::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindAdjustedChannelHeights()

std::vector< int > anonymous_namespace{TrackPanel.cpp}::FindAdjustedChannelHeights ( Track t)
Precondition
t.IsLeader()

Definition at line 896 of file TrackPanel.cpp.

897{
898 assert(t.IsLeader());
899 auto channels = t.Channels();
900 assert(!channels.empty());
901
902 // Collect heights, and count affordances
903 int nAffordances = 0;
904 int totalHeight = 0;
905 std::vector<int> oldHeights;
906 for (auto pChannel : channels) {
907 auto &view = ChannelView::Get(*pChannel);
908 const auto height = view.GetHeight();
909 totalHeight += height;
910 oldHeights.push_back(height);
911 if (view.GetAffordanceControls())
912 ++nAffordances;
913 }
914
915 // Allocate results
916 auto nChannels = static_cast<int>(oldHeights.size());
917 std::vector<int> results;
918 results.reserve(nChannels);
919
920 // Now reallocate the channel heights for the presence of affordances
921 // and separators
922 auto availableHeight = totalHeight
923 - nAffordances * kAffordancesAreaHeight
924 - (nChannels - 1) * kChannelSeparatorThickness
926 int cumulativeOldHeight = 0;
927 int cumulativeNewHeight = 0;
928 for (const auto &oldHeight : oldHeights) {
929 // Preserve the porportions among the stored heights
930 cumulativeOldHeight += oldHeight;
931 const auto newHeight =
932 cumulativeOldHeight * availableHeight / totalHeight
933 - cumulativeNewHeight;
934 cumulativeNewHeight += newHeight;
935 results.push_back(newHeight);
936 }
937
938 return results;
939}
@ kTrackSeparatorThickness
@ kChannelSeparatorThickness
@ kAffordancesAreaHeight
IteratorRange< ChannelIterator< ChannelType > > Channels()
Get range of channels with mutative access.
Definition: Channel.h:408
bool IsLeader() const override
Definition: Track.cpp:291

References ChannelGroup::Channels(), ChannelView::Get(), Track::IsLeader(), kAffordancesAreaHeight, kChannelSeparatorThickness, and kTrackSeparatorThickness.

Referenced by anonymous_namespace{TrackPanel.cpp}::ChannelStack::Children(), anonymous_namespace{TrackPanel.cpp}::ChannelStack::Draw(), and TrackPanel::UpdateTrackVRuler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindTrack()

std::shared_ptr< Track > anonymous_namespace{TrackPanel.cpp}::FindTrack ( TrackPanelCell pCell)

Definition at line 537 of file TrackPanel.cpp.

538 {
539 if (pCell)
540 return static_cast<CommonTrackPanelCell*>( pCell )->FindTrack();
541 return {};
542 }
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:537

References FindTrack().

Referenced by MenuButtonHandle::CommitChanges(), StretchHandle::Drag(), FindTrack(), WaveChannelSubView::GetMenuItems(), CloseButtonHandle::HitTest(), MenuButtonHandle::HitTest(), MinimizeButtonHandle::HitTest(), SelectButtonHandle::HitTest(), TrackPanel::OnMouseEvent(), and TrackPanel::ProcessUIHandleResult().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTrack() [1/2]

Track & anonymous_namespace{TrackPanel.cpp}::GetTrack ( Channel channel)

Definition at line 1039 of file TrackPanel.cpp.

1040{
1041 // It is assumed that all channels we ever see are in groups that are
1042 // also Tracks
1043 return static_cast<Track &>(channel.GetChannelGroup());
1044}
ChannelGroup & GetChannelGroup()
Channel object's lifetime is assumed to be nested in its Track's.
Definition: Channel.cpp:71
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122

References Channel::GetChannelGroup().

Here is the call graph for this function:

◆ GetTrack() [2/2]

const Track & anonymous_namespace{TrackPanel.cpp}::GetTrack ( const Channel channel)

Definition at line 1046 of file TrackPanel.cpp.

1047{
1048 // It is assumed that all channels we ever see are in groups that are
1049 // also Tracks
1050 return static_cast<const Track &>(channel.GetChannelGroup());
1051}

References Channel::GetChannelGroup().

Referenced by anonymous_namespace{TrackPanel.cpp}::EmptyPanelRect::DoFindTrack(), DrawTrackName(), and GetTrackNameExtent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTrackNameExtent()

void anonymous_namespace{TrackPanel.cpp}::GetTrackNameExtent ( wxDC &  dc,
const Channel channel,
wxCoord *  pW,
wxCoord *  pH 
)

Definition at line 1053 of file TrackPanel.cpp.

1055{
1056 wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1057 dc.SetFont(labelFont);
1058 dc.GetTextExtent(GetTrack(channel).GetName(), pW, pH);
1059}

References GetTrack().

Referenced by anonymous_namespace{TrackPanel.cpp}::VRulersAndChannels::DrawingArea(), and DrawTrackName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTrackNameRect()

wxRect anonymous_namespace{TrackPanel.cpp}::GetTrackNameRect ( int  leftOffset,
const wxRect &  trackRect,
wxCoord  textWidth,
wxCoord  textHeight 
)

Definition at line 1061 of file TrackPanel.cpp.

1064{
1065 return {
1066 leftOffset + DisplaceX,
1067 trackRect.y + DisplaceY,
1068 textWidth + MarginsX,
1069 textHeight + MarginsY
1070 };
1071}

References DisplaceX, DisplaceY, MarginsX, and MarginsY.

Referenced by anonymous_namespace{TrackPanel.cpp}::VRulersAndChannels::DrawingArea(), and DrawTrackName().

Here is the caller graph for this function:

Variable Documentation

◆ sKey

AttachedWindows::RegisteredFactory anonymous_namespace{TrackPanel.cpp}::sKey
Initial value:
{
[]( AudacityProject &project ) -> wxWeakRef< wxWindow > {
auto &viewInfo = ViewInfo::Get( project );
auto &window = ProjectWindow::Get( project );
auto mainPage = window.GetTrackListWindow();
wxASSERT( mainPage );
auto result = safenew TrackPanel(mainPage,
window.NextWindowID(),
wxDefaultPosition,
wxDefaultSize,
tracks.shared_from_this(),
&viewInfo,
&ruler);
SetProjectPanel( project, *result );
return result;
}
}
#define safenew
Definition: MemoryX.h:10
AUDACITY_DLL_API void SetProjectPanel(AudacityProject &project, wxWindow &panel)
const auto tracks
const auto project
static AdornedRulerPanel & Get(AudacityProject &project)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ProjectWindow & Get(AudacityProject &project)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:63
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

Definition at line 209 of file TrackPanel.cpp.

Referenced by TrackPanel::Destroy(), and TrackPanel::Get().