2019-05-09 21:27:36 +02:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
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"
|
|
|
|
#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 {
|
|
|
|
|
2019-12-22 19:01:51 +01:00
|
|
|
struct BackgroundFill {
|
2019-12-22 02:02:39 +01:00
|
|
|
int32 top_color = 0;
|
|
|
|
int32 bottom_color = 0;
|
2019-12-22 20:32:01 +01:00
|
|
|
int32 rotation_angle = 0;
|
2019-12-22 02:02:39 +01:00
|
|
|
|
2019-12-22 19:01:51 +01:00
|
|
|
BackgroundFill() = default;
|
|
|
|
explicit BackgroundFill(int32 solid_color) : top_color(solid_color), bottom_color(solid_color) {
|
|
|
|
}
|
2019-12-22 20:32:01 +01:00
|
|
|
BackgroundFill(int32 top_color, int32 bottom_color, int32 rotation_angle)
|
|
|
|
: top_color(top_color), bottom_color(bottom_color), rotation_angle(rotation_angle) {
|
2019-12-22 02:02:39 +01:00
|
|
|
}
|
2019-12-22 18:11:54 +01:00
|
|
|
|
2021-05-20 01:21:20 +02:00
|
|
|
enum class Type : int32 { Solid, Gradient };
|
|
|
|
Type get_type() const {
|
|
|
|
if (top_color == bottom_color) {
|
|
|
|
return Type::Solid;
|
|
|
|
}
|
|
|
|
return Type::Gradient;
|
2019-12-22 18:11:54 +01:00
|
|
|
}
|
2019-12-22 20:32:01 +01:00
|
|
|
|
|
|
|
int64 get_id() const;
|
|
|
|
|
|
|
|
static bool is_valid_id(int64 id);
|
|
|
|
|
|
|
|
static bool is_valid_rotation_angle(int32 rotation_angle) {
|
|
|
|
return 0 <= rotation_angle && rotation_angle < 360 && rotation_angle % 45 == 0;
|
|
|
|
}
|
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
|
|
|
|
2019-05-09 21:27:36 +02:00
|
|
|
struct BackgroundType {
|
2019-12-22 19:01:51 +01:00
|
|
|
enum class Type : int32 { Wallpaper, Pattern, Fill };
|
|
|
|
Type type = Type::Fill;
|
2019-05-09 21:27:36 +02:00
|
|
|
bool is_blurred = false;
|
|
|
|
bool is_moving = false;
|
|
|
|
int32 intensity = 0;
|
2019-12-22 19:01:51 +01:00
|
|
|
BackgroundFill fill;
|
2019-05-09 21:27:36 +02:00
|
|
|
|
|
|
|
BackgroundType() = default;
|
|
|
|
BackgroundType(bool is_blurred, bool is_moving)
|
|
|
|
: type(Type::Wallpaper), is_blurred(is_blurred), is_moving(is_moving) {
|
|
|
|
}
|
2019-12-22 21:02:36 +01:00
|
|
|
BackgroundType(bool is_moving, const BackgroundFill &fill, int32 intensity)
|
|
|
|
: type(Type::Pattern), is_moving(is_moving), intensity(intensity), fill(fill) {
|
2019-05-09 21:27:36 +02:00
|
|
|
}
|
2019-12-23 18:48:30 +01:00
|
|
|
explicit BackgroundType(BackgroundFill fill) : type(Type::Fill), fill(fill) {
|
2019-12-21 03:28:07 +01:00
|
|
|
}
|
2019-05-10 14:36:37 +02:00
|
|
|
|
2019-12-22 02:34:39 +01:00
|
|
|
bool is_server() const {
|
|
|
|
return type == Type::Wallpaper || type == Type::Pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
string get_link() const;
|
2019-05-09 21:27:36 +02:00
|
|
|
};
|
|
|
|
|
2019-05-10 14:36:37 +02:00
|
|
|
bool operator==(const BackgroundType &lhs, const BackgroundType &rhs);
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const BackgroundType &type);
|
|
|
|
|
2019-05-09 21:27:36 +02:00
|
|
|
Result<BackgroundType> get_background_type(const td_api::BackgroundType *type);
|
|
|
|
|
|
|
|
BackgroundType get_background_type(bool is_pattern, telegram_api::object_ptr<telegram_api::wallPaperSettings> settings);
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const BackgroundType &type);
|
|
|
|
|
2019-05-10 14:36:37 +02:00
|
|
|
telegram_api::object_ptr<telegram_api::wallPaperSettings> get_input_wallpaper_settings(const BackgroundType &type);
|
|
|
|
|
2019-05-09 21:27:36 +02:00
|
|
|
} // namespace td
|