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();
|
assertInGuiThread();
|
||||||
|
|
||||||
|
this->load();
|
||||||
|
|
||||||
|
return this->frames_->current();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Image::load() const
|
||||||
|
{
|
||||||
|
assertInGuiThread();
|
||||||
|
|
||||||
if (this->shouldLoad_)
|
if (this->shouldLoad_)
|
||||||
{
|
{
|
||||||
const_cast<Image *>(this)->shouldLoad_ = false;
|
const_cast<Image *>(this)->shouldLoad_ = false;
|
||||||
const_cast<Image *>(this)->load();
|
const_cast<Image *>(this)->actuallyLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->frames_->current();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal Image::scale() const
|
qreal Image::scale() const
|
||||||
|
@ -332,7 +339,7 @@ int Image::height() const
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::load()
|
void Image::actuallyLoad()
|
||||||
{
|
{
|
||||||
NetworkRequest(this->url().string)
|
NetworkRequest(this->url().string)
|
||||||
.concurrent()
|
.concurrent()
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
bool loaded() const;
|
bool loaded() const;
|
||||||
// either returns the current pixmap, or triggers loading it (lazy loading)
|
// either returns the current pixmap, or triggers loading it (lazy loading)
|
||||||
boost::optional<QPixmap> pixmapOrLoad() const;
|
boost::optional<QPixmap> pixmapOrLoad() const;
|
||||||
|
void load() const;
|
||||||
qreal scale() const;
|
qreal scale() const;
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
int width() const;
|
int width() const;
|
||||||
|
@ -72,7 +73,7 @@ private:
|
||||||
|
|
||||||
void setPixmap(const QPixmap &pixmap);
|
void setPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
void load();
|
void actuallyLoad();
|
||||||
|
|
||||||
Url url_{};
|
Url url_{};
|
||||||
qreal scale_{1};
|
qreal scale_{1};
|
||||||
|
|
|
@ -58,31 +58,36 @@ const ImagePtr &ImageSet::getImage3() const
|
||||||
return this->imageX3_;
|
return this->imageX3_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImagePtr &ImageSet::getImage(float scale) const
|
const std::shared_ptr<Image> &getImagePriv(const ImageSet &set, float scale)
|
||||||
{
|
{
|
||||||
|
scale *= getSettings()->emoteScale;
|
||||||
|
|
||||||
|
int quality = 1;
|
||||||
|
|
||||||
|
if (scale > 2.001f)
|
||||||
|
quality = 3;
|
||||||
|
else if (scale > 1.001f)
|
||||||
|
quality = 2;
|
||||||
|
|
||||||
|
if (!set.getImage3()->isEmpty() && quality == 3)
|
||||||
|
{
|
||||||
|
return set.getImage3();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!set.getImage2()->isEmpty() && quality >= 2)
|
||||||
|
{
|
||||||
|
return set.getImage2();
|
||||||
|
}
|
||||||
|
|
||||||
|
return set.getImage1();
|
||||||
|
}
|
||||||
|
|
||||||
|
const ImagePtr &ImageSet::getImageOrLoaded(float scale) const
|
||||||
|
{
|
||||||
|
auto &&result = getImagePriv(*this, scale);
|
||||||
|
|
||||||
// get best image based on scale
|
// get best image based on scale
|
||||||
auto &&result = [&]() -> const std::shared_ptr<Image> & {
|
result->load();
|
||||||
scale *= getSettings()->emoteScale;
|
|
||||||
|
|
||||||
int quality = 1;
|
|
||||||
|
|
||||||
if (scale > 2.001f)
|
|
||||||
quality = 3;
|
|
||||||
else if (scale > 1.001f)
|
|
||||||
quality = 2;
|
|
||||||
|
|
||||||
if (!this->imageX3_->isEmpty() && quality == 3)
|
|
||||||
{
|
|
||||||
return this->imageX3_;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->imageX2_->isEmpty() && quality == 2)
|
|
||||||
{
|
|
||||||
return this->imageX2_;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this->imageX1_;
|
|
||||||
}();
|
|
||||||
|
|
||||||
// prefer other image if selected image is not loaded yet
|
// prefer other image if selected image is not loaded yet
|
||||||
if (result->loaded())
|
if (result->loaded())
|
||||||
|
@ -99,6 +104,11 @@ const ImagePtr &ImageSet::getImage(float scale) const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ImagePtr &ImageSet::getImage(float scale) const
|
||||||
|
{
|
||||||
|
return getImagePriv(*this, scale);
|
||||||
|
}
|
||||||
|
|
||||||
bool ImageSet::operator==(const ImageSet &other) const
|
bool ImageSet::operator==(const ImageSet &other) const
|
||||||
{
|
{
|
||||||
return std::tie(this->imageX1_, this->imageX2_, this->imageX3_) ==
|
return std::tie(this->imageX1_, this->imageX2_, this->imageX3_) ==
|
||||||
|
|
|
@ -19,6 +19,9 @@ public:
|
||||||
const ImagePtr &getImage2() const;
|
const ImagePtr &getImage2() const;
|
||||||
const ImagePtr &getImage3() 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;
|
const ImagePtr &getImage(float scale) const;
|
||||||
|
|
||||||
bool operator==(const ImageSet &other) const;
|
bool operator==(const ImageSet &other) const;
|
||||||
|
|
|
@ -134,7 +134,8 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container,
|
||||||
{
|
{
|
||||||
if (flags.has(MessageElementFlag::EmoteImages))
|
if (flags.has(MessageElementFlag::EmoteImages))
|
||||||
{
|
{
|
||||||
auto image = this->emote_->images.getImage(container.getScale());
|
auto image =
|
||||||
|
this->emote_->images.getImageOrLoaded(container.getScale());
|
||||||
if (image->isEmpty())
|
if (image->isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -171,7 +172,8 @@ void BadgeElement::addToContainer(MessageLayoutContainer &container,
|
||||||
{
|
{
|
||||||
if (flags.hasAny(this->getFlags()))
|
if (flags.hasAny(this->getFlags()))
|
||||||
{
|
{
|
||||||
auto image = this->emote_->images.getImage(container.getScale());
|
auto image =
|
||||||
|
this->emote_->images.getImageOrLoaded(container.getScale());
|
||||||
if (image->isEmpty())
|
if (image->isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue