Refactored TimeLineWidget to use uInt32 throughout:

- this fixes issues with signed vs. unsigned in some areas
- it also self-documents, in that the slider should never use negative values
This commit is contained in:
Stephen Anthony 2018-02-04 11:15:42 -03:30
parent 9e53641add
commit f29dcfece1
4 changed files with 28 additions and 31 deletions

View File

@ -76,6 +76,7 @@ using std::memcpy;
// Common array types
using IntArray = std::vector<Int32>;
using uIntArray = std::vector<uInt32>;
using BoolArray = std::vector<bool>;
using ByteArray = std::vector<uInt8>;
using ShortArray = std::vector<uInt16>;

View File

@ -28,11 +28,11 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TimeLineWidget::TimeLineWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h,
const string& label, int labelWidth, int cmd)
const string& label, uInt32 labelWidth, int cmd)
: ButtonWidget(boss, font, x, y, w, h, label, cmd),
_value(0),
_valueMin(0),
_valueMax(100),
_valueMax(0),
_isDragging(false),
_labelWidth(labelWidth)
{
@ -45,14 +45,13 @@ TimeLineWidget::TimeLineWidget(GuiObject* boss, const GUI::Font& font,
_w = w + _labelWidth;
_stepValue.reserve(_valueMax);
_stepValue.reserve(100);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TimeLineWidget::setValue(int value)
void TimeLineWidget::setValue(uInt32 value)
{
if(value < _valueMin) value = _valueMin;
else if(value > _valueMax) value = _valueMax;
value = BSPF::clamp(value, _valueMin, _valueMax);
if(value != _value)
{
@ -63,13 +62,13 @@ void TimeLineWidget::setValue(int value)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TimeLineWidget::setMinValue(int value)
void TimeLineWidget::setMinValue(uInt32 value)
{
_valueMin = value;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TimeLineWidget::setMaxValue(int value)
void TimeLineWidget::setMaxValue(uInt32 value)
{
_valueMax = value;
}
@ -129,9 +128,9 @@ void TimeLineWidget::handleMouseWheel(int x, int y, int direction)
{
if(isEnabled())
{
if(direction < 0)
if(direction < 0 && _value < _valueMax)
setValue(_value + 1);
else if(direction > 0)
else if(direction > 0 && _value > _valueMin)
setValue(_value - 1);
}
}
@ -186,16 +185,13 @@ void TimeLineWidget::drawWidget(bool hilite)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int TimeLineWidget::valueToPos(int value)
uInt32 TimeLineWidget::valueToPos(uInt32 value)
{
if(_valueMax >= 0)
return _stepValue[BSPF::clamp(value, _valueMin, _valueMax)];
else
return 0;
return _stepValue[BSPF::clamp(value, _valueMin, _valueMax)];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int TimeLineWidget::posToValue(int pos)
uInt32 TimeLineWidget::posToValue(uInt32 pos)
{
// Find the interval in which 'pos' falls, and then the endpoint which
// it is closest to

View File

@ -25,15 +25,15 @@ class TimeLineWidget : public ButtonWidget
public:
TimeLineWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h, const string& label = "",
int labelWidth = 0, int cmd = 0);
uInt32 labelWidth = 0, int cmd = 0);
void setValue(int value);
int getValue() const { return _value; }
void setValue(uInt32 value);
uInt32 getValue() const { return _value; }
void setMinValue(int value);
int getMinValue() const { return _valueMin; }
void setMaxValue(int value);
int getMaxValue() const { return _valueMax; }
void setMinValue(uInt32 value);
uInt32 getMinValue() const { return _valueMin; }
void setMaxValue(uInt32 value);
uInt32 getMaxValue() const { return _valueMax; }
/**
Steps are not necessarily linear in a timeline, so we need info
@ -49,16 +49,16 @@ class TimeLineWidget : public ButtonWidget
void drawWidget(bool hilite) override;
int valueToPos(int value);
int posToValue(int pos);
uInt32 valueToPos(uInt32 value);
uInt32 posToValue(uInt32 pos);
protected:
int _value;
int _valueMin, _valueMax;
bool _isDragging;
int _labelWidth;
uInt32 _value;
uInt32 _valueMin, _valueMax;
bool _isDragging;
uInt32 _labelWidth;
IntArray _stepValue;
uIntArray _stepValue;
private:
// Following constructors and assignment operators not supported

View File

@ -212,7 +212,7 @@ void TimeMachineDialog::loadConfig()
IntArray cycles = r.cyclesList();
// Set range and intervals for timeline
myTimeline->setMaxValue(int(cycles.size()) - 1);
myTimeline->setMaxValue(cycles.size() > 1 ? cycles.size() - 1 : 0);
myTimeline->setStepValues(cycles);
// Enable blending (only once is necessary)