2021-08-26 13:25:48 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "base/timer.h"
|
|
|
|
#include "base/weak_ptr.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
2021-08-26 15:02:21 +00:00
|
|
|
|
2021-08-26 13:25:48 +00:00
|
|
|
struct BubblePattern;
|
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
struct ChatPaintContext {
|
|
|
|
not_null<const style::palette*> st;
|
|
|
|
const BubblePattern *bubblesPattern = nullptr;
|
|
|
|
QRect viewport;
|
|
|
|
QRect clip;
|
|
|
|
TextSelection selection;
|
|
|
|
crl::time now = 0;
|
|
|
|
|
|
|
|
void translate(int x, int y) {
|
|
|
|
viewport.translate(x, y);
|
|
|
|
clip.translate(x, y);
|
|
|
|
}
|
|
|
|
void translate(QPoint point) {
|
|
|
|
translate(point.x(), point.y());
|
|
|
|
}
|
|
|
|
[[nodiscard]] ChatPaintContext translated(int x, int y) const {
|
|
|
|
auto result = *this;
|
|
|
|
result.translate(x, y);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
[[nodiscard]] ChatPaintContext translated(QPoint point) const {
|
|
|
|
return translated(point.x(), point.y());
|
|
|
|
}
|
|
|
|
};
|
2021-08-26 13:25:48 +00:00
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
struct ChatThemeBackground {
|
2021-08-26 13:25:48 +00:00
|
|
|
QImage prepared;
|
|
|
|
QImage preparedForTiled;
|
2021-08-26 15:02:21 +00:00
|
|
|
QImage gradientForFill;
|
|
|
|
std::optional<QColor> colorForFill;
|
|
|
|
std::vector<QColor> colors;
|
|
|
|
float64 patternOpacity = 1.;
|
2021-08-26 13:25:48 +00:00
|
|
|
int gradientRotation = 0;
|
|
|
|
bool isPattern = false;
|
2021-08-26 15:02:21 +00:00
|
|
|
bool tile = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const ChatThemeBackground &a, const ChatThemeBackground &b);
|
|
|
|
bool operator!=(const ChatThemeBackground &a, const ChatThemeBackground &b);
|
|
|
|
|
|
|
|
struct CacheBackgroundRequest {
|
|
|
|
ChatThemeBackground background;
|
|
|
|
QSize area;
|
|
|
|
int gradientRotationAdd = 0;
|
2021-08-26 13:25:48 +00:00
|
|
|
float64 gradientProgress = 1.;
|
|
|
|
|
|
|
|
explicit operator bool() const {
|
2021-08-26 15:02:21 +00:00
|
|
|
return !background.prepared.isNull()
|
|
|
|
|| !background.gradientForFill.isNull();
|
2021-08-26 13:25:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(
|
|
|
|
const CacheBackgroundRequest &a,
|
|
|
|
const CacheBackgroundRequest &b);
|
|
|
|
bool operator!=(
|
|
|
|
const CacheBackgroundRequest &a,
|
|
|
|
const CacheBackgroundRequest &b);
|
|
|
|
|
|
|
|
struct CacheBackgroundResult {
|
|
|
|
QImage image;
|
|
|
|
QImage gradient;
|
|
|
|
QSize area;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CachedBackground {
|
|
|
|
CachedBackground() = default;
|
|
|
|
CachedBackground(CacheBackgroundResult &&result);
|
|
|
|
|
|
|
|
QPixmap pixmap;
|
|
|
|
QSize area;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BackgroundState {
|
|
|
|
CachedBackground was;
|
|
|
|
CachedBackground now;
|
|
|
|
float64 shown = 1.;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChatThemeDescriptor {
|
2021-08-26 15:02:21 +00:00
|
|
|
uint64 id = 0;
|
2021-08-26 13:25:48 +00:00
|
|
|
Fn<void(style::palette&)> preparePalette;
|
|
|
|
Fn<ChatThemeBackground()> prepareBackground;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChatTheme final : public base::has_weak_ptr {
|
|
|
|
public:
|
|
|
|
ChatTheme();
|
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
// Expected to be invoked on a background thread. Invokes callbacks there.
|
|
|
|
ChatTheme(ChatThemeDescriptor &&descriptor);
|
2021-08-26 13:25:48 +00:00
|
|
|
|
|
|
|
[[nodiscard]] uint64 key() const;
|
|
|
|
[[nodiscard]] not_null<const style::palette*> palette() const {
|
|
|
|
return _palette.get();
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
void setBackground(ChatThemeBackground &&background);
|
|
|
|
const ChatThemeBackground &background() const {
|
|
|
|
return _mutableBackground;
|
|
|
|
}
|
2021-08-26 13:25:48 +00:00
|
|
|
|
|
|
|
void setBubblesBackground(QImage image);
|
2021-08-26 15:02:21 +00:00
|
|
|
const BubblePattern *bubblesBackgroundPattern() const {
|
2021-08-26 13:25:48 +00:00
|
|
|
return _bubblesBackgroundPattern.get();
|
|
|
|
}
|
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
[[nodiscard]] ChatPaintContext preparePaintContext(
|
2021-08-26 13:25:48 +00:00
|
|
|
QRect viewport,
|
|
|
|
QRect clip);
|
|
|
|
[[nodiscard]] const BackgroundState &backgroundState(QSize area);
|
|
|
|
[[nodiscard]] rpl::producer<> repaintBackgroundRequests() const;
|
|
|
|
void rotateComplexGradientBackground();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void cacheBackground();
|
|
|
|
void cacheBackgroundNow();
|
|
|
|
void cacheBackgroundAsync(
|
|
|
|
const CacheBackgroundRequest &request,
|
|
|
|
Fn<void(CacheBackgroundResult&&)> done = nullptr);
|
|
|
|
void setCachedBackground(CacheBackgroundResult &&cached);
|
|
|
|
[[nodiscard]] CacheBackgroundRequest currentCacheRequest(
|
|
|
|
QSize area,
|
|
|
|
int addRotation = 0) const;
|
|
|
|
[[nodiscard]] bool readyForBackgroundRotation() const;
|
|
|
|
void generateNextBackgroundRotation();
|
|
|
|
|
|
|
|
uint64 _id = 0;
|
|
|
|
std::unique_ptr<style::palette> _palette;
|
2021-08-26 15:02:21 +00:00
|
|
|
ChatThemeBackground _mutableBackground;
|
2021-08-26 13:25:48 +00:00
|
|
|
BackgroundState _backgroundState;
|
2021-08-26 15:02:21 +00:00
|
|
|
Animations::Simple _backgroundFade;
|
2021-08-26 13:25:48 +00:00
|
|
|
CacheBackgroundRequest _backgroundCachingRequest;
|
|
|
|
CacheBackgroundResult _backgroundNext;
|
|
|
|
int _backgroundAddRotation = 0;
|
|
|
|
QSize _willCacheForArea;
|
|
|
|
crl::time _lastAreaChangeTime = 0;
|
|
|
|
std::optional<base::Timer> _cacheBackgroundTimer;
|
|
|
|
CachedBackground _bubblesBackground;
|
|
|
|
QImage _bubblesBackgroundPrepared;
|
2021-08-26 15:02:21 +00:00
|
|
|
std::unique_ptr<BubblePattern> _bubblesBackgroundPattern;
|
2021-08-26 13:25:48 +00:00
|
|
|
|
|
|
|
rpl::event_stream<> _repaintBackgroundRequests;
|
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
struct ChatBackgroundRects {
|
|
|
|
QRect from;
|
|
|
|
QRect to;
|
|
|
|
};
|
|
|
|
[[nodiscard]] ChatBackgroundRects ComputeChatBackgroundRects(
|
|
|
|
QSize fillSize,
|
|
|
|
QSize imageSize);
|
|
|
|
|
|
|
|
} // namespace Ui
|