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

Classes

struct  ChannelGroup
 
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)
 
void GetTrackNameExtent (wxDC &dc, const Track *t, wxCoord *pW, wxCoord *pH)
 
wxRect GetTrackNameRect (int leftOffset, const wxRect &trackRect, wxCoord textWidth, wxCoord textHeight)
 
void DrawTrackName (int leftOffset, TrackPanelDrawingContext &context, const Track *t, 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 1083 of file TrackPanel.cpp.

1083  : int {
1084  // Displacement of the rectangle from upper left corner
1085  DisplaceX = 7, DisplaceY = 1,
1086  // Size of margins about the text extent that determine the rectangle size
1087  MarginX = 8, MarginY = 2,
1088  // Derived constants
1089  MarginsX = 2 * MarginX, MarginsY = 2 * MarginY,
1090  };

Function Documentation

◆ DrawTrackName()

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

Definition at line 1113 of file TrackPanel.cpp.

1116 {
1117  if( !TrackArtist::Get( context )->mbShowTrackNameInTrack )
1118  return;
1119  auto name = t->GetName();
1120  if( name.IsEmpty())
1121  return;
1122  if( !t->IsLeader())
1123  return;
1124  auto &dc = context.dc;
1125  wxBrush Brush;
1126  wxCoord textWidth, textHeight;
1127  GetTrackNameExtent( dc, t, &textWidth, &textHeight );
1128 
1129  // Logic for name background translucency (aka 'shields')
1130  // Tracks less than kOpaqueHeight high will have opaque shields.
1131  // Tracks more than kTranslucentHeight will have maximum translucency for shields.
1132  const int kOpaqueHeight = 44;
1133  const int kTranslucentHeight = 124;
1134 
1135  // PRL: to do: reexamine this strange use of TrackView::GetHeight,
1136  // ultimately to compute an opacity
1137  int h = TrackView::Get( *t ).GetHeight();
1138 
1139  // f codes the opacity as a number between 0.0 and 1.0
1140  float f = wxClip((h-kOpaqueHeight)/(float)(kTranslucentHeight-kOpaqueHeight),0.0,1.0);
1141  // kOpaque is the shield's alpha for tracks that are not tall
1142  // kTranslucent is the shield's alpha for tracks that are tall.
1143  const int kOpaque = 255;
1144  const int kTranslucent = 140;
1145  // 0.0 maps to full opacity, 1.0 maps to full translucency.
1146  int opacity = 255 - (255-140)*f;
1147 
1148  const auto nameRect =
1149  GetTrackNameRect( leftOffset, rect, textWidth, textHeight );
1150 
1151 #ifdef __WXMAC__
1152  // Mac dc is a graphics dc already.
1153  AColor::UseThemeColour( &dc, clrTrackInfoSelected, clrTrackPanelText, opacity );
1154  dc.DrawRoundedRectangle( nameRect, 8.0 );
1155 #else
1156  // This little dance with wxImage in order to draw to a graphic dc
1157  // which we can then paste as a translucent bitmap onto the real dc.
1158  enum : int {
1159  SecondMarginX = 1, SecondMarginY = 1,
1160  SecondMarginsX = 2 * SecondMarginX, SecondMarginsY = 2 * SecondMarginY,
1161  };
1162  wxImage image(
1163  textWidth + MarginsX + SecondMarginsX,
1164  textHeight + MarginsY + SecondMarginsY );
1165  image.InitAlpha();
1166  unsigned char *alpha=image.GetAlpha();
1167  memset(alpha, wxIMAGE_ALPHA_TRANSPARENT, image.GetWidth()*image.GetHeight());
1168 
1169  {
1170  std::unique_ptr< wxGraphicsContext >
1171  pGc{ wxGraphicsContext::Create(image) };
1172  auto &gc = *pGc;
1173  // This is to a gc, not a dc.
1174  AColor::UseThemeColour( &gc, clrTrackInfoSelected, clrTrackPanelText, opacity );
1175  // Draw at 1,1, not at 0,0 to avoid clipping of the antialiasing.
1176  gc.DrawRoundedRectangle(
1177  SecondMarginX, SecondMarginY,
1178  textWidth + MarginsX, textHeight + MarginsY, 8.0 );
1179  // destructor of gc updates the wxImage.
1180  }
1181  wxBitmap bitmap( image );
1182  dc.DrawBitmap( bitmap,
1183  nameRect.x - SecondMarginX, nameRect.y - SecondMarginY );
1184 #endif
1185  dc.SetTextForeground(theTheme.Colour( clrTrackPanelText ));
1186  dc.DrawText(t->GetName(),
1187  nameRect.x + MarginX,
1188  nameRect.y + MarginY);
1189 }

References ThemeBase::Colour(), TrackPanelDrawingContext::dc, TrackView::Get(), TrackArtist::Get(), TrackView::GetHeight(), Track::GetName(), GetTrackNameExtent(), GetTrackNameRect(), Track::IsLeader(), MarginsX, MarginsY, MarginX, MarginY, name, theTheme, and AColor::UseThemeColour().

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

880 {
881  auto channels = TrackList::Channels(&t);
882  wxASSERT(!channels.empty());
883 
884  // Collect heights, and count affordances
885  int nAffordances = 0;
886  int totalHeight = 0;
887  std::vector<int> oldHeights;
888  for (auto channel : channels) {
889  auto &view = TrackView::Get( *channel );
890  const auto height = view.GetHeight();
891  totalHeight += height;
892  oldHeights.push_back( height );
893  if (view.GetAffordanceControls())
894  ++nAffordances;
895  }
896 
897  // Allocate results
898  auto nChannels = static_cast<int>(oldHeights.size());
899  std::vector<int> results;
900  results.reserve(nChannels);
901 
902  // Now reallocate the channel heights for the presence of affordances
903  // and separators
904  auto availableHeight = totalHeight
905  - nAffordances * kAffordancesAreaHeight
906  - (nChannels - 1) * kChannelSeparatorThickness
908  int cumulativeOldHeight = 0;
909  int cumulativeNewHeight = 0;
910  for (const auto &oldHeight : oldHeights) {
911  // Preserve the porportions among the stored heights
912  cumulativeOldHeight += oldHeight;
913  const auto newHeight =
914  cumulativeOldHeight * availableHeight / totalHeight
915  - cumulativeNewHeight;
916  cumulativeNewHeight += newHeight;
917  results.push_back(newHeight);
918  }
919 
920  return results;
921 }

References TrackList::Channels(), TrackView::Get(), kAffordancesAreaHeight, kChannelSeparatorThickness, and kTrackSeparatorThickness.

Referenced by anonymous_namespace{TrackPanel.cpp}::ChannelGroup::Children(), anonymous_namespace{TrackPanel.cpp}::ChannelGroup::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 530 of file TrackPanel.cpp.

531  {
532  if (pCell)
533  return static_cast<CommonTrackPanelCell*>( pCell )->FindTrack();
534  return {};
535  }

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

Here is the caller graph for this function:

◆ GetTrackNameExtent()

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

Definition at line 1092 of file TrackPanel.cpp.

1094 {
1095  wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1096  dc.SetFont(labelFont);
1097  dc.GetTextExtent( t->GetName(), pW, pH );
1098 }

References Track::GetName().

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

1103 {
1104  return {
1105  leftOffset + DisplaceX,
1106  trackRect.y + DisplaceY,
1107  textWidth + MarginsX,
1108  textHeight + MarginsY
1109  };
1110 }

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 &ruler = AdornedRulerPanel::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto &window = ProjectWindow::Get( project );
auto mainPage = window.GetMainPage();
wxASSERT( mainPage );
auto &tracks = TrackList::Get( project );
auto result = safenew TrackPanel(mainPage,
window.NextWindowID(),
wxDefaultPosition,
wxDefaultSize,
tracks.shared_from_this(),
&viewInfo,
&project,
&ruler);
SetProjectPanel( project, *result );
return result;
}
}

Definition at line 203 of file TrackPanel.cpp.

anonymous_namespace{TrackPanel.cpp}::MarginsY
@ MarginsY
Definition: TrackPanel.cpp:1089
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:161
AColor::UseThemeColour
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:283
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
Track::GetName
wxString GetName() const
Definition: Track.h:426
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
anonymous_namespace{TrackPanel.cpp}::DisplaceX
@ DisplaceX
Definition: TrackPanel.cpp:1085
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
ProjectWindow::Get
static ProjectWindow & Get(AudacityProject &project)
Definition: ProjectWindow.cpp:535
anonymous_namespace{TrackPanel.cpp}::MarginX
@ MarginX
Definition: TrackPanel.cpp:1087
anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler
Ruler & ruler()
Definition: TimeTrackVRulerControls.cpp:34
TrackPanel
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:67
AdornedRulerPanel::Get
static AdornedRulerPanel & Get(AudacityProject &project)
Definition: AdornedRulerPanel.cpp:874
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
anonymous_namespace{TrackPanel.cpp}::DisplaceY
@ DisplaceY
Definition: TrackPanel.cpp:1085
name
const TranslatableString name
Definition: Distortion.cpp:98
anonymous_namespace{TrackPanel.cpp}::FindTrack
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:530
anonymous_namespace{TrackPanel.cpp}::MarginsX
@ MarginsX
Definition: TrackPanel.cpp:1089
anonymous_namespace{TrackPanel.cpp}::GetTrackNameExtent
void GetTrackNameExtent(wxDC &dc, const Track *t, wxCoord *pW, wxCoord *pH)
Definition: TrackPanel.cpp:1092
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
Track::IsLeader
bool IsLeader() const
Definition: Track.cpp:379
kTrackSeparatorThickness
@ kTrackSeparatorThickness
Definition: TrackPanelConstants.h:23
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
kAffordancesAreaHeight
@ kAffordancesAreaHeight
Definition: TrackPanelConstants.h:19
SetProjectPanel
AUDACITY_DLL_API void SetProjectPanel(AudacityProject &project, wxWindow &panel)
Definition: ProjectWindows.cpp:66
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1197
anonymous_namespace{TrackPanel.cpp}::MarginY
@ MarginY
Definition: TrackPanel.cpp:1087
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
kChannelSeparatorThickness
@ kChannelSeparatorThickness
Definition: TrackPanelConstants.h:24
anonymous_namespace{TrackPanel.cpp}::GetTrackNameRect
wxRect GetTrackNameRect(int leftOffset, const wxRect &trackRect, wxCoord textWidth, wxCoord textHeight)
Definition: TrackPanel.cpp:1100
CommonTrackPanelCell
Definition: CommonTrackPanelCell.h:28
safenew
#define safenew
Definition: MemoryX.h:10
TrackView::GetHeight
int GetHeight() const
Definition: TrackView.cpp:149