Add class StickerMaskPosition.
This commit is contained in:
parent
5a39bb4952
commit
6ba394fc41
@ -453,6 +453,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/SponsoredMessageManager.cpp
|
||||
td/telegram/StateManager.cpp
|
||||
td/telegram/StickerFormat.cpp
|
||||
td/telegram/StickerMaskPosition.cpp
|
||||
td/telegram/StickerPhotoSize.cpp
|
||||
td/telegram/StickersManager.cpp
|
||||
td/telegram/StickerType.cpp
|
||||
@ -727,6 +728,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/SponsoredMessageManager.h
|
||||
td/telegram/StateManager.h
|
||||
td/telegram/StickerFormat.h
|
||||
td/telegram/StickerMaskPosition.h
|
||||
td/telegram/StickerPhotoSize.h
|
||||
td/telegram/StickerSetId.h
|
||||
td/telegram/StickersManager.h
|
||||
@ -798,6 +800,7 @@ set(TDLIB_SOURCE
|
||||
td/telegram/ScopeNotificationSettings.hpp
|
||||
td/telegram/SecureValue.hpp
|
||||
td/telegram/SendCodeHelper.hpp
|
||||
td/telegram/StickerMaskPosition.hpp
|
||||
td/telegram/StickerPhotoSize.hpp
|
||||
td/telegram/StickerSetId.hpp
|
||||
td/telegram/StickersManager.hpp
|
||||
|
97
td/telegram/StickerMaskPosition.cpp
Normal file
97
td/telegram/StickerMaskPosition.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
//
|
||||
// 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/StickerMaskPosition.h"
|
||||
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
static td_api::object_ptr<td_api::MaskPoint> get_mask_point_object(int32 point) {
|
||||
switch (point) {
|
||||
case 0:
|
||||
return td_api::make_object<td_api::maskPointForehead>();
|
||||
case 1:
|
||||
return td_api::make_object<td_api::maskPointEyes>();
|
||||
case 2:
|
||||
return td_api::make_object<td_api::maskPointMouth>();
|
||||
case 3:
|
||||
return td_api::make_object<td_api::maskPointChin>();
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
StickerMaskPosition::StickerMaskPosition(const telegram_api::object_ptr<telegram_api::maskCoords> &mask_coords) {
|
||||
if (mask_coords == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32 point = mask_coords->n_;
|
||||
if (point < 0 || point > 3) {
|
||||
return;
|
||||
}
|
||||
point_ = mask_coords->n_;
|
||||
x_shift_ = mask_coords->x_;
|
||||
y_shift_ = mask_coords->y_;
|
||||
scale_ = mask_coords->zoom_;
|
||||
}
|
||||
|
||||
StickerMaskPosition::StickerMaskPosition(const td_api::object_ptr<td_api::maskPosition> &mask_position) {
|
||||
if (mask_position == nullptr || mask_position->point_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
point_ = [mask_point_id = mask_position->point_->get_id()] {
|
||||
switch (mask_point_id) {
|
||||
case td_api::maskPointForehead::ID:
|
||||
return 0;
|
||||
case td_api::maskPointEyes::ID:
|
||||
return 1;
|
||||
case td_api::maskPointMouth::ID:
|
||||
return 2;
|
||||
case td_api::maskPointChin::ID:
|
||||
return 3;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return -1;
|
||||
}
|
||||
}();
|
||||
x_shift_ = mask_position->x_shift_;
|
||||
y_shift_ = mask_position->y_shift_, scale_ = mask_position->scale_;
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::maskCoords> StickerMaskPosition::get_input_mask_coords_object() const {
|
||||
if (point_ < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return telegram_api::make_object<telegram_api::maskCoords>(point_, x_shift_, y_shift_, scale_);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::maskPosition> StickerMaskPosition::get_mask_position_object() const {
|
||||
if (point_ < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return td_api::make_object<td_api::maskPosition>(get_mask_point_object(point_), x_shift_, y_shift_, scale_);
|
||||
}
|
||||
|
||||
bool operator==(const StickerMaskPosition &lhs, const StickerMaskPosition &rhs) {
|
||||
return lhs.point_ == rhs.point_ && lhs.x_shift_ == rhs.x_shift_ && lhs.y_shift_ == rhs.y_shift_ &&
|
||||
lhs.scale_ == rhs.scale_;
|
||||
}
|
||||
|
||||
bool operator!=(const StickerMaskPosition &lhs, const StickerMaskPosition &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const StickerMaskPosition &sticker_mask_position) {
|
||||
if (sticker_mask_position.point_ < 0) {
|
||||
return string_builder << "MaskPosition[]";
|
||||
}
|
||||
return string_builder << "MaskPosition[" << sticker_mask_position.point_ << ' ' << sticker_mask_position.x_shift_
|
||||
<< ' ' << sticker_mask_position.y_shift_ << ' ' << sticker_mask_position.scale_;
|
||||
}
|
||||
|
||||
} // namespace td
|
51
td/telegram/StickerMaskPosition.h
Normal file
51
td/telegram/StickerMaskPosition.h
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// 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/Status.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class StickerMaskPosition {
|
||||
int32 point_ = -1;
|
||||
double x_shift_ = 0;
|
||||
double y_shift_ = 0;
|
||||
double scale_ = 0;
|
||||
|
||||
friend bool operator==(const StickerMaskPosition &lhs, const StickerMaskPosition &rhs);
|
||||
|
||||
friend StringBuilder &operator<<(StringBuilder &string_builder, const StickerMaskPosition &sticker_mask_position);
|
||||
|
||||
public:
|
||||
StickerMaskPosition() = default;
|
||||
|
||||
explicit StickerMaskPosition(const td_api::object_ptr<td_api::maskPosition> &mask_position);
|
||||
|
||||
explicit StickerMaskPosition(const telegram_api::object_ptr<telegram_api::maskCoords> &mask_coords);
|
||||
|
||||
telegram_api::object_ptr<telegram_api::maskCoords> get_input_mask_coords_object() const;
|
||||
|
||||
td_api::object_ptr<td_api::maskPosition> get_mask_position_object() const;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const;
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser);
|
||||
};
|
||||
|
||||
bool operator==(const StickerMaskPosition &lhs, const StickerMaskPosition &rhs);
|
||||
bool operator!=(const StickerMaskPosition &lhs, const StickerMaskPosition &rhs);
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const StickerMaskPosition &sticker_mask_position);
|
||||
|
||||
} // namespace td
|
32
td/telegram/StickerMaskPosition.hpp
Normal file
32
td/telegram/StickerMaskPosition.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// 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/StickerMaskPosition.h"
|
||||
#include "td/telegram/StickerSetId.hpp"
|
||||
|
||||
#include "td/utils/tl_helpers.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
template <class StorerT>
|
||||
void StickerMaskPosition::store(StorerT &storer) const {
|
||||
td::store(point_, storer);
|
||||
td::store(x_shift_, storer);
|
||||
td::store(y_shift_, storer);
|
||||
td::store(scale_, storer);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void StickerMaskPosition::parse(ParserT &parser) {
|
||||
td::parse(point_, parser);
|
||||
td::parse(x_shift_, parser);
|
||||
td::parse(y_shift_, parser);
|
||||
td::parse(scale_, parser);
|
||||
}
|
||||
|
||||
} // namespace td
|
@ -1985,22 +1985,6 @@ void StickersManager::tear_down() {
|
||||
parent_.reset();
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::MaskPoint> StickersManager::get_mask_point_object(int32 point) {
|
||||
switch (point) {
|
||||
case 0:
|
||||
return td_api::make_object<td_api::maskPointForehead>();
|
||||
case 1:
|
||||
return td_api::make_object<td_api::maskPointEyes>();
|
||||
case 2:
|
||||
return td_api::make_object<td_api::maskPointMouth>();
|
||||
case 3:
|
||||
return td_api::make_object<td_api::maskPointChin>();
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
StickerType StickersManager::get_sticker_type(FileId file_id) const {
|
||||
const auto *sticker = get_sticker(file_id);
|
||||
CHECK(sticker != nullptr);
|
||||
@ -2339,14 +2323,8 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
|
||||
: nullptr;
|
||||
return td_api::make_object<td_api::stickerFullTypeRegular>(std::move(premium_animation_object));
|
||||
}
|
||||
case StickerType::Mask: {
|
||||
td_api::object_ptr<td_api::maskPosition> mask_position;
|
||||
if (sticker->point_ >= 0) {
|
||||
mask_position = td_api::make_object<td_api::maskPosition>(
|
||||
get_mask_point_object(sticker->point_), sticker->x_shift_, sticker->y_shift_, sticker->scale_);
|
||||
}
|
||||
return td_api::make_object<td_api::stickerFullTypeMask>(std::move(mask_position));
|
||||
}
|
||||
case StickerType::Mask:
|
||||
return td_api::make_object<td_api::stickerFullTypeMask>(sticker->mask_position_.get_mask_position_object());
|
||||
case StickerType::CustomEmoji:
|
||||
return td_api::make_object<td_api::stickerFullTypeCustomEmoji>(get_custom_emoji_id(sticker->file_id_).get(),
|
||||
sticker->has_text_color_);
|
||||
@ -2893,11 +2871,8 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
s->type_ = new_sticker->type_;
|
||||
is_changed = true;
|
||||
}
|
||||
if (s->point_ != new_sticker->point_ && new_sticker->point_ != -1) {
|
||||
s->point_ = new_sticker->point_;
|
||||
s->x_shift_ = new_sticker->x_shift_;
|
||||
s->y_shift_ = new_sticker->y_shift_;
|
||||
s->scale_ = new_sticker->scale_;
|
||||
if (s->mask_position_ != new_sticker->mask_position_) {
|
||||
s->mask_position_ = new_sticker->mask_position_;
|
||||
is_changed = true;
|
||||
}
|
||||
if (s->emoji_receive_date_ < new_sticker->emoji_receive_date_) {
|
||||
@ -3399,16 +3374,7 @@ void StickersManager::create_sticker(FileId file_id, FileId premium_animation_fi
|
||||
if ((sticker->flags_ & telegram_api::documentAttributeSticker::MASK_MASK) != 0) {
|
||||
s->type_ = StickerType::Mask;
|
||||
}
|
||||
if ((sticker->flags_ & telegram_api::documentAttributeSticker::MASK_COORDS_MASK) != 0) {
|
||||
CHECK(sticker->mask_coords_ != nullptr);
|
||||
int32 point = sticker->mask_coords_->n_;
|
||||
if (0 <= point && point <= 3) {
|
||||
s->point_ = sticker->mask_coords_->n_;
|
||||
s->x_shift_ = sticker->mask_coords_->x_;
|
||||
s->y_shift_ = sticker->mask_coords_->y_;
|
||||
s->scale_ = sticker->mask_coords_->zoom_;
|
||||
}
|
||||
}
|
||||
s->mask_position_ = StickerMaskPosition(sticker->mask_coords_);
|
||||
} else if (custom_emoji != nullptr) {
|
||||
s->set_id_ = on_get_input_sticker_set(file_id, std::move(custom_emoji->stickerset_), load_data_multipromise_ptr);
|
||||
s->alt_ = std::move(custom_emoji->alt_);
|
||||
@ -7984,29 +7950,9 @@ tl_object_ptr<telegram_api::inputStickerSetItem> StickersManager::get_input_stic
|
||||
CHECK(file_view.has_remote_location());
|
||||
auto input_document = file_view.main_remote_location().as_input_document();
|
||||
|
||||
tl_object_ptr<telegram_api::maskCoords> mask_coords;
|
||||
auto mask_position = sticker->mask_position_.get();
|
||||
if (mask_position != nullptr && mask_position->point_ != nullptr) {
|
||||
auto point = [mask_point_id = mask_position->point_->get_id()] {
|
||||
switch (mask_point_id) {
|
||||
case td_api::maskPointForehead::ID:
|
||||
return 0;
|
||||
case td_api::maskPointEyes::ID:
|
||||
return 1;
|
||||
case td_api::maskPointMouth::ID:
|
||||
return 2;
|
||||
case td_api::maskPointChin::ID:
|
||||
return 3;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return -1;
|
||||
}
|
||||
}();
|
||||
mask_coords = make_tl_object<telegram_api::maskCoords>(point, mask_position->x_shift_, mask_position->y_shift_,
|
||||
mask_position->scale_);
|
||||
}
|
||||
|
||||
int32 flags = 0;
|
||||
|
||||
auto mask_coords = StickerMaskPosition(sticker->mask_position_).get_input_mask_coords_object();
|
||||
if (mask_coords != nullptr) {
|
||||
flags |= telegram_api::inputStickerSetItem::MASK_COORDS_MASK;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "td/telegram/SecretInputMedia.h"
|
||||
#include "td/telegram/SpecialStickerSetType.h"
|
||||
#include "td/telegram/StickerFormat.h"
|
||||
#include "td/telegram/StickerMaskPosition.h"
|
||||
#include "td/telegram/StickerSetId.h"
|
||||
#include "td/telegram/StickerType.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
@ -452,10 +453,7 @@ class StickersManager final : public Actor {
|
||||
bool has_text_color_ = false;
|
||||
bool is_from_database_ = false;
|
||||
bool is_being_reloaded_ = false;
|
||||
int32 point_ = -1;
|
||||
double x_shift_ = 0;
|
||||
double y_shift_ = 0;
|
||||
double scale_ = 0;
|
||||
StickerMaskPosition mask_position_;
|
||||
int32 emoji_receive_date_ = 0;
|
||||
};
|
||||
|
||||
@ -628,8 +626,6 @@ class StickersManager final : public Actor {
|
||||
|
||||
static double get_sticker_set_minithumbnail_zoom(const StickerSet *sticker_set);
|
||||
|
||||
static tl_object_ptr<td_api::MaskPoint> get_mask_point_object(int32 point);
|
||||
|
||||
td_api::object_ptr<td_api::thumbnail> get_sticker_set_thumbnail_object(const StickerSet *sticker_set) const;
|
||||
|
||||
tl_object_ptr<td_api::stickerSetInfo> get_sticker_set_info_object(StickerSetId sticker_set_id, size_t covers_limit,
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "td/telegram/misc.h"
|
||||
#include "td/telegram/PhotoSize.hpp"
|
||||
#include "td/telegram/StickerFormat.h"
|
||||
#include "td/telegram/StickerMaskPosition.hpp"
|
||||
#include "td/telegram/StickersManager.h"
|
||||
#include "td/telegram/Td.h"
|
||||
|
||||
@ -63,10 +64,7 @@ void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT
|
||||
store(sticker->m_thumbnail_, storer);
|
||||
store(file_id, storer);
|
||||
if (is_mask) {
|
||||
store(sticker->point_, storer);
|
||||
store(sticker->x_shift_, storer);
|
||||
store(sticker->y_shift_, storer);
|
||||
store(sticker->scale_, storer);
|
||||
store(sticker->mask_position_, storer);
|
||||
}
|
||||
if (has_minithumbnail) {
|
||||
store(sticker->minithumbnail_, storer);
|
||||
@ -149,10 +147,7 @@ FileId StickersManager::parse_sticker(bool in_sticker_set, ParserT &parser) {
|
||||
add_sticker_thumbnail(sticker.get(), thumbnail);
|
||||
parse(sticker->file_id_, parser);
|
||||
if (is_mask) {
|
||||
parse(sticker->point_, parser);
|
||||
parse(sticker->x_shift_, parser);
|
||||
parse(sticker->y_shift_, parser);
|
||||
parse(sticker->scale_, parser);
|
||||
parse(sticker->mask_position_, parser);
|
||||
}
|
||||
if (has_minithumbnail) {
|
||||
parse(sticker->minithumbnail_, parser);
|
||||
|
Loading…
Reference in New Issue
Block a user