diff --git a/CMakeLists.txt b/CMakeLists.txt index dd9ceba..1f9a6cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -261,6 +261,7 @@ PRIVATE ui/abstract_button.h ui/animated_icon.cpp ui/animated_icon.h + ui/arc_angles.h ui/basic_click_handlers.cpp ui/basic_click_handlers.h ui/cached_special_layer_shadow_corners.cpp diff --git a/ui/arc_angles.h b/ui/arc_angles.h new file mode 100644 index 0000000..39c1ce2 --- /dev/null +++ b/ui/arc_angles.h @@ -0,0 +1,18 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace arc { + +constexpr auto kFullLength = 360 * 16; +constexpr auto kHalfLength = (kFullLength / 2); +constexpr auto kQuarterLength = (kFullLength / 4); +constexpr auto kMinLength = (kFullLength / 360); +constexpr auto kAlmostFullLength = (kFullLength - kMinLength); + +} // namespace arc diff --git a/ui/effects/cross_animation.cpp b/ui/effects/cross_animation.cpp index 18a9cd4..e847ab3 100644 --- a/ui/effects/cross_animation.cpp +++ b/ui/effects/cross_animation.cpp @@ -7,6 +7,7 @@ #include "ui/effects/cross_animation.h" #include "ui/effects/animation_value.h" +#include "ui/arc_angles.h" #include "ui/painter.h" #include @@ -17,7 +18,6 @@ namespace { constexpr auto kPointCount = 12; constexpr auto kStaticLoadingValue = float64(-666); -constexpr auto kFullArcLength = 360 * 16; // @@ -148,12 +148,12 @@ void CrossAnimation::paint( auto pathDeleteSize = kPointCount; const auto staticLoading = (loading == kStaticLoadingValue); - auto loadingArcLength = staticLoading ? kFullArcLength : 0; + auto loadingArcLength = staticLoading ? arc::kFullLength : 0; if (loading > 0.) { transformLoadingCross(loading, pathDelete, pathDeleteSize); auto loadingArc = (loading >= 0.5) ? (loading - 1.) : loading; - loadingArcLength = qRound(-loadingArc * 2 * kFullArcLength); + loadingArcLength = qRound(-loadingArc * 2 * arc::kFullLength); } if (!staticLoading) { @@ -184,9 +184,9 @@ void CrossAnimation::paint( if (staticLoading) { anim::DrawStaticLoading(p, roundPart, stroke, color); } else { - auto loadingArcStart = kFullArcLength / 8; + auto loadingArcStart = arc::kQuarterLength / 2; if (shown < 1.) { - loadingArcStart -= qRound(-(shown - 1.) * kFullArcLength / 4.); + loadingArcStart -= qRound(-(shown - 1.) * arc::kQuarterLength); } if (loadingArcLength < 0) { loadingArcStart += loadingArcLength; diff --git a/ui/effects/radial_animation.cpp b/ui/effects/radial_animation.cpp index 2ae1d53..8de21b6 100644 --- a/ui/effects/radial_animation.cpp +++ b/ui/effects/radial_animation.cpp @@ -6,16 +6,14 @@ // #include "ui/effects/radial_animation.h" +#include "ui/arc_angles.h" #include "ui/painter.h" #include "styles/style_widgets.h" namespace Ui { namespace { -constexpr auto kFullArcLength = 360 * 16; -constexpr auto kQuarterArcLength = (kFullArcLength / 4); -constexpr auto kMinArcLength = (kFullArcLength / 360); -constexpr auto kAlmostFullArcLength = (kFullArcLength - kMinArcLength); +constexpr auto kFullArcLength = arc::kFullLength; } // namespace @@ -23,14 +21,14 @@ const int RadialState::kFull = kFullArcLength; void RadialAnimation::start(float64 prg) { _firstStart = _lastStart = _lastTime = crl::now(); - const auto iprg = qRound(qMax(prg, 0.0001) * kAlmostFullArcLength); - const auto iprgstrict = qRound(prg * kAlmostFullArcLength); + const auto iprg = qRound(qMax(prg, 0.0001) * arc::kAlmostFullLength); + const auto iprgstrict = qRound(prg * arc::kAlmostFullLength); _arcEnd = anim::value(iprgstrict, iprg); _animation.start(); } bool RadialAnimation::update(float64 prg, bool finished, crl::time ms) { - const auto iprg = qRound(qMax(prg, 0.0001) * kAlmostFullArcLength); + const auto iprg = qRound(qMax(prg, 0.0001) * arc::kAlmostFullLength); const auto result = (iprg != qRound(_arcEnd.to())) || (_finished != finished); if (_finished != finished) { @@ -101,13 +99,13 @@ void RadialAnimation::draw( } RadialState RadialAnimation::computeState() const { - auto length = kMinArcLength + qRound(_arcEnd.current()); - auto from = kQuarterArcLength + auto length = arc::kMinLength + qRound(_arcEnd.current()); + auto from = arc::kQuarterLength - length - (anim::Disabled() ? 0 : qRound(_arcStart.current())); if (style::RightToLeft()) { - from = kQuarterArcLength - (from - kQuarterArcLength) - length; - if (from < 0) from += kFullArcLength; + from = arc::kQuarterLength - (from - arc::kQuarterLength) - length; + if (from < 0) from += arc::kFullLength; } return { _opacity, from, length }; }