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