Support BackgroundFill in backgroundTypePattern.

GitOrigin-RevId: 2d8e594c4acb0380b1ebb687c3727abea09dedc7
This commit is contained in:
levlam 2019-12-22 23:02:36 +03:00
parent 68a211a368
commit 13a6973f4b
5 changed files with 71 additions and 27 deletions

View File

@ -2113,13 +2113,13 @@ backgroundFillGradient top_color:int32 bottom_color:int32 rotation_angle:int32 =
//@is_moving True, if the background needs to be slightly moved when device is rotated
backgroundTypeWallpaper is_blurred:Bool is_moving:Bool = BackgroundType;
//@description A PNG pattern to be combined with the color chosen by the user
//@description A PNG pattern to be combined with the background fill chosen by the user
//@fill Description of the background fill
//@intensity Intensity of the pattern when it is shown above the filled background, 0-100
//@is_moving True, if the background needs to be slightly moved when device is rotated
//@color Main color of the background in RGB24 format
//@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;
backgroundTypePattern fill:BackgroundFill intensity:int32 is_moving:Bool = BackgroundType;
//@description A filled background @fill Background fill description
//@description A filled background @fill Description of the background fill
backgroundTypeFill fill:BackgroundFill = BackgroundType;

Binary file not shown.

View File

@ -147,7 +147,10 @@ Result<BackgroundType> get_background_type(const td_api::BackgroundType *type) {
}
case td_api::backgroundTypePattern::ID: {
auto pattern = static_cast<const td_api::backgroundTypePattern *>(type);
result = BackgroundType(pattern->is_moving_, pattern->color_, pattern->intensity_);
if (pattern->fill_ == nullptr) {
return Status::Error(400, "Fill info must not be empty");
}
result = BackgroundType(pattern->is_moving_, get_background_fill(pattern->fill_.get()), pattern->intensity_);
break;
}
case td_api::backgroundTypeFill::ID: {
@ -180,12 +183,14 @@ BackgroundType get_background_type(bool is_pattern,
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings) {
bool is_blurred = false;
bool is_moving = false;
int32 color = 0;
BackgroundFill fill;
int32 intensity = 0;
if (settings) {
auto flags = settings->flags_;
is_blurred = (flags & telegram_api::wallPaperSettings::BLUR_MASK) != 0;
is_moving = (flags & telegram_api::wallPaperSettings::MOTION_MASK) != 0;
int32 color = 0;
if ((flags & telegram_api::wallPaperSettings::BACKGROUND_COLOR_MASK) != 0) {
color = settings->background_color_;
if (!is_valid_color(color)) {
@ -193,6 +198,24 @@ BackgroundType get_background_type(bool is_pattern,
color = 0;
}
}
if ((flags & telegram_api::wallPaperSettings::SECOND_BACKGROUND_COLOR_MASK) != 0) {
int32 second_color = settings->background_color_;
if (!is_valid_color(second_color)) {
LOG(ERROR) << "Receive " << to_string(settings);
second_color = 0;
}
int32 rotation_angle = settings->rotation_;
if (!BackgroundFill::is_valid_rotation_angle(rotation_angle)) {
LOG(ERROR) << "Receive " << to_string(settings);
rotation_angle = 0;
}
fill = BackgroundFill(color, second_color, rotation_angle);
} else {
fill = BackgroundFill(color);
}
if ((flags & telegram_api::wallPaperSettings::INTENSITY_MASK) != 0) {
intensity = settings->intensity_;
if (!is_valid_intensity(intensity)) {
@ -202,7 +225,7 @@ BackgroundType get_background_type(bool is_pattern,
}
}
if (is_pattern) {
return BackgroundType(is_moving, color, intensity);
return BackgroundType(is_moving, fill, intensity);
} else {
return BackgroundType(is_blurred, is_moving);
}
@ -220,7 +243,8 @@ td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const Back
case BackgroundType::Type::Wallpaper:
return td_api::make_object<td_api::backgroundTypeWallpaper>(type.is_blurred, type.is_moving);
case BackgroundType::Type::Pattern:
return td_api::make_object<td_api::backgroundTypePattern>(type.is_moving, type.fill.top_color, type.intensity);
return td_api::make_object<td_api::backgroundTypePattern>(get_background_fill_object(type.fill), type.intensity,
type.is_moving);
case BackgroundType::Type::Fill:
return td_api::make_object<td_api::backgroundTypeFill>(get_background_fill_object(type.fill));
default:

View File

@ -54,8 +54,8 @@ struct BackgroundType {
BackgroundType(bool is_blurred, bool is_moving)
: type(Type::Wallpaper), is_blurred(is_blurred), is_moving(is_moving) {
}
BackgroundType(bool is_moving, int32 color, int32 intensity)
: type(Type::Pattern), is_moving(is_moving), fill(color), intensity(intensity) {
BackgroundType(bool is_moving, const BackgroundFill &fill, int32 intensity)
: type(Type::Pattern), is_moving(is_moving), intensity(intensity), fill(fill) {
}
BackgroundType(BackgroundFill fill) : type(Type::Fill), fill(fill) {
}

View File

@ -1271,15 +1271,31 @@ class CliClient final : public Actor {
return td_api::make_object<td_api::messageSchedulingStateSendAtDate>(send_date);
}
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));
static td_api::object_ptr<td_api::BackgroundFill> get_background_fill(int32 color) {
return td_api::make_object<td_api::backgroundFillSolid>(color);
}
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, Random::fast(0, 7) * 45);
return td_api::make_object<td_api::backgroundTypeFill>(std::move(gradient));
static td_api::object_ptr<td_api::BackgroundFill> get_background_fill(int32 top_color, int32 bottom_color) {
return td_api::make_object<td_api::backgroundFillGradient>(top_color, bottom_color, Random::fast(0, 7) * 45);
}
static td_api::object_ptr<td_api::BackgroundType> get_solid_pattern_background(int32 color, int32 intensity,
bool is_moving) {
return get_gradient_pattern_background(color, color, intensity, is_moving);
}
static td_api::object_ptr<td_api::BackgroundType> get_gradient_pattern_background(int32 top_color, int32 bottom_color,
int32 intensity, bool is_moving) {
return td_api::make_object<td_api::backgroundTypePattern>(get_background_fill(top_color, bottom_color), intensity,
is_moving);
}
static td_api::object_ptr<td_api::BackgroundType> get_solid_background(int32 color) {
return td_api::make_object<td_api::backgroundTypeFill>(get_background_fill(color));
}
static td_api::object_ptr<td_api::BackgroundType> get_gradient_background(int32 top_color, int32 bottom_color) {
return td_api::make_object<td_api::backgroundTypeFill>(get_background_fill(top_color, bottom_color));
}
static td_api::object_ptr<td_api::Object> execute(td_api::object_ptr<td_api::Function> f) {
@ -2103,13 +2119,17 @@ class CliClient final : public Actor {
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(false, true));
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(true, false));
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(true, true));
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, -1, 0));
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(true, 0x1000000, 0));
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, 0, -1));
send_get_background_url(td_api::make_object<td_api::backgroundTypePattern>(false, 0, 101));
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(get_solid_pattern_background(-1, 0, false));
send_get_background_url(get_solid_pattern_background(0x1000000, 0, true));
send_get_background_url(get_solid_pattern_background(0, -1, false));
send_get_background_url(get_solid_pattern_background(0, 101, false));
send_get_background_url(get_solid_pattern_background(0, 0, false));
send_get_background_url(get_solid_pattern_background(0xFFFFFF, 100, true));
send_get_background_url(get_solid_pattern_background(0xABCDEF, 49, true));
send_get_background_url(get_gradient_pattern_background(0, 0, 0, false));
send_get_background_url(get_gradient_pattern_background(0xFFFFFF, 0, 100, true));
send_get_background_url(get_gradient_pattern_background(0xABCDEF, 0xFEDCBA, 49, true));
send_get_background_url(get_gradient_pattern_background(0, 0x1000000, 49, true));
send_get_background_url(get_solid_background(-1));
send_get_background_url(get_solid_background(0xABCDEF));
send_get_background_url(get_solid_background(0x1000000));
@ -2127,7 +2147,7 @@ class CliClient final : public Actor {
} else if (op == "sbgp" || op == "sbgpd") {
send_request(td_api::make_object<td_api::setBackground>(
td_api::make_object<td_api::inputBackgroundLocal>(as_input_file(args)),
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49), op == "sbgpd"));
get_solid_pattern_background(0xABCDEF, 49, true), op == "sbgpd"));
} else if (op == "sbgs" || op == "sbgsd") {
send_request(td_api::make_object<td_api::setBackground>(nullptr, get_solid_background(to_integer<int32>(args)),
op == "sbgsd"));
@ -2144,7 +2164,7 @@ class CliClient final : public Actor {
} else if (op == "sbgpid" || op == "sbgpidd") {
send_request(td_api::make_object<td_api::setBackground>(
td_api::make_object<td_api::inputBackgroundRemote>(to_integer<int64>(args)),
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49), op == "sbgpidd"));
get_solid_pattern_background(0xabcdef, 49, true), op == "sbgpidd"));
} else if (op == "rbg") {
send_request(td_api::make_object<td_api::removeBackground>(to_integer<int64>(args)));
} else if (op == "rbgs") {