Move common values to ui/arc_angles.h.

This commit is contained in:
John Preston 2024-05-03 11:50:18 +04:00
parent db8c3d16e8
commit 4cc4d2ff56
4 changed files with 33 additions and 16 deletions

View file

@ -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

18
ui/arc_angles.h Normal file
View file

@ -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

View file

@ -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 <QtCore/QtMath>
@ -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;

View file

@ -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 };
}