mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Fixes #438 message buffers not growing on message resize
This commit is contained in:
parent
4f35d8854a
commit
783b9096c3
|
@ -22,8 +22,8 @@ namespace messages {
|
||||||
namespace layouts {
|
namespace layouts {
|
||||||
|
|
||||||
MessageLayout::MessageLayout(MessagePtr message)
|
MessageLayout::MessageLayout(MessagePtr message)
|
||||||
: m_message(message)
|
: message_(message)
|
||||||
, m_buffer(nullptr)
|
, buffer_(nullptr)
|
||||||
{
|
{
|
||||||
util::DebugCount::increase("message layout");
|
util::DebugCount::increase("message layout");
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,13 @@ MessageLayout::~MessageLayout()
|
||||||
|
|
||||||
Message *MessageLayout::getMessage()
|
Message *MessageLayout::getMessage()
|
||||||
{
|
{
|
||||||
return this->m_message.get();
|
return this->message_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Height
|
// Height
|
||||||
int MessageLayout::getHeight() const
|
int MessageLayout::getHeight() const
|
||||||
{
|
{
|
||||||
return m_container.getHeight();
|
return container_.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
|
@ -55,28 +55,28 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||||
bool layoutRequired = false;
|
bool layoutRequired = false;
|
||||||
|
|
||||||
// check if width changed
|
// check if width changed
|
||||||
bool widthChanged = width != this->m_currentLayoutWidth;
|
bool widthChanged = width != this->currentLayoutWidth_;
|
||||||
layoutRequired |= widthChanged;
|
layoutRequired |= widthChanged;
|
||||||
this->m_currentLayoutWidth = width;
|
this->currentLayoutWidth_ = width;
|
||||||
|
|
||||||
// check if emotes changed
|
// check if emotes changed
|
||||||
bool imagesChanged = this->m_emoteGeneration != app->emotes->getGeneration();
|
bool imagesChanged = this->emoteGeneration_ != app->emotes->getGeneration();
|
||||||
layoutRequired |= imagesChanged;
|
layoutRequired |= imagesChanged;
|
||||||
this->m_emoteGeneration = app->emotes->getGeneration();
|
this->emoteGeneration_ = app->emotes->getGeneration();
|
||||||
|
|
||||||
// check if text changed
|
// check if text changed
|
||||||
bool textChanged = this->m_fontGeneration != app->fonts->getGeneration();
|
bool textChanged = this->fontGeneration_ != app->fonts->getGeneration();
|
||||||
layoutRequired |= textChanged;
|
layoutRequired |= textChanged;
|
||||||
this->m_fontGeneration = app->fonts->getGeneration();
|
this->fontGeneration_ = app->fonts->getGeneration();
|
||||||
|
|
||||||
// check if work mask changed
|
// check if work mask changed
|
||||||
bool wordMaskChanged = this->m_currentWordFlags != flags; // app->settings->getWordTypeMask();
|
bool wordMaskChanged = this->currentWordFlags_ != flags; // app->settings->getWordTypeMask();
|
||||||
layoutRequired |= wordMaskChanged;
|
layoutRequired |= wordMaskChanged;
|
||||||
this->m_currentWordFlags = flags; // app->settings->getWordTypeMask();
|
this->currentWordFlags_ = flags; // app->settings->getWordTypeMask();
|
||||||
|
|
||||||
// check if timestamp format changed
|
// check if timestamp format changed
|
||||||
bool timestampFormatChanged = this->m_timestampFormat != app->settings->timestampFormat;
|
bool timestampFormatChanged = this->timestampFormat_ != app->settings->timestampFormat;
|
||||||
this->m_timestampFormat = app->settings->timestampFormat.getValue();
|
this->timestampFormat_ = app->settings->timestampFormat.getValue();
|
||||||
|
|
||||||
layoutRequired |= timestampFormatChanged;
|
layoutRequired |= timestampFormatChanged;
|
||||||
|
|
||||||
|
@ -85,14 +85,12 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||||
this->flags &= ~RequiresLayout;
|
this->flags &= ~RequiresLayout;
|
||||||
|
|
||||||
// check if dpi changed
|
// check if dpi changed
|
||||||
bool scaleChanged = this->m_scale != scale;
|
bool scaleChanged = this->scale_ != scale;
|
||||||
layoutRequired |= scaleChanged;
|
layoutRequired |= scaleChanged;
|
||||||
this->m_scale = scale;
|
this->scale_ = scale;
|
||||||
imagesChanged |= scaleChanged;
|
imagesChanged |= scaleChanged;
|
||||||
textChanged |= scaleChanged;
|
textChanged |= scaleChanged;
|
||||||
|
|
||||||
// assert(layoutRequired);
|
|
||||||
|
|
||||||
// update word sizes if needed
|
// update word sizes if needed
|
||||||
if (imagesChanged) {
|
if (imagesChanged) {
|
||||||
// this->container.updateImages();
|
// this->container.updateImages();
|
||||||
|
@ -112,7 +110,11 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int oldHeight = this->container_.getHeight();
|
||||||
this->actuallyLayout(width, flags);
|
this->actuallyLayout(width, flags);
|
||||||
|
if (this->container_.getHeight() != oldHeight) {
|
||||||
|
this->deleteBuffer();
|
||||||
|
}
|
||||||
this->invalidateBuffer();
|
this->invalidateBuffer();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -120,30 +122,30 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
|
||||||
|
|
||||||
void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
|
void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
|
||||||
{
|
{
|
||||||
auto messageFlags = this->m_message->flags.value;
|
auto messageFlags = this->message_->flags.value;
|
||||||
|
|
||||||
if (this->flags & MessageLayout::Expanded ||
|
if (this->flags & MessageLayout::Expanded ||
|
||||||
(_flags & MessageElement::ModeratorTools &&
|
(_flags & MessageElement::ModeratorTools &&
|
||||||
!(this->m_message->flags & Message::MessageFlags::Disabled))) {
|
!(this->message_->flags & Message::MessageFlags::Disabled))) {
|
||||||
messageFlags = Message::MessageFlags(messageFlags & ~Message::MessageFlags::Collapsed);
|
messageFlags = Message::MessageFlags(messageFlags & ~Message::MessageFlags::Collapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_container.begin(width, this->m_scale, messageFlags);
|
this->container_.begin(width, this->scale_, messageFlags);
|
||||||
|
|
||||||
for (const std::unique_ptr<MessageElement> &element : this->m_message->getElements()) {
|
for (const std::unique_ptr<MessageElement> &element : this->message_->getElements()) {
|
||||||
element->addToContainer(this->m_container, _flags);
|
element->addToContainer(this->container_, _flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->m_height != this->m_container.getHeight()) {
|
if (this->height_ != this->container_.getHeight()) {
|
||||||
this->deleteBuffer();
|
this->deleteBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_container.end();
|
this->container_.end();
|
||||||
this->m_height = this->m_container.getHeight();
|
this->height_ = this->container_.getHeight();
|
||||||
|
|
||||||
// collapsed state
|
// collapsed state
|
||||||
this->flags &= ~Flags::Collapsed;
|
this->flags &= ~Flags::Collapsed;
|
||||||
if (this->m_container.isCollapsed()) {
|
if (this->container_.isCollapsed()) {
|
||||||
this->flags |= Flags::Collapsed;
|
this->flags |= Flags::Collapsed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,24 +155,24 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||||
Selection &selection, bool isLastReadMessage, bool isWindowFocused)
|
Selection &selection, bool isLastReadMessage, bool isWindowFocused)
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
QPixmap *pixmap = this->m_buffer.get();
|
QPixmap *pixmap = this->buffer_.get();
|
||||||
|
|
||||||
// create new buffer if required
|
// create new buffer if required
|
||||||
if (!pixmap) {
|
if (!pixmap) {
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
pixmap = new QPixmap(int(width * painter.device()->devicePixelRatioF()),
|
pixmap = new QPixmap(int(width * painter.device()->devicePixelRatioF()),
|
||||||
int(width * painter.device()->devicePixelRatioF()));
|
int(container_.getHeight() * painter.device()->devicePixelRatioF()));
|
||||||
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
|
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
|
||||||
#else
|
#else
|
||||||
pixmap = new QPixmap(width, std::max(16, this->m_container.getHeight()));
|
pixmap = new QPixmap(width, std::max(16, this->container_.getHeight()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->m_buffer = std::shared_ptr<QPixmap>(pixmap);
|
this->buffer_ = std::shared_ptr<QPixmap>(pixmap);
|
||||||
this->m_bufferValid = false;
|
this->bufferValid_ = false;
|
||||||
util::DebugCount::increase("message drawing buffers");
|
util::DebugCount::increase("message drawing buffers");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->m_bufferValid || !selection.isEmpty()) {
|
if (!this->bufferValid_ || !selection.isEmpty()) {
|
||||||
this->updateBuffer(pixmap, messageIndex, selection);
|
this->updateBuffer(pixmap, messageIndex, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,21 +181,21 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||||
// painter.drawPixmap(0, y, this->container.width, this->container.getHeight(), *pixmap);
|
// painter.drawPixmap(0, y, this->container.width, this->container.getHeight(), *pixmap);
|
||||||
|
|
||||||
// draw gif emotes
|
// draw gif emotes
|
||||||
this->m_container.paintAnimatedElements(painter, y);
|
this->container_.paintAnimatedElements(painter, y);
|
||||||
|
|
||||||
// draw disabled
|
// draw disabled
|
||||||
if (this->m_message->flags.HasFlag(Message::Disabled)) {
|
if (this->message_->flags.HasFlag(Message::Disabled)) {
|
||||||
painter.fillRect(0, y, pixmap->width(), pixmap->height(), app->themes->messages.disabled);
|
painter.fillRect(0, y, pixmap->width(), pixmap->height(), app->themes->messages.disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw selection
|
// draw selection
|
||||||
if (!selection.isEmpty()) {
|
if (!selection.isEmpty()) {
|
||||||
this->m_container.paintSelection(painter, messageIndex, selection, y);
|
this->container_.paintSelection(painter, messageIndex, selection, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw message seperation line
|
// draw message seperation line
|
||||||
if (app->settings->seperateMessages.getValue()) {
|
if (app->settings->seperateMessages.getValue()) {
|
||||||
painter.fillRect(0, y, this->m_container.getWidth(), 1,
|
painter.fillRect(0, y, this->container_.getWidth(), 1,
|
||||||
app->themes->splits.messageSeperator);
|
app->themes->splits.messageSeperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,11 +206,11 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||||
|
|
||||||
QBrush brush(color, Qt::VerPattern);
|
QBrush brush(color, Qt::VerPattern);
|
||||||
|
|
||||||
painter.fillRect(0, y + this->m_container.getHeight() - 1, this->m_container.getWidth(), 1,
|
painter.fillRect(0, y + this->container_.getHeight() - 1, this->container_.getWidth(), 1,
|
||||||
brush);
|
brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_bufferValid = true;
|
this->bufferValid_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/)
|
void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/)
|
||||||
|
@ -221,7 +223,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
|
||||||
|
|
||||||
// draw background
|
// draw background
|
||||||
QColor backgroundColor;
|
QColor backgroundColor;
|
||||||
if (this->m_message->flags & Message::Highlighted) {
|
if (this->message_->flags & Message::Highlighted) {
|
||||||
backgroundColor = app->themes->messages.backgrounds.highlighted;
|
backgroundColor = app->themes->messages.backgrounds.highlighted;
|
||||||
} else if (app->settings->alternateMessageBackground.getValue() &&
|
} else if (app->settings->alternateMessageBackground.getValue() &&
|
||||||
this->flags & MessageLayout::AlternateBackground) {
|
this->flags & MessageLayout::AlternateBackground) {
|
||||||
|
@ -232,7 +234,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
|
||||||
painter.fillRect(buffer->rect(), backgroundColor);
|
painter.fillRect(buffer->rect(), backgroundColor);
|
||||||
|
|
||||||
// draw message
|
// draw message
|
||||||
this->m_container.paintElements(painter);
|
this->container_.paintElements(painter);
|
||||||
|
|
||||||
#ifdef FOURTF
|
#ifdef FOURTF
|
||||||
// debug
|
// debug
|
||||||
|
@ -250,15 +252,15 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
|
||||||
|
|
||||||
void MessageLayout::invalidateBuffer()
|
void MessageLayout::invalidateBuffer()
|
||||||
{
|
{
|
||||||
this->m_bufferValid = false;
|
this->bufferValid_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLayout::deleteBuffer()
|
void MessageLayout::deleteBuffer()
|
||||||
{
|
{
|
||||||
if (this->m_buffer != nullptr) {
|
if (this->buffer_ != nullptr) {
|
||||||
util::DebugCount::decrease("message drawing buffers");
|
util::DebugCount::decrease("message drawing buffers");
|
||||||
|
|
||||||
this->m_buffer = nullptr;
|
this->buffer_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +269,7 @@ void MessageLayout::deleteCache()
|
||||||
this->deleteBuffer();
|
this->deleteBuffer();
|
||||||
|
|
||||||
#ifdef XD
|
#ifdef XD
|
||||||
this->m_container.clear();
|
this->container_.clear();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,22 +282,22 @@ void MessageLayout::deleteCache()
|
||||||
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point)
|
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point)
|
||||||
{
|
{
|
||||||
// go through all words and return the first one that contains the point.
|
// go through all words and return the first one that contains the point.
|
||||||
return this->m_container.getElementAt(point);
|
return this->container_.getElementAt(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageLayout::getLastCharacterIndex() const
|
int MessageLayout::getLastCharacterIndex() const
|
||||||
{
|
{
|
||||||
return this->m_container.getLastCharacterIndex();
|
return this->container_.getLastCharacterIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageLayout::getSelectionIndex(QPoint position)
|
int MessageLayout::getSelectionIndex(QPoint position)
|
||||||
{
|
{
|
||||||
return this->m_container.getSelectionIndex(position);
|
return this->container_.getSelectionIndex(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLayout::addSelectionText(QString &str, int from, int to)
|
void MessageLayout::addSelectionText(QString &str, int from, int to)
|
||||||
{
|
{
|
||||||
this->m_container.addSelectionText(str, from, to);
|
this->container_.addSelectionText(str, from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace layouts
|
} // namespace layouts
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
Expanded = 1 << 5,
|
Expanded = 1 << 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageLayout(MessagePtr m_message);
|
MessageLayout(MessagePtr message_);
|
||||||
~MessageLayout();
|
~MessageLayout();
|
||||||
|
|
||||||
Message *getMessage();
|
Message *getMessage();
|
||||||
|
@ -39,7 +39,7 @@ public:
|
||||||
util::FlagsEnum<Flags> flags;
|
util::FlagsEnum<Flags> flags;
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
bool layout(int width, float m_scale, MessageElement::Flags flags);
|
bool layout(int width, float scale_, MessageElement::Flags flags);
|
||||||
|
|
||||||
// Painting
|
// Painting
|
||||||
void paint(QPainter &painter, int width, int y, int messageIndex, Selection &selection,
|
void paint(QPainter &painter, int width, int y, int messageIndex, Selection &selection,
|
||||||
|
@ -59,23 +59,23 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// variables
|
// variables
|
||||||
MessagePtr m_message;
|
MessagePtr message_;
|
||||||
MessageLayoutContainer m_container;
|
MessageLayoutContainer container_;
|
||||||
std::shared_ptr<QPixmap> m_buffer = nullptr;
|
std::shared_ptr<QPixmap> buffer_ = nullptr;
|
||||||
bool m_bufferValid = false;
|
bool bufferValid_ = false;
|
||||||
|
|
||||||
int m_height = 0;
|
int height_ = 0;
|
||||||
|
|
||||||
int m_currentLayoutWidth = -1;
|
int currentLayoutWidth_ = -1;
|
||||||
int m_fontGeneration = -1;
|
int fontGeneration_ = -1;
|
||||||
int m_emoteGeneration = -1;
|
int emoteGeneration_ = -1;
|
||||||
QString m_timestampFormat;
|
QString timestampFormat_;
|
||||||
float m_scale = -1;
|
float scale_ = -1;
|
||||||
unsigned int m_bufferUpdatedCount = 0;
|
unsigned int bufferUpdatedCount_ = 0;
|
||||||
|
|
||||||
MessageElement::Flags m_currentWordFlags = MessageElement::None;
|
MessageElement::Flags currentWordFlags_ = MessageElement::None;
|
||||||
|
|
||||||
int m_collapsedHeight = 32;
|
int collapsedHeight_ = 32;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
void actuallyLayout(int width, MessageElement::Flags flags);
|
void actuallyLayout(int width, MessageElement::Flags flags);
|
||||||
|
|
|
@ -475,8 +475,6 @@ void MessageLayoutContainer::addSelectionText(QString &str, int from, int to)
|
||||||
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements) {
|
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements) {
|
||||||
int c = ele->getSelectionIndexCount();
|
int c = ele->getSelectionIndexCount();
|
||||||
|
|
||||||
qDebug() << c;
|
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
if (index + c > from) {
|
if (index + c > from) {
|
||||||
ele->addCopyTextToString(str, from - index, to - index);
|
ele->addCopyTextToString(str, from - index, to - index);
|
||||||
|
|
|
@ -190,8 +190,6 @@ bool TwitchChannel::isBroadcaster()
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
||||||
qDebug() << "ASD" << (this->name == app->accounts->twitch.getCurrent()->getUserName());
|
|
||||||
|
|
||||||
return this->name == app->accounts->twitch.getCurrent()->getUserName();
|
return this->name == app->accounts->twitch.getCurrent()->getUserName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue