mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-12 06:37:52 +02:00
Scrubber holds preference, AdornedRulerPanel updates in idle time...
... removing two uses of AdornedRulerPanel in Scrubbing
This commit is contained in:
parent
3c858dd343
commit
9faa746d4d
@ -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<TrackPanelNode> AdornedRulerPanel::Root()
|
||||
{
|
||||
|
@ -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];
|
||||
|
@ -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();
|
||||
|
@ -17,7 +17,8 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include <wx/longlong.h>
|
||||
|
||||
#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
|
||||
|
Loading…
x
Reference in New Issue
Block a user