Add storyAreaPosition.corner_radius_percentage.

This commit is contained in:
levlam 2024-06-16 22:00:48 +03:00
parent 315ee9b1d1
commit 442484d2d5
5 changed files with 31 additions and 11 deletions

View File

@ -3877,7 +3877,8 @@ emojiCategoryTypeChatPhoto = EmojiCategoryType;
//@width_percentage The width of the rectangle, as a percentage of the media width //@width_percentage The width of the rectangle, as a percentage of the media width
//@height_percentage The height of the rectangle, as a percentage of the media height //@height_percentage The height of the rectangle, as a percentage of the media height
//@rotation_angle Clockwise rotation angle of the rectangle, in degrees; 0-360 //@rotation_angle Clockwise rotation angle of the rectangle, in degrees; 0-360
storyAreaPosition x_percentage:double y_percentage:double width_percentage:double height_percentage:double rotation_angle:double = StoryAreaPosition; //@corner_radius_percentage The radius of the rectangle corner rounding, as a percentage of the media width
storyAreaPosition x_percentage:double y_percentage:double width_percentage:double height_percentage:double rotation_angle:double corner_radius_percentage:double = StoryAreaPosition;
//@class StoryAreaType @description Describes type of clickable rectangle area on a story media //@class StoryAreaType @description Describes type of clickable rectangle area on a story media

View File

@ -19,7 +19,7 @@ static double fix_double(double &value, double min_value = 0.0, double max_value
return clamp(value, min_value, max_value); return clamp(value, min_value, max_value);
} }
void MediaAreaCoordinates::init(double x, double y, double width, double height, double rotation_angle) { void MediaAreaCoordinates::init(double x, double y, double width, double height, double rotation_angle, double radius) {
x_ = fix_double(x); x_ = fix_double(x);
y_ = fix_double(y); y_ = fix_double(y);
width_ = fix_double(width); width_ = fix_double(width);
@ -28,6 +28,7 @@ void MediaAreaCoordinates::init(double x, double y, double width, double height,
if (rotation_angle_ < 0) { if (rotation_angle_ < 0) {
rotation_angle_ += 360.0; rotation_angle_ += 360.0;
} }
radius_ = fix_double(radius);
} }
MediaAreaCoordinates::MediaAreaCoordinates( MediaAreaCoordinates::MediaAreaCoordinates(
@ -35,7 +36,8 @@ MediaAreaCoordinates::MediaAreaCoordinates(
if (coordinates == nullptr) { if (coordinates == nullptr) {
return; return;
} }
init(coordinates->x_, coordinates->y_, coordinates->w_, coordinates->h_, coordinates->rotation_); init(coordinates->x_, coordinates->y_, coordinates->w_, coordinates->h_, coordinates->rotation_,
coordinates->radius_);
} }
MediaAreaCoordinates::MediaAreaCoordinates(const td_api::object_ptr<td_api::storyAreaPosition> &position) { MediaAreaCoordinates::MediaAreaCoordinates(const td_api::object_ptr<td_api::storyAreaPosition> &position) {
@ -44,24 +46,29 @@ MediaAreaCoordinates::MediaAreaCoordinates(const td_api::object_ptr<td_api::stor
} }
init(position->x_percentage_, position->y_percentage_, position->width_percentage_, position->height_percentage_, init(position->x_percentage_, position->y_percentage_, position->width_percentage_, position->height_percentage_,
position->rotation_angle_); position->rotation_angle_, position->corner_radius_percentage_);
} }
td_api::object_ptr<td_api::storyAreaPosition> MediaAreaCoordinates::get_story_area_position_object() const { td_api::object_ptr<td_api::storyAreaPosition> MediaAreaCoordinates::get_story_area_position_object() const {
CHECK(is_valid()); CHECK(is_valid());
return td_api::make_object<td_api::storyAreaPosition>(x_, y_, width_, height_, rotation_angle_); return td_api::make_object<td_api::storyAreaPosition>(x_, y_, width_, height_, rotation_angle_, radius_);
} }
telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> MediaAreaCoordinates::get_input_media_area_coordinates() telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> MediaAreaCoordinates::get_input_media_area_coordinates()
const { const {
CHECK(is_valid()); CHECK(is_valid());
return telegram_api::make_object<telegram_api::mediaAreaCoordinates>(0, x_, y_, width_, height_, rotation_angle_, 0.0); int32 flags = 0;
if (radius_ > 0) {
flags |= telegram_api::mediaAreaCoordinates::RADIUS_MASK;
}
return telegram_api::make_object<telegram_api::mediaAreaCoordinates>(flags, x_, y_, width_, height_, rotation_angle_,
radius_);
} }
bool operator==(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs) { bool operator==(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs) {
return std::abs(lhs.x_ - rhs.x_) < 1e-6 && std::abs(lhs.y_ - rhs.y_) < 1e-6 && return std::abs(lhs.x_ - rhs.x_) < 1e-6 && std::abs(lhs.y_ - rhs.y_) < 1e-6 &&
std::abs(lhs.width_ - rhs.width_) < 1e-6 && std::abs(lhs.height_ - rhs.height_) < 1e-6 && std::abs(lhs.width_ - rhs.width_) < 1e-6 && std::abs(lhs.height_ - rhs.height_) < 1e-6 &&
std::abs(lhs.rotation_angle_ - rhs.rotation_angle_) < 1e-6; std::abs(lhs.rotation_angle_ - rhs.rotation_angle_) < 1e-6 && std::abs(lhs.radius_ - rhs.radius_) < 1e-6;
} }
bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs) { bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs) {
@ -71,7 +78,7 @@ bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs
StringBuilder &operator<<(StringBuilder &string_builder, const MediaAreaCoordinates &coordinates) { StringBuilder &operator<<(StringBuilder &string_builder, const MediaAreaCoordinates &coordinates) {
return string_builder << "StoryAreaPosition[" << coordinates.x_ << ", " << coordinates.y_ << ", " return string_builder << "StoryAreaPosition[" << coordinates.x_ << ", " << coordinates.y_ << ", "
<< coordinates.width_ << ", " << coordinates.height_ << ", " << coordinates.rotation_angle_ << coordinates.width_ << ", " << coordinates.height_ << ", " << coordinates.rotation_angle_
<< ']'; << ", " << coordinates.radius_ << ']';
} }
} // namespace td } // namespace td

View File

@ -20,13 +20,14 @@ class MediaAreaCoordinates {
double width_ = 0.0; double width_ = 0.0;
double height_ = 0.0; double height_ = 0.0;
double rotation_angle_ = 0.0; double rotation_angle_ = 0.0;
double radius_ = 0.0;
friend bool operator==(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs); friend bool operator==(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs);
friend bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs); friend bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const MediaAreaCoordinates &coordinates); friend StringBuilder &operator<<(StringBuilder &string_builder, const MediaAreaCoordinates &coordinates);
void init(double x, double y, double width, double height, double rotation_angle); void init(double x, double y, double width, double height, double rotation_angle, double radius);
public: public:
MediaAreaCoordinates() = default; MediaAreaCoordinates() = default;

View File

@ -15,31 +15,42 @@ namespace td {
template <class StorerT> template <class StorerT>
void MediaAreaCoordinates::store(StorerT &storer) const { void MediaAreaCoordinates::store(StorerT &storer) const {
using td::store; using td::store;
bool has_radius = radius_ > 0.0;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(has_radius);
END_STORE_FLAGS(); END_STORE_FLAGS();
store(x_, storer); store(x_, storer);
store(y_, storer); store(y_, storer);
store(width_, storer); store(width_, storer);
store(height_, storer); store(height_, storer);
store(rotation_angle_, storer); store(rotation_angle_, storer);
if (has_radius) {
store(radius_, storer);
}
} }
template <class ParserT> template <class ParserT>
void MediaAreaCoordinates::parse(ParserT &parser) { void MediaAreaCoordinates::parse(ParserT &parser) {
using td::parse; using td::parse;
bool has_radius;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_radius);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
double x; double x;
double y; double y;
double width; double width;
double height; double height;
double rotation_angle; double rotation_angle;
double radius = 0.0;
parse(x, parser); parse(x, parser);
parse(y, parser); parse(y, parser);
parse(width, parser); parse(width, parser);
parse(height, parser); parse(height, parser);
parse(rotation_angle, parser); parse(rotation_angle, parser);
init(x, y, width, height, rotation_angle); if (has_radius) {
parse(radius, parser);
}
init(x, y, width, height, rotation_angle, radius);
} }
} // namespace td } // namespace td

View File

@ -1358,7 +1358,7 @@ class CliClient final : public Actor {
} }
auto position = td_api::make_object<td_api::storyAreaPosition>( auto position = td_api::make_object<td_api::storyAreaPosition>(
Random::fast(1, 99) * 0.01, Random::fast(1, 99) * 0.01, Random::fast(1, 99) * 0.01, Random::fast(1, 99) * 0.01, Random::fast(1, 99) * 0.01, Random::fast(1, 99) * 0.01,
Random::fast(1, 99) * 0.01, Random::fast(0, 360)); Random::fast(1, 99) * 0.01, Random::fast(0, 360), Random::fast(1, 19) * 0.01);
td_api::object_ptr<td_api::InputStoryAreaType> type; td_api::object_ptr<td_api::InputStoryAreaType> type;
if (area == "l") { if (area == "l") {
type = td_api::make_object<td_api::inputStoryAreaTypeLocation>( type = td_api::make_object<td_api::inputStoryAreaTypeLocation>(