Add flag backgroundTypePattern.is_inverted instead of negative intensity.
This commit is contained in:
parent
5a85c8a95b
commit
f98eeda616
@ -2688,9 +2688,10 @@ backgroundTypeWallpaper is_blurred:Bool is_moving:Bool = BackgroundType;
|
||||
|
||||
//@description A PNG or TGV (gzipped subset of SVG with MIME type "application/x-tgwallpattern") 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; -100-100. If negative, the pattern color and the filled background colors needs to be inverted
|
||||
//@intensity Intensity of the pattern when it is shown above the filled background; 0-100.
|
||||
//@is_inverted True, if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only
|
||||
//@is_moving True, if the background needs to be slightly moved when device is tilted
|
||||
backgroundTypePattern fill:BackgroundFill intensity:int32 is_moving:Bool = BackgroundType;
|
||||
backgroundTypePattern fill:BackgroundFill intensity:int32 is_inverted:Bool is_moving:Bool = BackgroundType;
|
||||
|
||||
//@description A filled background @fill Description of the background fill
|
||||
backgroundTypeFill fill:BackgroundFill = BackgroundType;
|
||||
|
@ -39,6 +39,10 @@ static bool is_valid_rotation_angle(int32 rotation_angle) {
|
||||
return 0 <= rotation_angle && rotation_angle < 360 && rotation_angle % 45 == 0;
|
||||
}
|
||||
|
||||
static bool is_valid_intensity(int32 intensity, bool allow_negative) {
|
||||
return (allow_negative ? -100 : 0) <= intensity && intensity <= 100;
|
||||
}
|
||||
|
||||
BackgroundFill::BackgroundFill(const telegram_api::wallPaperSettings *settings) {
|
||||
if (settings == nullptr) {
|
||||
return;
|
||||
@ -207,10 +211,6 @@ string BackgroundFill::get_link(bool is_first) const {
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_valid_intensity(int32 intensity) {
|
||||
return -100 <= intensity && intensity <= 100;
|
||||
}
|
||||
|
||||
bool BackgroundFill::is_dark() const {
|
||||
switch (get_type()) {
|
||||
case Type::Solid:
|
||||
@ -258,7 +258,7 @@ void BackgroundType::apply_parameters_from_link(Slice name) {
|
||||
if (!intensity_arg.empty()) {
|
||||
intensity_ = to_integer<int32>(intensity_arg);
|
||||
}
|
||||
if (!is_valid_intensity(intensity_)) {
|
||||
if (!is_valid_intensity(intensity_, true)) {
|
||||
intensity_ = 50;
|
||||
}
|
||||
|
||||
@ -345,10 +345,11 @@ Result<BackgroundType> BackgroundType::get_background_type(const td_api::Backgro
|
||||
case td_api::backgroundTypePattern::ID: {
|
||||
auto pattern_type = static_cast<const td_api::backgroundTypePattern *>(background_type);
|
||||
TRY_RESULT(background_fill, BackgroundFill::get_background_fill(pattern_type->fill_.get()));
|
||||
if (!is_valid_intensity(pattern_type->intensity_)) {
|
||||
if (!is_valid_intensity(pattern_type->intensity_, false)) {
|
||||
return Status::Error(400, "Wrong intensity value");
|
||||
}
|
||||
return BackgroundType(pattern_type->is_moving_, std::move(background_fill), pattern_type->intensity_);
|
||||
auto intensity = pattern_type->is_inverted_ ? -max(pattern_type->intensity_, 1) : pattern_type->intensity_;
|
||||
return BackgroundType(pattern_type->is_moving_, std::move(background_fill), intensity);
|
||||
}
|
||||
case td_api::backgroundTypeFill::ID: {
|
||||
auto fill_type = static_cast<const td_api::backgroundTypeFill *>(background_type);
|
||||
@ -379,7 +380,7 @@ BackgroundType::BackgroundType(bool is_fill, bool is_pattern,
|
||||
is_moving_ = (settings->flags_ & telegram_api::wallPaperSettings::MOTION_MASK) != 0;
|
||||
if ((settings->flags_ & telegram_api::wallPaperSettings::INTENSITY_MASK) != 0) {
|
||||
intensity_ = settings->intensity_;
|
||||
if (!is_valid_intensity(intensity_)) {
|
||||
if (!is_valid_intensity(intensity_, true)) {
|
||||
LOG(ERROR) << "Receive " << to_string(settings);
|
||||
intensity_ = 50;
|
||||
}
|
||||
@ -418,8 +419,8 @@ td_api::object_ptr<td_api::BackgroundType> BackgroundType::get_background_type_o
|
||||
case Type::Wallpaper:
|
||||
return td_api::make_object<td_api::backgroundTypeWallpaper>(is_blurred_, is_moving_);
|
||||
case Type::Pattern:
|
||||
return td_api::make_object<td_api::backgroundTypePattern>(fill_.get_background_fill_object(), intensity_,
|
||||
is_moving_);
|
||||
return td_api::make_object<td_api::backgroundTypePattern>(
|
||||
fill_.get_background_fill_object(), intensity_ < 0 ? -intensity_ : intensity_, intensity_ < 0, is_moving_);
|
||||
case Type::Fill:
|
||||
return td_api::make_object<td_api::backgroundTypeFill>(fill_.get_background_fill_object());
|
||||
default:
|
||||
|
@ -1534,20 +1534,22 @@ class CliClient final : public Actor {
|
||||
|
||||
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);
|
||||
return get_gradient_pattern_background(color, color, intensity, false, 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) {
|
||||
int32 intensity, bool is_inverted,
|
||||
bool is_moving) {
|
||||
return td_api::make_object<td_api::backgroundTypePattern>(get_background_fill(top_color, bottom_color), intensity,
|
||||
is_moving);
|
||||
is_inverted, is_moving);
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::BackgroundType> get_freeform_gradient_pattern_background(vector<int32> colors,
|
||||
int32 intensity,
|
||||
bool is_inverted,
|
||||
bool is_moving) {
|
||||
return td_api::make_object<td_api::backgroundTypePattern>(get_background_fill(std::move(colors)), intensity,
|
||||
is_moving);
|
||||
is_inverted, is_moving);
|
||||
}
|
||||
|
||||
static td_api::object_ptr<td_api::BackgroundType> get_solid_background(int32 color) {
|
||||
@ -2228,14 +2230,16 @@ class CliClient final : public Actor {
|
||||
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_freeform_gradient_pattern_background({0xABCDEF, 0xFEDCBA}, 49, true));
|
||||
send_get_background_url(get_freeform_gradient_pattern_background({0xABCDEF, 0x111111, 0x222222}, 49, true));
|
||||
send_get_background_url(get_gradient_pattern_background(0, 0, 0, false, false));
|
||||
send_get_background_url(get_gradient_pattern_background(0, 0, 0, true, false));
|
||||
send_get_background_url(get_gradient_pattern_background(0xFFFFFF, 0, 100, false, true));
|
||||
send_get_background_url(get_gradient_pattern_background(0xFFFFFF, 0, 100, true, true));
|
||||
send_get_background_url(get_gradient_pattern_background(0xABCDEF, 0xFEDCBA, 49, false, true));
|
||||
send_get_background_url(get_gradient_pattern_background(0, 0x1000000, 49, false, true));
|
||||
send_get_background_url(get_freeform_gradient_pattern_background({0xABCDEF, 0xFEDCBA}, 49, false, true));
|
||||
send_get_background_url(get_freeform_gradient_pattern_background({0xABCDEF, 0x111111, 0x222222}, 49, true, true));
|
||||
send_get_background_url(
|
||||
get_freeform_gradient_pattern_background({0xABCDEF, 0xFEDCBA, 0x111111, 0x222222}, 49, true));
|
||||
get_freeform_gradient_pattern_background({0xABCDEF, 0xFEDCBA, 0x111111, 0x222222}, 49, false, 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));
|
||||
@ -2260,7 +2264,7 @@ class CliClient final : public Actor {
|
||||
} else if (op == "sbggp" || op == "sbggpd") {
|
||||
send_request(td_api::make_object<td_api::setBackground>(
|
||||
td_api::make_object<td_api::inputBackgroundLocal>(as_input_file(args)),
|
||||
get_gradient_pattern_background(0xABCDEF, 0xFE, 51, false), op == "sbggpd"));
|
||||
get_gradient_pattern_background(0xABCDEF, 0xFE, 51, op == "sbggpd", false), op == "sbggpd"));
|
||||
} else if (op == "sbgs" || op == "sbgsd") {
|
||||
int32 color;
|
||||
get_args(args, color);
|
||||
|
Loading…
x
Reference in New Issue
Block a user