Audacity  3.2.0
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 1078 of file TrackPanel.cpp.

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

Function Documentation

◆ DrawTrackName()

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

Definition at line 1108 of file TrackPanel.cpp.

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

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

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

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

526  {
527  if (pCell)
528  return static_cast<CommonTrackPanelCell*>( pCell )->FindTrack();
529  return {};
530  }

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

1089 {
1090  wxFont labelFont(12, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1091  dc.SetFont(labelFont);
1092  dc.GetTextExtent( t->GetName(), pW, pH );
1093 }

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

1098 {
1099  return {
1100  leftOffset + DisplaceX,
1101  trackRect.y + DisplaceY,
1102  textWidth + MarginsX,
1103  textHeight + MarginsY
1104  };
1105 }

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.

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

anonymous_namespace{TrackPanel.cpp}::MarginsY
@ MarginsY
Definition: TrackPanel.cpp:1084
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
AColor::UseThemeColour
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:280
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:69
Track::GetName
wxString GetName() const
Definition: Track.h:423
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1483
anonymous_namespace{TrackPanel.cpp}::DisplaceX
@ DisplaceX
Definition: TrackPanel.cpp:1080
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
ProjectWindow::Get
static ProjectWindow & Get(AudacityProject &project)
Definition: ProjectWindow.cpp:525
anonymous_namespace{TrackPanel.cpp}::MarginX
@ MarginX
Definition: TrackPanel.cpp:1082
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:65
AdornedRulerPanel::Get
static AdornedRulerPanel & Get(AudacityProject &project)
Definition: AdornedRulerPanel.cpp:1233
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
anonymous_namespace{TrackPanel.cpp}::DisplaceY
@ DisplaceY
Definition: TrackPanel.cpp:1080
name
const TranslatableString name
Definition: Distortion.cpp:98
anonymous_namespace{TrackPanel.cpp}::FindTrack
std::shared_ptr< Track > FindTrack(TrackPanelCell *pCell)
Definition: TrackPanel.cpp:525
theTheme
THEME_API Theme theTheme
Definition: Theme.cpp:82
anonymous_namespace{TrackPanel.cpp}::MarginsX
@ MarginsX
Definition: TrackPanel.cpp:1084
anonymous_namespace{TrackPanel.cpp}::GetTrackNameExtent
void GetTrackNameExtent(wxDC &dc, const Track *t, wxCoord *pW, wxCoord *pH)
Definition: TrackPanel.cpp:1087
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:377
Track::IsLeader
bool IsLeader() const
Definition: Track.cpp:298
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:89
kAffordancesAreaHeight
@ kAffordancesAreaHeight
Definition: TrackPanelConstants.h:19
SetProjectPanel
AUDACITY_DLL_API void SetProjectPanel(AudacityProject &project, wxWindow &panel)
Definition: ProjectWindows.cpp:66
anonymous_namespace{TrackPanel.cpp}::MarginY
@ MarginY
Definition: TrackPanel.cpp:1082
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:1095
CommonTrackPanelCell
Definition: CommonTrackPanelCell.h:31
ThemeBase::Colour
wxColour & Colour(int iIndex)
safenew
#define safenew
Definition: MemoryX.h:10
TrackView::GetHeight
int GetHeight() const
Definition: TrackView.cpp:164