1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +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 );
}
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
// Hence after docking we need to enlarge the bar (using fit)
// so that the resizer can be reached.

View File

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

View File

@ -43,7 +43,10 @@
#include "../KeyboardCapture.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../ProjectAudioIO.h"
#include "../ProjectSettings.h"
#include "../Snap.h"
#include "../ViewInfo.h"
#include "../widgets/NumericTextCtrl.h"
#include "../AllThemeResources.h"
@ -59,8 +62,9 @@ enum {
};
BEGIN_EVENT_TABLE(TimerToolBar, ToolBar)
EVT_SIZE(TimerToolBar::OnSize)
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TimerToolBar::OnCaptureKey)
EVT_SIZE(TimerToolBar::OnSize)
EVT_IDLE( TimerToolBar::OnIdle )
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TimerToolBar::OnCaptureKey)
END_EVENT_TABLE()
TimerToolBar::TimerToolBar( AudacityProject &project )
@ -119,26 +123,36 @@ void TimerToolBar::UpdatePrefs()
ToolBar::UpdatePrefs();
}
void TimerToolBar::OnSize(wxSizeEvent & event)
void TimerToolBar::OnSize(wxSizeEvent & ev)
{
event.Skip();
ev.Skip();
if (!mAudioTime)
return;
int sh = GetSize().GetHeight() - 10;
if (mAudioTime)
{
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);
//evt.Skip();
// This 'OnSize' function is also called during moving the
// toolbar.
// 10 and 40 are magic numbers to allow some space around
// 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)
@ -169,9 +183,24 @@ void TimerToolBar::OnCaptureKey(wxCommandEvent &event)
event.Skip();
}
void TimerToolBar::SetDocked(ToolDock *dock, bool pushed) {
ToolBar::SetDocked(dock, pushed);
Fit();
void TimerToolBar::OnIdle( wxIdleEvent &evt )
{
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 RegenerateTooltips() override {};
wxSize GetDockedSize() override {
return GetSmartDockedSize();
};
private:
NumericTextCtrl * AddTime( const TranslatableString &Name, int id);
@ -44,8 +48,8 @@ private:
void OnFocus(wxFocusEvent &event);
void OnCaptureKey(wxCommandEvent &event);
void OnSize(wxSizeEvent &evt);
void OnIdle( wxIdleEvent &evt );
void OnSnapTo(wxCommandEvent & event);
virtual void SetDocked(ToolDock *dock, bool pushed) override;
SelectionBarListener * mListener;
double mRate;

View File

@ -483,6 +483,22 @@ void ToolBar::SetToDefaultSize(){
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()
{
wxSize sz3 = GetSize();

View File

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

View File

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

View File

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

View File

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