From 643486da14d93cc96ddb462554e86eced9df1085 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 28 Jan 2018 16:29:47 +0100 Subject: [PATCH] enabled compact emtoes again --- chatterino.pro | 1 - src/messages/layouts/messagelayout.cpp | 9 ++-- src/messages/layouts/messagelayout.hpp | 3 +- .../layouts/messagelayoutcontainer.cpp | 50 +++++++++++++------ .../layouts/messagelayoutcontainer.hpp | 15 ++++-- src/messages/messageelement.cpp | 18 +++---- src/widgets/helper/notebooktab.hpp | 6 +-- 7 files changed, 64 insertions(+), 38 deletions(-) diff --git a/chatterino.pro b/chatterino.pro index 5df70d4c8..5513c6d6c 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -276,7 +276,6 @@ HEADERS += \ src/widgets/settingspages/ignoreuserspage.hpp \ src/widgets/settingspages/ignoremessagespage.hpp \ src/widgets/settingspages/specialchannelspage.hpp \ - src/widgets/settingspages/keyboardsettings.hpp \ src/widgets/settingspages/keyboardsettingspage.hpp \ src/widgets/helper/titlebarbutton.hpp \ src/widgets/helper/label.hpp \ diff --git a/src/messages/layouts/messagelayout.cpp b/src/messages/layouts/messagelayout.cpp index 2253ae0f8..334bfc0c1 100644 --- a/src/messages/layouts/messagelayout.cpp +++ b/src/messages/layouts/messagelayout.cpp @@ -107,9 +107,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) void MessageLayout::actuallyLayout(int width, MessageElement::Flags flags) { - this->container.clear(); - this->container.width = width; - this->container.scale = this->scale; + this->container.begin(width, this->scale, this->message->flags.value); for (const std::unique_ptr &element : this->message->getElements()) { element->addToContainer(this->container, flags); @@ -138,7 +136,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection (int)(this->container.getHeight() * painter.device()->devicePixelRatioF())); pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF()); #else - pixmap = new QPixmap(this->container.width, std::max(16, this->container.getHeight())); + pixmap = new QPixmap(this->container.getWidth(), std::max(16, this->container.getHeight())); #endif this->buffer = std::shared_ptr(pixmap); @@ -168,7 +166,8 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection QBrush brush = QBrush(color, Qt::VerPattern); - painter.fillRect(0, y + this->container.getHeight() - 1, this->container.width, 1, brush); + painter.fillRect(0, y + this->container.getHeight() - 1, this->container.getWidth(), 1, + brush); } this->bufferValid = true; diff --git a/src/messages/layouts/messagelayout.hpp b/src/messages/layouts/messagelayout.hpp index fbd871859..a4e3079cb 100644 --- a/src/messages/layouts/messagelayout.hpp +++ b/src/messages/layouts/messagelayout.hpp @@ -15,7 +15,8 @@ namespace chatterino { namespace messages { namespace layouts { -struct MessageLayout : boost::noncopyable { +class MessageLayout : boost::noncopyable +{ public: enum Flags : uint8_t { Collapsed, RequiresBufferUpdate, RequiresLayout }; diff --git a/src/messages/layouts/messagelayoutcontainer.cpp b/src/messages/layouts/messagelayoutcontainer.cpp index dd74df637..7a236615a 100644 --- a/src/messages/layouts/messagelayoutcontainer.cpp +++ b/src/messages/layouts/messagelayoutcontainer.cpp @@ -14,8 +14,8 @@ namespace messages { namespace layouts { MessageLayoutContainer::MessageLayoutContainer() : scale(1) + , flags(Message::None) , margin(4, 8, 4, 8) - , centered(false) { this->clear(); } @@ -25,7 +25,25 @@ int MessageLayoutContainer::getHeight() const return this->height; } +int MessageLayoutContainer::getWidth() const +{ + return this->width; +} + +float MessageLayoutContainer::getScale() const +{ + return this->scale; +} + // methods +void MessageLayoutContainer::begin(int width, float _scale, Message::MessageFlags _flags) +{ + this->clear(); + this->width = width; + this->scale = this->scale; + this->flags = _flags; +} + void MessageLayoutContainer::clear() { this->elements.clear(); @@ -56,24 +74,31 @@ void MessageLayoutContainer::addElementNoLineBreak(MessageLayoutElement *element void MessageLayoutContainer::_addElement(MessageLayoutElement *element) { + // top margin if (this->elements.size() == 0) { this->currentY = this->margin.top * this->scale; } int newLineHeight = element->getRect().height(); - // fourtf: xD - // bool compactEmotes = true; - // if (compactEmotes && element->word.isImage() && word.getFlags() & - // MessageElement::EmoteImages) { - // newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale; - // } + // compact emote offset + bool isCompactEmote = !(this->flags & Message::DisableCompactEmotes) && + element->getCreator().getFlags() & MessageElement::EmoteImages; + if (isCompactEmote) { + newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale; + } + + // update line height this->lineHeight = std::max(this->lineHeight, newLineHeight); + // set move element element->setPosition(QPoint(this->currentX, this->currentY - element->getRect().height())); + + // add element this->elements.push_back(std::unique_ptr(element)); + // set current x this->currentX += element->getRect().width(); if (element->hasTrailingSpace()) { @@ -85,19 +110,16 @@ void MessageLayoutContainer::breakLine() { int xOffset = 0; - if (this->centered && this->elements.size() > 0) { + if (this->flags & Message::Centered && this->elements.size() > 0) { xOffset = (width - this->elements.at(this->elements.size() - 1)->getRect().right()) / 2; } for (size_t i = lineStart; i < this->elements.size(); i++) { MessageLayoutElement *element = this->elements.at(i).get(); - bool isCompactEmote = false; - - // fourtf: xD - // this->enableCompactEmotes && element->getWord().isImage() && - // element->getWord().getFlags() & - // MessageElement::EmoteImages; + bool isCompactEmote = + !(this->flags & Message::DisableCompactEmotes) && + (this->flags & element->getCreator().getFlags()) & MessageElement::EmoteImages; int yExtra = 0; if (isCompactEmote) { diff --git a/src/messages/layouts/messagelayoutcontainer.hpp b/src/messages/layouts/messagelayoutcontainer.hpp index d39e53fc1..9656b9b45 100644 --- a/src/messages/layouts/messagelayoutcontainer.hpp +++ b/src/messages/layouts/messagelayoutcontainer.hpp @@ -6,6 +6,7 @@ #include #include +#include "messages/message.hpp" #include "messages/selection.hpp" class QPainter; @@ -41,27 +42,28 @@ struct Margin { } }; -struct MessageLayoutContainer -{ +struct MessageLayoutContainer { public: MessageLayoutContainer(); - float scale; Margin margin; bool centered; bool enableCompactEmotes; - int width; int getHeight() const; + int getWidth() const; + float getScale() const; // methods + void begin(int width, float scale, Message::MessageFlags flags); + void finish(); + void clear(); void addElement(MessageLayoutElement *element); void addElementNoLineBreak(MessageLayoutElement *element); void breakLine(); bool atStartOfLine(); bool fitsInLine(int width); - void finish(); MessageLayoutElement *getElementAt(QPoint point); // painting @@ -87,6 +89,9 @@ private: void _addElement(MessageLayoutElement *element); // variables + float scale; + int width; + Message::MessageFlags flags; int line; int height; int currentX, currentY; diff --git a/src/messages/messageelement.cpp b/src/messages/messageelement.cpp index 7285d2721..e5d34b912 100644 --- a/src/messages/messageelement.cpp +++ b/src/messages/messageelement.cpp @@ -62,8 +62,8 @@ ImageElement::ImageElement(Image *_image, MessageElement::Flags flags) void ImageElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) { if (_flags & this->getFlags()) { - QSize size(this->image->getWidth() * this->image->getScale() * container.scale, - this->image->getHeight() * this->image->getScale() * container.scale); + QSize size(this->image->getWidth() * this->image->getScale() * container.getScale(), + this->image->getHeight() * this->image->getScale() * container.getScale()); container.addElement( (new ImageLayoutElement(*this, this->image, size))->setLink(this->getLink())); @@ -108,8 +108,8 @@ void EmoteElement::addToContainer(MessageLayoutContainer &container, MessageElem _image = this->data.image1x; } - QSize size((int)(container.scale * _image->getScaledWidth()), - (int)(container.scale * _image->getScaledHeight())); + QSize size((int)(container.getScale() * _image->getScaledWidth()), + (int)(container.getScale() * _image->getScaledHeight())); container.addElement( (new ImageLayoutElement(*this, _image, size))->setLink(this->getLink())); @@ -137,8 +137,8 @@ TextElement::TextElement(const QString &text, MessageElement::Flags flags, void TextElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) { if (_flags & this->getFlags()) { - QFontMetrics &metrics = - singletons::FontManager::getInstance().getFontMetrics(this->style, container.scale); + QFontMetrics &metrics = singletons::FontManager::getInstance().getFontMetrics( + this->style, container.getScale()); singletons::ThemeManager &themeManager = singletons::ThemeManager::ThemeManager::getInstance(); @@ -148,7 +148,7 @@ void TextElement::addToContainer(MessageLayoutContainer &container, MessageEleme themeManager.normalizeColor(color); auto e = (new TextLayoutElement(*this, text, QSize(width, metrics.height()), color, - this->style, container.scale)) + this->style, container.getScale())) ->setLink(this->getLink()); e->setTrailingSpace(trailingSpace); return e; @@ -265,7 +265,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container, MessageElement::Flags _flags) { if (_flags & MessageElement::ModeratorTools) { - QSize size((int)(container.scale * 16), (int)(container.scale * 16)); + QSize size((int)(container.getScale() * 16), (int)(container.getScale() * 16)); for (const singletons::ModerationAction &m : singletons::SettingManager::getInstance().getModerationActions()) { @@ -274,7 +274,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container, ->setLink(Link(Link::UserAction, m.getAction()))); } else { container.addElement((new TextIconLayoutElement(*this, m.getLine1(), m.getLine2(), - container.scale, size)) + container.getScale(), size)) ->setLink(Link(Link::UserAction, m.getAction()))); } } diff --git a/src/widgets/helper/notebooktab.hpp b/src/widgets/helper/notebooktab.hpp index f97171932..8cdb96567 100644 --- a/src/widgets/helper/notebooktab.hpp +++ b/src/widgets/helper/notebooktab.hpp @@ -82,9 +82,9 @@ private: QRect getXRect() { - float scale = this->getScale(); - return QRect(this->width() - static_cast(20 * scale), static_cast(4 * scale), - static_cast(16 * scale), static_cast(16 * scale)); + float s = this->getScale(); + return QRect(this->width() - static_cast(20 * s), static_cast(4 * s), + static_cast(16 * s), static_cast(16 * s)); } };