Options for constructing ASlider, and can specify scroll increments

This commit is contained in:
Paul Licameli 2017-11-03 15:46:42 -04:00
parent 228388a63c
commit 5e10ec0def
6 changed files with 62 additions and 47 deletions

View File

@ -62,13 +62,8 @@ MixerTrackSlider::MixerTrackSlider(wxWindow * parent,
const wxString &name,
const wxPoint & pos,
const wxSize & size,
int style /*= FRAC_SLIDER*/,
bool popup /*= true*/,
bool canUseShift /*= true*/,
float stepValue /*= STEP_CONTINUOUS*/,
int orientation /*= wxHORIZONTAL*/)
: ASlider(parent, id, name, pos, size,
style, popup, canUseShift, stepValue, orientation)
const ASlider::Options &options)
: ASlider(parent, id, name, pos, size, options)
{
}
@ -209,8 +204,10 @@ MixerTrackCluster::MixerTrackCluster(wxWindow* parent,
this, ID_SLIDER_GAIN,
/* i18n-hint: title of the Gain slider, used to adjust the volume */
_("Gain"),
ctrlPos, ctrlSize, DB_SLIDER, true,
true, 0.0, wxVERTICAL);
ctrlPos, ctrlSize,
ASlider::Options{}
.Style( DB_SLIDER )
.Orientation( wxVERTICAL ));
mSlider_Gain->SetName(_("Gain"));
this->UpdateGain();
#ifdef EXPERIMENTAL_MIDI_OUT
@ -219,8 +216,10 @@ MixerTrackCluster::MixerTrackCluster(wxWindow* parent,
this, ID_SLIDER_VELOCITY,
/* i18n-hint: title of the MIDI Velocity slider */
_("Velocity"),
ctrlPos, ctrlSize, VEL_SLIDER, true,
true, 0.0, wxVERTICAL);
ctrlPos, ctrlSize,
ASlider::Options{}
.Style( VEL_SLIDER )
.Orientation( wxVERTICAL ));
mSlider_Velocity->SetName(_("Velocity"));
this->UpdateVelocity();
#endif
@ -254,7 +253,8 @@ MixerTrackCluster::MixerTrackCluster(wxWindow* parent,
this, ID_SLIDER_PAN,
/* i18n-hint: Title of the Pan slider, used to move the sound left or right */
_("Pan"),
ctrlPos, ctrlSize, PAN_SLIDER, true);
ctrlPos, ctrlSize,
ASlider::Options{}.Style( PAN_SLIDER ));
mSlider_Pan->SetName(_("Pan"));
this->UpdatePan();

View File

@ -39,11 +39,7 @@ public:
const wxString &name,
const wxPoint & pos,
const wxSize & size,
int style = FRAC_SLIDER,
bool popup = true,
bool canUseShift = true,
float stepValue = STEP_CONTINUOUS,
int orientation = wxHORIZONTAL);
const ASlider::Options &options = ASlider::Options{});
virtual ~MixerTrackSlider() {}
void OnMouseEvent(wxMouseEvent & event);

View File

@ -78,8 +78,8 @@ void MixerToolBar::Populate()
wxID_ANY,
theTheme.Bitmap(bmpMic)), 0, wxALIGN_CENTER);
mInputSlider = safenew ASlider(this, wxID_ANY, _("Recording Volume"),
wxDefaultPosition, wxSize(130, 25));
mInputSlider->SetScroll(0.1f, 2.0f);
wxDefaultPosition, wxSize(130, 25),
ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
mInputSlider->SetName(_("Slider Recording"));
Add(mInputSlider, 0, wxALIGN_CENTER);
@ -88,8 +88,8 @@ void MixerToolBar::Populate()
wxID_ANY,
theTheme.Bitmap(bmpSpeaker)), 0, wxALIGN_CENTER);
mOutputSlider = safenew ASlider(this, wxID_ANY, _("Playback Volume"),
wxDefaultPosition, wxSize(130, 25));
mOutputSlider->SetScroll(0.1f, 2.0f);
wxDefaultPosition, wxSize(130, 25),
ASlider::Options{}.Line( 0.1f ).Page( 2.0f ));
mOutputSlider->SetName(_("Slider Playback"));
Add(mOutputSlider, 0, wxALIGN_CENTER);

View File

@ -186,15 +186,18 @@ void TranscriptionToolBar::Populate()
//Add a slider that controls the speed of playback.
const int SliderWidth=100;
mPlaySpeedSlider = safenew ASlider(this,
TTB_PlaySpeedSlider,
_("Playback Speed"),
wxDefaultPosition,
wxSize(SliderWidth,25),
SPEED_SLIDER);
TTB_PlaySpeedSlider,
_("Playback Speed"),
wxDefaultPosition,
wxSize(SliderWidth,25),
ASlider::Options{}
.Style( SPEED_SLIDER )
// 6 steps using page up/down, and 60 using arrow keys
.Line( 0.16667f )
.Page( 0.16667f )
);
mPlaySpeedSlider->Set(mPlaySpeed / 100.0);
mPlaySpeedSlider->SetLabel(_("Playback Speed"));
// 6 steps using page up/down, and 60 using arrow keys
mPlaySpeedSlider->SetScroll(0.16667f, 1.6667f);
Add( mPlaySpeedSlider, 0, wxALIGN_CENTER );
mPlaySpeedSlider->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(TranscriptionToolBar::OnFocus),

View File

@ -215,9 +215,8 @@ SliderDialog::SliderDialog(wxWindow * parent, wxWindowID id,
title,
wxDefaultPosition,
size,
style,
false);
mSlider->SetScroll(line, page);
ASlider::Options{}
.Style( style ).Line( line ).Page( page ) );
S.AddWindow(mSlider, wxEXPAND);
}
S.EndVerticalLay();
@ -1557,11 +1556,7 @@ ASlider::ASlider( wxWindow * parent,
const wxString &name,
const wxPoint & pos,
const wxSize & size,
int style,
bool popup,
bool canUseShift,
float stepValue,
int orientation /*= wxHORIZONTAL*/)
const Options &options)
: wxPanel( parent, id, pos, size, wxWANTS_CHARS )
{
//wxColour Col(parent->GetBackgroundColour());
@ -1571,23 +1566,25 @@ ASlider::ASlider( wxWindow * parent,
name,
wxPoint(0,0),
size,
style,
canUseShift,
popup,
orientation);
mLWSlider->mStepValue = stepValue;
options.style,
options.canUseShift,
options.popup,
options.orientation);
mLWSlider->mStepValue = options.stepValue;
mLWSlider->SetId( id );
SetName( name );
mSliderIsFocused = false;
mStyle = style;
mStyle = options.style;
mTimer.SetOwner(this);
#if wxUSE_ACCESSIBILITY
SetAccessible( safenew ASliderAx( this ) );
#endif
mLWSlider->SetScroll( options.line, options.page );
}

View File

@ -244,16 +244,35 @@ class ASlider /* not final */ : public wxPanel
friend class ASliderAx;
public:
struct Options {
Options() {}
int style{ FRAC_SLIDER };
wxOrientation orientation{ wxHORIZONTAL };
bool popup{ true };
bool canUseShift{ true };
float stepValue{ STEP_CONTINUOUS };
float line{ 1.0 };
float page{ 5.0 };
Options& Style( int s ) { style = s; return *this; }
Options& Orientation( wxOrientation o )
{ orientation = o; return *this; }
Options& Popup( bool p ) { popup = p; return *this; }
Options& CanUseShift( bool c ) { canUseShift = c; return *this; }
Options& StepValue( float v ) { stepValue = v; return *this; }
Options& Line( float l ) { line = l; return *this; }
Options& Page( float p ) { page = p; return *this; }
};
ASlider( wxWindow * parent,
wxWindowID id,
const wxString &name,
const wxPoint & pos,
const wxSize & size,
int style = FRAC_SLIDER,
bool popup = true,
bool canUseShift = true,
float stepValue = STEP_CONTINUOUS,
int orientation = wxHORIZONTAL);
const Options &options = Options{});
virtual ~ASlider();
bool AcceptsFocus() const override { return s_AcceptsFocus; }