diff --git a/src/toolbars/SpectralSelectionBar.cpp b/src/toolbars/SpectralSelectionBar.cpp index ae6167e44..713e62a08 100644 --- a/src/toolbars/SpectralSelectionBar.cpp +++ b/src/toolbars/SpectralSelectionBar.cpp @@ -265,6 +265,10 @@ void SpectralSelectionBar::ModifySpectralSelection(bool done) top = SelectedRegion::UndefinedFrequency; } + mLow = bottom; + mHigh = top; + SetBounds(); + // Notify project and track panel, which may change // the values again, and call back to us in SetFrequencies() mListener->SSBL_ModifySpectralSelection(bottom, top, done); @@ -349,11 +353,25 @@ void SpectralSelectionBar::ValuesToControls() mWidthCtrl->SetValue(mWidth); } else { + SetBounds(); mLowCtrl->SetValue(mLow); mHighCtrl->SetValue(mHigh); } } +void SpectralSelectionBar::SetBounds() +{ + if (mHigh >= 0) + mLowCtrl->SetMaxValue(mHigh); + else + mLowCtrl->ResetMaxValue(); + + if (mLow >= 0) + mHighCtrl->SetMinValue(mLow); + else + mHighCtrl->ResetMinValue(); +} + void SpectralSelectionBar::SetFrequencies(double bottom, double top) { mLow = bottom; diff --git a/src/toolbars/SpectralSelectionBar.h b/src/toolbars/SpectralSelectionBar.h index 953d13045..4bdd0fbf1 100644 --- a/src/toolbars/SpectralSelectionBar.h +++ b/src/toolbars/SpectralSelectionBar.h @@ -49,6 +49,7 @@ public: private: void ValuesToControls(); + void SetBounds(); void OnUpdate(wxCommandEvent &evt); void OnCtrl(wxCommandEvent &evt); void OnChoice(wxCommandEvent &evt); diff --git a/src/widgets/NumericTextCtrl.cpp b/src/widgets/NumericTextCtrl.cpp index 99ad5892a..a17d65d95 100644 --- a/src/widgets/NumericTextCtrl.cpp +++ b/src/widgets/NumericTextCtrl.cpp @@ -531,6 +531,9 @@ NumericConverter::NumericConverter(Type type, double value, double sampleRate) { + ResetMinValue(); + ResetMaxValue(); + mDefaultNdx = 0; mType = type; @@ -904,7 +907,7 @@ void NumericConverter::ControlsToValue() t = frames * 1.001 / 30.; } - mValue = t; + mValue = std::max(mMinValue, std::min(mMaxValue, t)); } void NumericConverter::SetFormatName(const wxString & formatName) @@ -935,6 +938,35 @@ void NumericConverter::SetValue(double newValue) ControlsToValue(); } +void NumericConverter::SetMinValue(double minValue) +{ + mMinValue = minValue; + if (mMaxValue < minValue) + mMaxValue = minValue; + if (mValue < minValue) + SetValue(minValue); +} + +void NumericConverter::ResetMinValue() +{ + mMinValue = std::numeric_limits::min(); +} + +void NumericConverter::SetMaxValue(double maxValue) +{ + mMaxValue = maxValue; + if (mMinValue > maxValue) { + mMinValue = maxValue; + } + if (mValue > maxValue) + SetValue(maxValue); +} + +void NumericConverter::ResetMaxValue() +{ + mMaxValue = std::numeric_limits::max(); +} + double NumericConverter::GetValue() { ControlsToValue(); @@ -1073,6 +1105,8 @@ void NumericConverter::Adjust(int steps, int dir) mValue = 0.; } + mValue = std::max(mMinValue, std::min(mMaxValue, mValue)); + mValue /= mScalingFactor; if (!mNtscDrop) @@ -1615,7 +1649,7 @@ void NumericTextCtrl::OnKeyDown(wxKeyEvent &event) if (!mReadOnly && (keyCode >= '0' && keyCode <= '9')) { int digitPosition = mDigits[mFocusedDigit].pos; if (mValueString[digitPosition] == wxChar('-')) { - mValue = 0; + mValue = std::max(mMinValue, std::min(mMaxValue, 0.0)); ValueToControls(); // Beware relocation of the string digitPosition = mDigits[mFocusedDigit].pos; diff --git a/src/widgets/NumericTextCtrl.h b/src/widgets/NumericTextCtrl.h index 631042e01..87cfec599 100644 --- a/src/widgets/NumericTextCtrl.h +++ b/src/widgets/NumericTextCtrl.h @@ -71,6 +71,10 @@ public: void SetFormatString(const wxString & formatString); void SetSampleRate(double sampleRate); void SetValue(double newValue); + void SetMinValue(double minValue); + void ResetMinValue(); + void SetMaxValue(double maxValue); + void ResetMaxValue(); double GetValue(); wxString GetString(); @@ -95,6 +99,9 @@ protected: double mValue; + double mMinValue; + double mMaxValue; + wxString mFormatString; NumericFieldArray mFields;