Skip to content

Commit

Permalink
Improve Appearance of Reply Curve (#4077)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsge authored Nov 2, 2022
1 parent 495f3ed commit 7640677
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unversioned

- Major: Added support for Twitch's Chat Replies. [Wiki Page](https://wiki.chatterino.com/Features/#message-replies) (#3722, #3989, #4041, #4047, #4055, #4067)
- Major: Added support for Twitch's Chat Replies. [Wiki Page](https://wiki.chatterino.com/Features/#message-replies) (#3722, #3989, #4041, #4047, #4055, #4067, #4077)
- Major: Added multi-channel searching to search dialog via keyboard shortcut. (Ctrl+Shift+F by default) (#3694, #3875)
- Major: Added support for emotes and badges from [7TV](https://7tv.app). [Wiki Page](https://wiki.chatterino.com/Third_party_services/#7tv) (#4002, #4062)
- Minor: Added highlights for `Elevated Messages`. (#4016)
Expand Down
16 changes: 9 additions & 7 deletions src/messages/MessageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,21 +678,23 @@ void ScalingImageElement::addToContainer(MessageLayoutContainer &container,

ReplyCurveElement::ReplyCurveElement()
: MessageElement(MessageElementFlag::RepliedMessage)
// these values nicely align with a single badge
, neededMargin_(3)
, size_(18, 14)
{
}

void ReplyCurveElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
static const int width = 18; // Overall width
static const float thickness = 1.5; // Pen width
static const int radius = 6; // Radius of the top left corner
static const int margin = 2; // Top/Left/Bottom margin

if (flags.hasAny(this->getFlags()))
{
QSize boxSize = this->size_ * container.getScale();
container.addElement(new ReplyCurveLayoutElement(
*this, boxSize, 1.5 * container.getScale(),
this->neededMargin_ * container.getScale()));
float scale = container.getScale();
container.addElement(
new ReplyCurveLayoutElement(*this, width * scale, thickness * scale,
radius * scale, margin * scale));
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/messages/MessageElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,6 @@ class ReplyCurveElement : public MessageElement

void addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags) override;

private:
int neededMargin_;
QSize size_;
};

} // namespace chatterino
17 changes: 3 additions & 14 deletions src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,20 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
this->currentY_ = int(this->margin.top * this->scale_);
}

int newLineHeight = element->getRect().height();
int elementLineHeight = element->getRect().height();

// compact emote offset
bool isCompactEmote =
getSettings()->compactEmotes &&
!this->flags_.has(MessageFlag::DisableCompactEmotes) &&
element->getCreator().getFlags().has(MessageElementFlag::EmoteImages);

if (isCompactEmote)
{
newLineHeight -= COMPACT_EMOTES_OFFSET * this->scale_;
elementLineHeight -= COMPACT_EMOTES_OFFSET * this->scale_;
}

// update line height
this->lineHeight_ = std::max(this->lineHeight_, newLineHeight);
this->lineHeight_ = std::max(this->lineHeight_, elementLineHeight);

auto xOffset = 0;
bool isZeroWidthEmote = element->getCreator().getFlags().has(
Expand Down Expand Up @@ -218,7 +217,6 @@ void MessageLayoutContainer::breakLine()
MessageLayoutElement *element = this->elements_.at(i).get();

bool isCompactEmote =
getSettings()->compactEmotes &&
!this->flags_.has(MessageFlag::DisableCompactEmotes) &&
element->getCreator().getFlags().has(
MessageElementFlag::EmoteImages);
Expand All @@ -229,15 +227,6 @@ void MessageLayoutContainer::breakLine()
yExtra = (COMPACT_EMOTES_OFFSET / 2) * this->scale_;
}

// if (element->getCreator().getFlags() &
// MessageElementFlag::Badges)
// {
if (element->getRect().height() < this->textLineHeight_)
{
// yExtra -= (this->textLineHeight_ - element->getRect().height()) /
// 2;
}

element->setPosition(
QPoint(element->getRect().x() + xOffset +
int(this->margin.left * this->scale_),
Expand Down
42 changes: 28 additions & 14 deletions src/messages/layouts/MessageLayoutElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,35 +442,49 @@ int TextIconLayoutElement::getXFromIndex(int index)
}

ReplyCurveLayoutElement::ReplyCurveLayoutElement(MessageElement &creator,
const QSize &size,
float thickness,
int width, float thickness,
float radius,
float neededMargin)
: MessageLayoutElement(creator, size)
: MessageLayoutElement(creator, QSize(width, 0))
, pen_(QColor("#888"), thickness, Qt::SolidLine, Qt::RoundCap)
, radius_(radius)
, neededMargin_(neededMargin)
{
}

void ReplyCurveLayoutElement::paint(QPainter &painter)
{
QRectF paintRect(this->getRect());
QPainterPath bezierPath;
QPainterPath path;

QRectF curveRect = paintRect.marginsRemoved(QMarginsF(
this->neededMargin_, this->neededMargin_, 0, this->neededMargin_));

// Make sure that our curveRect can always fit the radius curve
if (curveRect.height() < this->radius_)
{
curveRect.setTop(curveRect.top() -
(this->radius_ - curveRect.height()));
}

QPointF bStartPoint(curveRect.left(), curveRect.top() + this->radius_);
QPointF bEndPoint(curveRect.left() + this->radius_, curveRect.top());
QPointF bControlPoint(curveRect.topLeft());

// Draw line from bottom left to curve
path.moveTo(curveRect.bottomLeft());
path.lineTo(bStartPoint);

qreal top = paintRect.top() + paintRect.height() * 0.25; // 25% from top
qreal left = paintRect.left() + this->neededMargin_;
qreal bottom = paintRect.bottom() - this->neededMargin_;
QPointF startPoint(left, bottom);
QPointF controlPoint(left, top);
QPointF endPoint(paintRect.right(), top);
// Draw curve path
path.quadTo(bControlPoint, bEndPoint);

// Create curve path
bezierPath.moveTo(startPoint);
bezierPath.quadTo(controlPoint, endPoint);
// Draw line from curve to top right
path.lineTo(curveRect.topRight());

// Render curve
painter.setPen(this->pen_);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawPath(bezierPath);
painter.drawPath(path);
}

void ReplyCurveLayoutElement::paintAnimated(QPainter &painter, int yOffset)
Expand Down
5 changes: 3 additions & 2 deletions src/messages/layouts/MessageLayoutElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class TextIconLayoutElement : public MessageLayoutElement
class ReplyCurveLayoutElement : public MessageLayoutElement
{
public:
ReplyCurveLayoutElement(MessageElement &creator, const QSize &size,
float thickness, float lMargin);
ReplyCurveLayoutElement(MessageElement &creator, int width, float thickness,
float radius, float neededMargin);

protected:
void paint(QPainter &painter) override;
Expand All @@ -177,6 +177,7 @@ class ReplyCurveLayoutElement : public MessageLayoutElement

private:
const QPen pen_;
const float radius_;
const float neededMargin_;
};

Expand Down
1 change: 0 additions & 1 deletion src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Settings : public ABSettings, public ConcurrentSettings
false};
BoolSetting separateMessages = {"/appearance/messages/separateMessages",
false};
BoolSetting compactEmotes = {"/appearance/messages/compactEmotes", true};
BoolSetting hideModerated = {"/appearance/messages/hideModerated", false};
BoolSetting hideModerationActions = {
"/appearance/messages/hideModerationActions", false};
Expand Down

0 comments on commit 7640677

Please sign in to comment.