Added class for linear gradient color animation.
This commit is contained in:
parent
7dd1950c23
commit
75171a0585
1 changed files with 50 additions and 0 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#include "ui/style/style_core.h"
|
||||
|
||||
#include <QtGui/QPainterPath>
|
||||
#include <QtGui/QLinearGradient>
|
||||
|
||||
namespace anim {
|
||||
|
||||
|
|
@ -354,4 +355,53 @@ void DrawStaticLoading(
|
|||
QPen pen,
|
||||
QBrush brush = Qt::NoBrush);
|
||||
|
||||
class linear_gradient {
|
||||
public:
|
||||
linear_gradient(
|
||||
std::vector<QColor> colors_from,
|
||||
std::vector<QColor> colors_to,
|
||||
QPointF point1,
|
||||
QPointF point2)
|
||||
: _colors_from(colors_from)
|
||||
, _colors_to(colors_to)
|
||||
, _point1(point1)
|
||||
, _point2(point2)
|
||||
, _gradient_from(gradient(colors_from))
|
||||
, _gradient_to(gradient(colors_to)) {
|
||||
Expects(colors_from.size() == colors_to.size());
|
||||
}
|
||||
|
||||
QLinearGradient gradient(float64 b_ratio) const {
|
||||
if (b_ratio == 0.) {
|
||||
return _gradient_from;
|
||||
} else if (b_ratio == 1.) {
|
||||
return _gradient_to;
|
||||
}
|
||||
auto colors = std::vector<QColor>(_colors_to.size());
|
||||
for (auto i = 0; i < colors.size(); i++) {
|
||||
colors[i] = color(_colors_from[i], _colors_to[i], b_ratio);
|
||||
}
|
||||
return gradient(colors);
|
||||
}
|
||||
|
||||
private:
|
||||
QLinearGradient gradient(const std::vector<QColor> &colors) const {
|
||||
auto gradient = QLinearGradient(_point1, _point2);
|
||||
const auto size = colors.size();
|
||||
for (auto i = 0; i < size; i++) {
|
||||
gradient.setColorAt(i / (size - 1), colors[i]);
|
||||
}
|
||||
return gradient;
|
||||
}
|
||||
|
||||
std::vector<QColor> _colors_from;
|
||||
std::vector<QColor> _colors_to;
|
||||
QPointF _point1;
|
||||
QPointF _point2;
|
||||
|
||||
QLinearGradient _gradient_from;
|
||||
QLinearGradient _gradient_to;
|
||||
|
||||
};
|
||||
|
||||
} // namespace anim
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue