diff --git a/src/AColor.cpp b/src/AColor.cpp index 590680e3a..f29e55e8e 100644 --- a/src/AColor.cpp +++ b/src/AColor.cpp @@ -183,7 +183,7 @@ void AColor::DrawFocus(wxDC & dc, wxRect & rect) dc.SetLogicalFunction(wxCOPY); } -void AColor::Bevel(wxDC & dc, bool up, wxRect & r) +void AColor::Bevel(wxDC & dc, bool up, const wxRect & r) { if (up) AColor::Light(&dc, false); @@ -211,7 +211,7 @@ wxColour AColor::Blend( const wxColour & c1, const wxColour & c2 ) return c3; } -void AColor::BevelTrackInfo(wxDC & dc, bool up, wxRect & r) +void AColor::BevelTrackInfo(wxDC & dc, bool up, const wxRect & r) { #ifndef EXPERIMENTAL_THEMING Bevel( dc, up, r ); diff --git a/src/AColor.h b/src/AColor.h index d18efc037..bacbca786 100644 --- a/src/AColor.h +++ b/src/AColor.h @@ -38,8 +38,8 @@ class AColor { static void Arrow(wxDC & dc, wxCoord x, wxCoord y, int width, bool down = true); static void Line(wxDC & dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); static void DrawFocus(wxDC & dc, wxRect & r); - static void Bevel(wxDC & dc, bool up, wxRect & r); - static void BevelTrackInfo(wxDC & dc, bool up, wxRect & r); + static void Bevel(wxDC & dc, bool up, const wxRect & r); + static void BevelTrackInfo(wxDC & dc, bool up, const wxRect & r); static wxColour Blend(const wxColour & c1, const wxColour & c2); static void UseThemeColour( wxDC * dc, int iIndex ); diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index a6fa27657..5981b8fcf 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -1830,6 +1830,9 @@ AdornedRulerPanel::AdornedRulerPanel(AudacityProject* parent, mPlayRegionDragsSelection = (gPrefs->Read(wxT("/QuickPlay/DragSelection"), 0L) == 1)? true : false; mQuickPlayEnabled = !!gPrefs->Read(wxT("/QuickPlay/QuickPlayEnabled"), 1L); + int fontSize = 10; + mButtonFont.Create(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); + UpdatePrefs(); #if wxUSE_TOOLTIPS @@ -1980,7 +1983,7 @@ int AdornedRulerPanel::IndicatorBigWidth() enum { ScrubHeight = 14, - RulerHeight = 28 + ProperRulerHeight = 28 }; int AdornedRulerPanel::IndicatorBigHeight() @@ -2027,6 +2030,8 @@ void AdornedRulerPanel::OnPaint(wxPaintEvent & WXUNUSED(evt)) DoDrawPlayRegion(&mBackDC); + DoDrawPushbuttons(&mBackDC); + dc.Blit(0, 0, mBack->GetWidth(), mBack->GetHeight(), &mBackDC, 0, 0); if (mQuickPlayInd) @@ -2777,6 +2782,95 @@ void AdornedRulerPanel::DoDrawPlayRegion(wxDC * dc) } } +wxRect AdornedRulerPanel::GetButtonAreaRect() const +{ + auto x = LeftMargin, y = TopMargin; + wxRect rect { + x, y, + mProject->GetTrackPanel()->GetLeftOffset() - x, + GetRulerHeight() - y - BottomMargin + }; + + // Leave room for one digit on the ruler, so "0.0" is not obscured if you go to start. + // But the digit string at the left end may be longer if you are not at the start. + // Perhaps there should be room for more than one digit. + wxScreenDC dc; + dc.SetFont(*mRuler.GetFonts().major); + rect.width -= dc.GetTextExtent(wxT("0")).GetWidth(); + + return rect; +} + +wxRect AdornedRulerPanel::GetButtonRect( Button button ) const +{ + wxRect rect { GetButtonAreaRect() }; + + // Reduce the height + rect.height -= (GetRulerHeight() - ProperRulerHeight); + + auto num = static_cast(button); + auto denom = static_cast(Button::NumButtons); + rect.x += (num * rect.width) / denom; + rect.width = (((1 + num) * rect.width) / denom) - rect.x; + + return rect; +} + +bool AdornedRulerPanel::GetButtonState( Button button ) const +{ + switch(button) { + case Button::QuickPlay: + return mQuickPlayEnabled; + case Button::ScrubBar: + return mShowScrubbing; + default: + wxASSERT(false); + return false; + } +} + +void AdornedRulerPanel::DoDrawPushbutton(wxDC *dc, Button button, bool down) const +{ + // Adapted from TrackInfo::DrawMuteSolo() + + static const wxString labels[static_cast(Button::NumButtons)] { + XO("Quick Play"), + /* i18n-hint: A long screen area (bar) controlling variable speed play (scrubbing) */ + XO("Scrub Bar"), + }; + + const auto bev = GetButtonRect( button ).Inflate(-1, -1); + if (down) + AColor::Solo(dc, true, false); + else + AColor::MediumTrackInfo(dc, false); + dc->SetPen( *wxTRANSPARENT_PEN );//No border! + dc->DrawRectangle(bev); + + dc->SetTextForeground(theTheme.Colour(clrTrackPanelText)); + + wxCoord textWidth, textHeight; + wxString str = wxGetTranslation(labels[static_cast(button)]); + dc->SetFont(mButtonFont); + dc->GetTextExtent(str, &textWidth, &textHeight); + dc->DrawText(str, bev.x + (bev.width - textWidth) / 2, + bev.y + (bev.height - textHeight) / 2); + AColor::BevelTrackInfo(*dc, !down, bev); +} + +void AdornedRulerPanel::DoDrawPushbuttons(wxDC *dc) const +{ + // Paint the area behind the buttons + wxRect background = GetButtonAreaRect(); + AColor::MediumTrackInfo(dc, false); + dc->DrawRectangle(background); + + for (unsigned ii = 0; ii < static_cast(Button::NumButtons); ++ii) { + auto button = static_cast