Audacity  3.0.3
Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Ruler Class Reference

Used to display a Ruler. More...

#include <Ruler.h>

Collaboration diagram for Ruler:
[legend]

Classes

struct  Cache
 
struct  Fonts
 
class  Label
 An array of these created by the Ruler is used to determine what and where text annotations to the numbers on the Ruler get drawn. More...
 
struct  TickSizes
 
struct  Updater
 

Public Types

enum  RulerFormat {
  IntFormat, RealFormat, RealLogFormat, TimeFormat,
  LinearDBFormat
}
 

Public Member Functions

 Ruler ()
 
 ~Ruler ()
 
void SetBounds (int left, int top, int right, int bottom)
 
void SetOrientation (int orient)
 
void SetRange (double min, double max)
 
void SetRange (double min, double max, double hiddenMin, double hiddenMax)
 
void SetTwoTone (bool twoTone)
 
void SetFormat (RulerFormat format)
 
void SetUnits (const TranslatableString &units)
 
void SetDbMirrorValue (const double d)
 
void SetLog (bool log)
 
void SetSpacing (int spacing)
 
void SetLabelEdges (bool labelEdges)
 
void SetFlip (bool flip)
 
void SetMinor (bool value)
 
void SetFonts (const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont)
 
Fonts GetFonts () const
 
void SetNumberScale (const NumberScale &scale)
 
void OfflimitsPixels (int start, int end)
 
void GetMaxSize (wxCoord *width, wxCoord *height)
 
void SetCustomMode (bool value)
 
void SetCustomMajorLabels (const TranslatableStrings &labels, int start, int step)
 
void SetCustomMinorLabels (const TranslatableStrings &labels, int start, int step)
 
void SetUseZoomInfo (int leftOffset, const ZoomInfo *zoomInfo)
 
void Draw (wxDC &dc) const
 
void Draw (wxDC &dc, const Envelope *envelope) const
 
void DrawGrid (wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
 
void SetTickColour (const wxColour &colour)
 
void Invalidate ()
 

Public Attributes

bool mbTicksOnly
 
bool mbTicksAtExtremes
 

Private Types

using Labels = std::vector< Label >
 
using Bits = std::vector< bool >
 

Private Member Functions

void ChooseFonts (wxDC &dc) const
 
void UpdateCache (wxDC &dc, const Envelope *envelope) const
 
int FindZero (const Labels &labels) const
 
int GetZeroPosition () const
 

Static Private Member Functions

static std::pair< wxRect, LabelMakeTick (Label lab, wxDC &dc, wxFont font, std::vector< bool > &bits, int left, int top, int spacing, int lead, bool flip, int orientation)
 

Private Attributes

wxColour mTickColour
 
wxPen mPen
 
int mLeft
 
int mTop
 
int mRight
 
int mBottom
 
int mLength
 
std::unique_ptr< FontsmpUserFonts
 
std::unique_ptr< FontsmpFonts
 
double mMin
 
double mMax
 
double mHiddenMin
 
double mHiddenMax
 
Bits mUserBits
 
std::unique_ptr< CachempCache
 
int mOrientation
 
int mSpacing
 
double mDbMirrorValue
 
bool mHasSetSpacing
 
bool mLabelEdges
 
RulerFormat mFormat
 
bool mLog
 
bool mFlip
 
bool mCustom
 
bool mbMinor
 
TranslatableString mUnits
 
bool mTwoTone
 
const ZoomInfomUseZoomInfo
 
int mLeftOffset
 
NumberScale mNumberScale
 

Detailed Description

Used to display a Ruler.

This is a generic class which can be used to display just about any kind of ruler.

At a minimum, the user must specify the dimensions of the ruler, its orientation (horizontal or vertical), and the values displayed at the two ends of the ruler (min and max). By default, this class will display tick marks at reasonable round numbers and fractions, for example, 100, 50, 10, 5, 1, 0.5, 0.1, etc.

The class is designed to display a small handful of labeled Major ticks, and a few Minor ticks between each of these. Minor ticks are labeled if there is enough space. Labels will never run into each other.

In addition to Real numbers, the Ruler currently supports two other formats for its display:

Integer - never shows tick marks for fractions of an integer

Time - Assumes values represent seconds, and labels the tick marks in "HH:MM:SS" format, e.g. 4000 seconds becomes "1:06:40", for example. Will display fractions of a second, and tick marks are all reasonable round numbers for time (i.e. 15 seconds, 30 seconds, etc.)

Definition at line 26 of file Ruler.h.

Member Typedef Documentation

◆ Bits

using Ruler::Bits = std::vector< bool >
private

Definition at line 168 of file Ruler.h.

◆ Labels

using Ruler::Labels = std::vector<Label>
private

Definition at line 166 of file Ruler.h.

Member Enumeration Documentation

◆ RulerFormat

Enumerator
IntFormat 
RealFormat 
RealLogFormat 
TimeFormat 
LinearDBFormat 

Definition at line 29 of file Ruler.h.

29  {
30  IntFormat,
31  RealFormat,
33  TimeFormat,
35  };

Constructor & Destructor Documentation

◆ Ruler()

Ruler::Ruler ( )

Definition at line 79 of file Ruler.cpp.

80 {
81  mMin = mHiddenMin = 0.0;
82  mMax = mHiddenMax = 100.0;
83  mOrientation = wxHORIZONTAL;
84  mSpacing = 6;
85  mHasSetSpacing = false;
87  mFlip = false;
88  mLog = false;
89  mLabelEdges = false;
90 
91  mLeft = -1;
92  mTop = -1;
93  mRight = -1;
94  mBottom = -1;
95  mbTicksOnly = true;
96  mbTicksAtExtremes = false;
97  mTickColour = wxColour( theTheme.Colour( clrTrackPanelText ));
98  mPen.SetColour(mTickColour);
99  mDbMirrorValue = 0.0;
100 
101  // Note: the font size is now adjusted automatically whenever
102  // Invalidate is called on a horizontal Ruler, unless the user
103  // calls SetFonts manually. So the defaults here are not used
104  // often.
105 
106  int fontSize = 10;
107 #ifdef __WXMSW__
108  fontSize = 8;
109 #endif
110 
111  mLength = 0;
112 
113  mCustom = false;
114  mbMinor = true;
115 
116  mTwoTone = false;
117 
118  mUseZoomInfo = NULL;
119 }

References ThemeBase::Colour(), mbMinor, mBottom, mbTicksAtExtremes, mbTicksOnly, mCustom, mDbMirrorValue, mFlip, mFormat, mHasSetSpacing, mHiddenMax, mHiddenMin, mLabelEdges, mLeft, mLength, mLog, mMax, mMin, mOrientation, mPen, mRight, mSpacing, mTickColour, mTop, mTwoTone, mUseZoomInfo, RealFormat, and theTheme.

Here is the call graph for this function:

◆ ~Ruler()

Ruler::~Ruler ( )

Definition at line 121 of file Ruler.cpp.

122 {
123  Invalidate(); // frees up our arrays
124 }

References Invalidate().

Here is the call graph for this function:

Member Function Documentation

◆ ChooseFonts()

void Ruler::ChooseFonts ( wxDC &  dc) const
private

Definition at line 1355 of file Ruler.cpp.

1356 {
1358  mOrientation == wxHORIZONTAL
1359  ? mBottom - mTop - 5 // height less ticks and 1px gap
1360  : MaxPixelHeight
1361  );
1362 }

References Ruler::Updater::ChooseFonts(), MaxPixelHeight, mBottom, mOrientation, mpFonts, mpUserFonts, and mTop.

Referenced by GetFonts(), and UpdateCache().

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

◆ Draw() [1/2]

void Ruler::Draw ( wxDC &  dc) const

Definition at line 1428 of file Ruler.cpp.

1429 {
1430  Draw( dc, NULL);
1431 }

Referenced by WaveTrackVRulerControls::DoDraw(), AdornedRulerPanel::DoDrawMarks(), anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve(), EffectCompressorPanel::OnPaint(), MeterPanel::OnPaint(), RulerPanel::OnPaint(), and AudacityPrintout::OnPrintPage().

Here is the caller graph for this function:

◆ Draw() [2/2]

void Ruler::Draw ( wxDC &  dc,
const Envelope envelope 
) const

Definition at line 1433 of file Ruler.cpp.

1434 {
1435  if( mLength <=0 )
1436  return;
1437 
1438  UpdateCache( dc, envelope );
1439  auto &cache = *mpCache;
1440 
1441  dc.SetTextForeground( mTickColour );
1442 #ifdef EXPERIMENTAL_THEMING
1443  dc.SetPen(mPen);
1444 #else
1445  dc.SetPen(*wxBLACK_PEN);
1446 #endif
1447 
1448  // Draws a long line the length of the ruler.
1449  if( !mbTicksOnly )
1450  {
1451  if (mOrientation == wxHORIZONTAL) {
1452  if (mFlip)
1453  AColor::Line(dc, mLeft, mTop, mRight, mTop);
1454  else
1456  }
1457  else {
1458  if (mFlip)
1460  else
1461  {
1462  // These calculations appear to be wrong, and to never have been used (so not tested) prior to MixerBoard.
1463  // AColor::Line(dc, mRect.x-mRect.width, mTop, mRect.x-mRect.width, mBottom);
1464  const int nLineX = mRight - 1;
1465  AColor::Line(dc, nLineX, mTop, nLineX, mBottom);
1466  }
1467  }
1468  }
1469 
1470  dc.SetFont( mpFonts->major );
1471 
1472  // We may want to not show the ticks at the extremes,
1473  // though still showing the labels.
1474  // This gives a better look when the ruler is on a bevelled
1475  // button, since otherwise the tick is drawn on the bevel.
1476  int iMaxPos = (mOrientation==wxHORIZONTAL)? mRight : mBottom-5;
1477 
1478  auto drawLabel = [this, iMaxPos, &dc]( const Label &label, int length ){
1479  int pos = label.pos;
1480 
1481  if( mbTicksAtExtremes || ((pos!=0)&&(pos!=iMaxPos)))
1482  {
1483  if (mOrientation == wxHORIZONTAL) {
1484  if (mFlip)
1485  AColor::Line(dc, mLeft + pos, mTop,
1486  mLeft + pos, mTop + length);
1487  else
1488  AColor::Line(dc, mLeft + pos, mBottom - length,
1489  mLeft + pos, mBottom);
1490  }
1491  else {
1492  if (mFlip)
1493  AColor::Line(dc, mLeft, mTop + pos,
1494  mLeft + length, mTop + pos);
1495  else
1496  AColor::Line(dc, mRight - length, mTop + pos,
1497  mRight, mTop + pos);
1498  }
1499  }
1500 
1501  label.Draw(dc, mTwoTone, mTickColour);
1502  };
1503 
1504  for( const auto &label : cache.mMajorLabels )
1505  drawLabel( label, 4 );
1506 
1507  if( mbMinor ) {
1508  dc.SetFont( mpFonts->minor );
1509  for( const auto &label : cache.mMinorLabels )
1510  drawLabel( label, 2 );
1511  }
1512 
1513  dc.SetFont( mpFonts->minorMinor );
1514 
1515  for( const auto &label : cache.mMinorMinorLabels )
1516  if ( !label.text.empty() )
1517  drawLabel( label, 2 );
1518 }

References TranslatableString::empty(), label, AColor::Line(), mbMinor, mBottom, mbTicksAtExtremes, mbTicksOnly, mFlip, mLeft, mLength, mOrientation, mpCache, mPen, mpFonts, mRight, mTickColour, mTop, mTwoTone, and UpdateCache().

Here is the call graph for this function:

◆ DrawGrid()

void Ruler::DrawGrid ( wxDC &  dc,
int  length,
bool  minor = true,
bool  major = true,
int  xOffset = 0,
int  yOffset = 0 
) const

Definition at line 1521 of file Ruler.cpp.

1525 {
1526  UpdateCache( dc, nullptr );
1527  auto &cache = *mpCache;
1528 
1529  int gridPos;
1530  wxPen gridPen;
1531 
1532  if(mbMinor && (minorGrid && (gridLineLength != 0 ))) {
1533  gridPen.SetColour(178, 178, 178); // very light grey
1534  dc.SetPen(gridPen);
1535  for( const auto &label : cache.mMinorLabels ) {
1536  gridPos = label.pos;
1537  if(mOrientation == wxHORIZONTAL) {
1538  if((gridPos != 0) && (gridPos != gridLineLength))
1539  AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, gridLineLength-1+yOffset);
1540  }
1541  else {
1542  if((gridPos != 0) && (gridPos != gridLineLength))
1543  AColor::Line(dc, xOffset, gridPos+yOffset, gridLineLength-1+xOffset, gridPos+yOffset);
1544  }
1545  }
1546  }
1547 
1548  if(majorGrid && (gridLineLength != 0 )) {
1549  gridPen.SetColour(127, 127, 127); // light grey
1550  dc.SetPen(gridPen);
1551  for( const auto &label : cache.mMajorLabels ) {
1552  gridPos = label.pos;
1553  if(mOrientation == wxHORIZONTAL) {
1554  if((gridPos != 0) && (gridPos != gridLineLength))
1555  AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, gridLineLength-1+yOffset);
1556  }
1557  else {
1558  if((gridPos != 0) && (gridPos != gridLineLength))
1559  AColor::Line(dc, xOffset, gridPos+yOffset, gridLineLength-1+xOffset, gridPos+yOffset);
1560  }
1561  }
1562 
1563  int zeroPosition = GetZeroPosition();
1564  if(zeroPosition > 0) {
1565  // Draw 'zero' grid line in black
1566  dc.SetPen(*wxBLACK_PEN);
1567  if(mOrientation == wxHORIZONTAL) {
1568  if(zeroPosition != gridLineLength)
1569  AColor::Line(dc, zeroPosition+xOffset, yOffset, zeroPosition+xOffset, gridLineLength-1+yOffset);
1570  }
1571  else {
1572  if(zeroPosition != gridLineLength)
1573  AColor::Line(dc, xOffset, zeroPosition+yOffset, gridLineLength-1+xOffset, zeroPosition+yOffset);
1574  }
1575  }
1576  }
1577 }

References GetZeroPosition(), label, AColor::Line(), mbMinor, mOrientation, mpCache, and UpdateCache().

Referenced by FrequencyPlotDialog::DrawPlot(), EqualizationPanel::OnPaint(), and EffectScienFilterPanel::OnPaint().

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

◆ FindZero()

int Ruler::FindZero ( const Labels labels) const
private

Definition at line 1579 of file Ruler.cpp.

1580 {
1581  auto begin = labels.begin(), end = labels.end(),
1582  iter = std::find_if( begin, end, []( const Label &label ){
1583  return label.value == 0.0;
1584  } );
1585 
1586  if ( iter == end )
1587  return -1;
1588  else
1589  return iter->pos;
1590 }

References label.

Referenced by GetZeroPosition().

Here is the caller graph for this function:

◆ GetFonts()

auto Ruler::GetFonts ( ) const

Definition at line 1418 of file Ruler.cpp.

1419 {
1420  if ( !mpFonts ) {
1421  wxScreenDC dc;
1422  ChooseFonts( dc );
1423  }
1424 
1425  return *mpFonts;
1426 }

References ChooseFonts(), and mpFonts.

Here is the call graph for this function:

◆ GetMaxSize()

void Ruler::GetMaxSize ( wxCoord *  width,
wxCoord *  height 
)

Definition at line 1603 of file Ruler.cpp.

1604 {
1605  if ( !mpCache ) {
1606  wxScreenDC sdc;
1607  UpdateCache( sdc, nullptr );
1608  }
1609 
1610  auto &cache = *mpCache;
1611  if (width)
1612  *width = cache.mRect.GetWidth();
1613 
1614  if (height)
1615  *height = cache.mRect.GetHeight();
1616 }

References mpCache, and UpdateCache().

Referenced by FrequencyPlotDialog::DrawPlot(), AdornedRulerPanel::GetMaxSize(), EffectCompressorPanel::OnPaint(), RulerPanel::RulerPanel(), MeterPanel::SetActiveStyle(), EffectEqualization::TransferDataFromWindow(), and EffectScienFilter::TransferGraphLimitsFromWindow().

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

◆ GetZeroPosition()

int Ruler::GetZeroPosition ( ) const
private

Definition at line 1592 of file Ruler.cpp.

1593 {
1594  wxASSERT( mpCache );
1595  auto &cache = *mpCache;
1596  int zero;
1597  if( (zero = FindZero( cache.mMajorLabels ) ) < 0)
1598  zero = FindZero( cache.mMinorLabels );
1599  // PRL: don't consult minor minor??
1600  return zero;
1601 }

References FindZero(), and mpCache.

Referenced by DrawGrid().

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

◆ Invalidate()

void Ruler::Invalidate ( )

Definition at line 345 of file Ruler.cpp.

346 {
347  if (mOrientation == wxHORIZONTAL)
348  mLength = mRight-mLeft;
349  else
350  mLength = mBottom-mTop;
351 
352  mpCache.reset();
353  // Bug 2316 we must preserve off-limit pixels.
354  // mUserBits.clear();
355 }

References mBottom, mLeft, mLength, mOrientation, mpCache, mRight, and mTop.

Referenced by anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve(), AdornedRulerPanel::InvalidateRuler(), OfflimitsPixels(), SetBounds(), SetCustomMode(), SetDbMirrorValue(), SetFlip(), SetFonts(), SetFormat(), SetLabelEdges(), SetLog(), SetNumberScale(), SetOrientation(), SetRange(), SetSpacing(), SetUnits(), SetUseZoomInfo(), and ~Ruler().

Here is the caller graph for this function:

◆ MakeTick()

auto Ruler::MakeTick ( Label  lab,
wxDC &  dc,
wxFont  font,
std::vector< bool > &  bits,
int  left,
int  top,
int  spacing,
int  lead,
bool  flip,
int  orientation 
)
staticprivate

Definition at line 758 of file Ruler.cpp.

765 {
766  lab.lx = left - 1000; // don't display
767  lab.ly = top - 1000; // don't display
768 
769  auto length = bits.size() - 1;
770  auto pos = lab.pos;
771 
772  dc.SetFont( font );
773 
774  wxCoord strW, strH, strD, strL;
775  auto str = lab.text;
776  // Do not put the text into results until we are sure it does not overlap
777  lab.text = {};
778  dc.GetTextExtent(str.Translation(), &strW, &strH, &strD, &strL);
779 
780  int strPos, strLen, strLeft, strTop;
781  if ( orientation == wxHORIZONTAL ) {
782  strLen = strW;
783  strPos = pos - strW/2;
784  if (strPos < 0)
785  strPos = 0;
786  if (strPos + strW >= length)
787  strPos = length - strW;
788  strLeft = left + strPos;
789  if ( flip )
790  strTop = top + 4;
791  else
792  strTop = -strH - lead;
793 // strTop = top - lead + 4;// More space was needed...
794  }
795  else {
796  strLen = strH;
797  strPos = pos - strH/2;
798  if (strPos < 0)
799  strPos = 0;
800  if (strPos + strH >= length)
801  strPos = length - strH;
802  strTop = top + strPos;
803  if ( flip )
804  strLeft = left + 5;
805  else
806  strLeft = -strW - 6;
807  }
808 
809  // FIXME: we shouldn't even get here if strPos < 0.
810  // Ruler code currently does not handle very small or
811  // negative sized windows (i.e. don't draw) properly.
812  if( strPos < 0 )
813  return { {}, lab };
814 
815  // See if any of the pixels we need to draw this
816  // label is already covered
817 
818  int i;
819  for(i=0; i<strLen; i++)
820  if ( bits[strPos+i] )
821  return { {}, lab };
822 
823  // If not, position the label
824 
825  lab.lx = strLeft;
826  lab.ly = strTop;
827 
828  // And mark these pixels, plus some surrounding
829  // ones (the spacing between labels), as covered
830  int leftMargin = spacing;
831  if (strPos < leftMargin)
832  leftMargin = strPos;
833  strPos -= leftMargin;
834  strLen += leftMargin;
835 
836  int rightMargin = spacing;
837  if (strPos + strLen > length - spacing)
838  rightMargin = length - strPos - strLen;
839  strLen += rightMargin;
840 
841  for(i=0; i<strLen; i++)
842  bits[strPos+i] = true;
843 
844  // Good to display the text
845  lab.text = str;
846  return { { strLeft, strTop, strW, strH }, lab };
847 }

Referenced by Ruler::Updater::Tick(), and Ruler::Updater::TickCustom().

Here is the caller graph for this function:

◆ OfflimitsPixels()

void Ruler::OfflimitsPixels ( int  start,
int  end 
)

Definition at line 302 of file Ruler.cpp.

303 {
304  int length = mLength;
305  if (mOrientation == wxHORIZONTAL)
306  length = mRight - mLeft;
307  else
308  length = mBottom - mTop;
309  if( length < 0 )
310  return;
311 
312  auto size = static_cast<size_t>( length + 1 );
313  if ( mUserBits.size() < size ) {
314  mLength = length;
315  mUserBits.resize( size, false );
316  }
317 
318  if (end < start)
319  std::swap( start, end );
320 
321  if (start < 0)
322  start = 0;
323  if (end > mLength)
324  end = mLength;
325 
326  for(int i = start; i <= end; i++)
327  mUserBits[i] = true;
328 
329  Invalidate();
330 }

References Invalidate(), mBottom, mLeft, mLength, mOrientation, mRight, mTop, mUserBits, and anonymous_namespace{NoteTrack.cpp}::swap().

Referenced by MeterPanel::HandleLayout().

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

◆ SetBounds()

void Ruler::SetBounds ( int  left,
int  top,
int  right,
int  bottom 
)

Definition at line 332 of file Ruler.cpp.

333 {
334  if (mLeft != left || mTop != top ||
335  mRight != right || mBottom != bottom) {
336  mLeft = left;
337  mTop = top;
338  mRight = right;
339  mBottom = bottom;
340 
341  Invalidate();
342  }
343 }

References Invalidate(), mBottom, mLeft, mRight, and mTop.

Referenced by RulerPanel::DoSetSize(), anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve(), MeterPanel::HandleLayout(), EffectCompressorPanel::OnPaint(), AudacityPrintout::OnPrintPage(), RulerPanel::RulerPanel(), MeterPanel::SetActiveStyle(), AdornedRulerPanel::UpdateRects(), and NoteTrackVRulerControls::UpdateRuler().

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

◆ SetCustomMajorLabels()

void Ruler::SetCustomMajorLabels ( const TranslatableStrings labels,
int  start,
int  step 
)

◆ SetCustomMinorLabels()

void Ruler::SetCustomMinorLabels ( const TranslatableStrings labels,
int  start,
int  step 
)

◆ SetCustomMode()

void Ruler::SetCustomMode ( bool  value)

Definition at line 1619 of file Ruler.cpp.

1620 {
1621  if ( mCustom != value ) {
1622  mCustom = value;
1623  Invalidate();
1624  }
1625 }

References Invalidate(), and mCustom.

Here is the call graph for this function:

◆ SetDbMirrorValue()

void Ruler::SetDbMirrorValue ( const double  d)

Definition at line 165 of file Ruler.cpp.

166 {
167  if (mDbMirrorValue != d) {
168  mDbMirrorValue = d;
169 
170  Invalidate();
171  }
172 }

References Invalidate(), and mDbMirrorValue.

Here is the call graph for this function:

◆ SetFlip()

void Ruler::SetFlip ( bool  flip)

Definition at line 239 of file Ruler.cpp.

240 {
241  // If this is true, the orientation of the tick marks
242  // is reversed from the default; eg. above the line
243  // instead of below
244 
245  if (mFlip != flip) {
246  mFlip = flip;
247 
248  Invalidate();
249  }
250 }

References Invalidate(), and mFlip.

Referenced by anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve(), EffectCompressorPanel::OnPaint(), and RulerPanel::RulerPanel().

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

◆ SetFonts()

void Ruler::SetFonts ( const wxFont &  minorFont,
const wxFont &  majorFont,
const wxFont &  minorMinorFont 
)

Definition at line 278 of file Ruler.cpp.

279 {
280  // Won't override these fonts
281 
282  mpUserFonts = std::make_unique<Fonts>(
283  Fonts{ majorFont, minorFont, minorMinorFont, 0 } );
284 
285  wxScreenDC dc;
286  wxCoord height;
287  FindFontHeights( height, mpUserFonts->lead, dc, majorFont );
288 
289  mpFonts.reset();
290  mpFonts.reset();
291  Invalidate();
292 }

References anonymous_namespace{Ruler.cpp}::FindFontHeights(), Invalidate(), mpFonts, and mpUserFonts.

Here is the call graph for this function:

◆ SetFormat()

void Ruler::SetFormat ( RulerFormat  format)

Definition at line 131 of file Ruler.cpp.

132 {
133  // IntFormat, RealFormat, RealLogFormat, TimeFormat, or LinearDBFormat
134 
135  if (mFormat != format) {
136  mFormat = format;
137 
138  Invalidate();
139  }
140 }

References format, Invalidate(), and mFormat.

Referenced by AdornedRulerPanel::AdornedRulerPanel(), FrequencyPlotDialog::DrawPlot(), EffectCompressorPanel::OnPaint(), AudacityPrintout::OnPrintPage(), RulerPanel::RulerPanel(), and MeterPanel::SetActiveStyle().

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

◆ SetLabelEdges()

void Ruler::SetLabelEdges ( bool  labelEdges)

Definition at line 226 of file Ruler.cpp.

227 {
228  // If this is true, the edges of the ruler will always
229  // receive a label. If not, the nearest round number is
230  // labeled (which may or may not be the edge).
231 
232  if (mLabelEdges != labelEdges) {
233  mLabelEdges = labelEdges;
234 
235  Invalidate();
236  }
237 }

References Invalidate(), and mLabelEdges.

Referenced by AdornedRulerPanel::AdornedRulerPanel(), AudacityPrintout::OnPrintPage(), and RulerPanel::RulerPanel().

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

◆ SetLog()

void Ruler::SetLog ( bool  log)

Definition at line 142 of file Ruler.cpp.

143 {
144  // Logarithmic
145 
146  if (mLog != log) {
147  mLog = log;
148 
149  Invalidate();
150  }
151 }

References Invalidate(), and mLog.

Referenced by FrequencyPlotDialog::DrawPlot(), EffectEqualization::OnLinFreq(), RulerPanel::RulerPanel(), EffectEqualization::UpdateDraw(), and EffectEqualization::UpdateGraphic().

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

◆ SetMinor()

void Ruler::SetMinor ( bool  value)

Definition at line 252 of file Ruler.cpp.

253 {
254  mbMinor = value;
255 }

References mbMinor.

◆ SetNumberScale()

void Ruler::SetNumberScale ( const NumberScale scale)

Definition at line 294 of file Ruler.cpp.

295 {
296  if ( mNumberScale != scale ) {
297  mNumberScale = scale;
298  Invalidate();
299  }
300 }

References Invalidate(), and mNumberScale.

Here is the call graph for this function:

◆ SetOrientation()

void Ruler::SetOrientation ( int  orient)

Definition at line 174 of file Ruler.cpp.

175 {
176  // wxHORIZONTAL || wxVERTICAL
177 
178  if (mOrientation != orient) {
179  mOrientation = orient;
180 
181  if (mOrientation == wxVERTICAL && !mHasSetSpacing)
182  mSpacing = 2;
183 
184  Invalidate();
185  }
186 }

References Invalidate(), mHasSetSpacing, mOrientation, and mSpacing.

Referenced by EffectCompressorPanel::OnPaint(), AudacityPrintout::OnPrintPage(), RulerPanel::RulerPanel(), and MeterPanel::SetActiveStyle().

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

◆ SetRange() [1/2]

void Ruler::SetRange ( double  min,
double  max 
)

Definition at line 188 of file Ruler.cpp.

189 {
190  SetRange(min, max, min, max);
191 }

References min().

Referenced by AdornedRulerPanel::DoDrawMarks(), anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve(), FrequencyPlotDialog::DrawPlot(), EffectEqualization::OnLinFreq(), EffectCompressorPanel::OnPaint(), AudacityPrintout::OnPrintPage(), RulerPanel::RulerPanel(), MeterPanel::SetActiveStyle(), EffectEqualization::TransferDataFromWindow(), EffectScienFilter::TransferGraphLimitsFromWindow(), EffectEqualization::UpdateDraw(), and EffectEqualization::UpdateGraphic().

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

◆ SetRange() [2/2]

void Ruler::SetRange ( double  min,
double  max,
double  hiddenMin,
double  hiddenMax 
)

Definition at line 193 of file Ruler.cpp.

195 {
196  // For a horizontal ruler,
197  // min is the value in the center of pixel "left",
198  // max is the value in the center of pixel "right".
199 
200  // In the special case of a time ruler,
201  // hiddenMin and hiddenMax are values that would be shown with the fisheye
202  // turned off. In other cases they equal min and max respectively.
203 
204  if (mMin != min || mMax != max ||
205  mHiddenMin != hiddenMin || mHiddenMax != hiddenMax) {
206  mMin = min;
207  mMax = max;
208  mHiddenMin = hiddenMin;
209  mHiddenMax = hiddenMax;
210 
211  Invalidate();
212  }
213 }

References Invalidate(), mHiddenMax, mHiddenMin, min(), mMax, and mMin.

Here is the call graph for this function:

◆ SetSpacing()

void Ruler::SetSpacing ( int  spacing)

Definition at line 215 of file Ruler.cpp.

216 {
217  mHasSetSpacing = true;
218 
219  if (mSpacing != spacing) {
220  mSpacing = spacing;
221 
222  Invalidate();
223  }
224 }

References Invalidate(), mHasSetSpacing, and mSpacing.

Here is the call graph for this function:

◆ SetTickColour()

void Ruler::SetTickColour ( const wxColour &  colour)
inline

Definition at line 148 of file Ruler.h.

149  { mTickColour = colour; mPen.SetColour( colour );}

Referenced by WaveTrackVRulerControls::DoDraw(), AdornedRulerPanel::DoDrawMarks(), anonymous_namespace{TimeTrackView.cpp}::DrawHorzRulerAndCurve(), EffectCompressorPanel::OnPaint(), MeterPanel::OnPaint(), RulerPanel::RulerPanel(), and RulerPanel::SetTickColour().

Here is the caller graph for this function:

◆ SetTwoTone()

void Ruler::SetTwoTone ( bool  twoTone)

Definition at line 126 of file Ruler.cpp.

127 {
128  mTwoTone = twoTone;
129 }

References mTwoTone.

Referenced by AdornedRulerPanel::UpdatePrefs().

Here is the caller graph for this function:

◆ SetUnits()

void Ruler::SetUnits ( const TranslatableString units)

Definition at line 153 of file Ruler.cpp.

154 {
155  // Specify the name of the units (like "dB") if you
156  // want numbers like "1.6" formatted as "1.6 dB".
157 
158  if (mUnits != units) {
159  mUnits = units;
160 
161  Invalidate();
162  }
163 }

References Invalidate(), and mUnits.

Referenced by FrequencyPlotDialog::DrawPlot(), EffectCompressorPanel::OnPaint(), and RulerPanel::RulerPanel().

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

◆ SetUseZoomInfo()

void Ruler::SetUseZoomInfo ( int  leftOffset,
const ZoomInfo zoomInfo 
)

Definition at line 1680 of file Ruler.cpp.

1681 {
1682 
1683  if ( mLeftOffset != leftOffset ||
1684  // Hm, is this invalidation sufficient? What if *zoomInfo changes under us?
1685  mUseZoomInfo != zoomInfo
1686  ) {
1687  mLeftOffset = leftOffset;
1688  mUseZoomInfo = zoomInfo;
1689  Invalidate();
1690  }
1691 }

References Invalidate(), mLeftOffset, and mUseZoomInfo.

Referenced by AdornedRulerPanel::AdornedRulerPanel(), and AdornedRulerPanel::SetLeftOffset().

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

◆ UpdateCache()

void Ruler::UpdateCache ( wxDC &  dc,
const Envelope envelope 
) const
private

Definition at line 1364 of file Ruler.cpp.

1367 {
1368  if ( mpCache )
1369  return;
1370 
1371  const ZoomInfo *zoomInfo = NULL;
1372  if (!mLog && mOrientation == wxHORIZONTAL)
1373  zoomInfo = mUseZoomInfo;
1374 
1375  // This gets called when something has been changed
1376  // (i.e. we've been invalidated). Recompute all
1377  // tick positions and font size.
1378 
1379  ChooseFonts( dc );
1380  mpCache = std::make_unique< Cache >();
1381  auto &cache = *mpCache;
1382 
1383  // If ruler is being resized, we could end up with it being too small.
1384  // Values of mLength of zero or below cause bad array allocations and
1385  // division by zero. So...
1386  // IF too small THEN bail out and don't draw.
1387  if( mLength <= 0 )
1388  return;
1389 
1390  if (mOrientation == wxHORIZONTAL)
1391  cache.mRect = { 0, 0, mLength, 0 };
1392  else
1393  cache.mRect = { 0, 0, 0, mLength };
1394 
1395  // FIXME: Surely we do not need to allocate storage for the labels?
1396  // We can just recompute them as we need them? Yes, but only if
1397  // mCustom is false!!!!
1398 
1399  if(!mCustom) {
1400  cache.mMajorLabels.clear();
1401  cache.mMinorLabels.clear();
1402  cache.mMinorMinorLabels.clear();
1403  }
1404 
1405  cache.mBits = mUserBits;
1406  cache.mBits.resize( static_cast<size_t>(mLength + 1), false );
1407 
1408  // Keep Updater const! We want no hidden state changes affecting its
1409  // computations.
1410  const Updater updater{ *this, zoomInfo };
1411  Updater::UpdateOutputs allOutputs{
1412  cache.mMajorLabels, cache.mMinorLabels, cache.mMinorMinorLabels,
1413  cache.mBits, cache.mRect
1414  };
1415  updater.Update(dc, envelope, allOutputs);
1416 }

References ChooseFonts(), mCustom, mLength, mLog, mOrientation, mpCache, mUserBits, and mUseZoomInfo.

Referenced by Draw(), DrawGrid(), and GetMaxSize().

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

Member Data Documentation

◆ mbMinor

bool Ruler::mbMinor
private

Definition at line 219 of file Ruler.h.

Referenced by Draw(), DrawGrid(), Ruler(), and SetMinor().

◆ mBottom

int Ruler::mBottom
private

◆ mbTicksAtExtremes

bool Ruler::mbTicksAtExtremes

Definition at line 178 of file Ruler.h.

Referenced by Draw(), Ruler(), and RulerPanel::RulerPanel().

◆ mbTicksOnly

bool Ruler::mbTicksOnly

Definition at line 177 of file Ruler.h.

Referenced by Draw(), and Ruler().

◆ mCustom

bool Ruler::mCustom
private

Definition at line 218 of file Ruler.h.

Referenced by Ruler(), SetCustomMode(), Ruler::Updater::Update(), and UpdateCache().

◆ mDbMirrorValue

double Ruler::mDbMirrorValue
private

Definition at line 212 of file Ruler.h.

Referenced by Ruler(), SetDbMirrorValue(), and Ruler::Updater::UpdateLinear().

◆ mFlip

bool Ruler::mFlip
private

Definition at line 217 of file Ruler.h.

Referenced by Draw(), Ruler(), SetFlip(), Ruler::Updater::TickCustom(), and Ruler::Updater::Update().

◆ mFormat

RulerFormat Ruler::mFormat
private

◆ mHasSetSpacing

bool Ruler::mHasSetSpacing
private

Definition at line 213 of file Ruler.h.

Referenced by Ruler(), SetOrientation(), and SetSpacing().

◆ mHiddenMax

double Ruler::mHiddenMax
private

◆ mHiddenMin

double Ruler::mHiddenMin
private

◆ mLabelEdges

bool Ruler::mLabelEdges
private

Definition at line 214 of file Ruler.h.

Referenced by Ruler(), SetLabelEdges(), and Ruler::Updater::UpdateLinear().

◆ mLeft

int Ruler::mLeft
private

◆ mLeftOffset

int Ruler::mLeftOffset
private

Definition at line 223 of file Ruler.h.

Referenced by SetUseZoomInfo(), and Ruler::Updater::UpdateLinear().

◆ mLength

int Ruler::mLength
private

◆ mLog

bool Ruler::mLog
private

Definition at line 216 of file Ruler.h.

Referenced by Ruler(), SetLog(), Ruler::Updater::Update(), and UpdateCache().

◆ mMax

double Ruler::mMax
private

◆ mMin

double Ruler::mMin
private

◆ mNumberScale

NumberScale Ruler::mNumberScale
private

Definition at line 225 of file Ruler.h.

Referenced by SetNumberScale(), and Ruler::Updater::UpdateNonlinear().

◆ mOrientation

int Ruler::mOrientation
private

◆ mpCache

std::unique_ptr<Cache> Ruler::mpCache
mutableprivate

Definition at line 203 of file Ruler.h.

Referenced by Draw(), DrawGrid(), GetMaxSize(), GetZeroPosition(), Invalidate(), and UpdateCache().

◆ mPen

wxPen Ruler::mPen
private

Definition at line 182 of file Ruler.h.

Referenced by Draw(), and Ruler().

◆ mpFonts

std::unique_ptr<Fonts> Ruler::mpFonts
mutableprivate

Definition at line 188 of file Ruler.h.

Referenced by ChooseFonts(), Draw(), GetFonts(), and SetFonts().

◆ mpUserFonts

std::unique_ptr<Fonts> Ruler::mpUserFonts
private

Definition at line 187 of file Ruler.h.

Referenced by ChooseFonts(), and SetFonts().

◆ mRight

int Ruler::mRight
private

◆ mSpacing

int Ruler::mSpacing
private

Definition at line 211 of file Ruler.h.

Referenced by Ruler(), SetOrientation(), SetSpacing(), and Ruler::Updater::TickCustom().

◆ mTickColour

wxColour Ruler::mTickColour
private

Definition at line 181 of file Ruler.h.

Referenced by Draw(), and Ruler().

◆ mTop

int Ruler::mTop
private

◆ mTwoTone

bool Ruler::mTwoTone
private

Definition at line 221 of file Ruler.h.

Referenced by Draw(), Ruler(), and SetTwoTone().

◆ mUnits

TranslatableString Ruler::mUnits
private

Definition at line 220 of file Ruler.h.

Referenced by SetUnits().

◆ mUserBits

Bits Ruler::mUserBits
private

Definition at line 193 of file Ruler.h.

Referenced by OfflimitsPixels(), and UpdateCache().

◆ mUseZoomInfo

const ZoomInfo* Ruler::mUseZoomInfo
private

Definition at line 222 of file Ruler.h.

Referenced by Ruler(), SetUseZoomInfo(), and UpdateCache().


The documentation for this class was generated from the following files:
Ruler::mOrientation
int mOrientation
Definition: Ruler.h:210
Ruler::UpdateCache
void UpdateCache(wxDC &dc, const Envelope *envelope) const
Definition: Ruler.cpp:1364
Ruler::mLog
bool mLog
Definition: Ruler.h:216
Ruler::ChooseFonts
void ChooseFonts(wxDC &dc) const
Definition: Ruler.cpp:1355
Ruler::mLeft
int mLeft
Definition: Ruler.h:184
TranslatableString::empty
bool empty() const
Definition: TranslatableString.h:72
Ruler::mHiddenMin
double mHiddenMin
Definition: Ruler.h:191
Ruler::LinearDBFormat
@ LinearDBFormat
Definition: Ruler.h:34
Ruler::FindZero
int FindZero(const Labels &labels) const
Definition: Ruler.cpp:1579
Ruler::mTwoTone
bool mTwoTone
Definition: Ruler.h:221
Ruler::mUseZoomInfo
const ZoomInfo * mUseZoomInfo
Definition: Ruler.h:222
ZoomInfo
Definition: ZoomInfo.h:47
AColor::Line
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:112
Ruler::mLength
int mLength
Definition: Ruler.h:185
Ruler::mTickColour
wxColour mTickColour
Definition: Ruler.h:181
Ruler::Draw
void Draw(wxDC &dc) const
Definition: Ruler.cpp:1428
Ruler::RealFormat
@ RealFormat
Definition: Ruler.h:31
Ruler::mpCache
std::unique_ptr< Cache > mpCache
Definition: Ruler.h:202
Ruler::mPen
wxPen mPen
Definition: Ruler.h:182
Ruler::TimeFormat
@ TimeFormat
Definition: Ruler.h:33
Ruler::mLeftOffset
int mLeftOffset
Definition: Ruler.h:223
Ruler::mFormat
RulerFormat mFormat
Definition: Ruler.h:215
Ruler::mMax
double mMax
Definition: Ruler.h:190
Ruler::mbTicksOnly
bool mbTicksOnly
Definition: Ruler.h:174
Ruler::mDbMirrorValue
double mDbMirrorValue
Definition: Ruler.h:212
Ruler::mbTicksAtExtremes
bool mbTicksAtExtremes
Definition: Ruler.h:178
Ruler::mLabelEdges
bool mLabelEdges
Definition: Ruler.h:214
label
TranslatableString label
Definition: Tags.cpp:756
anonymous_namespace{Ruler.cpp}::FindFontHeights
void FindFontHeights(wxCoord &height, wxCoord &lead, wxDC &dc, int fontSize, wxFontWeight weight=wxFONTWEIGHT_NORMAL)
Definition: Ruler.cpp:269
Ruler::Updater::ChooseFonts
static void ChooseFonts(std::unique_ptr< Fonts > &pFonts, const Fonts *pUserFonts, wxDC &dc, int desiredPixelHeight)
Definition: Ruler.cpp:1017
Ruler::mNumberScale
NumberScale mNumberScale
Definition: Ruler.h:225
Ruler::mpUserFonts
std::unique_ptr< Fonts > mpUserFonts
Definition: Ruler.h:187
Ruler::mUnits
TranslatableString mUnits
Definition: Ruler.h:220
format
int format
Definition: ExportPCM.cpp:56
Ruler::GetZeroPosition
int GetZeroPosition() const
Definition: Ruler.cpp:1592
Ruler::mHiddenMax
double mHiddenMax
Definition: Ruler.h:191
Ruler::Invalidate
void Invalidate()
Definition: Ruler.cpp:345
Ruler::SetRange
void SetRange(double min, double max)
Definition: Ruler.cpp:188
Ruler::IntFormat
@ IntFormat
Definition: Ruler.h:30
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:735
Ruler::RealLogFormat
@ RealLogFormat
Definition: Ruler.h:32
Ruler::mRight
int mRight
Definition: Ruler.h:184
Ruler::mFlip
bool mFlip
Definition: Ruler.h:217
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
Ruler::mpFonts
std::unique_ptr< Fonts > mpFonts
Definition: Ruler.h:188
Ruler::mBottom
int mBottom
Definition: Ruler.h:184
Ruler::mMin
double mMin
Definition: Ruler.h:190
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1197
TrackKind::Label
@ Label
Ruler::mSpacing
int mSpacing
Definition: Ruler.h:211
MaxPixelHeight
static constexpr int MaxPixelHeight
Definition: Ruler.cpp:1007
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
Ruler::mTop
int mTop
Definition: Ruler.h:184
Ruler::mCustom
bool mCustom
Definition: Ruler.h:218
Ruler::mHasSetSpacing
bool mHasSetSpacing
Definition: Ruler.h:213
Ruler::mUserBits
Bits mUserBits
Definition: Ruler.h:193
Ruler::mbMinor
bool mbMinor
Definition: Ruler.h:219