Moved computing of premium gradient parts to separated class.

This commit is contained in:
23rd 2022-07-06 00:41:05 +03:00 committed by John Preston
parent 99676c4cf8
commit 009ef829a0
1 changed files with 45 additions and 21 deletions

View File

@ -69,6 +69,45 @@ constexpr auto kStepAfterDeflection = kStepBeforeDeflection
return gradient; return gradient;
} }
class PartialGradient final {
public:
PartialGradient(int from, int to, QGradientStops stops);
[[nodiscard]] QLinearGradient compute(int position, int size) const;
private:
const int _from;
const int _to;
QLinearGradient _gradient;
};
PartialGradient::PartialGradient(int from, int to, QGradientStops stops)
: _from(from)
, _to(to)
, _gradient(0, 0, 0, to - from) {
_gradient.setStops(std::move(stops));
}
QLinearGradient PartialGradient::compute(int position, int size) const {
const auto pointTop = position - _from;
const auto pointBottom = pointTop + size;
const auto ratioTop = pointTop / float64(_to - _from);
const auto ratioBottom = pointBottom / float64(_to - _from);
auto resultGradient = QLinearGradient(
QPointF(),
QPointF(0, pointBottom - pointTop));
resultGradient.setColorAt(
.0,
anim::gradient_color_at(_gradient, ratioTop));
resultGradient.setColorAt(
.1,
anim::gradient_color_at(_gradient, ratioBottom));
return resultGradient;
}
class Bubble final { class Bubble final {
public: public:
using EdgeProgress = float64; using EdgeProgress = float64;
@ -863,36 +902,21 @@ void ShowListBox(
Assert(lines.size() > 2); Assert(lines.size() > 2);
const auto from = lines.front()->y(); const auto from = lines.front()->y();
const auto to = lines.back()->y() + lines.back()->height(); const auto to = lines.back()->y() + lines.back()->height();
auto gradient = QLinearGradient(0, 0, 0, to - from);
{ const auto partialGradient = [&] {
auto stops = Ui::Premium::FullHeightGradientStops(); auto stops = Ui::Premium::FullHeightGradientStops();
// Reverse.
for (auto &stop : stops) { for (auto &stop : stops) {
stop.first = std::abs(stop.first - 1.); stop.first = std::abs(stop.first - 1.);
} }
gradient.setStops(std::move(stops)); return PartialGradient(from, to, std::move(stops));
} }();
for (auto i = 0; i < int(lines.size()); i++) { for (auto i = 0; i < int(lines.size()); i++) {
const auto &line = lines[i]; const auto &line = lines[i];
const auto pointTop = line->y() - from; const auto brush = QBrush(
const auto pointBottom = pointTop + line->height(); partialGradient.compute(line->y(), line->height()));
const auto ratioTop = pointTop / float64(to - from);
const auto ratioBottom = pointBottom / float64(to - from);
auto resultGradient = QLinearGradient(
QPointF(),
QPointF(0, pointBottom - pointTop));
resultGradient.setColorAt(
.0,
anim::gradient_color_at(gradient, ratioTop));
resultGradient.setColorAt(
.1,
anim::gradient_color_at(gradient, ratioBottom));
const auto brush = QBrush(resultGradient);
line->setColorOverride(brush); line->setColorOverride(brush);
} }
box->addSkip(st::settingsPremiumPreviewLinePadding.bottom()); box->addSkip(st::settingsPremiumPreviewLinePadding.bottom());