mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Moved paint of toggle up-down arrow from main menu to td_ui.
This commit is contained in:
parent
21cd1555f0
commit
4598fc3d53
4 changed files with 79 additions and 33 deletions
51
Telegram/SourceFiles/ui/effects/toggle_arrow.cpp
Normal file
51
Telegram/SourceFiles/ui/effects/toggle_arrow.cpp
Normal file
|
@ -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<QPointF, kPointCount>{ {
|
||||
{ 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
|
19
Telegram/SourceFiles/ui/effects/toggle_arrow.h
Normal file
19
Telegram/SourceFiles/ui/effects/toggle_arrow.h
Normal file
|
@ -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
|
|
@ -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<QPointF, kPointCount> 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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue