gradient.cpp 864 B

123456789101112131415161718192021222324252627282930
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/effects/gradient.h"
  8. namespace anim {
  9. QColor gradient_color_at(const QGradientStops &stops, float64 ratio) {
  10. for (auto i = 1; i < stops.size(); i++) {
  11. const auto currentPoint = stops[i].first;
  12. const auto previousPoint = stops[i - 1].first;
  13. if ((ratio <= currentPoint) && (ratio >= previousPoint)) {
  14. return anim::color(
  15. stops[i - 1].second,
  16. stops[i].second,
  17. (ratio - previousPoint) / (currentPoint - previousPoint));
  18. }
  19. }
  20. return QColor();
  21. }
  22. QColor gradient_color_at(const QGradient &gradient, float64 ratio) {
  23. return gradient_color_at(gradient.stops(), ratio);
  24. }
  25. } // namespace anim