mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixed emote preview not using 3x images
This commit is contained in:
parent
67aadfe61f
commit
dbc20baa65
5 changed files with 53 additions and 30 deletions
|
@ -286,13 +286,20 @@ boost::optional<QPixmap> Image::pixmapOrLoad() const
|
|||
{
|
||||
assertInGuiThread();
|
||||
|
||||
this->load();
|
||||
|
||||
return this->frames_->current();
|
||||
}
|
||||
|
||||
void Image::load() const
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
if (this->shouldLoad_)
|
||||
{
|
||||
const_cast<Image *>(this)->shouldLoad_ = false;
|
||||
const_cast<Image *>(this)->load();
|
||||
const_cast<Image *>(this)->actuallyLoad();
|
||||
}
|
||||
|
||||
return this->frames_->current();
|
||||
}
|
||||
|
||||
qreal Image::scale() const
|
||||
|
@ -332,7 +339,7 @@ int Image::height() const
|
|||
return 16;
|
||||
}
|
||||
|
||||
void Image::load()
|
||||
void Image::actuallyLoad()
|
||||
{
|
||||
NetworkRequest(this->url().string)
|
||||
.concurrent()
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
bool loaded() const;
|
||||
// either returns the current pixmap, or triggers loading it (lazy loading)
|
||||
boost::optional<QPixmap> pixmapOrLoad() const;
|
||||
void load() const;
|
||||
qreal scale() const;
|
||||
bool isEmpty() const;
|
||||
int width() const;
|
||||
|
@ -72,7 +73,7 @@ private:
|
|||
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
|
||||
void load();
|
||||
void actuallyLoad();
|
||||
|
||||
Url url_{};
|
||||
qreal scale_{1};
|
||||
|
|
|
@ -58,10 +58,8 @@ const ImagePtr &ImageSet::getImage3() const
|
|||
return this->imageX3_;
|
||||
}
|
||||
|
||||
const ImagePtr &ImageSet::getImage(float scale) const
|
||||
const std::shared_ptr<Image> &getImagePriv(const ImageSet &set, float scale)
|
||||
{
|
||||
// get best image based on scale
|
||||
auto &&result = [&]() -> const std::shared_ptr<Image> & {
|
||||
scale *= getSettings()->emoteScale;
|
||||
|
||||
int quality = 1;
|
||||
|
@ -71,18 +69,25 @@ const ImagePtr &ImageSet::getImage(float scale) const
|
|||
else if (scale > 1.001f)
|
||||
quality = 2;
|
||||
|
||||
if (!this->imageX3_->isEmpty() && quality == 3)
|
||||
if (!set.getImage3()->isEmpty() && quality == 3)
|
||||
{
|
||||
return this->imageX3_;
|
||||
return set.getImage3();
|
||||
}
|
||||
|
||||
if (!this->imageX2_->isEmpty() && quality == 2)
|
||||
if (!set.getImage2()->isEmpty() && quality >= 2)
|
||||
{
|
||||
return this->imageX2_;
|
||||
return set.getImage2();
|
||||
}
|
||||
|
||||
return this->imageX1_;
|
||||
}();
|
||||
return set.getImage1();
|
||||
}
|
||||
|
||||
const ImagePtr &ImageSet::getImageOrLoaded(float scale) const
|
||||
{
|
||||
auto &&result = getImagePriv(*this, scale);
|
||||
|
||||
// get best image based on scale
|
||||
result->load();
|
||||
|
||||
// prefer other image if selected image is not loaded yet
|
||||
if (result->loaded())
|
||||
|
@ -99,6 +104,11 @@ const ImagePtr &ImageSet::getImage(float scale) const
|
|||
return result;
|
||||
}
|
||||
|
||||
const ImagePtr &ImageSet::getImage(float scale) const
|
||||
{
|
||||
return getImagePriv(*this, scale);
|
||||
}
|
||||
|
||||
bool ImageSet::operator==(const ImageSet &other) const
|
||||
{
|
||||
return std::tie(this->imageX1_, this->imageX2_, this->imageX3_) ==
|
||||
|
|
|
@ -19,6 +19,9 @@ public:
|
|||
const ImagePtr &getImage2() const;
|
||||
const ImagePtr &getImage3() const;
|
||||
|
||||
/// Preferes getting an already loaded image, even if it is smaller/bigger.
|
||||
/// However, it starts loading the proper image.
|
||||
const ImagePtr &getImageOrLoaded(float scale) const;
|
||||
const ImagePtr &getImage(float scale) const;
|
||||
|
||||
bool operator==(const ImageSet &other) const;
|
||||
|
|
|
@ -134,7 +134,8 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
|
|||
{
|
||||
if (flags.has(MessageElementFlag::EmoteImages))
|
||||
{
|
||||
auto image = this->emote_->images.getImage(container.getScale());
|
||||
auto image =
|
||||
this->emote_->images.getImageOrLoaded(container.getScale());
|
||||
if (image->isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -171,7 +172,8 @@ void BadgeElement::addToContainer(MessageLayoutContainer &container,
|
|||
{
|
||||
if (flags.hasAny(this->getFlags()))
|
||||
{
|
||||
auto image = this->emote_->images.getImage(container.getScale());
|
||||
auto image =
|
||||
this->emote_->images.getImageOrLoaded(container.getScale());
|
||||
if (image->isEmpty())
|
||||
return;
|
||||
|
||||
|
|
Loading…
Reference in a new issue