selects correct image when scaling emotes
This commit is contained in:
@@ -97,19 +97,10 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElem
|
||||
return;
|
||||
}
|
||||
|
||||
int quality = getApp()->settings->preferredEmoteQuality;
|
||||
Image *_image = this->data.getImage(container.getScale());
|
||||
|
||||
Image *_image;
|
||||
if (quality == 3 && this->data.image3x != nullptr) {
|
||||
_image = this->data.image3x;
|
||||
} else if (quality >= 2 && this->data.image2x != nullptr) {
|
||||
_image = this->data.image2x;
|
||||
} else {
|
||||
_image = this->data.image1x;
|
||||
}
|
||||
|
||||
QSize size((int)(container.getScale() * _image->getScaledWidth()),
|
||||
(int)(container.getScale() * _image->getScaledHeight()));
|
||||
QSize size(int(container.getScale() * _image->getScaledWidth()),
|
||||
int(container.getScale() * _image->getScaledHeight()));
|
||||
|
||||
container.addElement(
|
||||
(new ImageLayoutElement(*this, _image, size))->setLink(this->getLink()));
|
||||
|
||||
@@ -42,7 +42,10 @@ void SettingManager::initialize()
|
||||
app->windows->layoutVisibleChatWidgets();
|
||||
});
|
||||
|
||||
this->emoteScale.connect([](auto, auto) { getApp()->windows->layoutVisibleChatWidgets(); });
|
||||
this->emoteScale.connect([](auto, auto) {
|
||||
getApp()->fonts->incGeneration();
|
||||
getApp()->windows->layoutVisibleChatWidgets();
|
||||
});
|
||||
}
|
||||
|
||||
MessageElement::Flags SettingManager::getWordFlags()
|
||||
|
||||
@@ -78,10 +78,10 @@ public:
|
||||
BoolSetting enableGifAnimations = {"/emotes/enableGifAnimations", true};
|
||||
FloatSetting emoteScale = {"/emotes/scale", 1.f};
|
||||
|
||||
// 0 = Smallest size
|
||||
// 1 = One size above 0 (usually size of 0 * 2)
|
||||
// 2 = One size above 1 (usually size of 1 * 2)
|
||||
// etc...
|
||||
// 0 = No preference
|
||||
// 1 = 1x
|
||||
// 2 = 2x
|
||||
// 3 = 3x
|
||||
IntSetting preferredEmoteQuality = {"/emotes/preferredEmoteQuality", 0};
|
||||
|
||||
/// Links
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "emotemap.hpp"
|
||||
|
||||
#include "application.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
EmoteData::EmoteData(messages::Image *_image)
|
||||
: image1x(_image)
|
||||
{
|
||||
}
|
||||
|
||||
// Emotes must have a 1x image to be valid
|
||||
bool EmoteData::isValid() const
|
||||
{
|
||||
return this->image1x != nullptr;
|
||||
}
|
||||
|
||||
messages::Image *EmoteData::getImage(float scale) const
|
||||
{
|
||||
int quality = getApp()->settings->preferredEmoteQuality;
|
||||
|
||||
if (quality == 0) {
|
||||
scale *= getApp()->settings->emoteScale.getValue();
|
||||
quality = [&] {
|
||||
if (scale <= 1)
|
||||
return 1;
|
||||
if (scale <= 2)
|
||||
return 2;
|
||||
return 3;
|
||||
}();
|
||||
}
|
||||
|
||||
messages::Image *_image;
|
||||
if (quality == 3 && this->image3x != nullptr) {
|
||||
_image = this->image3x;
|
||||
} else if (quality >= 2 && this->image2x != nullptr) {
|
||||
_image = this->image2x;
|
||||
} else {
|
||||
_image = this->image1x;
|
||||
}
|
||||
|
||||
return _image;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace chatterino
|
||||
@@ -9,16 +9,11 @@ namespace util {
|
||||
struct EmoteData {
|
||||
EmoteData() = default;
|
||||
|
||||
EmoteData(messages::Image *_image)
|
||||
: image1x(_image)
|
||||
{
|
||||
}
|
||||
EmoteData(messages::Image *_image);
|
||||
|
||||
// Emotes must have a 1x image to be valid
|
||||
bool isValid() const
|
||||
{
|
||||
return this->image1x != nullptr;
|
||||
}
|
||||
bool isValid() const;
|
||||
messages::Image *getImage(float scale) const;
|
||||
|
||||
messages::Image *image1x = nullptr;
|
||||
messages::Image *image2x = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user