diff --git a/Telegram/SourceFiles/ui/effects/toggle_arrow.cpp b/Telegram/SourceFiles/ui/effects/toggle_arrow.cpp new file mode 100644 index 0000000000..8813d07a1e --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/toggle_arrow.cpp @@ -0,0 +1,51 @@ +/* +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 +*/ +#include "ui/effects/toggle_arrow.h" + +namespace Ui { + +[[nodiscard]] QPainterPath ToggleUpDownArrowPath( + float64 x, + float64 y, + float64 size, + float64 fourStrokes, + float64 progress) { + const auto size2 = size / 2.; + const auto stroke = (fourStrokes / 4.) / M_SQRT2; + const auto left = x - size; + const auto right = x + size; + const auto bottom = y + size2; + constexpr auto kPointCount = 6; + auto points = std::array{ { + { left - stroke, bottom - stroke }, + { x, bottom - stroke - size - stroke }, + { right + stroke, bottom - stroke }, + { right - stroke, bottom + stroke }, + { x, bottom + stroke - size + stroke }, + { left + stroke, bottom + stroke } + } }; + const auto alpha = (progress - 1.) * M_PI; + const auto cosalpha = cos(alpha); + const auto sinalpha = sin(alpha); + for (auto &point : points) { + auto px = point.x() - x; + auto py = point.y() - y; + point.setX(x + px * cosalpha - py * sinalpha); + point.setY(y + py * cosalpha + px * sinalpha); + } + auto path = QPainterPath(); + path.moveTo(points.front()); + for (int i = 1; i != kPointCount; ++i) { + path.lineTo(points[i]); + } + path.lineTo(points.front()); + + return path; +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/toggle_arrow.h b/Telegram/SourceFiles/ui/effects/toggle_arrow.h new file mode 100644 index 0000000000..3a12c7e4de --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/toggle_arrow.h @@ -0,0 +1,19 @@ +/* +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 Ui { + +[[nodiscard]] QPainterPath ToggleUpDownArrowPath( + float64 x, + float64 y, + float64 size, + float64 fourStrokes, + float64 progress); + +} // namespace Ui diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 868d3690b7..f85868c40c 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_theme.h" #include "ui/controls/userpic_button.h" #include "ui/effects/snowflakes.h" +#include "ui/effects/toggle_arrow.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/widgets/popup_menu.h" @@ -267,39 +268,12 @@ MainMenu::ToggleAccountsButton::ToggleAccountsButton(QWidget *parent) void MainMenu::ToggleAccountsButton::paintEvent(QPaintEvent *e) { auto p = Painter(this); - const auto toggled = _toggledAnimation.value(_toggled ? 1. : 0.); - const auto x = 0. + width() - st::mainMenuTogglePosition.x(); - const auto y = 0. + height() - st::mainMenuTogglePosition.y(); - const auto size = st::mainMenuToggleSize; - const auto size2 = size / 2.; - const auto stroke = (st::mainMenuToggleFourStrokes / 4.) / M_SQRT2; - const auto left = x - size; - const auto right = x + size; - const auto bottom = y + size2; - constexpr auto kPointCount = 6; - std::array points = { { - { left - stroke, bottom - stroke }, - { x, bottom - stroke - size - stroke }, - { right + stroke, bottom - stroke }, - { right - stroke, bottom + stroke }, - { x, bottom + stroke - size + stroke }, - { left + stroke, bottom + stroke } - } }; - const auto alpha = (toggled - 1.) * M_PI; - const auto cosalpha = cos(alpha); - const auto sinalpha = sin(alpha); - for (auto &point : points) { - auto px = point.x() - x; - auto py = point.y() - y; - point.setX(x + px * cosalpha - py * sinalpha); - point.setY(y + py * cosalpha + px * sinalpha); - } - QPainterPath path; - path.moveTo(points[0]); - for (int i = 1; i != kPointCount; ++i) { - path.lineTo(points[i]); - } - path.lineTo(points[0]); + const auto path = Ui::ToggleUpDownArrowPath( + 0. + width() - st::mainMenuTogglePosition.x(), + 0. + height() - st::mainMenuTogglePosition.y(), + st::mainMenuToggleSize, + st::mainMenuToggleFourStrokes, + _toggledAnimation.value(_toggled ? 1. : 0.)); auto hq = PainterHighQualityEnabler(p); p.fillPath(path, st::windowSubTextFg); diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index e015d73d98..14ff995828 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -268,6 +268,8 @@ PRIVATE ui/effects/scroll_content_shadow.h ui/effects/snowflakes.cpp ui/effects/snowflakes.h + ui/effects/toggle_arrow.cpp + ui/effects/toggle_arrow.h ui/text/format_song_name.cpp ui/text/format_song_name.h ui/text/format_values.cpp