1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

ToolsToolBar.cpp is free from cycles...

... Use ProjectSettings instead to communicate just an integer to the rest of
the program.
This commit is contained in:
Paul Licameli 2019-06-13 01:53:45 -04:00
parent 4cc35b145b
commit 2f18c624f8
10 changed files with 75 additions and 38 deletions

View File

@ -75,6 +75,14 @@ ProjectSettings::ProjectSettings( AudacityProject &project )
}
gPrefs->Read(wxT("/GUI/SyncLockTracks"), &mIsSyncLocked, false);
bool multiToolActive = false;
gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
if (multiToolActive)
mCurrentTool = ToolCodes::multiTool;
else
mCurrentTool = ToolCodes::selectTool;
UpdatePrefs();
}

View File

@ -29,6 +29,21 @@ enum
SNAP_PRIOR
};
namespace ToolCodes {
enum {
selectTool,
envelopeTool,
drawTool,
zoomTool,
slideTool,
multiTool,
numTools,
firstTool = selectTool,
lastTool = multiTool,
};
}
///\brief Holds various per-project settings values, including the sample rate,
/// and sends events to the project when certain values change
class ProjectSettings final
@ -68,6 +83,11 @@ public:
void SetSnapTo(int snap);
int GetSnapTo() const;
// Current tool
void SetTool(int tool) { mCurrentTool = tool; }
int GetTool() const { return mCurrentTool; }
// Selection Format
void SetSelectionFormat(const NumericFormatSymbol & format);
@ -103,6 +123,8 @@ private:
sampleFormat mDefaultFormat;
int mSnapTo;
int mCurrentTool;
bool mTracksFitVerticallyZoomed{ false }; //lda
bool mShowId3Dialog{ true }; //lda

View File

@ -99,7 +99,6 @@ is time to refresh some aspect of the screen.
#include "ondemand/ODTask.h"
#include "toolbars/ControlToolBar.h"
#include "toolbars/ToolsToolBar.h"
#include "tracks/ui/TrackVRulerControls.h" // for inheritance relation
@ -1155,10 +1154,13 @@ void TrackPanel::DrawTracks(wxDC * dc)
// Don't draw a bottom margin here.
auto pTtb = &ToolsToolBar::Get( *GetProject() );
bool bMultiToolDown = pTtb->IsDown(multiTool);
bool envelopeFlag = pTtb->IsDown(envelopeTool) || bMultiToolDown;
bool bigPointsFlag = pTtb->IsDown(drawTool) || bMultiToolDown;
const auto &settings = ProjectSettings::Get( *GetProject() );
bool bMultiToolDown =
(ToolCodes::multiTool == settings.GetTool());
bool envelopeFlag =
bMultiToolDown || (ToolCodes::envelopeTool == settings.GetTool());
bool bigPointsFlag =
bMultiToolDown || (ToolCodes::drawTool == settings.GetTool());
bool sliderFlag = bMultiToolDown;
const bool hasSolo = GetTracks()->Any< PlayableTrack >()

View File

@ -3,6 +3,7 @@
#include "../Menus.h"
#include "../TrackPanel.h"
#include "../ProjectSettings.h"
#include "../commands/CommandContext.h"
#include "../commands/CommandManager.h"
#include "../toolbars/ToolManager.h"
@ -171,35 +172,35 @@ void OnShowSpectralSelectionToolBar(const CommandContext &context)
/// Handler to set the select tool active
void OnSelectTool(const CommandContext &context)
{
SetTool(context.project, selectTool);
SetTool(context.project, ToolCodes::selectTool);
}
/// Handler to set the Envelope tool active
void OnEnvelopeTool(const CommandContext &context)
{
SetTool(context.project, envelopeTool);
SetTool(context.project, ToolCodes::envelopeTool);
}
void OnDrawTool(const CommandContext &context)
{
SetTool(context.project, drawTool);
SetTool(context.project, ToolCodes::drawTool);
}
/// Handler to set the Zoom tool active
void OnZoomTool(const CommandContext &context)
{
SetTool(context.project, zoomTool);
SetTool(context.project, ToolCodes::zoomTool);
}
/// Handler to set the Time shift tool active
void OnTimeShiftTool(const CommandContext &context)
{
SetTool(context.project, slideTool);
SetTool(context.project, ToolCodes::slideTool);
}
void OnMultiTool(const CommandContext &context)
{
SetTool(context.project, multiTool);
SetTool(context.project, ToolCodes::multiTool);
}
void OnPrevTool(const CommandContext &context)
@ -208,6 +209,7 @@ void OnPrevTool(const CommandContext &context)
auto &toolbar = ToolsToolBar::Get( project );
auto &trackPanel = TrackPanel::Get( project );
using namespace ToolCodes;
// Use GetDownTool() here since GetCurrentTool() can return a value that
// doesn't represent the real tool if the Multi-tool is being used.
toolbar.SetCurrentTool((toolbar.GetDownTool()+(numTools-1))%numTools);
@ -220,6 +222,7 @@ void OnNextTool(const CommandContext &context)
auto &toolbar = ToolsToolBar::Get( project );
auto &trackPanel = TrackPanel::Get( project );
using namespace ToolCodes;
// Use GetDownTool() here since GetCurrentTool() can return a value that
// doesn't represent the real tool if the Multi-tool is being used.
toolbar.SetCurrentTool((toolbar.GetDownTool()+1)%numTools);

View File

@ -51,6 +51,7 @@
#include "../AllThemeResources.h"
#include "../ImageManipulation.h"
#include "../Project.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../tracks/ui/Scrubbing.h"
@ -64,8 +65,8 @@ IMPLEMENT_CLASS(ToolsToolBar, ToolBar);
////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE(ToolsToolBar, ToolBar)
EVT_COMMAND_RANGE(firstTool+FirstToolID,
lastTool+FirstToolID,
EVT_COMMAND_RANGE(ToolCodes::firstTool + FirstToolID,
ToolCodes::lastTool + FirstToolID,
wxEVT_COMMAND_BUTTON_CLICKED,
ToolsToolBar::OnTool)
END_EVENT_TABLE()
@ -74,6 +75,8 @@ END_EVENT_TABLE()
ToolsToolBar::ToolsToolBar( AudacityProject &project )
: ToolBar(project, ToolsBarID, _("Tools"), wxT("Tools"))
{
using namespace ToolCodes;
//Read the following wxASSERTs as documentating a design decision
wxASSERT( selectTool == selectTool - firstTool );
wxASSERT( envelopeTool == envelopeTool - firstTool );
@ -93,6 +96,8 @@ ToolsToolBar::ToolsToolBar( AudacityProject &project )
ToolsToolBar::~ToolsToolBar()
{
static_assert( ToolsToolBar::numTools == ToolCodes::numTools,
"mismatch in number of tools" );
}
ToolsToolBar &ToolsToolBar::Get( AudacityProject &project )
@ -132,6 +137,8 @@ void ToolsToolBar::RegenerateTooltips()
#if wxUSE_TOOLTIPS
using namespace ToolCodes;
static const struct Entry {
int tool;
CommandID commandName;
@ -190,6 +197,7 @@ void ToolsToolBar::Populate()
Add(mToolSizer = safenew wxGridSizer(2, 3, 1, 1));
/* Tools */
using namespace ToolCodes;
mTool[ selectTool ] = MakeTool( this, bmpIBeam, selectTool, _("Selection Tool") );
mTool[ envelopeTool ] = MakeTool( this, bmpEnvelope, envelopeTool, _("Envelope Tool") );
mTool[ drawTool ] = MakeTool( this, bmpDraw, drawTool, _("Draw Tool") );
@ -217,6 +225,7 @@ void ToolsToolBar::SetCurrentTool(int tool)
//In multi-mode the current tool is shown by the
//cursor icon. The buttons are not updated.
using namespace ToolCodes;
bool leavingMulticlipMode =
IsDown(multiTool) && tool != multiTool;
@ -237,6 +246,8 @@ void ToolsToolBar::SetCurrentTool(int tool)
gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
IsDown(multiTool));
gPrefs->Flush();
ProjectSettings::Get( mProject ).SetTool( mCurrentTool );
}
bool ToolsToolBar::IsDown(int tool) const
@ -248,6 +259,7 @@ int ToolsToolBar::GetDownTool()
{
int tool;
using namespace ToolCodes;
for (tool = firstTool; tool <= lastTool; tool++)
if (IsDown(tool))
return tool;
@ -257,6 +269,7 @@ int ToolsToolBar::GetDownTool()
void ToolsToolBar::OnTool(wxCommandEvent & evt)
{
using namespace ToolCodes;
mCurrentTool = evt.GetId() - firstTool - FirstToolID;
for (int i = 0; i < numTools; i++)
if (i == mCurrentTool)
@ -270,6 +283,8 @@ void ToolsToolBar::OnTool(wxCommandEvent & evt)
gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
IsDown(multiTool));
gPrefs->Flush();
ProjectSettings::Get( mProject ).SetTool( mCurrentTool );
}
void ToolsToolBar::Create(wxWindow * parent)

View File

@ -30,19 +30,6 @@ class AudacityProject;
// Code duplication warning: these apparently need to be in the
// same order as the enum in ToolsToolBar.cpp
enum {
selectTool,
envelopeTool,
drawTool,
zoomTool,
slideTool,
multiTool,
numTools,
firstTool = selectTool,
lastTool = multiTool,
};
const int FirstToolID = 11200;
class ToolsToolBar final : public ToolBar {
@ -78,6 +65,7 @@ class ToolsToolBar final : public ToolBar {
static AButton *MakeTool(
ToolsToolBar *pBar, teBmps eTool, int id, const wxChar *label);
enum { numTools = 6 };
AButton *mTool[numTools];
wxGridSizer *mToolSizer;
int mCurrentTool;

View File

@ -15,13 +15,13 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../HitTestResult.h"
#include "../../../../TrackPanelMouseEvent.h"
#include "../../../../toolbars/ToolsToolBar.h"
#include "CutlineHandle.h"
#include "../../../ui/SelectHandle.h"
#include "../../../ui/EnvelopeHandle.h"
#include "SampleHandle.h"
#include "../../../ui/TimeShiftHandle.h"
#include "../../../ProjectSettings.h"
std::vector<UIHandlePtr> WaveTrack::DetailedHitTest
(const TrackPanelMouseState &st,
@ -79,13 +79,13 @@ std::vector<UIHandlePtr> WaveTrack::DetailedHitTest
switch ( currentTool ) {
// Unconditional hits appropriate to the tool
// If tools toolbar were eliminated, we would eliminate these
case envelopeTool: {
case ToolCodes::envelopeTool: {
auto envelope = GetEnvelopeAtX( st.state.m_x );
result = EnvelopeHandle::HitAnywhere(
mEnvelopeHandle, envelope, false);
break;
}
case drawTool:
case ToolCodes::drawTool:
result = SampleHandle::HitAnywhere(
mSampleHandle, st.state, SharedPointer<WaveTrack>());
break;

View File

@ -33,7 +33,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../WaveTrack.h"
#include "../../ondemand/ODManager.h"
#include "../../prefs/SpectrogramSettings.h"
#include "../../toolbars/ToolsToolBar.h"
#include "../../../images/Cursors.h"
#include <wx/event.h>
@ -904,7 +903,7 @@ HitTestPreview SelectHandle::Preview
auto xx = viewInfo.TimeToPosition(time, mRect.x);
const bool bMultiToolMode =
ToolsToolBar::Get( *pProject ).IsDown(multiTool);
(ToolCodes::multiTool == ProjectSettings::Get( *pProject ).GetTool());
//In Multi-tool mode, give multitool prompt if no-special-hit.
if (bMultiToolMode) {

View File

@ -21,7 +21,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../ProjectSettings.h"
#include "../../RefreshCode.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../toolbars/ToolsToolBar.h"
#include "../../UndoManager.h"
#include "../../WaveClip.h"
#include "../../ViewInfo.h"
@ -371,8 +370,8 @@ UIHandle::Result TimeShiftHandle::Click
mClipMoveState.clear();
mDidSlideVertically = false;
const auto ttb = &ToolsToolBar::Get( *pProject );
const bool multiToolModeActive = (ttb && ttb->IsDown(multiTool));
const bool multiToolModeActive =
(ToolCodes::multiTool == ProjectSettings::Get( *pProject ).GetTool());
const double clickTime =
viewInfo.PositionToTime(event.m_x, rect.x);

View File

@ -15,7 +15,6 @@ Paul Licameli split from TrackPanel.cpp
#include "TrackVRulerControls.h"
#include "../../HitTestResult.h"
#include "../../toolbars/ToolsToolBar.h"
#include "../ui/SelectHandle.h"
#include "EnvelopeHandle.h"
@ -24,16 +23,18 @@ Paul Licameli split from TrackPanel.cpp
#include "TimeShiftHandle.h"
#include "../../TrackPanelResizerCell.h"
#include "BackgroundCell.h"
#include "../../ProjectSettings.h"
std::vector<UIHandlePtr> Track::HitTest
(const TrackPanelMouseState &st,
const AudacityProject *pProject)
{
UIHandlePtr result;
using namespace ToolCodes;
std::vector<UIHandlePtr> results;
auto pTtb = &ToolsToolBar::Get( *pProject );
const bool isMultiTool = pTtb->IsDown(multiTool);
const auto currentTool = pTtb->GetCurrentTool();
const auto &settings = ProjectSettings::Get( *pProject );
const auto currentTool = settings.GetTool();
const bool isMultiTool = ( currentTool == multiTool );
if ( !isMultiTool && currentTool == zoomTool ) {
// Zoom tool is a non-selecting tool that takes precedence in all tracks