Audacity  3.0.3
Functions | Variables
TrackArt Namespace Reference

Functions

AUDACITY_DLL_API void DrawClipAffordance (wxDC &dc, const wxRect &affordanceRect, const wxString &title, bool highlight=false, bool selected=false)
 
AUDACITY_DLL_API wxRect GetAffordanceTitleRect (const wxRect &affordanceRect)
 
AUDACITY_DLL_API void DrawClipEdges (wxDC &dc, const wxRect &clipRect, bool selected=false)
 
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

◆ DrawBackgroundWithSelection()

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

Definition at line 502 of file TrackArtist.cpp.

506 {
507  const auto dc = &context.dc;
508  const auto artist = TrackArtist::Get( context );
509  const auto &selectedRegion = *artist->pSelectedRegion;
510  const auto &zoomInfo = *artist->pZoomInfo;
511 
512  //MM: Draw background. We should optimize that a bit more.
513  const double sel0 = useSelection ? selectedRegion.t0() : 0.0;
514  const double sel1 = useSelection ? selectedRegion.t1() : 0.0;
515 
516  dc->SetPen(*wxTRANSPARENT_PEN);
517  if (track->GetSelected() || track->IsSyncLockSelected())
518  {
519  // Rectangles before, within, after the selection
520  wxRect before = rect;
521  wxRect within = rect;
522  wxRect after = rect;
523 
524  before.width = (int)(zoomInfo.TimeToPosition(sel0) );
525  if (before.GetRight() > rect.GetRight()) {
526  before.width = rect.width;
527  }
528 
529  if (before.width > 0) {
530  dc->SetBrush(unselBrush);
531  dc->DrawRectangle(before);
532 
533  within.x = 1 + before.GetRight();
534  }
535  within.width = rect.x + (int)(zoomInfo.TimeToPosition(sel1) ) - within.x -1;
536 
537  if (within.GetRight() > rect.GetRight()) {
538  within.width = 1 + rect.GetRight() - within.x;
539  }
540 
541  // Bug 2389 - Selection can disappear
542  // This handles case where no waveform is visible.
543  if (within.width < 1)
544  {
545  within.width = 1;
546  }
547 
548  if (within.width > 0) {
549  if (track->GetSelected()) {
550  dc->SetBrush(selBrush);
551  dc->DrawRectangle(within);
552  }
553  else {
554  // Per condition above, track must be sync-lock selected
555  dc->SetBrush(unselBrush);
556  dc->DrawRectangle(within);
557  DrawSyncLockTiles( context, within );
558  }
559 
560  after.x = 1 + within.GetRight();
561  }
562  else {
563  // `within` not drawn; start where it would have gone
564  after.x = within.x;
565  }
566 
567  after.width = 1 + rect.GetRight() - after.x;
568  if (after.width > 0) {
569  dc->SetBrush(unselBrush);
570  dc->DrawRectangle(after);
571  }
572  }
573  else
574  {
575  // Track not selected; just draw background
576  dc->SetBrush(unselBrush);
577  dc->DrawRectangle(rect);
578  }
579 }

References TrackPanelDrawingContext::dc, DrawSyncLockTiles(), TrackArtist::Get(), Track::GetSelected(), Track::IsSyncLockSelected(), 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()

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

Definition at line 302 of file TrackArtist.cpp.

303 {
304  if (selected)
305  {
306  wxRect strokeRect{
307  rect.x - ClipSelectionStrokeSize,
308  rect.y,
309  rect.width + ClipSelectionStrokeSize * 2,
310  rect.height + ClipFrameRadius };
311  dc.SetBrush(*wxTRANSPARENT_BRUSH);
312  AColor::UseThemeColour(&dc, clrClipAffordanceStroke, clrClipAffordanceStroke);
313  dc.DrawRoundedRectangle(strokeRect, ClipFrameRadius);
314  }
315 
316  AColor::UseThemeColour(&dc, highlight ? clrClipAffordanceActiveBrush : clrClipAffordanceInactiveBrush, clrClipAffordanceOutlinePen);
317  dc.DrawRoundedRectangle(wxRect(rect.x, rect.y + ClipSelectionStrokeSize, rect.width, rect.height + ClipFrameRadius), ClipFrameRadius);
318 
319  if (!title.empty())
320  {
321  auto titleRect = TrackArt::GetAffordanceTitleRect(rect);
322 
323  auto truncatedTitle = TrackArt::TruncateText(dc, title, titleRect.GetWidth());
324  if (!truncatedTitle.empty())
325  {
326  auto hAlign = wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ? wxALIGN_RIGHT : wxALIGN_LEFT;
327  dc.DrawLabel(truncatedTitle, titleRect, hAlign | wxALIGN_CENTER_VERTICAL);
328  }
329  }
330 }

References ClipFrameRadius, ClipSelectionStrokeSize, GetAffordanceTitleRect(), title, TruncateText(), 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 342 of file TrackArtist.cpp.

343 {
344  dc.SetBrush(*wxTRANSPARENT_BRUSH);
345  {
346  AColor::UseThemeColour(&dc, -1, clrClipAffordanceOutlinePen);
347  AColor::Line(dc,
348  clipRect.GetLeft(), clipRect.GetTop(),
349  clipRect.GetLeft(), clipRect.GetBottom());
350  AColor::Line(dc,
351  clipRect.GetRight(), clipRect.GetTop(),
352  clipRect.GetRight(), clipRect.GetBottom());
353  }
354  if(selected)
355  {
356  if constexpr (ClipSelectionStrokeSize == 1)
357  {
358  AColor::UseThemeColour(&dc, -1, clrClipAffordanceStroke);
359  AColor::Line(dc,
360  clipRect.GetLeft() - ClipSelectionStrokeSize, clipRect.GetTop(),
361  clipRect.GetLeft() - ClipSelectionStrokeSize, clipRect.GetBottom());
362  AColor::Line(dc,
363  clipRect.GetRight() + ClipSelectionStrokeSize, clipRect.GetTop(),
364  clipRect.GetRight() + ClipSelectionStrokeSize, clipRect.GetBottom());
365  }
366  else if constexpr (ClipSelectionStrokeSize > 1)
367  {
368  AColor::UseThemeColour(&dc, clrClipAffordanceStroke, clrClipAffordanceStroke);
369  dc.DrawRectangle(wxRect(
370  clipRect.GetLeft() - ClipSelectionStrokeSize, clipRect.GetTop(),
371  ClipSelectionStrokeSize, clipRect.GetHeight()));
372  dc.DrawRectangle(wxRect(
373  clipRect.GetRight() + 1, clipRect.GetTop(),
374  ClipSelectionStrokeSize, clipRect.GetHeight()));
375  }
376  }
377 }

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:

◆ DrawCursor()

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

Definition at line 581 of file TrackArtist.cpp.

583 {
584  const auto dc = &context.dc;
585  const auto artist = TrackArtist::Get(context);
586  const auto& selectedRegion = *artist->pSelectedRegion;
587 
588  if (selectedRegion.isPoint())
589  {
590  const auto& zoomInfo = *artist->pZoomInfo;
591  auto x = static_cast<int>(zoomInfo.TimeToPosition(selectedRegion.t0(), rect.x));
592  if (x >= rect.GetLeft() && x <= rect.GetRight())
593  {
595  AColor::Line(*dc, x, rect.GetTop(), x, rect.GetBottom());
596  }
597  }
598 }

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

Referenced by anonymous_namespace{TrackPanel.cpp}::ChannelGroup::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 213 of file TrackArtist.cpp.

215 {
216  auto &dc = context.dc;
217 
218  // Draws two black arrows on the left side of the track to
219  // indicate the user that the track has been time-shifted
220  // to the left beyond t=0.0.
221 
222  dc.SetPen(*wxBLACK_PEN);
223  AColor::Line(dc,
224  rect.x + 2, rect.y + 6,
225  rect.x + 8, rect.y + 6);
226  AColor::Line(dc,
227  rect.x + 2, rect.y + 6,
228  rect.x + 6, rect.y + 2);
229  AColor::Line(dc,
230  rect.x + 2, rect.y + 6,
231  rect.x + 6, rect.y + 10);
232  AColor::Line(dc,
233  rect.x + 2, rect.y + rect.height - 8,
234  rect.x + 8, rect.y + rect.height - 8);
235  AColor::Line(dc,
236  rect.x + 2, rect.y + rect.height - 8,
237  rect.x + 6, rect.y + rect.height - 4);
238  AColor::Line(dc,
239  rect.x + 2, rect.y + rect.height - 8,
240  rect.x + 6, rect.y + rect.height - 12);
241 }

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 392 of file TrackArtist.cpp.

394 {
395  const auto dc = &context.dc;
396 
397  wxBitmap syncLockBitmap(theTheme.Image(bmpSyncLockSelTile));
398 
399  // Grid spacing is a bit smaller than actual image size
400  int gridW = syncLockBitmap.GetWidth() - 6;
401  int gridH = syncLockBitmap.GetHeight() - 8;
402 
403  // Horizontal position within the grid, modulo its period
404  int blockX = (rect.x / gridW) % 5;
405 
406  // Amount to offset drawing of first column
407  int xOffset = rect.x % gridW;
408  if (xOffset < 0) xOffset += gridW;
409 
410  // Check if we're missing an extra column to the left (this can happen
411  // because the tiles are bigger than the grid spacing)
412  bool extraCol = false;
413  if (syncLockBitmap.GetWidth() - gridW > xOffset) {
414  extraCol = true;
415  xOffset += gridW;
416  blockX = (blockX - 1) % 5;
417  }
418  // Make sure blockX is non-negative
419  if (blockX < 0) blockX += 5;
420 
421  int xx = 0;
422  while (xx < rect.width) {
423  int width = syncLockBitmap.GetWidth() - xOffset;
424  if (xx + width > rect.width)
425  width = rect.width - xx;
426 
427  //
428  // Draw each row in this column
429  //
430 
431  // Vertical position in the grid, modulo its period
432  int blockY = (rect.y / gridH) % 5;
433 
434  // Amount to offset drawing of first row
435  int yOffset = rect.y % gridH;
436  if (yOffset < 0) yOffset += gridH;
437 
438  // Check if we're missing an extra row on top (this can happen because
439  // the tiles are bigger than the grid spacing)
440  bool extraRow = false;
441  if (syncLockBitmap.GetHeight() - gridH > yOffset) {
442  extraRow = true;
443  yOffset += gridH;
444  blockY = (blockY - 1) % 5;
445  }
446  // Make sure blockY is non-negative
447  if (blockY < 0) blockY += 5;
448 
449  int yy = 0;
450  while (yy < rect.height)
451  {
452  int height = syncLockBitmap.GetHeight() - yOffset;
453  if (yy + height > rect.height)
454  height = rect.height - yy;
455 
456  // AWD: draw blocks according to our pattern
457  if ((blockX == 0 && blockY == 0) || (blockX == 2 && blockY == 1) ||
458  (blockX == 4 && blockY == 2) || (blockX == 1 && blockY == 3) ||
459  (blockX == 3 && blockY == 4))
460  {
461 
462  // Do we need to get a sub-bitmap?
463  if (width != syncLockBitmap.GetWidth() || height != syncLockBitmap.GetHeight()) {
464  wxBitmap subSyncLockBitmap =
465  syncLockBitmap.GetSubBitmap(wxRect(xOffset, yOffset, width, height));
466  dc->DrawBitmap(subSyncLockBitmap, rect.x + xx, rect.y + yy, true);
467  }
468  else {
469  dc->DrawBitmap(syncLockBitmap, rect.x + xx, rect.y + yy, true);
470  }
471  }
472 
473  // Updates for next row
474  if (extraRow) {
475  // Second offset row, still at y = 0; no more extra rows
476  yOffset -= gridH;
477  extraRow = false;
478  }
479  else {
480  // Move on in y, no more offset rows
481  yy += gridH - yOffset;
482  yOffset = 0;
483  }
484  blockY = (blockY + 1) % 5;
485  }
486 
487  // Updates for next column
488  if (extraCol) {
489  // Second offset column, still at x = 0; no more extra columns
490  xOffset -= gridW;
491  extraCol = false;
492  }
493  else {
494  // Move on in x, no more offset rows
495  xx += gridW - xOffset;
496  xOffset = 0;
497  }
498  blockX = (blockX + 1) % 5;
499  }
500 }

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:

◆ GetAffordanceTitleRect()

AUDACITY_DLL_API wxRect TrackArt::GetAffordanceTitleRect ( const wxRect &  affordanceRect)

Definition at line 332 of file TrackArtist.cpp.

333 {
334  constexpr int FrameThickness{ 1 };
335  return wxRect(
336  rect.GetLeft() + ClipFrameRadius,
337  rect.GetTop() + ClipSelectionStrokeSize + FrameThickness,
338  rect.GetWidth() - ClipFrameRadius * 2,
339  rect.GetHeight() - ClipSelectionStrokeSize - FrameThickness);
340 }

References ClipFrameRadius, and ClipSelectionStrokeSize.

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

Here is the caller graph for this function:

◆ TruncateText()

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

Definition at line 243 of file TrackArtist.cpp.

244 {
245  static const wxString ellipsis = "\u2026";
246 
247  if (dc.GetTextExtent(text).GetWidth() <= maxWidth)
248  return text;
249 
250  auto left = 0;
251  //no need to check text + '...'
252  auto right = static_cast<int>(text.Length() - 2);
253 
254  while (left <= right)
255  {
256  auto middle = (left + right) / 2;
257  auto str = text.SubString(0, middle).Trim() + ellipsis;
258  auto strWidth = dc.GetTextExtent(str).GetWidth();
259  if (strWidth < maxWidth)
260  //if left == right (== middle), then exit loop
261  //with right equals to the last knwon index for which
262  //strWidth < maxWidth
263  left = middle + 1;
264  else if (strWidth > maxWidth)
265  //if right == left (== middle), then exit loop with
266  //right equals to (left - 1), which is the last known
267  //index for which (strWidth < maxWidth) or -1
268  right = middle - 1;
269  else
270  return str;
271  }
272  if (right >= 0)
273  return text.SubString(0, right).Trim() + ellipsis;
274 
275  return wxEmptyString;
276 }

Referenced by DrawClipAffordance().

Here is the caller graph for this function:

Variable Documentation

◆ ClipFrameRadius

constexpr int TrackArt::ClipFrameRadius { 6 }
staticconstexpr

Definition at line 41 of file TrackArtist.h.

Referenced by DrawClipAffordance(), and GetAffordanceTitleRect().

AColor::UseThemeColour
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:283
AColor::CursorColor
static void CursorColor(wxDC *dc)
Definition: AColor.cpp:374
TrackArt::ClipFrameRadius
static constexpr int ClipFrameRadius
Definition: TrackArtist.h:41
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:112
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
Track::IsSyncLockSelected
bool IsSyncLockSelected() const
Definition: Track.cpp:254
TrackArt::GetAffordanceTitleRect
AUDACITY_DLL_API wxRect GetAffordanceTitleRect(const wxRect &affordanceRect)
Definition: TrackArtist.cpp:332
TrackArt::DrawSyncLockTiles
AUDACITY_DLL_API void DrawSyncLockTiles(TrackPanelDrawingContext &context, const wxRect &rect)
Definition: TrackArtist.cpp:392
TrackArtist::Get
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:79
ClipSelectionStrokeSize
static constexpr int ClipSelectionStrokeSize
Definition: TrackArtist.cpp:61
ThemeBase::Image
wxImage & Image(int iIndex)
Definition: Theme.cpp:1223
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
Track::GetSelected
bool GetSelected() const
Definition: Track.h:431
TrackArt::TruncateText
AUDACITY_DLL_API wxString TruncateText(wxDC &dc, const wxString &text, const int maxWidth)
Definition: TrackArtist.cpp:243
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
within
bool within(A a, B b, DIST d)
Definition: TrackPanel.cpp:163