From 9faa746d4ddfa9252e582717409bc0f551de20d3 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 4 Jul 2019 08:59:57 -0400 Subject: [PATCH] Scrubber holds preference, AdornedRulerPanel updates in idle time... ... removing two uses of AdornedRulerPanel in Scrubbing --- src/AdornedRulerPanel.cpp | 68 +++++++++++++------------------------ src/AdornedRulerPanel.h | 7 ++-- src/tracks/ui/Scrubbing.cpp | 33 ++++++++++++++++-- src/tracks/ui/Scrubbing.h | 8 ++++- 4 files changed, 63 insertions(+), 53 deletions(-) diff --git a/src/AdornedRulerPanel.cpp b/src/AdornedRulerPanel.cpp index c2befa121..fc594de91 100644 --- a/src/AdornedRulerPanel.cpp +++ b/src/AdornedRulerPanel.cpp @@ -744,7 +744,7 @@ private: bool canScrub = scrubber.CanScrub() && mParent && - mParent->mShowScrubbing; + mParent->ShowingScrubRuler(); if (!canScrub) return RefreshCode::Cancelled; @@ -948,25 +948,6 @@ AdornedRulerPanel::~AdornedRulerPanel() { } -#if 1 -namespace { - static const wxChar *scrubEnabledPrefName = wxT("/QuickPlay/ScrubbingEnabled"); - - bool ReadScrubEnabledPref() - { - bool result {}; - gPrefs->Read(scrubEnabledPrefName, &result, false); - - return result; - } - - void WriteScrubEnabledPref(bool value) - { - gPrefs->Write(scrubEnabledPrefName, value); - } -} -#endif - void AdornedRulerPanel::UpdatePrefs() { if (mNeedButtonUpdate) { @@ -990,11 +971,6 @@ void AdornedRulerPanel::UpdatePrefs() } #endif #endif - - mShowScrubbing = ReadScrubEnabledPref(); - // Affected by the last - UpdateRects(); - SetPanelSize(); } void AdornedRulerPanel::ReCreateButtons() @@ -1134,6 +1110,9 @@ void AdornedRulerPanel::OnIdle( wxIdleEvent &evt ) { evt.Skip(); + UpdateRects(); + SetPanelSize(); + auto &project = *mProject; auto &viewInfo = ViewInfo::Get( project ); const auto &selectedRegion = viewInfo.selectedRegion; @@ -1220,7 +1199,7 @@ void AdornedRulerPanel::UpdateRects() auto top = &mInner; auto bottom = &mInner; - if (mShowScrubbing) { + if (ShowingScrubRuler()) { mScrubZone = mInner; auto scrubHeight = std::min(mScrubZone.height, (int)(ScrubHeight)); @@ -1245,7 +1224,7 @@ void AdornedRulerPanel::UpdateRects() bottom->height -= BottomMargin; - if (!mShowScrubbing) + if (!ShowingScrubRuler()) mScrubZone = mInner; mRuler.SetBounds(mInner.GetLeft(), @@ -1677,20 +1656,15 @@ void AdornedRulerPanel::OnToggleScrubRulerFromMenu(wxCommandEvent&) scrubber.OnToggleScrubRuler(*mProject); } -void AdornedRulerPanel::OnToggleScrubRuler(/*wxCommandEvent&*/) -{ - mShowScrubbing = !mShowScrubbing; - WriteScrubEnabledPref(mShowScrubbing); - gPrefs->Flush(); - SetPanelSize(); -} - void AdornedRulerPanel::SetPanelSize() { - wxSize size { GetSize().GetWidth(), GetRulerHeight(mShowScrubbing) }; - SetSize(size); - SetMinSize(size); - GetParent()->PostSizeEventToParent(); + const auto oldSize = GetSize(); + wxSize size { oldSize.GetWidth(), GetRulerHeight(ShowingScrubRuler()) }; + if ( size != oldSize ) { + SetSize(size); + SetMinSize(size); + GetParent()->PostSizeEventToParent(); + } } void AdornedRulerPanel::DrawBothOverlays() @@ -1801,7 +1775,7 @@ void AdornedRulerPanel::ShowMenu(const wxPoint & pos) prlitem->Enable( playRegion.Locked() || !playRegion.Empty() ); wxMenuItem *ruleritem; - if (mShowScrubbing) + if (ShowingScrubRuler()) ruleritem = rulerMenu.Append(OnScrubRulerID, _("Disable Scrub Ruler")); else ruleritem = rulerMenu.Append(OnScrubRulerID, _("Enable Scrub Ruler")); @@ -1975,7 +1949,7 @@ void AdornedRulerPanel::DoDrawBackground(wxDC * dc) AColor::UseThemeColour( dc, clrTrackInfo ); dc->DrawRectangle( mInner ); - if (mShowScrubbing) { + if (ShowingScrubRuler()) { // Let's distinguish the scrubbing area by using a themable // colour and a line to set it off. AColor::UseThemeColour(dc, clrScrubRuler, clrTrackPanelText ); @@ -2060,7 +2034,7 @@ void AdornedRulerPanel::DoDrawIndicator const int TriangleWidth = width * 3 / 8; // Double-double headed, left-right - auto yy = mShowScrubbing + auto yy = ShowingScrubRuler() ? mScrubZone.y : (mInner.GetBottom() + 1) - 1 /* bevel */ - height; tri[ 0 ].x = xx - IndicatorOffset; @@ -2091,7 +2065,7 @@ void AdornedRulerPanel::DoDrawIndicator const int IndicatorHalfWidth = width / 2; // Double headed, left-right - auto yy = mShowScrubbing + auto yy = ShowingScrubRuler() ? mScrubZone.y : (mInner.GetBottom() + 1) - 1 /* bevel */ - height; tri[ 0 ].x = xx - IndicatorOffset; @@ -2180,7 +2154,7 @@ struct AdornedRulerPanel::Subgroup final : TrackPanelGroup { explicit Subgroup( const AdornedRulerPanel &ruler ) : mRuler{ ruler } {} Subdivision Children( const wxRect & ) override { - return { Axis::Y, ( mRuler.mShowScrubbing ) + return { Axis::Y, ( mRuler.ShowingScrubRuler() ) ? Refinement{ { mRuler.mInner.GetTop(), mRuler.mQPCell }, { mRuler.mScrubZone.GetTop(), mRuler.mScrubbingCell }, @@ -2207,6 +2181,12 @@ struct AdornedRulerPanel::MainGroup final : TrackPanelGroup { const AdornedRulerPanel &mRuler; }; +bool AdornedRulerPanel::ShowingScrubRuler() const +{ + auto &scrubber = Scrubber::Get( *GetProject() ); + return scrubber.ShowsBar(); +} + // CellularPanel implementation std::shared_ptr AdornedRulerPanel::Root() { diff --git a/src/AdornedRulerPanel.h b/src/AdornedRulerPanel.h index 19a4ef828..179a4d857 100644 --- a/src/AdornedRulerPanel.h +++ b/src/AdornedRulerPanel.h @@ -44,7 +44,7 @@ public: void SetFocusFromKbd() override; public: - int GetRulerHeight() { return GetRulerHeight(mShowScrubbing); } + int GetRulerHeight() { return GetRulerHeight( ShowingScrubRuler() ); } static int GetRulerHeight(bool showScrubBar); wxRect GetInnerRect() const { return mInner; } @@ -67,8 +67,7 @@ public: void UpdateQuickPlayPos(wxCoord &mousePosX, bool shiftDown); - bool ShowingScrubRuler() const { return mShowScrubbing; } - void OnToggleScrubRuler(/*wxCommandEvent& */); + bool ShowingScrubRuler() const; void OnToggleScrubRulerFromMenu(wxCommandEvent& ); void SetPanelSize(); @@ -170,8 +169,6 @@ private: double mLeftDownClick; // click position in seconds bool mIsDragging; - bool mShowScrubbing { false }; - DECLARE_EVENT_TABLE() wxWindow *mButtons[3]; diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index 207c3e242..4c3b9a0ef 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -233,6 +233,8 @@ Scrubber::Scrubber(AudacityProject *project) &Scrubber::OnActivateOrDeactivateApp, this); if (mWindow) mWindow->PushEventHandler(&mForwarder); + + UpdatePrefs(); } Scrubber::~Scrubber() @@ -749,7 +751,7 @@ void Scrubber::StopScrubbing() bool Scrubber::ShowsBar() const { - return AdornedRulerPanel::Get( *mProject ).ShowingScrubRuler(); + return mShowScrubbing; } bool Scrubber::IsScrubbing() const @@ -1113,10 +1115,35 @@ void Scrubber::OnSeek(const CommandContext&) CheckMenuItems(); } +#if 1 +namespace { + static const wxChar *scrubEnabledPrefName = wxT("/QuickPlay/ScrubbingEnabled"); + + bool ReadScrubEnabledPref() + { + bool result {}; + gPrefs->Read(scrubEnabledPrefName, &result, false); + + return result; + } + + void WriteScrubEnabledPref(bool value) + { + gPrefs->Write(scrubEnabledPrefName, value); + } +} +#endif + +void Scrubber::UpdatePrefs() +{ + mShowScrubbing = ReadScrubEnabledPref(); +} + void Scrubber::OnToggleScrubRuler(const CommandContext&) { - auto &ruler = AdornedRulerPanel::Get( *mProject ); - ruler.OnToggleScrubRuler(); + mShowScrubbing = !mShowScrubbing; + WriteScrubEnabledPref(mShowScrubbing); + gPrefs->Flush(); const auto toolbar = ToolManager::Get( *mProject ).GetToolBar( ScrubbingBarID ); toolbar->EnableDisableButtons(); diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index 0cfa1a26c..10211a94f 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -17,7 +17,8 @@ Paul Licameli split from TrackPanel.cpp #include #include "../../AudioIOBase.h" // for ScrubbingOptions -#include "../../ClientData.h" +#include "../../ClientData.h" // to inherit +#include "../../Prefs.h" // to inherit #include "../../widgets/Overlay.h" // to inherit #include "../../commands/CommandContext.h" #include "../../commands/CommandManager.h" // for MenuTable @@ -39,6 +40,7 @@ extern AudacityProject *GetActiveProject(); class Scrubber final : public wxEvtHandler , public ClientData::Base + , private PrefsListener { public: static Scrubber &Get( AudacityProject &project ); @@ -130,6 +132,8 @@ public: bool IsTransportingPinned() const; private: + void UpdatePrefs() override; + void StartPolling(); void StopPolling(); void DoScrub(bool seek); @@ -185,6 +189,8 @@ private: ScrubbingOptions mOptions; double mMaxSpeed { 1.0 }; + + bool mShowScrubbing { false }; }; // Specialist in drawing the scrub speed, and listening for certain events