mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Support custom emoji in IsolatedEmoji.
This commit is contained in:
@@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/text/text_block.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_chat.h"
|
||||
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
@@ -36,7 +37,8 @@ using SizeTag = CustomEmojiManager::SizeTag;
|
||||
using LottieSize = ChatHelpers::StickerLottieSize;
|
||||
switch (tag) {
|
||||
case SizeTag::Normal: return LottieSize::MessageHistory;
|
||||
case SizeTag::Large: return LottieSize::EmojiInteraction;
|
||||
case SizeTag::Large: return LottieSize::StickersPanel;
|
||||
case SizeTag::Isolated: return LottieSize::EmojiInteraction;
|
||||
}
|
||||
Unexpected("SizeTag value in CustomEmojiManager-LottieSizeFromTag.");
|
||||
}
|
||||
@@ -45,6 +47,9 @@ using SizeTag = CustomEmojiManager::SizeTag;
|
||||
switch (tag) {
|
||||
case SizeTag::Normal: return Ui::Emoji::GetSizeNormal();
|
||||
case SizeTag::Large: return Ui::Emoji::GetSizeLarge();
|
||||
case SizeTag::Isolated:
|
||||
return (st::largeEmojiSize + 2 * st::largeEmojiOutline)
|
||||
* style::DevicePixelRatio();
|
||||
}
|
||||
Unexpected("SizeTag value in CustomEmojiManager-SizeFromTag.");
|
||||
}
|
||||
@@ -396,20 +401,25 @@ std::unique_ptr<Ui::Text::CustomEmoji> CustomEmojiManager::create(
|
||||
Ui::CustomEmoji::Preview CustomEmojiManager::prepareNonExactPreview(
|
||||
DocumentId documentId,
|
||||
SizeTag tag) const {
|
||||
const auto &other = _instances[1 - SizeIndex(tag)];
|
||||
const auto j = other.find(documentId);
|
||||
if (j == end(other)) {
|
||||
return {};
|
||||
} else if (const auto nonExact = j->second->imagePreview()) {
|
||||
const auto size = SizeFromTag(tag);
|
||||
return {
|
||||
nonExact.image().scaled(
|
||||
size,
|
||||
size,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation),
|
||||
false,
|
||||
};
|
||||
for (auto i = _instances.size(); i != 0;) {
|
||||
if (SizeIndex(tag) == --i) {
|
||||
continue;
|
||||
}
|
||||
const auto &other = _instances[i];
|
||||
const auto j = other.find(documentId);
|
||||
if (j == end(other)) {
|
||||
continue;
|
||||
} else if (const auto nonExact = j->second->imagePreview()) {
|
||||
const auto size = SizeFromTag(tag);
|
||||
return {
|
||||
nonExact.image().scaled(
|
||||
size,
|
||||
size,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation),
|
||||
false,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -535,7 +545,7 @@ void CustomEmojiManager::requestSetFor(not_null<DocumentData*> document) {
|
||||
int CustomEmojiManager::SizeIndex(SizeTag tag) {
|
||||
const auto result = static_cast<int>(tag);
|
||||
|
||||
Ensures(result >= 0 && result < 2);
|
||||
Ensures(result >= 0 && result < kSizeCount);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,9 @@ public:
|
||||
enum class SizeTag {
|
||||
Normal,
|
||||
Large,
|
||||
Isolated,
|
||||
|
||||
kCount,
|
||||
};
|
||||
|
||||
CustomEmojiManager(not_null<Session*> owner);
|
||||
@@ -64,6 +67,8 @@ public:
|
||||
[[nodiscard]] Session &owner() const;
|
||||
|
||||
private:
|
||||
static constexpr auto kSizeCount = int(SizeTag::kCount);
|
||||
|
||||
struct RepaintBunch {
|
||||
crl::time when = 0;
|
||||
std::vector<base::weak_ptr<Ui::CustomEmoji::Instance>> instances;
|
||||
@@ -91,12 +96,16 @@ private:
|
||||
|
||||
const not_null<Session*> _owner;
|
||||
|
||||
base::flat_map<
|
||||
uint64,
|
||||
std::unique_ptr<Ui::CustomEmoji::Instance>> _instances[2];
|
||||
base::flat_map<
|
||||
uint64,
|
||||
std::vector<base::weak_ptr<CustomEmojiLoader>>> _loaders[2];
|
||||
std::array<
|
||||
base::flat_map<
|
||||
uint64,
|
||||
std::unique_ptr<Ui::CustomEmoji::Instance>>,
|
||||
kSizeCount> _instances;
|
||||
std::array<
|
||||
base::flat_map<
|
||||
uint64,
|
||||
std::vector<base::weak_ptr<CustomEmojiLoader>>>,
|
||||
kSizeCount> _loaders;
|
||||
base::flat_set<uint64> _pendingForRequest;
|
||||
mtpRequestId _requestId = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user