45#include <wx/dcclient.h>
46#include <wx/dcscreen.h>
158 (
double min,
double max,
double hiddenMin,
double hiddenMax)
212 wxCoord &height, wxCoord &lead, wxDC &dc,
const wxFont &font )
214 wxCoord strW, strH, strD, strL;
215 static const wxString exampleText =
wxT(
"0.9");
217 dc.GetTextExtent(exampleText, &strW, &strH, &strD, &strL);
218 height = strH - strD - strL;
223 wxCoord &height, wxCoord &lead,
224 wxDC &dc,
int fontSize, wxFontWeight weight = wxFONTWEIGHT_NORMAL )
226 const wxFont font{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, weight };
231void Ruler::SetFonts(
const wxFont &minorFont,
const wxFont &majorFont,
const wxFont &minorMinorFont)
235 mpUserFonts = std::make_unique<RulerStruct::Fonts>(
284 auto size =
static_cast<size_t>( length + 1 );
298 for(
int i = start; i <=
end; i++)
380 while (height <= desiredPixelHeight && fontSize < 40) {
387 fonts.major = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD };
388 fonts.minor = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
389 fonts.minorMinor = wxFont{ fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
394 wxDC &dc,
const Envelope* envelope )
405 mpCache = std::make_unique< Cache >();
406 auto &cache = *mpCache;
412 if( mRulerStruct.mLength <= 0 )
415 if (mRulerStruct.mOrientation == wxHORIZONTAL)
416 cache.mRect = { 0, 0, mRulerStruct.mLength, 0 };
418 cache.mRect = { 0, 0, 0, mRulerStruct.mLength };
420 cache.mBits = mUserBits;
421 cache.mBits.resize(
static_cast<size_t>(mRulerStruct.mLength + 1),
false );
424 cache.mMajorLabels, cache.mMinorLabels, cache.mMinorMinorLabels,
425 cache.mBits, cache.mRect
428 mpUpdater->Update(dc, envelope, allOutputs, mRulerStruct);
513 for(
const auto &
label : cache.mMajorLabels )
518 for(
const auto &
label : cache.mMinorLabels )
524 for(
const auto &
label : cache.mMinorMinorLabels )
531 const int gridLineLength,
532 const bool minorGrid,
const bool majorGrid,
int xOffset,
int yOffset)
541 if(
mbMinor && (minorGrid && (gridLineLength != 0 ))) {
542 gridPen.SetColour(178, 178, 178);
544 for(
const auto &
label : cache.mMinorLabels ) {
547 if((gridPos != 0) && (gridPos != gridLineLength))
548 AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, gridLineLength-1+yOffset);
551 if((gridPos != 0) && (gridPos != gridLineLength))
552 AColor::Line(dc, xOffset, gridPos+yOffset, gridLineLength-1+xOffset, gridPos+yOffset);
557 if(majorGrid && (gridLineLength != 0 )) {
558 gridPen.SetColour(127, 127, 127);
560 for(
const auto &
label : cache.mMajorLabels ) {
563 if((gridPos != 0) && (gridPos != gridLineLength))
564 AColor::Line(dc, gridPos+xOffset, yOffset, gridPos+xOffset, gridLineLength-1+yOffset);
567 if((gridPos != 0) && (gridPos != gridLineLength))
568 AColor::Line(dc, xOffset, gridPos+yOffset, gridLineLength-1+xOffset, gridPos+yOffset);
573 if(zeroPosition > 0) {
575 dc.SetPen(*wxBLACK_PEN);
577 if(zeroPosition != gridLineLength)
578 AColor::Line(dc, zeroPosition+xOffset, yOffset, zeroPosition+xOffset, gridLineLength-1+yOffset);
581 if(zeroPosition != gridLineLength)
582 AColor::Line(dc, xOffset, zeroPosition+yOffset, gridLineLength-1+xOffset, zeroPosition+yOffset);
590 auto begin = labels.begin(),
end = labels.end(),
592 return label.value == 0.0;
606 if( (zero =
FindZero( cache.mMajorLabels ) ) < 0)
607 zero =
FindZero( cache.mMinorLabels );
621 *width = cache.mRect.GetWidth();
624 *height = cache.mRect.GetHeight();
static constexpr int MaxPixelHeight
static constexpr int MinPixelHeight
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Piecewise linear or piecewise exponential function from double to double.
CallbackReturn Publish(const RulerInvalidatedMessage &message)
Send a message to connected callbacks.
void OfflimitsPixels(int start, int end)
RulerStruct::Fonts GetFonts() const
std::unique_ptr< Cache > mpCache
int FindZero(const RulerUpdater::Labels &labels) const
RulerUpdater::Bits mUserBits
void UpdateCache(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
Ruler(const RulerUpdater &updater, const RulerFormat &format)
const RulerUpdater * mpUpdater
void SetUpdater(const RulerUpdater *pUpdater)
std::unique_ptr< RulerStruct::Fonts > mpUserFonts
void SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont)
void ChooseFonts(wxDC &dc) const
void SetNumberScale(const NumberScale &scale)
void SetOrientation(int orient)
void SetFormat(const RulerFormat *pFormat)
void Draw(wxDC &dc) const
void SetTickLengths(const TickLengths &tLengths)
void SetLabelEdges(bool labelEdges)
void GetMaxSize(wxCoord *width, wxCoord *height)
int GetZeroPosition() const
void SetBounds(int left, int top, int right, int bottom)
void SetUnits(const TranslatableString &units)
void SetRange(double min, double max)
void SetDbMirrorValue(const double d)
void SetTwoTone(bool twoTone)
void SetMinor(bool value)
std::vector< Label > Labels
wxColour & Colour(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
std::optional< LogWindowUpdater > pUpdater
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
void FindFontHeights(wxCoord &height, wxCoord &lead, wxDC &dc, int fontSize, wxFontWeight weight=wxFONTWEIGHT_NORMAL)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
RulerUpdater::Labels mMinorLabels
RulerUpdater::Labels mMinorMinorLabels
RulerUpdater::Labels mMajorLabels
std::unique_ptr< Fonts > mpFonts
TranslatableString mUnits
const RulerFormat * mpRulerFormat
An array of these created by the Updater is used to determine what and where text annotations to the ...