Add td_api::storyAreaPosition.

This commit is contained in:
levlam 2023-08-01 14:20:42 +03:00
parent d65f9ad5f3
commit 92f69a228d
5 changed files with 190 additions and 0 deletions

View File

@ -386,6 +386,7 @@ set(TDLIB_SOURCE
td/telegram/Location.cpp
td/telegram/logevent/LogEventHelper.cpp
td/telegram/Logging.cpp
td/telegram/MediaAreaCoordinates.cpp
td/telegram/MessageContent.cpp
td/telegram/MessageContentType.cpp
td/telegram/MessageDb.cpp
@ -659,6 +660,7 @@ set(TDLIB_SOURCE
td/telegram/logevent/LogEventHelper.h
td/telegram/logevent/SecretChatEvent.h
td/telegram/Logging.h
td/telegram/MediaAreaCoordinates.h
td/telegram/MessageContent.h
td/telegram/MessageContentType.h
td/telegram/MessageCopyOptions.h
@ -832,6 +834,7 @@ set(TDLIB_SOURCE
td/telegram/Game.hpp
td/telegram/InputInvoice.hpp
td/telegram/InputMessageText.hpp
td/telegram/MediaAreaCoordinates.hpp
td/telegram/MessageEntity.hpp
td/telegram/MessageExtendedMedia.hpp
td/telegram/MessageReaction.hpp

View File

@ -4907,6 +4907,15 @@ messageLink link:string is_public:Bool = MessageLink;
messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:message media_timestamp:int32 for_album:Bool = MessageLinkInfo;
//@description Describes a clickable rectangle area on a story media
//@x_percentage The abscissa of the rectangle's center, as a percentage of the media width
//@y_percentage The ordinate of the rectangle's center, as a percentage of the media height
//@width_percentage The width of the rectangle, as a percentage of the media width
//@height_percentage The ordinate of the rectangle's center, as a percentage of the media height
//@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;
//@description Describes a video file sent in a story
//@duration Duration of the video, in seconds
//@width Video width

View File

@ -0,0 +1,75 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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)
//
#include "td/telegram/MediaAreaCoordinates.h"
#include <cmath>
namespace td {
static double fix_double(double &value, double max_value = 100.0) {
if (!std::isfinite(value) || value < 0.0) {
return 0.0;
}
if (value > max_value) {
return max_value;
}
return value;
}
void MediaAreaCoordinates::init(double x, double y, double width, double height, double rotation_angle) {
x_ = fix_double(x);
y_ = fix_double(y);
width_ = fix_double(width);
height_ = fix_double(height);
rotation_angle_ = fix_double(rotation_angle, 360.0);
}
MediaAreaCoordinates::MediaAreaCoordinates(
const telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> &coordinates) {
if (coordinates == nullptr) {
return;
}
init(coordinates->x_, coordinates->y_, coordinates->w_, coordinates->h_, coordinates->rotation_);
}
MediaAreaCoordinates::MediaAreaCoordinates(const td_api::object_ptr<td_api::storyAreaPosition> &position) {
if (position == nullptr) {
return;
}
init(position->x_percentage_, position->y_percentage_, position->width_percentage_, position->height_percentage_,
position->rotation_angle_);
}
td_api::object_ptr<td_api::storyAreaPosition> MediaAreaCoordinates::get_story_area_position_object() const {
CHECK(is_valid());
return td_api::make_object<td_api::storyAreaPosition>(x_, y_, width_, height_, rotation_angle_);
}
telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> MediaAreaCoordinates::get_input_media_area_coordinates()
const {
CHECK(is_valid());
return telegram_api::make_object<telegram_api::mediaAreaCoordinates>(x_, y_, width_, height_, rotation_angle_);
}
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 &&
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;
}
bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const MediaAreaCoordinates &coordinates) {
return string_builder << "StoryAreaPosition[" << coordinates.x_ << ", " << coordinates.y_ << ", "
<< coordinates.width_ << ", " << coordinates.height_ << ", " << coordinates.rotation_angle_
<< ']';
}
} // namespace td

View File

@ -0,0 +1,58 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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/StringBuilder.h"
namespace td {
class MediaAreaCoordinates {
double x_ = 0.0;
double y_ = 0.0;
double width_ = 0.0;
double height_ = 0.0;
double rotation_angle_ = 0.0;
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);
void init(double x, double y, double width, double height, double rotation_angle);
public:
MediaAreaCoordinates() = default;
explicit MediaAreaCoordinates(const telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> &coordinates);
explicit MediaAreaCoordinates(const td_api::object_ptr<td_api::storyAreaPosition> &position);
td_api::object_ptr<td_api::storyAreaPosition> get_story_area_position_object() const;
telegram_api::object_ptr<telegram_api::mediaAreaCoordinates> get_input_media_area_coordinates() const;
bool is_valid() const {
return width_ > 0.0 && height_ > 0.0;
}
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
bool operator==(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs);
bool operator!=(const MediaAreaCoordinates &lhs, const MediaAreaCoordinates &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const MediaAreaCoordinates &coordinates);
} // namespace td

View File

@ -0,0 +1,45 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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/MediaAreaCoordinates.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void MediaAreaCoordinates::store(StorerT &storer) const {
using td::store;
BEGIN_STORE_FLAGS();
END_STORE_FLAGS();
store(x_, storer);
store(y_, storer);
store(width_, storer);
store(height_, storer);
store(rotation_angle_, storer);
}
template <class ParserT>
void MediaAreaCoordinates::parse(ParserT &parser) {
using td::parse;
BEGIN_PARSE_FLAGS();
END_PARSE_FLAGS();
double x;
double y;
double width;
double height;
double rotation_angle;
parse(x, parser);
parse(y, parser);
parse(width, parser);
parse(height, parser);
parse(rotation_angle, parser);
init(x, y, width, height, rotation_angle);
}
} // namespace td