1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-20 23:51:18 +01:00

Factor function to choose ruler fonts

This commit is contained in:
Paul Licameli
2020-01-22 09:54:56 -05:00
parent 3876031669
commit e08543650b
2 changed files with 42 additions and 46 deletions

View File

@@ -110,10 +110,6 @@ Ruler::Ruler()
fontSize = 8;
#endif
mFonts.minorMinor = wxFont{ fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
mFonts.minor = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
mFonts.major = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD };
mUserFonts = false;
mLength = 0;
@@ -921,26 +917,8 @@ double SolveWarpedLength(const Envelope &env, double t0, double length)
}
}
void Ruler::Update(
wxDC &dc, const Envelope* envelope )// Envelope *speedEnv, long minSpeed, long maxSpeed )
{
const ZoomInfo *zoomInfo = NULL;
if (!mLog && mOrientation == wxHORIZONTAL)
zoomInfo = mUseZoomInfo;
// This gets called when something has been changed
// (i.e. we've been invalidated). Recompute all
// tick positions and font size.
if (!mUserFonts) {
int fontSize = 4;
wxCoord strW, strH, strD, strL;
wxString exampleText = wxT("0.9"); //ignored for height calcs on all platforms
int desiredPixelHeight;
static const int MinPixelHeight = 10; // 8;
static const int MaxPixelHeight =
static constexpr int MinPixelHeight = 10; // 8;
static constexpr int MaxPixelHeight =
#ifdef __WXMAC__
10
#else
@@ -948,14 +926,14 @@ void Ruler::Update(
#endif
;
if (mOrientation == wxHORIZONTAL)
desiredPixelHeight = mBottom - mTop - 5; // height less ticks and 1px gap
else
desiredPixelHeight = MaxPixelHeight;
void Ruler::ChooseFonts( Fonts &fonts, wxDC &dc, int desiredPixelHeight )
{
int fontSize = 4;
wxCoord strW, strH, strD, strL;
wxString exampleText = wxT("0.9"); //ignored for height calcs on all platforms
desiredPixelHeight =
std::max(MinPixelHeight, std::min(MaxPixelHeight,
desiredPixelHeight));
std::max(MinPixelHeight, std::min(MaxPixelHeight, -desiredPixelHeight));
// Keep making the font bigger until it's too big, then subtract one.
dc.SetFont(wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
@@ -968,13 +946,30 @@ void Ruler::Update(
fontSize--;
dc.SetFont(wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
dc.GetTextExtent(exampleText, &strW, &strH, &strD, &strL);
mFonts.lead = strL;
mFonts.major = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD };
fonts.lead = strL;
fonts.major = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD };
fonts.minor = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
fonts.minorMinor = wxFont{ fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
}
mFonts.minor = wxFont{ fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
void Ruler::Update(
wxDC &dc, const Envelope* envelope )// Envelope *speedEnv, long minSpeed, long maxSpeed )
{
const ZoomInfo *zoomInfo = NULL;
if (!mLog && mOrientation == wxHORIZONTAL)
zoomInfo = mUseZoomInfo;
mFonts.minorMinor = wxFont{ fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL };
// This gets called when something has been changed
// (i.e. we've been invalidated). Recompute all
// tick positions and font size.
if (!mUserFonts) {
ChooseFonts( mFonts, dc,
mOrientation == wxHORIZONTAL
? mBottom - mTop - 5 // height less ticks and 1px gap
: MaxPixelHeight
);
}
// If ruler is being resized, we could end up with it being too small.

View File

@@ -157,6 +157,7 @@ class AUDACITY_DLL_API Ruler {
private:
struct TickSizes;
static void ChooseFonts( Fonts &fonts, wxDC &dc, int desiredPixelHeight );
void Update( wxDC &dc, const Envelope* envelope );
bool Tick( wxDC &dc,