mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
scaling emotes and badges
This commit is contained in:
parent
75627bc037
commit
65846fe1c7
6 changed files with 41 additions and 5 deletions
|
@ -240,7 +240,8 @@ int Image::getWidth() const
|
||||||
|
|
||||||
int Image::getScaledWidth() const
|
int Image::getScaledWidth() const
|
||||||
{
|
{
|
||||||
return static_cast<int>(this->getWidth() * this->scale);
|
return static_cast<int>(this->getWidth() * this->scale *
|
||||||
|
getApp()->settings->emoteScale.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Image::getHeight() const
|
int Image::getHeight() const
|
||||||
|
@ -253,7 +254,8 @@ int Image::getHeight() const
|
||||||
|
|
||||||
int Image::getScaledHeight() const
|
int Image::getScaledHeight() const
|
||||||
{
|
{
|
||||||
return static_cast<int>(this->getHeight() * this->scale);
|
return static_cast<int>(this->getHeight() * this->scale *
|
||||||
|
getApp()->settings->emoteScale.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace messages
|
} // namespace messages
|
||||||
|
|
|
@ -36,6 +36,9 @@ void MessageLayoutContainer::begin(int _width, float _scale, Message::MessageFla
|
||||||
this->width = _width;
|
this->width = _width;
|
||||||
this->scale = _scale;
|
this->scale = _scale;
|
||||||
this->flags = _flags;
|
this->flags = _flags;
|
||||||
|
auto mediumFontMetrics = getApp()->fonts->getFontMetrics(FontStyle::ChatMedium, _scale);
|
||||||
|
this->textLineHeight = mediumFontMetrics.height();
|
||||||
|
this->spaceWidth = mediumFontMetrics.width(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLayoutContainer::clear()
|
void MessageLayoutContainer::clear()
|
||||||
|
@ -129,6 +132,11 @@ void MessageLayoutContainer::breakLine()
|
||||||
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale;
|
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (element->getCreator().getFlags() & MessageElement::Badges) {
|
||||||
|
if (element->getRect().height() < this->textLineHeight) {
|
||||||
|
yExtra -= (this->textLineHeight - element->getRect().height()) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
element->setPosition(QPoint(element->getRect().x() + xOffset + this->margin.left,
|
element->setPosition(QPoint(element->getRect().x() + xOffset + this->margin.left,
|
||||||
element->getRect().y() + this->lineHeight + yExtra));
|
element->getRect().y() + this->lineHeight + yExtra));
|
||||||
}
|
}
|
||||||
|
@ -151,7 +159,7 @@ void MessageLayoutContainer::breakLine()
|
||||||
this->height = this->currentY + (this->margin.bottom * this->scale);
|
this->height = this->currentY + (this->margin.bottom * this->scale);
|
||||||
this->lineHeight = 0;
|
this->lineHeight = 0;
|
||||||
this->line++;
|
this->line++;
|
||||||
}
|
} // namespace layouts
|
||||||
|
|
||||||
bool MessageLayoutContainer::atStartOfLine()
|
bool MessageLayoutContainer::atStartOfLine()
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,6 +100,7 @@ private:
|
||||||
size_t lineStart = 0;
|
size_t lineStart = 0;
|
||||||
int lineHeight = 0;
|
int lineHeight = 0;
|
||||||
int spaceWidth = 4;
|
int spaceWidth = 4;
|
||||||
|
int textLineHeight = 0;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
|
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
|
||||||
std::vector<Line> lines;
|
std::vector<Line> lines;
|
||||||
|
|
|
@ -70,8 +70,8 @@ ImageElement::ImageElement(Image *_image, MessageElement::Flags flags)
|
||||||
void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
|
void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags)
|
||||||
{
|
{
|
||||||
if (_flags & this->getFlags()) {
|
if (_flags & this->getFlags()) {
|
||||||
QSize size(this->image->getWidth() * this->image->getScale() * container.getScale(),
|
QSize size(this->image->getScaledWidth() * this->image->getScale() * container.getScale(),
|
||||||
this->image->getHeight() * this->image->getScale() * container.getScale());
|
this->image->getScaledHeight() * this->image->getScale() * container.getScale());
|
||||||
|
|
||||||
container.addElement(
|
container.addElement(
|
||||||
(new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink()));
|
(new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink()));
|
||||||
|
|
|
@ -41,6 +41,8 @@ void SettingManager::initialize()
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
app->windows->layoutVisibleChatWidgets();
|
app->windows->layoutVisibleChatWidgets();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->emoteScale.connect([](auto, auto) { getApp()->windows->layoutVisibleChatWidgets(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageElement::Flags SettingManager::getWordFlags()
|
MessageElement::Flags SettingManager::getWordFlags()
|
||||||
|
|
|
@ -110,6 +110,29 @@ AppearancePage::AppearancePage()
|
||||||
emotes.append(this->createCheckBox("Enable emojis", app->settings->enableEmojis));
|
emotes.append(this->createCheckBox("Enable emojis", app->settings->enableEmojis));
|
||||||
emotes.append(
|
emotes.append(
|
||||||
this->createCheckBox("Enable animations", app->settings->enableGifAnimations));
|
this->createCheckBox("Enable animations", app->settings->enableGifAnimations));
|
||||||
|
|
||||||
|
auto scaleBox = emotes.emplace<QHBoxLayout>();
|
||||||
|
{
|
||||||
|
scaleBox.emplace<QLabel>("Emote scale:");
|
||||||
|
|
||||||
|
auto emoteScale = scaleBox.emplace<QSlider>(Qt::Horizontal);
|
||||||
|
emoteScale->setMinimum(5);
|
||||||
|
emoteScale->setMaximum(50);
|
||||||
|
|
||||||
|
auto scaleLabel = scaleBox.emplace<QLabel>("1.0");
|
||||||
|
scaleLabel->setFixedWidth(100);
|
||||||
|
QObject::connect(*emoteScale, &QSlider::valueChanged, [scaleLabel](int value) mutable {
|
||||||
|
float f = (float)value / 10.f;
|
||||||
|
scaleLabel->setText(QString::number(f));
|
||||||
|
|
||||||
|
getApp()->settings->emoteScale.setValue(f);
|
||||||
|
});
|
||||||
|
|
||||||
|
emoteScale->setValue(std::max<int>(
|
||||||
|
5, std::min<int>(50, (int)(app->settings->emoteScale.getValue() * 10.f))));
|
||||||
|
|
||||||
|
scaleLabel->setText(QString::number(app->settings->emoteScale.getValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layout->addStretch(1);
|
layout->addStretch(1);
|
||||||
|
|
Loading…
Reference in a new issue