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 1027 of file TrackPanel.cpp.

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

Function Documentation

◆ DrawTrackName()

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

Definition at line 1071 of file TrackPanel.cpp.

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

Definition at line 896 of file TrackPanel.cpp.

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

References ChannelGroup::Channels(), ChannelView::Get(), 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 538 of file TrackPanel.cpp.

539 {
540 if (pCell)
541 // FindTrack as applied through the CommonTrackPanelCell interface
542 // will really find a track, though for now it finds a left or right
543 // channel.
544 return static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
545 return {};
546 }
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:538

References FindTrack().

Referenced by FindTrack(), 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 1036 of file TrackPanel.cpp.

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

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 1043 of file TrackPanel.cpp.

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

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 1050 of file TrackPanel.cpp.

1052{
1053 wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1054 dc.SetFont(labelFont);
1055 dc.GetTextExtent(GetTrack(channel).GetName(), pW, pH);
1056}

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 1058 of file TrackPanel.cpp.

1061{
1062 return {
1063 leftOffset + DisplaceX,
1064 trackRect.y + DisplaceY,
1065 textWidth + MarginsX,
1066 textHeight + MarginsY
1067 };
1068}

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:9
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:314
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 210 of file TrackPanel.cpp.

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