Add pin/unpin button to the time ruler
This commit is contained in:
parent
2d14867aa8
commit
d424be9a78
|
@ -123,6 +123,9 @@ from there. Audacity will look for a file called "Pause.png".
|
|||
DEFINE_IMAGE( bmpMic, wxImage( 25, 25 ), wxT("Mic"));
|
||||
DEFINE_IMAGE( bmpSpeaker, wxImage( 25, 25 ), wxT("Speaker"));
|
||||
|
||||
DEFINE_IMAGE( bmpPinnedPlayRecordHead, wxImage( 27, 27 ), wxT("PinnedPlayRecordHead"));
|
||||
DEFINE_IMAGE( bmpUnpinnedPlayRecordHead, wxImage( 27, 27 ), wxT("UnpinnedPlayRecordHead"));
|
||||
|
||||
SET_THEME_FLAGS( resFlagPaired );
|
||||
DEFINE_IMAGE( bmpZoomFit, wxImage( 27, 27 ), wxT("ZoomFit"));
|
||||
DEFINE_IMAGE( bmpZoomFitDisabled, wxImage( 27, 27 ), wxT("ZoomFitDisabled"));
|
||||
|
|
|
@ -2380,6 +2380,11 @@ void AudacityProject::OnTogglePinnedHead()
|
|||
auto ctb = GetActiveProject()->GetControlToolBar();
|
||||
if (ctb)
|
||||
ctb->StartScrollingIfPreferred();
|
||||
|
||||
auto ruler = GetRulerPanel();
|
||||
if (ruler)
|
||||
// Update button image
|
||||
ruler->UpdateButtonStates();
|
||||
}
|
||||
|
||||
void AudacityProject::OnTogglePlayRecording()
|
||||
|
|
|
@ -66,6 +66,7 @@ array of Ruler::Label.
|
|||
#include <wx/menuitem.h>
|
||||
#include <wx/tooltip.h>
|
||||
|
||||
#include "AButton.h"
|
||||
#include "../AColor.h"
|
||||
#include "../AudioIO.h"
|
||||
#include "../Internat.h"
|
||||
|
@ -82,6 +83,7 @@ array of Ruler::Label.
|
|||
#include "../Prefs.h"
|
||||
#include "../Snap.h"
|
||||
#include "../tracks/ui/Scrubbing.h"
|
||||
#include "../prefs/PlaybackPrefs.h"
|
||||
#include "../prefs/TracksPrefs.h"
|
||||
|
||||
//#define SCRUB_ABOVE
|
||||
|
@ -1915,6 +1917,8 @@ enum {
|
|||
OnAutoScrollID,
|
||||
OnLockPlayRegionID,
|
||||
|
||||
OnTogglePinnedStateID,
|
||||
|
||||
OnShowHideScrubbingID,
|
||||
};
|
||||
|
||||
|
@ -1937,6 +1941,10 @@ BEGIN_EVENT_TABLE(AdornedRulerPanel, OverlayPanel)
|
|||
// Pop up menus on Windows
|
||||
EVT_CONTEXT_MENU(AdornedRulerPanel::OnContextMenu)
|
||||
|
||||
EVT_COMMAND( OnTogglePinnedStateID,
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
AdornedRulerPanel::OnTogglePinnedState )
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
AdornedRulerPanel::AdornedRulerPanel(AudacityProject* parent,
|
||||
|
@ -2033,6 +2041,9 @@ namespace {
|
|||
|
||||
void AdornedRulerPanel::UpdatePrefs()
|
||||
{
|
||||
// Update button texts for language change
|
||||
UpdateButtonStates();
|
||||
|
||||
#ifdef EXPERIMENTAL_SCROLLING_LIMITS
|
||||
#ifdef EXPERIMENTAL_TWO_TONE_TIME_RULER
|
||||
{
|
||||
|
@ -2051,8 +2062,56 @@ void AdornedRulerPanel::UpdatePrefs()
|
|||
RegenerateTooltips(mPrevZone);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
wxString ComposeButtonLabel
|
||||
(AudacityProject &project, const wxString &commandName, const wxString &label)
|
||||
{
|
||||
auto pCmdMgr = project.GetCommandManager();
|
||||
const auto &keyString = pCmdMgr->GetKeyFromName(commandName);
|
||||
return keyString.empty()
|
||||
? label
|
||||
: label + wxT(" (") + keyString + wxT(")");
|
||||
}
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::ReCreateButtons()
|
||||
{
|
||||
for (auto & button : mButtons) {
|
||||
if (button)
|
||||
button->Destroy();
|
||||
button = nullptr;
|
||||
}
|
||||
|
||||
// Make the short row of time ruler pushbottons.
|
||||
// Don't bother with sizers. Their sizes and positions are fixed.
|
||||
wxPoint position{ FocusBorderLeft, FocusBorderTop };
|
||||
size_t iButton = 0;
|
||||
const auto size = theTheme.ImageSize( bmpRecoloredUpSmall );
|
||||
|
||||
auto buttonMaker = [&]
|
||||
(wxWindowID id, teBmps bitmap, bool toggle)
|
||||
{
|
||||
const auto button =
|
||||
ToolBar::MakeButton(
|
||||
this,
|
||||
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall,
|
||||
bitmap, bitmap, bitmap,
|
||||
id, position, toggle, size
|
||||
);
|
||||
|
||||
position.x += size.GetWidth();
|
||||
mButtons[iButton++] = button;
|
||||
return button;
|
||||
};
|
||||
auto button = buttonMaker(OnTogglePinnedStateID, bmpPinnedPlayRecordHead, false);
|
||||
ToolBar::MakeAlternateImages(
|
||||
*button, 1,
|
||||
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall,
|
||||
bmpUnpinnedPlayRecordHead, bmpUnpinnedPlayRecordHead, bmpUnpinnedPlayRecordHead,
|
||||
size);
|
||||
|
||||
UpdateButtonStates();
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::InvalidateRuler()
|
||||
|
@ -2115,6 +2174,14 @@ void AdornedRulerPanel::OnCapture(wxCommandEvent & evt)
|
|||
|
||||
void AdornedRulerPanel::OnPaint(wxPaintEvent & WXUNUSED(evt))
|
||||
{
|
||||
if (mNeedButtonUpdate) {
|
||||
// Visit this block once only in the lifetime of this panel
|
||||
mNeedButtonUpdate = false;
|
||||
// Do this first time setting of button status texts
|
||||
// when we are sure the CommandManager is initialized.
|
||||
UpdateButtonStates();
|
||||
}
|
||||
|
||||
wxPaintDC dc(this);
|
||||
|
||||
auto &backDC = GetBackingDCForRepaint();
|
||||
|
@ -2698,6 +2765,28 @@ void AdornedRulerPanel::OnContextMenu(wxContextMenuEvent & WXUNUSED(event))
|
|||
ShowContextMenu(MenuChoice::QuickPlay, nullptr);
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::UpdateButtonStates()
|
||||
{
|
||||
bool state = PlaybackPrefs::GetPinnedHeadPreference();
|
||||
auto pinButton = static_cast<AButton*>(FindWindow(OnTogglePinnedStateID));
|
||||
pinButton->PopUp();
|
||||
pinButton->SetAlternateIdx(state ? 0 : 1);
|
||||
const auto label = state
|
||||
// Label descibes the present state, not what the click does
|
||||
// (which is, to toggle the state)
|
||||
? _("Pinned play/record Head")
|
||||
: _("Unpinned play/record Head");
|
||||
const auto &fullLabel = ComposeButtonLabel(*mProject, _("PinnedHead"), label);
|
||||
pinButton->SetLabel(fullLabel);
|
||||
pinButton->SetToolTip(fullLabel);
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::OnTogglePinnedState(wxCommandEvent & event)
|
||||
{
|
||||
mProject->OnTogglePinnedHead();
|
||||
UpdateButtonStates();
|
||||
}
|
||||
|
||||
void AdornedRulerPanel::OnCaptureLost(wxMouseCaptureLostEvent & WXUNUSED(evt))
|
||||
{
|
||||
HideQuickPlayIndicator();
|
||||
|
|
|
@ -349,8 +349,10 @@ private:
|
|||
void DoDrawEdge(wxDC *dc);
|
||||
void DoDrawMarks(wxDC * dc, bool /*text */ );
|
||||
void DoDrawSelection(wxDC * dc);
|
||||
|
||||
public:
|
||||
void DoDrawIndicator(wxDC * dc, wxCoord xx, bool playing, int width, bool scrub);
|
||||
void UpdateButtonStates();
|
||||
|
||||
private:
|
||||
QuickPlayIndicatorOverlay *GetOverlay();
|
||||
|
@ -415,6 +417,8 @@ private:
|
|||
|
||||
void OnContextMenu(wxContextMenuEvent & WXUNUSED(event));
|
||||
|
||||
void OnTogglePinnedState(wxCommandEvent & event);
|
||||
|
||||
bool mPlayRegionDragsSelection;
|
||||
bool mTimelineToolTip;
|
||||
bool mQuickPlayEnabled;
|
||||
|
@ -441,6 +445,9 @@ private:
|
|||
DECLARE_EVENT_TABLE()
|
||||
|
||||
friend QuickPlayRulerOverlay;
|
||||
|
||||
wxWindow *mButtons[1] { {} };
|
||||
bool mNeedButtonUpdate { true };
|
||||
};
|
||||
|
||||
#endif //define __AUDACITY_RULER__
|
||||
|
|
Loading…
Reference in New Issue