1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-01 17:12:20 +02:00

Fix Big Time TimerToolBar, Stage I

- Update on idle (new idiom from Paul)
- Dock at x1 or x2 size
- Smooth resizing
- Take some account of width when resizing
- Promote Resizable docking code to ToolBar class
This commit is contained in:
James Crook 2020-02-05 14:24:35 +00:00
parent 446ee8ef6e
commit 8168dce551
9 changed files with 89 additions and 49 deletions

View File

@ -248,21 +248,6 @@ bool MeterToolBar::Expose( bool show )
return ToolBar::Expose( show ); return ToolBar::Expose( show );
} }
wxSize MeterToolBar::GetDockedSize()
{
const int tbs = toolbarSingle + toolbarGap;
wxSize sz = GetSize();
wxSize sz2 = GetMinSize();
sz.x = wxMax( sz.x, sz2.x );
sz.y = wxMax( sz.y, sz2.y );
// 50 is the size where we switch from expanded to compact.
if( sz.y < 50 )
sz.y = tbs-1;
else
sz.y = 2 * tbs -1;
return sz;
}
// The meter's sizing code does not take account of the resizer // The meter's sizing code does not take account of the resizer
// Hence after docking we need to enlarge the bar (using fit) // Hence after docking we need to enlarge the bar (using fit)
// so that the resizer can be reached. // so that the resizer can be reached.

View File

@ -50,7 +50,9 @@ class MeterToolBar final : public ToolBar {
int GetInitialWidth() override {return (mWhichMeters == int GetInitialWidth() override {return (mWhichMeters ==
(kWithRecordMeter + kWithPlayMeter)) ? 338 : 460;} // Separate bars used to be smaller. (kWithRecordMeter + kWithPlayMeter)) ? 338 : 460;} // Separate bars used to be smaller.
int GetMinToolbarWidth() override { return 150; } int GetMinToolbarWidth() override { return 150; }
wxSize GetDockedSize() override; wxSize GetDockedSize() override {
return GetSmartDockedSize();
};
virtual void SetDocked(ToolDock *dock, bool pushed)override; virtual void SetDocked(ToolDock *dock, bool pushed)override;
private: private:

View File

@ -43,7 +43,10 @@
#include "../KeyboardCapture.h" #include "../KeyboardCapture.h"
#include "../Prefs.h" #include "../Prefs.h"
#include "../Project.h" #include "../Project.h"
#include "../ProjectAudioIO.h"
#include "../ProjectSettings.h"
#include "../Snap.h" #include "../Snap.h"
#include "../ViewInfo.h"
#include "../widgets/NumericTextCtrl.h" #include "../widgets/NumericTextCtrl.h"
#include "../AllThemeResources.h" #include "../AllThemeResources.h"
@ -60,6 +63,7 @@ enum {
BEGIN_EVENT_TABLE(TimerToolBar, ToolBar) BEGIN_EVENT_TABLE(TimerToolBar, ToolBar)
EVT_SIZE(TimerToolBar::OnSize) EVT_SIZE(TimerToolBar::OnSize)
EVT_IDLE( TimerToolBar::OnIdle )
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TimerToolBar::OnCaptureKey) EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TimerToolBar::OnCaptureKey)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -119,26 +123,36 @@ void TimerToolBar::UpdatePrefs()
ToolBar::UpdatePrefs(); ToolBar::UpdatePrefs();
} }
void TimerToolBar::OnSize(wxSizeEvent & event) void TimerToolBar::OnSize(wxSizeEvent & ev)
{ {
event.Skip(); ev.Skip();
int sh = GetSize().GetHeight() - 10; if (!mAudioTime)
return;
if (mAudioTime) // This 'OnSize' function is also called during moving the
{ // toolbar.
mAudioTime->SetDigitSize( sh*.63, sh );
wxSize ms = mAudioTime->GetSize();
//int mw = ms.GetWidth();
//mAudioTime->SetMinSize(GetSizer()->GetMinSize());
//printf("(size) %i %i\n", GetSizer()->GetSize());
}
//SetMinSize( GetSizer()->GetMinSize() );
//Layout();
//Fit();
//Refresh(true); // 10 and 40 are magic numbers to allow some space around
//evt.Skip(); // the numeric control. The horizontal space reserved
// is deliberately not quite enough. Size of font is set
// primarily by the height of the toolbar. The width
// calculations just stop the font width being
// ridiculously too large to fit.
// In practice a user will drag the size to get a good font
// size and adjust the width so that part of the control
// does not disappear.
float f = mAudioTime->GetAspectRatio();
int sh = wxMax( 5, ev.GetSize().GetHeight() - 10);
int sw = wxMax( sh, ev.GetSize().GetWidth() - 40)/f;
sh = wxMin( sh, sw );
mAudioTime->SetDigitSize( sh*0.63, sh );
// Refresh and update immediately, so that we don't get
// to see grot from partly redrawn toolbar during
// the resizing.
Refresh(false);
Update();
} }
void TimerToolBar::SetTimes(double audio) void TimerToolBar::SetTimes(double audio)
@ -169,9 +183,24 @@ void TimerToolBar::OnCaptureKey(wxCommandEvent &event)
event.Skip(); event.Skip();
} }
void TimerToolBar::SetDocked(ToolDock *dock, bool pushed) { void TimerToolBar::OnIdle( wxIdleEvent &evt )
ToolBar::SetDocked(dock, pushed); {
Fit(); evt.Skip();
auto &project = mProject;
double audioTime;
auto &projectAudioIO = ProjectAudioIO::Get( project );
if ( projectAudioIO.IsAudioActive() ){
auto gAudioIO = AudioIOBase::Get();
audioTime = gAudioIO->GetStreamTime();
}
else {
const auto &playRegion = ViewInfo::Get( project ).playRegion;
audioTime = playRegion.GetStart();
}
SetTimes( audioTime);
} }

View File

@ -37,6 +37,10 @@ public:
void SetTimes(double audio); void SetTimes(double audio);
void RegenerateTooltips() override {}; void RegenerateTooltips() override {};
wxSize GetDockedSize() override {
return GetSmartDockedSize();
};
private: private:
NumericTextCtrl * AddTime( const TranslatableString &Name, int id); NumericTextCtrl * AddTime( const TranslatableString &Name, int id);
@ -44,8 +48,8 @@ private:
void OnFocus(wxFocusEvent &event); void OnFocus(wxFocusEvent &event);
void OnCaptureKey(wxCommandEvent &event); void OnCaptureKey(wxCommandEvent &event);
void OnSize(wxSizeEvent &evt); void OnSize(wxSizeEvent &evt);
void OnIdle( wxIdleEvent &evt );
void OnSnapTo(wxCommandEvent & event); void OnSnapTo(wxCommandEvent & event);
virtual void SetDocked(ToolDock *dock, bool pushed) override;
SelectionBarListener * mListener; SelectionBarListener * mListener;
double mRate; double mRate;

View File

@ -483,6 +483,22 @@ void ToolBar::SetToDefaultSize(){
SetSize( sz ); SetSize( sz );
} }
wxSize ToolBar::GetSmartDockedSize()
{
const int tbs = toolbarSingle + toolbarGap;
wxSize sz = GetSize();
wxSize sz2 = GetMinSize();
sz.x = wxMax( sz.x, sz2.x );
sz.y = wxMax( sz.y, sz2.y );
// 46 is the size where we switch from expanded to compact.
if( sz.y < 46 )
sz.y = tbs-1;
else
sz.y = 2 * tbs -1;
return sz;
}
void ToolBar::ReCreateButtons() void ToolBar::ReCreateButtons()
{ {
wxSize sz3 = GetSize(); wxSize sz3 = GetSize();

View File

@ -142,6 +142,10 @@ public:
virtual int GetMinToolbarWidth() { return GetInitialWidth(); } virtual int GetMinToolbarWidth() { return GetInitialWidth(); }
virtual wxSize GetDockedSize() { return GetMinSize(); } virtual wxSize GetDockedSize() { return GetMinSize(); }
// Utility function for certain resizable toolbars.
// Allows them to dock at normal or double size.
wxSize GetSmartDockedSize();
public: public:
static static
AButton *MakeButton(wxWindow *parent, AButton *MakeButton(wxWindow *parent,

View File

@ -216,6 +216,8 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
int GetFocusedField() { return mLastField; } int GetFocusedField() { return mLastField; }
int GetFocusedDigit() { return mFocusedDigit; } int GetFocusedDigit() { return mFocusedDigit; }
// give a sane aspect ratio even if zero height.
float GetAspectRatio() { return mHeight ? (mWidth / mHeight):10; }
private: private:

View File

@ -596,6 +596,7 @@
<ClInclude Include="..\..\..\src\toolbars\ScrubbingToolBar.h" /> <ClInclude Include="..\..\..\src\toolbars\ScrubbingToolBar.h" />
<ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBar.h" /> <ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBar.h" />
<ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBarListener.h" /> <ClInclude Include="..\..\..\src\toolbars\SpectralSelectionBarListener.h" />
<ClInclude Include="..\..\..\src\toolbars\TimerToolBar.h" />
<ClInclude Include="..\..\..\src\TrackPanelCell.h" /> <ClInclude Include="..\..\..\src\TrackPanelCell.h" />
<ClInclude Include="..\..\..\src\TrackPanelDrawable.h" /> <ClInclude Include="..\..\..\src\TrackPanelDrawable.h" />
<ClInclude Include="..\..\..\src\TrackPanelDrawingContext.h" /> <ClInclude Include="..\..\..\src\TrackPanelDrawingContext.h" />

View File

@ -2467,6 +2467,9 @@
<ClInclude Include="..\..\..\src\effects\lv2\zix\ring.h"> <ClInclude Include="..\..\..\src\effects\lv2\zix\ring.h">
<Filter>src\effects\lv2\zix</Filter> <Filter>src\effects\lv2\zix</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\src\toolbars\TimerToolBar.h">
<Filter>src\toolbars</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="..\..\audacity.ico"> <Image Include="..\..\audacity.ico">
@ -2481,15 +2484,6 @@
<ItemGroup> <ItemGroup>
<None Include="..\..\ny.rules" /> <None Include="..\..\ny.rules" />
<None Include="..\..\po.rules" /> <None Include="..\..\po.rules" />
<None Include="..\..\..\nyquist\sliders.lsp">
<Filter>nyquist</Filter>
</None>
<None Include="..\..\..\nyquist\spec-plot.lsp">
<Filter>nyquist</Filter>
</None>
<None Include="..\..\..\nyquist\spectral-analysis.lsp">
<Filter>nyquist</Filter>
</None>
<None Include="..\..\..\nyquist\system.lsp"> <None Include="..\..\..\nyquist\system.lsp">
<Filter>nyquist</Filter> <Filter>nyquist</Filter>
</None> </None>
@ -2624,6 +2618,9 @@
<CustomBuild Include="..\..\..\nyquist\nyinit-dbg.lsp"> <CustomBuild Include="..\..\..\nyquist\nyinit-dbg.lsp">
<Filter>nyquist</Filter> <Filter>nyquist</Filter>
</CustomBuild> </CustomBuild>
<CustomBuild Include="..\..\..\nyquist\sliders.lsp" />
<CustomBuild Include="..\..\..\nyquist\spec-plot.lsp" />
<CustomBuild Include="..\..\..\nyquist\spectral-analysis.lsp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<copy Include="..\..\..\plug-ins\adjustable-fade.ny"> <copy Include="..\..\..\plug-ins\adjustable-fade.ny">