Added util for calculating of intermediate gradient value.
This commit is contained in:
parent
9c09b1fad0
commit
cea7f128a5
3 changed files with 33 additions and 0 deletions
|
|
@ -47,6 +47,7 @@ PRIVATE
|
|||
ui/effects/cross_line.h
|
||||
ui/effects/fade_animation.cpp
|
||||
ui/effects/fade_animation.h
|
||||
ui/effects/gradient.cpp
|
||||
ui/effects/gradient.h
|
||||
ui/effects/numbers_animation.cpp
|
||||
ui/effects/numbers_animation.h
|
||||
|
|
|
|||
28
ui/effects/gradient.cpp
Normal file
28
ui/effects/gradient.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#include "ui/effects/gradient.h"
|
||||
|
||||
namespace anim {
|
||||
|
||||
QColor gradient_color_at(const QGradient &gradient, float64 ratio) {
|
||||
const auto &stops = gradient.stops();
|
||||
|
||||
for (auto i = 1; i < stops.size(); i++) {
|
||||
const auto currentPoint = stops[i].first;
|
||||
const auto previousPoint = stops[i - 1].first;
|
||||
|
||||
if ((ratio <= currentPoint) && (ratio >= previousPoint)) {
|
||||
return anim::color(
|
||||
stops[i - 1].second,
|
||||
stops[i].second,
|
||||
(ratio - previousPoint) / (currentPoint - previousPoint));
|
||||
}
|
||||
}
|
||||
return QColor();
|
||||
}
|
||||
|
||||
} // namespace anim
|
||||
|
|
@ -14,6 +14,10 @@
|
|||
|
||||
namespace anim {
|
||||
|
||||
[[nodiscard]] QColor gradient_color_at(
|
||||
const QGradient &gradient,
|
||||
float64 ratio);
|
||||
|
||||
struct gradient_colors {
|
||||
explicit gradient_colors(QColor color) {
|
||||
stops.push_back({ 0., color });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue