mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Added second type of stars to animation of mini stars.
This commit is contained in:
parent
5e29f382cd
commit
0e30e306ff
5 changed files with 35 additions and 8 deletions
|
@ -17,7 +17,10 @@ namespace Premium {
|
|||
|
||||
constexpr auto kDeformationMax = 0.1;
|
||||
|
||||
MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque)
|
||||
MiniStars::MiniStars(
|
||||
Fn<void(const QRect &r)> updateCallback,
|
||||
bool opaque,
|
||||
Type type)
|
||||
: _availableAngles({
|
||||
Interval{ -10, 40 },
|
||||
Interval{ 180 + 10 - 40, 40 },
|
||||
|
@ -29,6 +32,7 @@ MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque)
|
|||
, _size({ 5, 10 })
|
||||
, _alpha({ opaque ? 100 : 40, opaque ? 100 : 60 })
|
||||
, _sinFactor({ 10, 190 })
|
||||
, _spritesCount({ 0, ((type == Type::MonoStars) ? 1 : 2) })
|
||||
, _appearProgressTill(0.2)
|
||||
, _disappearProgressAfter(0.8)
|
||||
, _distanceProgressStart(0.5)
|
||||
|
@ -41,6 +45,10 @@ MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque)
|
|||
updateCallback(base::take(_rectToUpdate));
|
||||
}
|
||||
}) {
|
||||
if (type == Type::BiStars) {
|
||||
_secondSprite = std::make_unique<QSvgRenderer>(
|
||||
u":/gui/icons/settings/star.svg"_q);
|
||||
}
|
||||
if (anim::Disabled()) {
|
||||
const auto from = _deathTime.from + _deathTime.length;
|
||||
auto r = bytes::vector(from + 1);
|
||||
|
@ -117,7 +125,7 @@ void MiniStars::paint(QPainter &p, const QRectF &rect) {
|
|||
- starHeight / 2.,
|
||||
starWidth,
|
||||
starHeight);
|
||||
_sprite.render(&p, renderRect);
|
||||
ministar.sprite->render(&p, renderRect);
|
||||
_rectToUpdate |= renderRect.toRect();
|
||||
}
|
||||
p.setOpacity(opacity);
|
||||
|
@ -128,7 +136,7 @@ void MiniStars::setPaused(bool paused) {
|
|||
}
|
||||
|
||||
void MiniStars::createStar(crl::time now) {
|
||||
constexpr auto kRandomSize = 8;
|
||||
constexpr auto kRandomSize = 9;
|
||||
auto random = bytes::vector(kRandomSize);
|
||||
base::RandomFill(random.data(), random.size());
|
||||
|
||||
|
@ -148,6 +156,9 @@ void MiniStars::createStar(crl::time now) {
|
|||
.alpha = float64(randomInterval(_alpha, next())) / 100.,
|
||||
.sinFactor = randomInterval(_sinFactor, next()) / 100.
|
||||
* ((uchar(next()) % 2) == 1 ? 1. : -1.),
|
||||
.sprite = ((randomInterval(_spritesCount, next()) && _secondSprite)
|
||||
? _secondSprite.get()
|
||||
: &_sprite),
|
||||
};
|
||||
for (auto i = 0; i < _ministars.size(); i++) {
|
||||
if (ministar.birthTime > _ministars[i].deathTime) {
|
||||
|
|
|
@ -16,7 +16,15 @@ namespace Premium {
|
|||
|
||||
class MiniStars final {
|
||||
public:
|
||||
MiniStars(Fn<void(const QRect &r)> updateCallback, bool opaque = false);
|
||||
enum class Type {
|
||||
MonoStars,
|
||||
BiStars,
|
||||
};
|
||||
|
||||
MiniStars(
|
||||
Fn<void(const QRect &r)> updateCallback,
|
||||
bool opaque = false,
|
||||
Type type = Type::MonoStars);
|
||||
|
||||
void paint(QPainter &p, const QRectF &rect);
|
||||
void setPaused(bool paused);
|
||||
|
@ -31,6 +39,7 @@ private:
|
|||
float64 size = 0.;
|
||||
float64 alpha = 0.;
|
||||
float64 sinFactor = 0.;
|
||||
not_null<QSvgRenderer*> sprite;
|
||||
};
|
||||
|
||||
struct Interval {
|
||||
|
@ -50,12 +59,14 @@ private:
|
|||
const Interval _size;
|
||||
const Interval _alpha;
|
||||
const Interval _sinFactor;
|
||||
const Interval _spritesCount;
|
||||
|
||||
const float64 _appearProgressTill;
|
||||
const float64 _disappearProgressAfter;
|
||||
const float64 _distanceProgressStart;
|
||||
|
||||
QSvgRenderer _sprite;
|
||||
std::unique_ptr<QSvgRenderer> _secondSprite;
|
||||
|
||||
Ui::Animations::Basic _animation;
|
||||
|
||||
|
|
|
@ -15,14 +15,16 @@ namespace Premium {
|
|||
|
||||
ColoredMiniStars::ColoredMiniStars(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
bool optimizeUpdate)
|
||||
bool optimizeUpdate,
|
||||
MiniStars::Type type)
|
||||
: _ministars(
|
||||
optimizeUpdate
|
||||
? Fn<void(const QRect &)>([=](const QRect &r) {
|
||||
parent->update(r.translated(_position));
|
||||
})
|
||||
: Fn<void(const QRect &)>([=](const QRect &) { parent->update(); }),
|
||||
true) {
|
||||
true,
|
||||
type) {
|
||||
}
|
||||
|
||||
void ColoredMiniStars::setSize(const QSize &size) {
|
||||
|
|
|
@ -17,7 +17,10 @@ namespace Premium {
|
|||
class ColoredMiniStars final {
|
||||
public:
|
||||
// optimizeUpdate may cause paint glitch.
|
||||
ColoredMiniStars(not_null<Ui::RpWidget*> parent, bool optimizeUpdate);
|
||||
ColoredMiniStars(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
bool optimizeUpdate,
|
||||
MiniStars::Type type = MiniStars::Type::MonoStars);
|
||||
|
||||
void setSize(const QSize &size);
|
||||
void setPosition(QPoint position);
|
||||
|
|
|
@ -174,7 +174,7 @@ TopBar::TopBar(
|
|||
, _titleFont(st.titleFont)
|
||||
, _titlePadding(st.titlePadding)
|
||||
, _about(this, std::move(descriptor.about), st.about)
|
||||
, _ministars(this, descriptor.optimizeMinistars) {
|
||||
, _ministars(this, descriptor.optimizeMinistars, MiniStars::Type::BiStars) {
|
||||
std::move(
|
||||
descriptor.title
|
||||
) | rpl::start_with_next([=](QString text) {
|
||||
|
|
Loading…
Add table
Reference in a new issue