Skip to content

Commit

Permalink
Support three-color quote outlines.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 26, 2023
1 parent 383b5b8 commit 9b3a49e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 20 additions & 12 deletions ui/text/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,13 @@ void ValidateQuotePaintCache(
const auto icon = st.icon.empty() ? nullptr : &st.icon;
if (!cache.corners.isNull()
&& cache.bgCached == cache.bg
&& cache.outline1Cached == cache.outline1
&& cache.outline2Cached == cache.outline2
&& cache.outlines == cache.outlines
&& (!st.header || cache.headerCached == cache.header)
&& (!icon || cache.iconCached == cache.icon)) {
return;
}
cache.bgCached = cache.bg;
cache.outline1Cached = cache.outline1;
cache.outline2Cached = cache.outline2;
cache.outlinesCached = cache.outlines;
if (st.header) {
cache.headerCached = cache.header;
}
Expand All @@ -220,25 +218,35 @@ void ValidateQuotePaintCache(
const auto full = QSize(side, side);
const auto ratio = style::DevicePixelRatio();

if (cache.outline1 == cache.outline2) {
if (!cache.outlines[1].alpha()) {
cache.outline = QImage();
} else if (const auto outline = st.outline) {
const auto size = QSize(outline, outline * 6);
const auto third = (cache.outlines[2].alpha() != 0);
const auto size = QSize(outline, outline * (third ? 6 : 4));
cache.outline = QImage(
size * ratio,
QImage::Format_ARGB32_Premultiplied);
cache.outline.fill(cache.outline1);
cache.outline.fill(cache.outlines[0]);
cache.outline.setDevicePixelRatio(ratio);
auto p = QPainter(&cache.outline);
p.setCompositionMode(QPainter::CompositionMode_Source);
auto hq = PainterHighQualityEnabler(p);
auto path = QPainterPath();
path.moveTo(outline, outline);
path.lineTo(outline, outline * 4);
path.lineTo(0, outline * 5);
path.lineTo(outline, outline * (third ? 4 : 3));
path.lineTo(0, outline * (third ? 5 : 4));
path.lineTo(0, outline * 2);
path.lineTo(outline, outline);
p.fillPath(path, cache.outline2);
p.fillPath(path, cache.outlines[1]);
if (third) {
auto path = QPainterPath();
path.moveTo(outline, outline * 3);
path.lineTo(outline, outline * 5);
path.lineTo(0, outline * 6);
path.lineTo(0, outline * 4);
path.lineTo(outline, outline * 3);
p.fillPath(path, cache.outlines[2]);
}
}

auto image = QImage(full * ratio, QImage::Format_ARGB32_Premultiplied);
Expand All @@ -260,7 +268,7 @@ void ValidateQuotePaintCache(
p.setClipRect(0, 0, outline, side);
p.drawRoundedRect(rect, radius, radius);
} else {
p.setBrush(cache.outline1);
p.setBrush(cache.outlines[0]);
p.setClipRect(0, 0, outline, side);
p.drawRoundedRect(rect, radius, radius);
}
Expand Down Expand Up @@ -408,7 +416,7 @@ void FillQuotePaint(
p.fillRect(0, skipped, outline, height, cache.outline);
p.translate(-x, -top);
} else {
p.fillRect(x, y, outline, height, cache.outline1);
p.fillRect(x, y, outline, height, cache.outlines[0]);
}
}
p.fillRect(x + outline, y, width - outline, height, cache.bg);
Expand Down
8 changes: 4 additions & 4 deletions ui/text/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,22 @@ struct GeometryDescriptor {
bool elisionOneLine,
bool elisionBreakEverywhere);

constexpr auto kMaxQuoteOutlines = 3;

struct QuotePaintCache {
QImage corners;
QImage outline;
mutable QImage bottomCorner;
mutable QImage bottomRounding;

std::array<QColor, kMaxQuoteOutlines> outlinesCached;
QColor headerCached;
QColor bgCached;
QColor outline1Cached;
QColor outline2Cached;
QColor iconCached;

std::array<QColor, kMaxQuoteOutlines> outlines;
QColor header;
QColor bg;
QColor outline1;
QColor outline2;
QColor icon;
};

Expand Down

0 comments on commit 9b3a49e

Please sign in to comment.