From 58ed30d30e084e9dc99811be3682e23cfff509ca Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 11 Jan 2023 07:56:01 +0300 Subject: [PATCH] Moved constants of arc angles to td_ui. --- Telegram/SourceFiles/boxes/connection_box.cpp | 4 ++-- .../boxes/peers/edit_peer_invite_links.cpp | 4 +--- .../chat_helpers/emoji_sets_manager.cpp | 4 ++-- Telegram/SourceFiles/core/utils.h | 5 ----- Telegram/SourceFiles/dialogs/dialogs_list.cpp | 1 - Telegram/SourceFiles/dialogs/dialogs_row.cpp | 4 +--- .../controls/history_view_voice_record_bar.cpp | 2 +- .../view/history_view_transcribe_button.cpp | 2 +- .../history/view/media/history_view_gif.cpp | 4 ++-- .../history/view/media/history_view_poll.cpp | 6 +++--- .../media/player/media_player_float.cpp | 4 ++-- Telegram/SourceFiles/stdafx.h | 1 + Telegram/SourceFiles/ui/arc_angles.h | 16 ++++++++++++++++ .../SourceFiles/ui/controls/download_bar.cpp | 4 +--- .../ui/effects/send_action_animations.cpp | 4 +++- Telegram/SourceFiles/ui/ui_pch.h | 1 + Telegram/cmake/td_ui.cmake | 1 + 17 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 Telegram/SourceFiles/ui/arc_angles.h diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 3170be3c3..8bdece0f3 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -459,7 +459,7 @@ void ProxyRow::paintEvent(QPaintEvent *e) { void ProxyRow::paintCheck(Painter &p) { const auto loading = _progress ? _progress->computeState() - : Ui::RadialState{ 0., 0, FullArcLength }; + : Ui::RadialState{ 0., 0, arc::kFullLength }; const auto toggled = _toggled.value(_view.selected ? 1. : 0.) * (1. - loading.shown); const auto _st = &st::defaultRadio; @@ -484,7 +484,7 @@ void ProxyRow::paintCheck(Painter &p) { _st->thickness, pen.color(), _st->bg); - } else if (loading.arcLength < FullArcLength) { + } else if (loading.arcLength < arc::kFullLength) { p.drawArc(rect, loading.arcFrom, loading.arcLength); } else { p.drawEllipse(rect); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp index 5df5929f2..1be67226d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp @@ -35,8 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -constexpr auto kFullArcLength = 360 * 16; - enum class Color { Permanent, Expiring, @@ -740,7 +738,7 @@ void LinksController::rowPaintIcon( margins, margins, margins, - }), (kFullArcLength / 4), kFullArcLength * (1. - progress)); + }), arc::kQuarterLength, arc::kFullLength * (1. - progress)); } } diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 4c1e58044..cc70419d5 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -262,7 +262,7 @@ void Row::paintRadio(QPainter &p) { } const auto loading = _loading ? _loading->computeState() - : Ui::RadialState{ 0., 0, FullArcLength }; + : Ui::RadialState{ 0., 0, arc::kFullLength }; const auto isToggledSet = v::is(_state.current()); const auto isActiveSet = isToggledSet || v::is(_state.current()); const auto toggled = _toggled.value(isToggledSet ? 1. : 0.); @@ -301,7 +301,7 @@ void Row::paintRadio(QPainter &p) { _st->thickness, pen.color(), _st->bg); - } else if (loading.arcLength < FullArcLength) { + } else if (loading.arcLength < arc::kFullLength) { p.drawArc(rect, loading.arcFrom, loading.arcLength); } else { p.drawEllipse(rect); diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 37f418e78..a09f60bd3 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -175,8 +175,3 @@ inline int ceilclamp(float64 value, int32 step, int32 lowest, int32 highest) { lowest, highest); } - -static int32 FullArcLength = 360 * 16; -static int32 QuarterArcLength = (FullArcLength / 4); -static int32 MinArcLength = (FullArcLength / 360); -static int32 AlmostFullArcLength = (FullArcLength - MinArcLength); diff --git a/Telegram/SourceFiles/dialogs/dialogs_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_list.cpp index d821acb6b..362f8b857 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_list.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_entry.h" #include "dialogs/ui/dialogs_layout.h" #include "data/data_session.h" -#include "mainwidget.h" namespace Dialogs { diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index 249f4cbee..b15c657d6 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -91,8 +91,6 @@ constexpr auto kNoneLayer = 0; style::al_center); constexpr auto kPenWidth = 1.5; - constexpr auto kAngleStart = 90 * 16; - constexpr auto kAngleSpan = 180 * 16; const auto penWidth = style::ConvertScaleExact(kPenWidth); auto pen = QPen(st::premiumButtonFg); @@ -102,7 +100,7 @@ constexpr auto kNoneLayer = 0; q.setPen(pen); q.setBrush(Qt::NoBrush); - q.drawArc(innerRect, kAngleStart, kAngleSpan); + q.drawArc(innerRect, arc::kQuarterLength, arc::kHalfLength); q.setClipRect(innerRect - QMargins(innerRect.width() / 2, 0, -penWidth, -penWidth)); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index a47fbc2a6..3b65bc18a 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -837,7 +837,7 @@ void RecordLock::drawProgress(Painter &p) { arcWidth, arcHeight * 2, 0, - 180 * 16); + arc::kHalfLength); const auto lockProgress = 1. - _lockToStopProgress; if (progress == 1. && lockProgress < 1.) { diff --git a/Telegram/SourceFiles/history/view/history_view_transcribe_button.cpp b/Telegram/SourceFiles/history/view/history_view_transcribe_button.cpp index 180f56939..1e89e5e46 100644 --- a/Telegram/SourceFiles/history/view/history_view_transcribe_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_transcribe_button.cpp @@ -106,7 +106,7 @@ void TranscribeButton::paint( _st->thickness, pen.color(), _st->bg); - } else if (state.arcLength < FullArcLength) { + } else if (state.arcLength < arc::kFullLength) { const auto opacity = p.opacity(); p.setOpacity(state.shown * (1. - opened)); p.drawArc(r, state.arcFrom, state.arcLength); diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 41200d6d8..303c22e24 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -486,8 +486,8 @@ void Gif::draw(Painter &p, const PaintContext &context) const { p.setPen(pen); p.setOpacity(st::historyVideoMessageProgressOpacity); - auto from = QuarterArcLength; - auto len = -qRound(FullArcLength * value); + auto from = arc::kQuarterLength; + auto len = -qRound(arc::kFullLength * value); auto stepInside = st::radialLine / 2; { PainterHighQualityEnabler hq(p); diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index b64aaeb14..b991e911f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -971,8 +971,8 @@ void Poll::paintCloseByTimer( auto hq = PainterHighQualityEnabler(p); const auto part = std::max( left / float64(radial), - 1. / FullArcLength); - const auto length = int(base::SafeRound(FullArcLength * part)); + 1. / arc::kFullLength); + const auto length = int(base::SafeRound(arc::kFullLength * part)); auto pen = regular->p; pen.setWidth(st::historyPollRadio.thickness); pen.setCapStyle(Qt::RoundCap); @@ -980,7 +980,7 @@ void Poll::paintCloseByTimer( const auto size = icon.width() / 2; const auto left = (x + (icon.width() - size) / 2); const auto top = (y + (icon.height() - size) / 2) + st::lineWidth; - p.drawArc(left, top, size, size, (FullArcLength / 4), length); + p.drawArc(left, top, size, size, (arc::kFullLength / 4), length); } else { icon.paint(p, x, y, width()); } diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index ee20a875d..321ce14b0 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -261,8 +261,8 @@ void Float::paintEvent(QPaintEvent *e) { p.setPen(pen); p.setOpacity(_opacity * st::historyVideoMessageProgressOpacity); - auto from = QuarterArcLength; - auto len = -qRound(FullArcLength * progress); + auto from = arc::kQuarterLength; + auto len = -qRound(arc::kFullLength * progress); auto stepInside = st::radialLine / 2; { PainterHighQualityEnabler hq(p); diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index 3dd24bd70..795adbddd 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -129,6 +129,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/palette.h" #include "styles/style_basic.h" +#include "ui/arc_angles.h" #include "ui/image/image_location.h" #include "ui/text/text.h" diff --git a/Telegram/SourceFiles/ui/arc_angles.h b/Telegram/SourceFiles/ui/arc_angles.h new file mode 100644 index 000000000..cfaa59b94 --- /dev/null +++ b/Telegram/SourceFiles/ui/arc_angles.h @@ -0,0 +1,16 @@ +/* +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 kQuarterLength = (kFullLength / 4); +constexpr auto kHalfLength = (kFullLength / 2); + +} // namespace arc diff --git a/Telegram/SourceFiles/ui/controls/download_bar.cpp b/Telegram/SourceFiles/ui/controls/download_bar.cpp index 8b8a47675..1f6e25af2 100644 --- a/Telegram/SourceFiles/ui/controls/download_bar.cpp +++ b/Telegram/SourceFiles/ui/controls/download_bar.cpp @@ -18,8 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { namespace { -constexpr auto kFullArcLength = 360 * 16; - [[nodiscard]] QImage Make(const QImage &image, int size) { if (image.isNull()) { return QImage(); @@ -209,7 +207,7 @@ void DownloadBar::paint(Painter &p, QRect clip) { p.setBrush(Qt::NoBrush); const auto m = added / 2.; auto rect = QRectF(full).marginsRemoved({ m, m, m, m }); - if (loading.arcLength < kFullArcLength) { + if (loading.arcLength < arc::kFullLength) { p.drawArc(rect, loading.arcFrom, loading.arcLength); } else { p.drawEllipse(rect); diff --git a/Telegram/SourceFiles/ui/effects/send_action_animations.cpp b/Telegram/SourceFiles/ui/effects/send_action_animations.cpp index 12fad042d..3cee43385 100644 --- a/Telegram/SourceFiles/ui/effects/send_action_animations.cpp +++ b/Telegram/SourceFiles/ui/effects/send_action_animations.cpp @@ -213,6 +213,8 @@ void RecordAnimation::paint( auto size = st::historySendActionRecordPosition.x() + st::historySendActionRecordDelta * progress; y += st::historySendActionRecordPosition.y(); + constexpr auto kAngleStart = -arc::kFullLength / 24; + constexpr auto kAngleSpan = arc::kFullLength / 12; for (auto i = 0; i != kRecordArcsCount; ++i) { p.setOpacity((i == 0) ? progress @@ -220,7 +222,7 @@ void RecordAnimation::paint( ? (1. - progress) : 1.); auto rect = QRectF(x - size, y - size, 2 * size, 2 * size); - p.drawArc(rect, -FullArcLength / 24, FullArcLength / 12); + p.drawArc(rect, kAngleStart, kAngleSpan); size += st::historySendActionRecordDelta; } p.setOpacity(1.); diff --git a/Telegram/SourceFiles/ui/ui_pch.h b/Telegram/SourceFiles/ui/ui_pch.h index 52bc1e52a..81a3e0adc 100644 --- a/Telegram/SourceFiles/ui/ui_pch.h +++ b/Telegram/SourceFiles/ui/ui_pch.h @@ -33,6 +33,7 @@ #include "base/flat_map.h" #include "base/flat_set.h" +#include "ui/arc_angles.h" #include "ui/text/text.h" #include "ui/effects/animations.h" #include "styles/palette.h" diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 4b6f0c650..dc968acab 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -277,6 +277,7 @@ PRIVATE ui/widgets/vertical_drum_picker.cpp ui/widgets/vertical_drum_picker.h + ui/arc_angles.h ui/cached_round_corners.cpp ui/cached_round_corners.h ui/color_contrast.cpp