2019-05-09 21:27:36 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2019-05-09 21:27:36 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2021-06-02 14:43:56 +02:00
|
|
|
#include "td/utils/Slice.h"
|
2019-05-09 21:27:36 +02:00
|
|
|
#include "td/utils/Status.h"
|
2019-05-10 14:36:37 +02:00
|
|
|
#include "td/utils/StringBuilder.h"
|
2019-05-09 21:27:36 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2021-06-10 01:16:46 +02:00
|
|
|
class BackgroundFill {
|
2021-06-10 00:44:46 +02:00
|
|
|
int32 top_color_ = 0;
|
|
|
|
int32 bottom_color_ = 0;
|
|
|
|
int32 rotation_angle_ = 0;
|
|
|
|
int32 third_color_ = -1;
|
|
|
|
int32 fourth_color_ = -1;
|
2019-12-22 02:02:39 +01:00
|
|
|
|
2019-12-22 19:01:51 +01:00
|
|
|
BackgroundFill() = default;
|
2021-06-10 00:44:46 +02:00
|
|
|
explicit BackgroundFill(int32 solid_color) : top_color_(solid_color), bottom_color_(solid_color) {
|
2019-12-22 19:01:51 +01:00
|
|
|
}
|
2019-12-22 20:32:01 +01:00
|
|
|
BackgroundFill(int32 top_color, int32 bottom_color, int32 rotation_angle)
|
2021-06-10 00:44:46 +02:00
|
|
|
: top_color_(top_color), bottom_color_(bottom_color), rotation_angle_(rotation_angle) {
|
2024-05-02 17:42:08 +02:00
|
|
|
if (get_type() != Type::Gradient) {
|
|
|
|
rotation_angle_ = 0;
|
|
|
|
}
|
2019-12-22 02:02:39 +01:00
|
|
|
}
|
2021-05-21 00:49:59 +02:00
|
|
|
BackgroundFill(int32 first_color, int32 second_color, int32 third_color, int32 fourth_color)
|
2021-06-10 00:44:46 +02:00
|
|
|
: top_color_(first_color), bottom_color_(second_color), third_color_(third_color), fourth_color_(fourth_color) {
|
2021-05-21 00:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit BackgroundFill(const telegram_api::wallPaperSettings *settings);
|
2019-12-22 18:11:54 +01:00
|
|
|
|
2021-06-10 01:16:46 +02:00
|
|
|
static Result<BackgroundFill> get_background_fill(const td_api::BackgroundFill *fill);
|
|
|
|
|
|
|
|
string get_link(bool is_first) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::BackgroundFill> get_background_fill_object() const;
|
2021-05-21 00:49:59 +02:00
|
|
|
|
|
|
|
enum class Type : int32 { Solid, Gradient, FreeformGradient };
|
2021-05-20 01:21:20 +02:00
|
|
|
Type get_type() const {
|
2021-06-10 00:44:46 +02:00
|
|
|
if (third_color_ != -1) {
|
2021-05-21 00:49:59 +02:00
|
|
|
return Type::FreeformGradient;
|
|
|
|
}
|
2021-06-10 00:44:46 +02:00
|
|
|
if (top_color_ == bottom_color_) {
|
2021-05-20 01:21:20 +02:00
|
|
|
return Type::Solid;
|
|
|
|
}
|
|
|
|
return Type::Gradient;
|
2019-12-22 18:11:54 +01:00
|
|
|
}
|
2019-12-22 20:32:01 +01:00
|
|
|
|
2021-06-10 01:16:46 +02:00
|
|
|
friend bool operator==(const BackgroundFill &lhs, const BackgroundFill &rhs);
|
|
|
|
|
2024-05-02 17:30:21 +02:00
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundFill &fill);
|
|
|
|
|
2021-06-10 01:16:46 +02:00
|
|
|
friend class BackgroundType;
|
|
|
|
|
|
|
|
static Result<BackgroundFill> get_background_fill(Slice name);
|
|
|
|
|
2021-05-21 00:49:59 +02:00
|
|
|
bool is_dark() const;
|
2019-12-22 02:02:39 +01:00
|
|
|
};
|
|
|
|
|
2019-12-22 19:01:51 +01:00
|
|
|
bool operator==(const BackgroundFill &lhs, const BackgroundFill &rhs);
|
2019-12-22 02:34:39 +01:00
|
|
|
|
2024-05-02 17:30:21 +02:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundFill &fill);
|
|
|
|
|
2021-06-10 00:29:42 +02:00
|
|
|
class BackgroundType {
|
2023-12-19 14:00:50 +01:00
|
|
|
enum class Type : int32 { Wallpaper, Pattern, Fill, ChatTheme };
|
2021-06-10 00:44:46 +02:00
|
|
|
Type type_ = Type::Fill;
|
|
|
|
bool is_blurred_ = false;
|
|
|
|
bool is_moving_ = false;
|
|
|
|
int32 intensity_ = 0;
|
|
|
|
BackgroundFill fill_;
|
2023-12-19 14:00:50 +01:00
|
|
|
string theme_name_;
|
2019-05-09 21:27:36 +02:00
|
|
|
|
2021-06-10 00:29:42 +02:00
|
|
|
friend bool operator==(const BackgroundType &lhs, const BackgroundType &rhs);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &type);
|
|
|
|
|
2023-04-11 23:59:53 +02:00
|
|
|
BackgroundType(bool is_blurred, bool is_moving, int32 dark_theme_dimming)
|
|
|
|
: type_(Type::Wallpaper), is_blurred_(is_blurred), is_moving_(is_moving), intensity_(dark_theme_dimming) {
|
2019-05-09 21:27:36 +02:00
|
|
|
}
|
2023-04-10 17:45:26 +02:00
|
|
|
BackgroundType(bool is_moving, BackgroundFill &&fill, int32 intensity)
|
|
|
|
: type_(Type::Pattern), is_moving_(is_moving), intensity_(intensity), fill_(std::move(fill)) {
|
2019-05-09 21:27:36 +02:00
|
|
|
}
|
2023-04-11 23:59:53 +02:00
|
|
|
BackgroundType(BackgroundFill &&fill, int32 dark_theme_dimming)
|
2023-04-18 23:50:13 +02:00
|
|
|
: type_(Type::Fill), intensity_(dark_theme_dimming), fill_(std::move(fill)) {
|
2019-12-21 03:28:07 +01:00
|
|
|
}
|
2023-12-19 14:00:50 +01:00
|
|
|
explicit BackgroundType(string theme_name) : type_(Type::ChatTheme), theme_name_(std::move(theme_name)) {
|
|
|
|
}
|
2019-05-10 14:36:37 +02:00
|
|
|
|
2021-06-10 03:44:39 +02:00
|
|
|
public:
|
|
|
|
BackgroundType() = default;
|
|
|
|
|
2023-12-19 14:00:50 +01:00
|
|
|
BackgroundType(bool has_no_file, bool is_pattern, telegram_api::object_ptr<telegram_api::wallPaperSettings> settings);
|
2021-06-09 20:19:08 +02:00
|
|
|
|
2023-04-10 17:45:26 +02:00
|
|
|
static Result<BackgroundType> get_background_type(const td_api::BackgroundType *background_type,
|
2023-04-11 23:59:53 +02:00
|
|
|
int32 dark_theme_dimming);
|
2021-06-09 20:19:08 +02:00
|
|
|
|
2021-06-10 03:44:39 +02:00
|
|
|
static Result<BackgroundType> get_local_background_type(Slice name);
|
|
|
|
|
2023-03-01 14:36:34 +01:00
|
|
|
static bool is_background_name_local(Slice name);
|
|
|
|
|
2021-06-08 00:10:19 +02:00
|
|
|
bool has_file() const {
|
2021-06-10 00:44:46 +02:00
|
|
|
return type_ == Type::Wallpaper || type_ == Type::Pattern;
|
2021-06-08 00:10:19 +02:00
|
|
|
}
|
2019-12-22 02:34:39 +01:00
|
|
|
|
2023-03-01 14:36:34 +01:00
|
|
|
bool has_gradient_fill() const {
|
|
|
|
return type_ == Type::Fill && fill_.get_type() != BackgroundFill::Type::Solid;
|
|
|
|
}
|
|
|
|
|
2021-06-09 19:58:39 +02:00
|
|
|
string get_mime_type() const;
|
|
|
|
|
2021-05-26 19:17:05 +02:00
|
|
|
void apply_parameters_from_link(Slice name);
|
|
|
|
|
2023-03-01 19:26:49 +01:00
|
|
|
string get_link(bool is_first = true) const;
|
2021-06-09 20:19:08 +02:00
|
|
|
|
2021-06-10 00:29:42 +02:00
|
|
|
bool has_equal_type(const BackgroundType &other) const {
|
2021-06-10 00:44:46 +02:00
|
|
|
return type_ == other.type_;
|
2021-06-10 00:29:42 +02:00
|
|
|
}
|
|
|
|
|
2021-06-09 20:19:08 +02:00
|
|
|
td_api::object_ptr<td_api::BackgroundType> get_background_type_object() const;
|
|
|
|
|
|
|
|
telegram_api::object_ptr<telegram_api::wallPaperSettings> get_input_wallpaper_settings() const;
|
2021-06-10 00:29:42 +02:00
|
|
|
|
2021-06-10 03:44:39 +02:00
|
|
|
bool is_dark() const {
|
|
|
|
CHECK(type_ == Type::Fill);
|
|
|
|
return fill_.is_dark();
|
|
|
|
}
|
|
|
|
|
2023-04-11 23:59:53 +02:00
|
|
|
int32 get_dark_theme_dimming() const {
|
2023-04-10 17:45:26 +02:00
|
|
|
if (type_ == Type::Pattern) {
|
2023-04-11 23:59:53 +02:00
|
|
|
return 0;
|
2023-04-10 17:45:26 +02:00
|
|
|
}
|
|
|
|
return intensity_;
|
|
|
|
}
|
|
|
|
|
2021-06-10 00:29:42 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2019-05-09 21:27:36 +02:00
|
|
|
};
|
|
|
|
|
2019-05-10 14:36:37 +02:00
|
|
|
bool operator==(const BackgroundType &lhs, const BackgroundType &rhs);
|
|
|
|
|
2021-08-24 16:13:51 +02:00
|
|
|
inline bool operator!=(const BackgroundType &lhs, const BackgroundType &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
2019-05-10 14:36:37 +02:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &type);
|
|
|
|
|
2019-05-09 21:27:36 +02:00
|
|
|
} // namespace td
|