Audacity 3.2.0
Functions | Variables
TrackArt Namespace Reference

Functions

AUDACITY_DLL_API wxRect DrawClipAffordance (wxDC &dc, const wxRect &affordanceRect, bool highlight=false, bool selected=false)
 
AUDACITY_DLL_API bool DrawClipTitle (wxDC &dc, const wxRect &titleRect, const wxString &title)
 
AUDACITY_DLL_API bool DrawAudioClipTitle (wxDC &dc, const wxRect &titleRect, const wxString &title, double clipStretchRatio)
 
AUDACITY_DLL_API void DrawClipEdges (wxDC &dc, const wxRect &clipRect, bool selected=false)
 
AUDACITY_DLL_API void DrawClipFolded (wxDC &dc, const wxRect &rect)
 
AUDACITY_DLL_API void DrawSyncLockTiles (TrackPanelDrawingContext &context, const wxRect &rect)
 
AUDACITY_DLL_API void DrawBackgroundWithSelection (TrackPanelDrawingContext &context, const wxRect &rect, const Track *track, const wxBrush &selBrush, const wxBrush &unselBrush, bool useSelection=true)
 
AUDACITY_DLL_API void DrawCursor (TrackPanelDrawingContext &context, const wxRect &rect, const Track *track)
 
AUDACITY_DLL_API void DrawNegativeOffsetTrackArrows (TrackPanelDrawingContext &context, const wxRect &rect)
 
AUDACITY_DLL_API wxString TruncateText (wxDC &dc, const wxString &text, const int maxWidth)
 

Variables

static constexpr int ClipFrameRadius { 6 }
 

Function Documentation

◆ DrawAudioClipTitle()

bool TrackArt::DrawAudioClipTitle ( wxDC &  dc,
const wxRect &  titleRect,
const wxString &  title,
double  clipStretchRatio 
)

Definition at line 333 of file TrackArt.cpp.

336{
337 const auto clipTitle = DoDrawAudioTitle(dc, titleRect, title);
338 if (!clipTitle.has_value())
339 return false;
340 if (!TimeAndPitchInterface::IsPassThroughMode(clipStretchRatio))
341 {
342 const auto fullText = GetPlaybackSpeedFullText(clipStretchRatio);
343 constexpr auto minSpaceBetweenTitleAndSpeed = 12; // pixels
344 const auto remainingWidth = std::max(
345 titleRect.GetWidth() - dc.GetTextExtent(clipTitle->text).GetWidth() -
346 minSpaceBetweenTitleAndSpeed,
347 0);
348 const auto truncatedText =
349 TrackArt::TruncateText(dc, fullText, remainingWidth);
350 if (truncatedText.find('%') != std::string::npos)
351 // Only show if there is room for the % sign, or else it can be hard to
352 // interpret.
353 dc.DrawLabel(
354 TrackArt::TruncateText(dc, fullText, remainingWidth), titleRect,
355 (clipTitle->alignment == HAlign::left ? wxALIGN_RIGHT :
356 wxALIGN_LEFT) |
357 wxALIGN_CENTER_VERTICAL);
358 }
359 return true;
360}
static const auto title
static bool IsPassThroughMode(double stretchRatio)
AUDACITY_DLL_API wxString TruncateText(wxDC &dc, const wxString &text, const int maxWidth)
Definition: TrackArt.cpp:166
constexpr size_t npos(-1)
wxString GetPlaybackSpeedFullText(double clipStretchRatio)
Definition: TrackArt.cpp:253
std::optional< ClipTitle > DoDrawAudioTitle(wxDC &dc, const wxRect &titleRect, const wxString &title)
Definition: TrackArt.cpp:303

References anonymous_namespace{TrackArt.cpp}::DoDrawAudioTitle(), anonymous_namespace{TrackArt.cpp}::GetPlaybackSpeedFullText(), TimeAndPitchInterface::IsPassThroughMode(), Tuple::detail::npos(), title, and TruncateText().

Referenced by WaveTrackAffordanceControls::Draw().

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

◆ DrawBackgroundWithSelection()

void TrackArt::DrawBackgroundWithSelection ( TrackPanelDrawingContext context,
const wxRect &  rect,
const Track track,
const wxBrush &  selBrush,
const wxBrush &  unselBrush,
bool  useSelection = true 
)

Definition at line 704 of file TrackArt.cpp.

708{
709 const auto dc = &context.dc;
710 const auto artist = TrackArtist::Get( context );
711 const auto &selectedRegion = *artist->pSelectedRegion;
712 const auto& zoomInfo = *artist->pZoomInfo;
713
714
715 //MM: Draw background. We should optimize that a bit more.
716 const double sel0 = useSelection ? selectedRegion.t0() : 0.0;
717 const double sel1 = useSelection ? selectedRegion.t1() : 0.0;
718
719 BeatsGridlinePainter gridlinePainter(zoomInfo, *track);
720
721 dc->SetPen(*wxTRANSPARENT_PEN);
722
723 auto drawBgRect = [dc, &gridlinePainter, artist, &rect](
724 const wxBrush& regularBrush,
725 const wxBrush& beatStrongBrush,
726 const wxBrush& beatWeakBrush, const wxRect& subRect)
727 {
728 if (!gridlinePainter.enabled)
729 {
730 // Track not selected; just draw background
731 dc->SetBrush(regularBrush);
732 dc->DrawRectangle(subRect);
733 }
734 else
735 {
736 gridlinePainter.DrawBackground(
737 *dc, subRect, rect, beatStrongBrush, beatWeakBrush);
738 }
739 };
740
742 {
743 // Rectangles before, within, after the selection
744 wxRect before = rect;
745 wxRect within = rect;
746 wxRect after = rect;
747
748 before.width = (int)(zoomInfo.TimeToPosition(sel0) );
749 if (before.GetRight() > rect.GetRight()) {
750 before.width = rect.width;
751 }
752
753 if (before.width > 0) {
754 drawBgRect(unselBrush, artist->beatStrongBrush, artist->beatWeakBrush, before);
755
756 within.x = 1 + before.GetRight();
757 }
758 within.width = rect.x + (int)(zoomInfo.TimeToPosition(sel1) ) - within.x -1;
759
760 if (within.GetRight() > rect.GetRight()) {
761 within.width = 1 + rect.GetRight() - within.x;
762 }
763
764 // Bug 2389 - Selection can disappear
765 // This handles case where no waveform is visible.
766 if (within.width < 1)
767 within.width = 1;
768
769 if (within.width > 0) {
770 if (track->GetSelected()) {
771 drawBgRect(selBrush, artist->beatStrongSelBrush, artist->beatWeakSelBrush, within);
772 }
773 else {
774 // Per condition above, track must be sync-lock selected
775 drawBgRect(
776 unselBrush, artist->beatStrongBrush, artist->beatWeakBrush, within);
777 DrawSyncLockTiles( context, within );
778 }
779
780 after.x = 1 + within.GetRight();
781 }
782 else {
783 // `within` not drawn; start where it would have gone
784 after.x = within.x;
785 }
786
787 after.width = 1 + rect.GetRight() - after.x;
788 if (after.width > 0)
789 drawBgRect(
790 unselBrush, artist->beatStrongBrush, artist->beatWeakBrush, after);
791 }
792 else
793 {
794 drawBgRect(
795 unselBrush, artist->beatStrongBrush, artist->beatWeakBrush, rect);
796 }
797
798 if (gridlinePainter.enabled)
799 gridlinePainter.DrawSeparators(*dc, rect, artist->beatSepearatorPen, artist->barSepearatorPen);
800}
bool within(A a, B b, DIST d)
Definition: TrackPanel.cpp:168
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
bool GetSelected() const
Selectedness is always the same for all channels of a group.
Definition: Track.cpp:70
AUDACITY_DLL_API void DrawSyncLockTiles(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArt.cpp:418

References TrackPanelDrawingContext::dc, DrawSyncLockTiles(), TrackArtist::Get(), Track::GetSelected(), SyncLock::IsSelectedOrSyncLockSelected(), ZoomInfo::TimeToPosition(), and within().

Referenced by SpectrumView::DoDraw(), WaveformView::DoDraw(), LabelTrackView::Draw(), NoteTrackAffordanceControls::Draw(), NoteTrackView::Draw(), and WaveTrackAffordanceControls::Draw().

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

◆ DrawClipAffordance()

wxRect TrackArt::DrawClipAffordance ( wxDC &  dc,
const wxRect &  affordanceRect,
bool  highlight = false,
bool  selected = false 
)

Definition at line 201 of file TrackArt.cpp.

202{
203 //To make sure that roundings do not overlap each other
204 auto clipFrameRadius = std::min(ClipFrameRadius, rect.width / 2);
205
206 wxRect clipRect;
207 bool hasClipRect = dc.GetClippingBox(clipRect);
208 //Fix #1689: visual glitches appear on attempt to draw a rectangle
209 //larger than 0x7FFFFFF pixels wide (value was discovered
210 //by manual testing, and maybe depends on OS being used), but
211 //it's very unlikely that such huge rectangle will be ever fully visible
212 //on the screen, so we can safely reduce its size to be slightly larger than
213 //clipping rectangle, and avoid that problem
214 auto drawingRect = rect;
215 if (hasClipRect)
216 {
217 //to make sure that rounding happends outside the clipping rectangle
218 drawingRect.SetLeft(std::max(rect.GetLeft(), clipRect.GetLeft() - clipFrameRadius - 1));
219 drawingRect.SetRight(std::min(rect.GetRight(), clipRect.GetRight() + clipFrameRadius + 1));
220 }
221
222 if (selected)
223 {
224 wxRect strokeRect{
225 drawingRect.x - ClipSelectionStrokeSize,
226 drawingRect.y,
227 drawingRect.width + ClipSelectionStrokeSize * 2,
228 drawingRect.height + clipFrameRadius };
229 dc.SetBrush(*wxTRANSPARENT_BRUSH);
230 AColor::UseThemeColour(&dc, clrClipAffordanceStroke, clrClipAffordanceStroke);
231 dc.DrawRoundedRectangle(strokeRect, clipFrameRadius);
232 }
233
234 AColor::UseThemeColour(&dc, highlight ? clrClipAffordanceActiveBrush : clrClipAffordanceInactiveBrush, clrClipAffordanceOutlinePen);
235 dc.DrawRoundedRectangle(
236 wxRect(
237 drawingRect.x,
238 drawingRect.y + ClipSelectionStrokeSize,
239 drawingRect.width,
240 drawingRect.height + clipFrameRadius
241 ), clipFrameRadius
242 );
243
244 auto titleRect = hasClipRect ?
245 //avoid drawing text outside the clipping rectangle if possible
246 GetAffordanceTitleRect(rect.Intersect(clipRect)) :
248
249 return titleRect;
250}
int min(int a, int b)
static constexpr int ClipSelectionStrokeSize
Definition: TrackArt.cpp:38
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:372
static constexpr int ClipFrameRadius
Definition: TrackArt.h:22
wxRect GetAffordanceTitleRect(const wxRect &rect)
Definition: TrackArt.cpp:45

References ClipFrameRadius, ClipSelectionStrokeSize, anonymous_namespace{TrackArt.cpp}::GetAffordanceTitleRect(), min(), and AColor::UseThemeColour().

Referenced by NoteTrackAffordanceControls::Draw(), and WaveTrackAffordanceControls::Draw().

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

◆ DrawClipEdges()

void TrackArt::DrawClipEdges ( wxDC &  dc,
const wxRect &  clipRect,
bool  selected = false 
)

Definition at line 362 of file TrackArt.cpp.

363{
364 dc.SetBrush(*wxTRANSPARENT_BRUSH);
365 {
366 AColor::UseThemeColour(&dc, -1, clrClipAffordanceOutlinePen);
367 AColor::Line(dc,
368 clipRect.GetLeft(), clipRect.GetTop(),
369 clipRect.GetLeft(), clipRect.GetBottom());
370 AColor::Line(dc,
371 clipRect.GetRight(), clipRect.GetTop(),
372 clipRect.GetRight(), clipRect.GetBottom());
373 }
374 if(selected)
375 {
376 if constexpr (ClipSelectionStrokeSize == 1)
377 {
378 AColor::UseThemeColour(&dc, -1, clrClipAffordanceStroke);
379 AColor::Line(dc,
380 clipRect.GetLeft() - ClipSelectionStrokeSize, clipRect.GetTop(),
381 clipRect.GetLeft() - ClipSelectionStrokeSize, clipRect.GetBottom());
382 AColor::Line(dc,
383 clipRect.GetRight() + ClipSelectionStrokeSize, clipRect.GetTop(),
384 clipRect.GetRight() + ClipSelectionStrokeSize, clipRect.GetBottom());
385 }
386 else if constexpr (ClipSelectionStrokeSize > 1)
387 {
388 AColor::UseThemeColour(&dc, clrClipAffordanceStroke, clrClipAffordanceStroke);
389 dc.DrawRectangle(wxRect(
390 clipRect.GetLeft() - ClipSelectionStrokeSize, clipRect.GetTop(),
391 ClipSelectionStrokeSize, clipRect.GetHeight()));
392 dc.DrawRectangle(wxRect(
393 clipRect.GetRight() + 1, clipRect.GetTop(),
394 ClipSelectionStrokeSize, clipRect.GetHeight()));
395 }
396 }
397}
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187

References ClipSelectionStrokeSize, AColor::Line(), and AColor::UseThemeColour().

Referenced by anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum(), anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), and anonymous_namespace{NoteTrackView.cpp}::DrawNoteTrack().

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

◆ DrawClipFolded()

void TrackArt::DrawClipFolded ( wxDC &  dc,
const wxRect &  rect 
)

Definition at line 399 of file TrackArt.cpp.

400{
401 AColor::UseThemeColour(&dc, clrClipAffordanceOutlinePen);
402 dc.DrawRectangle(rect);
403}

References AColor::UseThemeColour().

Referenced by WaveTrackAffordanceControls::Draw(), anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum(), and anonymous_namespace{WaveformView.cpp}::DrawClipWaveform().

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

◆ DrawClipTitle()

bool TrackArt::DrawClipTitle ( wxDC &  dc,
const wxRect &  titleRect,
const wxString &  title 
)

Definition at line 327 of file TrackArt.cpp.

329{
330 return DoDrawAudioTitle(dc, titleRect, title).has_value();
331}

References anonymous_namespace{TrackArt.cpp}::DoDrawAudioTitle(), and title.

Referenced by NoteTrackAffordanceControls::Draw().

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

◆ DrawCursor()

void TrackArt::DrawCursor ( TrackPanelDrawingContext context,
const wxRect &  rect,
const Track track 
)

Definition at line 802 of file TrackArt.cpp.

804{
805 const auto dc = &context.dc;
806 const auto artist = TrackArtist::Get(context);
807 const auto& selectedRegion = *artist->pSelectedRegion;
808
809 if (selectedRegion.isPoint())
810 {
811 const auto& zoomInfo = *artist->pZoomInfo;
812 auto x = static_cast<int>(zoomInfo.TimeToPosition(selectedRegion.t0(), rect.x));
813 if (x >= rect.GetLeft() && x <= rect.GetRight())
814 {
816 AColor::Line(*dc, x, rect.GetTop(), x, rect.GetBottom());
817 }
818 }
819}
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:463

References AColor::CursorColor(), TrackPanelDrawingContext::dc, TrackArtist::Get(), AColor::Line(), and ZoomInfo::TimeToPosition().

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

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

◆ DrawNegativeOffsetTrackArrows()

void TrackArt::DrawNegativeOffsetTrackArrows ( TrackPanelDrawingContext context,
const wxRect &  rect 
)

Definition at line 136 of file TrackArt.cpp.

138{
139 auto &dc = context.dc;
140
141 // Draws two black arrows on the left side of the track to
142 // indicate the user that the track has been time-shifted
143 // to the left beyond t=0.0.
144
145 dc.SetPen(*wxBLACK_PEN);
146 AColor::Line(dc,
147 rect.x + 2, rect.y + 6,
148 rect.x + 8, rect.y + 6);
149 AColor::Line(dc,
150 rect.x + 2, rect.y + 6,
151 rect.x + 6, rect.y + 2);
152 AColor::Line(dc,
153 rect.x + 2, rect.y + 6,
154 rect.x + 6, rect.y + 10);
155 AColor::Line(dc,
156 rect.x + 2, rect.y + rect.height - 8,
157 rect.x + 8, rect.y + rect.height - 8);
158 AColor::Line(dc,
159 rect.x + 2, rect.y + rect.height - 8,
160 rect.x + 6, rect.y + rect.height - 4);
161 AColor::Line(dc,
162 rect.x + 2, rect.y + rect.height - 8,
163 rect.x + 6, rect.y + rect.height - 12);
164}

References TrackPanelDrawingContext::dc, and AColor::Line().

Referenced by anonymous_namespace{WaveformView.cpp}::DrawClipWaveform(), and anonymous_namespace{NoteTrackView.cpp}::DrawNoteTrack().

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

◆ DrawSyncLockTiles()

void TrackArt::DrawSyncLockTiles ( TrackPanelDrawingContext context,
const wxRect &  rect 
)

Definition at line 418 of file TrackArt.cpp.

420{
421 const auto dc = &context.dc;
422
423 wxBitmap syncLockBitmap(theTheme.Image(bmpSyncLockSelTile));
424
425 // Grid spacing is a bit smaller than actual image size
426 int gridW = syncLockBitmap.GetWidth() - 6;
427 int gridH = syncLockBitmap.GetHeight() - 8;
428
429 // Horizontal position within the grid, modulo its period
430 int blockX = (rect.x / gridW) % 5;
431
432 // Amount to offset drawing of first column
433 int xOffset = rect.x % gridW;
434 if (xOffset < 0) xOffset += gridW;
435
436 // Check if we're missing an extra column to the left (this can happen
437 // because the tiles are bigger than the grid spacing)
438 bool extraCol = false;
439 if (syncLockBitmap.GetWidth() - gridW > xOffset) {
440 extraCol = true;
441 xOffset += gridW;
442 blockX = (blockX - 1) % 5;
443 }
444 // Make sure blockX is non-negative
445 if (blockX < 0) blockX += 5;
446
447 int xx = 0;
448 while (xx < rect.width) {
449 int width = syncLockBitmap.GetWidth() - xOffset;
450 if (xx + width > rect.width)
451 width = rect.width - xx;
452
453 //
454 // Draw each row in this column
455 //
456
457 // Vertical position in the grid, modulo its period
458 int blockY = (rect.y / gridH) % 5;
459
460 // Amount to offset drawing of first row
461 int yOffset = rect.y % gridH;
462 if (yOffset < 0) yOffset += gridH;
463
464 // Check if we're missing an extra row on top (this can happen because
465 // the tiles are bigger than the grid spacing)
466 bool extraRow = false;
467 if (syncLockBitmap.GetHeight() - gridH > yOffset) {
468 extraRow = true;
469 yOffset += gridH;
470 blockY = (blockY - 1) % 5;
471 }
472 // Make sure blockY is non-negative
473 if (blockY < 0) blockY += 5;
474
475 int yy = 0;
476 while (yy < rect.height)
477 {
478 int height = syncLockBitmap.GetHeight() - yOffset;
479 if (yy + height > rect.height)
480 height = rect.height - yy;
481
482 // AWD: draw blocks according to our pattern
483 if ((blockX == 0 && blockY == 0) || (blockX == 2 && blockY == 1) ||
484 (blockX == 4 && blockY == 2) || (blockX == 1 && blockY == 3) ||
485 (blockX == 3 && blockY == 4))
486 {
487
488 // Do we need to get a sub-bitmap?
489 if (width != syncLockBitmap.GetWidth() || height != syncLockBitmap.GetHeight()) {
490 wxBitmap subSyncLockBitmap =
491 syncLockBitmap.GetSubBitmap(wxRect(xOffset, yOffset, width, height));
492 dc->DrawBitmap(subSyncLockBitmap, rect.x + xx, rect.y + yy, true);
493 }
494 else {
495 dc->DrawBitmap(syncLockBitmap, rect.x + xx, rect.y + yy, true);
496 }
497 }
498
499 // Updates for next row
500 if (extraRow) {
501 // Second offset row, still at y = 0; no more extra rows
502 yOffset -= gridH;
503 extraRow = false;
504 }
505 else {
506 // Move on in y, no more offset rows
507 yy += gridH - yOffset;
508 yOffset = 0;
509 }
510 blockY = (blockY + 1) % 5;
511 }
512
513 // Updates for next column
514 if (extraCol) {
515 // Second offset column, still at x = 0; no more extra columns
516 xOffset -= gridW;
517 extraCol = false;
518 }
519 else {
520 // Move on in x, no more offset rows
521 xx += gridW - xOffset;
522 xOffset = 0;
523 }
524 blockX = (blockX + 1) % 5;
525 }
526}
THEME_API Theme theTheme
Definition: Theme.cpp:82
wxImage & Image(int iIndex)

References TrackPanelDrawingContext::dc, ThemeBase::Image(), and theTheme.

Referenced by DrawBackgroundWithSelection(), and anonymous_namespace{WaveformView.cpp}::DrawWaveformBackground().

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

◆ TruncateText()

wxString TrackArt::TruncateText ( wxDC &  dc,
const wxString &  text,
const int  maxWidth 
)

Definition at line 166 of file TrackArt.cpp.

167{
168 static const wxString ellipsis = "\u2026";
169
170 if (dc.GetTextExtent(text).GetWidth() <= maxWidth)
171 return text;
172
173 auto left = 0;
174 //no need to check text + '...'
175 auto right = static_cast<int>(text.Length() - 2);
176
177 while (left <= right)
178 {
179 auto middle = (left + right) / 2;
180 auto str = text.SubString(0, middle).Trim() + ellipsis;
181 auto strWidth = dc.GetTextExtent(str).GetWidth();
182 if (strWidth < maxWidth)
183 //if left == right (== middle), then exit loop
184 //with right equals to the last known index for which
185 //strWidth < maxWidth
186 left = middle + 1;
187 else if (strWidth > maxWidth)
188 //if right == left (== middle), then exit loop with
189 //right equals to (left - 1), which is the last known
190 //index for which (strWidth < maxWidth) or -1
191 right = middle - 1;
192 else
193 return str;
194 }
195 if (right >= 0)
196 return text.SubString(0, right).Trim() + ellipsis;
197
198 return wxEmptyString;
199}
#define str(a)

References str.

Referenced by anonymous_namespace{TrackArt.cpp}::DoDrawAudioTitle(), DrawAudioClipTitle(), and AButton::OnPaint().

Here is the caller graph for this function:

Variable Documentation

◆ ClipFrameRadius

constexpr int TrackArt::ClipFrameRadius { 6 }
staticconstexpr