United enum classes of arc directions into single enum class.

This commit is contained in:
23rd 2021-01-30 13:26:21 +03:00
parent 4748986bf4
commit 5f7ee9ed81
2 changed files with 25 additions and 42 deletions

View file

@ -30,28 +30,18 @@ ArcsAnimation::ArcsAnimation(
const style::ArcsAnimation &st, const style::ArcsAnimation &st,
std::vector<float> thresholds, std::vector<float> thresholds,
float64 startValue, float64 startValue,
VerticalDirection direction) Direction direction)
: _st(st) : _st(st)
, _horizontalDirection(HorizontalDirection::None) , _direction(direction)
, _verticalDirection(direction) , _startAngle(16
, _startAngle((st.deltaAngle * (st.deltaAngle
+ ((direction == VerticalDirection::Up) ? 90 : 270)) * 16) + ((direction == Direction::Up)
, _spanAngle(-st.deltaAngle * 2 * 16) ? 90
, _emptyRect(computeArcRect(0)) : (direction == Direction::Down)
, _currentValue(startValue) { ? 270
initArcs(std::move(thresholds)); : (direction == Direction::Left)
} ? 180
: 0)))
ArcsAnimation::ArcsAnimation(
const style::ArcsAnimation &st,
std::vector<float> thresholds,
float64 startValue,
HorizontalDirection direction)
: _st(st)
, _horizontalDirection(direction)
, _verticalDirection(VerticalDirection::None)
, _startAngle((st.deltaAngle
+ ((direction == HorizontalDirection::Left) ? 180 : 0)) * 16)
, _spanAngle(-st.deltaAngle * 2 * 16) , _spanAngle(-st.deltaAngle * 2 * 16)
, _emptyRect(computeArcRect(0)) , _emptyRect(computeArcRect(0))
, _currentValue(startValue) { , _currentValue(startValue) {
@ -74,20 +64,24 @@ void ArcsAnimation::initArcs(std::vector<float> thresholds) {
} }
} }
bool ArcsAnimation::isHorizontal() const {
return _direction == Direction::Left || _direction == Direction::Right;
}
QRectF ArcsAnimation::computeArcRect(int index) const { QRectF ArcsAnimation::computeArcRect(int index) const {
const auto w = _st.startWidth + _st.deltaWidth * index; const auto w = _st.startWidth + _st.deltaWidth * index;
const auto h = _st.startHeight + _st.deltaHeight * index; const auto h = _st.startHeight + _st.deltaHeight * index;
if (_horizontalDirection != HorizontalDirection::None) { if (isHorizontal()) {
auto rect = QRectF(0, -h / 2.0, w, h); auto rect = QRectF(0, -h / 2.0, w, h);
if (_horizontalDirection == HorizontalDirection::Right) { if (_direction == Direction::Right) {
rect.moveRight(index * _st.space); rect.moveRight(index * _st.space);
} else { } else {
rect.moveLeft(-index * _st.space); rect.moveLeft(-index * _st.space);
} }
return rect; return rect;
} else if (_verticalDirection != VerticalDirection::None) { } else {
auto rect = QRectF(-w / 2.0, 0, w, h); auto rect = QRectF(-w / 2.0, 0, w, h);
if (_verticalDirection == VerticalDirection::Up) { if (_direction == Direction::Up) {
rect.moveTop(-index * _st.space); rect.moveTop(-index * _st.space);
} else { } else {
rect.moveBottom(index * _st.space); rect.moveBottom(index * _st.space);

View file

@ -15,29 +15,18 @@ namespace Ui::Paint {
class ArcsAnimation { class ArcsAnimation {
public: public:
enum class HorizontalDirection { enum class Direction {
Left,
Right,
None,
};
enum class VerticalDirection {
Up, Up,
Down, Down,
None, Left,
Right,
}; };
ArcsAnimation( ArcsAnimation(
const style::ArcsAnimation &st, const style::ArcsAnimation &st,
std::vector<float> thresholds, std::vector<float> thresholds,
float64 startValue, float64 startValue,
VerticalDirection direction); Direction direction);
ArcsAnimation(
const style::ArcsAnimation &st,
std::vector<float> thresholds,
float64 startValue,
HorizontalDirection direction);
void paint( void paint(
Painter &p, Painter &p,
@ -69,6 +58,7 @@ private:
void initArcs(std::vector<float> thresholds); void initArcs(std::vector<float> thresholds);
QRectF computeArcRect(int index) const; QRectF computeArcRect(int index) const;
bool isHorizontal() const;
bool isArcFinished(const Arc &arc) const; bool isArcFinished(const Arc &arc) const;
void updateArcStartTime( void updateArcStartTime(
@ -77,8 +67,7 @@ private:
crl::time now); crl::time now);
const style::ArcsAnimation &_st; const style::ArcsAnimation &_st;
const HorizontalDirection _horizontalDirection; const Direction _direction;
const VerticalDirection _verticalDirection;
const int _startAngle; const int _startAngle;
const int _spanAngle; const int _spanAngle;
const QRectF _emptyRect; const QRectF _emptyRect;