Better scheme for BackgroundType.
GitOrigin-RevId: 01f15daff83986078b9fff55a5e3a70bab2a800b
This commit is contained in:
parent
e9bb8f2a29
commit
a1af39bc8f
@ -2096,8 +2096,13 @@ deviceTokenTizenPush reg_id:string = DeviceToken;
|
||||
pushReceiverId id:int64 = PushReceiverId;
|
||||
|
||||
|
||||
//@description Describes a gradient background @top_color A top color of the background in the RGB24 format @bottom_color A bottom color of the background in the RGB24 format
|
||||
gradientInfo top_color:int32 bottom_color:int32 = GradientInfo;
|
||||
//@class BackgroundFill @description Describes a fill of a background
|
||||
|
||||
//@description Describes a solid fill of a background @color A color of the background in the RGB24 format
|
||||
backgroundFillSolid color:int32 = BackgroundFill;
|
||||
|
||||
//@description Describes a gradient fill of a background @top_color A top color of the background in the RGB24 format @bottom_color A bottom color of the background in the RGB24 format
|
||||
backgroundFillGradient top_color:int32 bottom_color:int32 = BackgroundFill;
|
||||
|
||||
|
||||
//@class BackgroundType @description Describes a type of a background
|
||||
@ -2113,11 +2118,8 @@ backgroundTypeWallpaper is_blurred:Bool is_moving:Bool = BackgroundType;
|
||||
//@intensity Intensity of the pattern when it is shown above the main background color, 0-100
|
||||
backgroundTypePattern is_moving:Bool color:int32 intensity:int32 = BackgroundType;
|
||||
|
||||
//@description A solid background @color A color of the background in the RGB24 format
|
||||
backgroundTypeSolid color:int32 = BackgroundType;
|
||||
|
||||
//@description A gradient background @gradient Gradient description
|
||||
backgroundTypeGradient gradient:gradientInfo = BackgroundType;
|
||||
//@description A filled background @fill Background fill description
|
||||
backgroundTypeFill fill:BackgroundFill = BackgroundType;
|
||||
|
||||
|
||||
//@description Describes a chat background
|
||||
|
Binary file not shown.
@ -18,6 +18,23 @@ static string get_color_hex_string(int32 color) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static GradientInfo get_gradient_info(const td_api::BackgroundFill *fill) {
|
||||
CHECK(fill != nullptr);
|
||||
switch (fill->get_id()) {
|
||||
case td_api::backgroundFillSolid::ID: {
|
||||
auto solid = static_cast<const td_api::backgroundFillSolid *>(fill);
|
||||
return GradientInfo(solid->color_, solid->color_);
|
||||
}
|
||||
case td_api::backgroundFillGradient::ID: {
|
||||
auto gradient = static_cast<const td_api::backgroundFillGradient *>(fill);
|
||||
return GradientInfo(gradient->top_color_, gradient->bottom_color_);
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const GradientInfo &lhs, const GradientInfo &rhs) {
|
||||
return lhs.top_color == rhs.top_color && lhs.bottom_color == rhs.bottom_color;
|
||||
}
|
||||
@ -110,17 +127,12 @@ Result<BackgroundType> get_background_type(const td_api::BackgroundType *type) {
|
||||
result = BackgroundType(pattern->is_moving_, pattern->color_, pattern->intensity_);
|
||||
break;
|
||||
}
|
||||
case td_api::backgroundTypeSolid::ID: {
|
||||
auto solid = static_cast<const td_api::backgroundTypeSolid *>(type);
|
||||
result = BackgroundType(solid->color_);
|
||||
break;
|
||||
}
|
||||
case td_api::backgroundTypeGradient::ID: {
|
||||
auto gradient = static_cast<const td_api::backgroundTypeGradient *>(type);
|
||||
if (gradient->gradient_ == nullptr) {
|
||||
return Status::Error(400, "Gradient info must not be empty");
|
||||
case td_api::backgroundTypeFill::ID: {
|
||||
auto fill = static_cast<const td_api::backgroundTypeFill *>(type);
|
||||
if (fill->fill_ == nullptr) {
|
||||
return Status::Error(400, "Fill info must not be empty");
|
||||
}
|
||||
result = BackgroundType(GradientInfo(gradient->gradient_->top_color_, gradient->gradient_->bottom_color_));
|
||||
result = BackgroundType(get_gradient_info(fill->fill_.get()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -173,8 +185,15 @@ BackgroundType get_background_type(bool is_pattern,
|
||||
}
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::gradientInfo> get_gradient_info_object(const GradientInfo &gradient) {
|
||||
return td_api::make_object<td_api::gradientInfo>(gradient.top_color, gradient.bottom_color);
|
||||
static td_api::object_ptr<td_api::BackgroundFill> get_background_fill_object(int32 color) {
|
||||
return td_api::make_object<td_api::backgroundFillSolid>(color);
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::BackgroundFill> get_background_fill_object(const GradientInfo &gradient) {
|
||||
if (gradient.is_solid()) {
|
||||
return get_background_fill_object(gradient.top_color);
|
||||
}
|
||||
return td_api::make_object<td_api::backgroundFillGradient>(gradient.top_color, gradient.bottom_color);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const BackgroundType &type) {
|
||||
@ -184,9 +203,9 @@ td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const Back
|
||||
case BackgroundType::Type::Pattern:
|
||||
return td_api::make_object<td_api::backgroundTypePattern>(type.is_moving, type.color, type.intensity);
|
||||
case BackgroundType::Type::Solid:
|
||||
return td_api::make_object<td_api::backgroundTypeSolid>(type.color);
|
||||
return td_api::make_object<td_api::backgroundTypeFill>(get_background_fill_object(type.color));
|
||||
case BackgroundType::Type::Gradient:
|
||||
return td_api::make_object<td_api::backgroundTypeGradient>(get_gradient_info_object(type.gradient));
|
||||
return td_api::make_object<td_api::backgroundTypeFill>(get_background_fill_object(type.gradient));
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
|
@ -22,6 +22,10 @@ struct GradientInfo {
|
||||
GradientInfo() = default;
|
||||
GradientInfo(int32 top_color, int32 bottom_color) : top_color(top_color), bottom_color(bottom_color) {
|
||||
}
|
||||
|
||||
bool is_solid() const {
|
||||
return top_color == bottom_color;
|
||||
}
|
||||
};
|
||||
|
||||
bool operator==(const GradientInfo &lhs, const GradientInfo &rhs);
|
||||
@ -44,7 +48,8 @@ struct BackgroundType {
|
||||
}
|
||||
explicit BackgroundType(int32 color) : type(Type::Solid), color(color) {
|
||||
}
|
||||
BackgroundType(GradientInfo gradient) : type(Type::Gradient), gradient(gradient) {
|
||||
BackgroundType(GradientInfo gradient)
|
||||
: type(gradient.is_solid() ? Type::Solid : Type::Gradient), color(gradient.top_color), gradient(gradient) {
|
||||
}
|
||||
|
||||
bool is_server() const {
|
||||
|
@ -1271,9 +1271,14 @@ class CliClient final : public Actor {
|
||||
return td_api::make_object<td_api::messageSchedulingStateSendAtDate>(send_date);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::backgroundTypeGradient> get_gradient_background(int32 top_color, int32 bottom_color) {
|
||||
auto gradient_info = td_api::make_object<td_api::gradientInfo>(top_color, bottom_color);
|
||||
return td_api::make_object<td_api::backgroundTypeGradient>(std::move(gradient_info));
|
||||
td_api::object_ptr<td_api::backgroundTypeFill> get_solid_background(int32 color) {
|
||||
auto solid = td_api::make_object<td_api::backgroundFillSolid>(color);
|
||||
return td_api::make_object<td_api::backgroundTypeFill>(std::move(solid));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::backgroundTypeFill> get_gradient_background(int32 top_color, int32 bottom_color) {
|
||||
auto gradient = td_api::make_object<td_api::backgroundFillGradient>(top_color, bottom_color);
|
||||
return td_api::make_object<td_api::backgroundTypeFill>(std::move(gradient));
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::Object> execute(td_api::object_ptr<td_api::Function> f) {
|
||||
@ -2104,9 +2109,9 @@ class CliClient final : public Actor {
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, 0, 0));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(true, 0xFFFFFF, 100));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(true, 0xABCDEF, 49));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(-1));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(0xABCDEF));
|
||||
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(0x1000000));
|
||||
send_get_background_url(get_solid_background(-1));
|
||||
send_get_background_url(get_solid_background(0xABCDEF));
|
||||
send_get_background_url(get_solid_background(0x1000000));
|
||||
send_get_background_url(get_gradient_background(0xABCDEF, 0xFEDCBA));
|
||||
send_get_background_url(get_gradient_background(0, 0));
|
||||
send_get_background_url(get_gradient_background(-1, -1));
|
||||
@ -2123,8 +2128,8 @@ class CliClient final : public Actor {
|
||||
td_api::make_object<td_api::inputBackgroundLocal>(as_input_file(args)),
|
||||
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49), op == "sbgpd"));
|
||||
} else if (op == "sbgs" || op == "sbgsd") {
|
||||
send_request(td_api::make_object<td_api::setBackground>(
|
||||
nullptr, td_api::make_object<td_api::backgroundTypeSolid>(to_integer<int32>(args)), op == "sbgsd"));
|
||||
send_request(td_api::make_object<td_api::setBackground>(nullptr, get_solid_background(to_integer<int32>(args)),
|
||||
op == "sbgsd"));
|
||||
} else if (op == "sbgg" || op == "sbggd") {
|
||||
string top_color;
|
||||
string bottom_color;
|
||||
|
Reference in New Issue
Block a user