Fix rounded image spoiler filling.

This commit is contained in:
John Preston 2022-12-12 22:44:25 +04:00
parent f339dd3771
commit 64d2778914

View file

@ -136,8 +136,12 @@ struct Particle {
+ descriptor.particleFadeOutDuration; + descriptor.particleFadeOutDuration;
const auto max = int(std::ceil(speedMax * lifetime)); const auto max = int(std::ceil(speedMax * lifetime));
const auto k = speed / lifetime; const auto k = speed / lifetime;
const auto x = (RandomIndex(2 * max + 1, random) - max) / float64(max); const auto x = (speedMax > 0)
const auto y = sqrt(1 - x * x) * (negative ? -1 : 1); ? ((RandomIndex(2 * max + 1, random) - max) / float64(max))
: 0.;
const auto y = (speedMax > 0)
? (sqrt(1 - x * x) * (negative ? -1 : 1))
: 0.;
return { k * x, k * y }; return { k * x, k * y };
} }
@ -370,10 +374,13 @@ SpoilerMessCached GenerateSpoilerMess(
if (now <= 0 || now >= singleDuration) { if (now <= 0 || now >= singleDuration) {
return; return;
} }
const auto x = (particle.x + int(base::SafeRound(now * particle.dx))) const auto clamp = [&](int value) {
% size; return ((value % size) + size) % size;
const auto y = (particle.y + int(base::SafeRound(now * particle.dy))) };
% size; const auto x = clamp(
particle.x + int(base::SafeRound(now * particle.dx)));
const auto y = clamp(
particle.y + int(base::SafeRound(now * particle.dy)));
const auto opacity = (now < descriptor.particleFadeInDuration) const auto opacity = (now < descriptor.particleFadeInDuration)
? (now / float64(descriptor.particleFadeInDuration)) ? (now / float64(descriptor.particleFadeInDuration))
: (now > singleDuration - descriptor.particleFadeOutDuration) : (now > singleDuration - descriptor.particleFadeOutDuration)
@ -527,7 +534,7 @@ void FillSpoilerRect(
p, p,
part.translated(rect.topLeft()), part.translated(rect.topLeft()),
frame, frame,
originShift - part.topLeft()); originShift - rect.topLeft() - part.topLeft());
}; };
const auto fillCorner = [&](int x, int y, int index) { const auto fillCorner = [&](int x, int y, int index) {
const auto position = QPoint(x, y); const auto position = QPoint(x, y);
@ -562,70 +569,49 @@ void FillSpoilerRect(
}; };
const auto top = verticalSkip(kTopLeft, kTopRight); const auto top = verticalSkip(kTopLeft, kTopRight);
const auto bottom = verticalSkip(kBottomLeft, kBottomRight); const auto bottom = verticalSkip(kBottomLeft, kBottomRight);
if (top) { if (top) {
const auto left = cornerSize(kTopLeft); const auto left = cornerSize(kTopLeft);
const auto right = cornerSize(kTopRight); const auto right = cornerSize(kTopRight);
if (left) { if (left) {
fillCorner(rect.left(), rect.top(), kTopLeft); fillCorner(0, 0, kTopLeft);
if (const auto add = top - left) { if (const auto add = top - left) {
fillBg({ rect.left(), rect.top() + left, left, add }); fillBg({ 0, left, left, add });
} }
} }
if (const auto fill = rect.width() - left - right; fill > 0) { if (const auto fill = rect.width() - left - right; fill > 0) {
fillBg({ rect.left() + left, rect.top(), fill, top }); fillBg({ left, 0, fill, top });
} }
if (right) { if (right) {
fillCorner( fillCorner(rect.width() - right, 0, kTopRight);
rect.left() + rect.width() - right,
rect.top(),
kTopRight);
if (const auto add = top - right) { if (const auto add = top - right) {
fillBg({ fillBg({ rect.width() - right, right, right, add });
rect.left() + rect.width() - right,
rect.top() + right,
right,
add,
});
} }
} }
} }
if (const auto h = rect.height() - top - bottom; h > 0) { if (const auto h = rect.height() - top - bottom; h > 0) {
fillBg({ rect.left(), rect.top() + top, rect.width(), h }); fillBg({ 0, top, rect.width(), h });
} }
if (bottom) { if (bottom) {
const auto left = cornerSize(kBottomLeft); const auto left = cornerSize(kBottomLeft);
const auto right = cornerSize(kBottomRight); const auto right = cornerSize(kBottomRight);
if (left) { if (left) {
fillCorner( fillCorner(0, rect.height() - left, kBottomLeft);
rect.left(),
rect.top() + rect.height() - left,
kBottomLeft);
if (const auto add = bottom - left) { if (const auto add = bottom - left) {
fillBg({ fillBg({ 0, rect.height() - bottom, left, add });
rect.left(),
rect.top() + rect.height() - bottom,
left,
add,
});
} }
} }
if (const auto fill = rect.width() - left - right; fill > 0) { if (const auto fill = rect.width() - left - right; fill > 0) {
fillBg({ fillBg({ left, rect.height() - bottom, fill, bottom });
rect.left() + left,
rect.top() + rect.height() - bottom,
fill,
bottom,
});
} }
if (right) { if (right) {
fillCorner( fillCorner(
rect.left() + rect.width() - right, rect.width() - right,
rect.top() + rect.height() - right, rect.height() - right,
kBottomRight); kBottomRight);
if (const auto add = bottom - right) { if (const auto add = bottom - right) {
fillBg({ fillBg({
rect.left() + rect.width() - right, rect.width() - right,
rect.top() + rect.height() - bottom, rect.height() - bottom,
right, right,
add, add,
}); });