Add a small scale for stories siblings.

This commit is contained in:
John Preston 2023-07-25 17:59:53 +04:00
parent 5aa6102903
commit 0f2e8d9a79
6 changed files with 30 additions and 4 deletions

View File

@ -32,6 +32,7 @@ constexpr auto kSiblingFade = 0.5;
constexpr auto kSiblingFadeOver = 0.4;
constexpr auto kSiblingNameOpacity = 0.8;
constexpr auto kSiblingNameOpacityOver = 1.;
constexpr auto kSiblingScaleOver = 0.05;
[[nodiscard]] StoryId LookupShownId(
const Data::StoriesSource &source,
@ -325,6 +326,7 @@ SiblingView Sibling::view(const SiblingLayout &layout, float64 over) {
.namePosition = namePosition(layout, name),
.nameOpacity = (kSiblingNameOpacity * (1 - over)
+ kSiblingNameOpacityOver * over),
.scale = 1. + (over * kSiblingScaleOver),
};
}

View File

@ -25,6 +25,7 @@ class Controller;
struct ContentLayout {
QRect geometry;
float64 fade = 0.;
float64 scale = 1.;
int radius = 0;
bool headerOutside = false;
};
@ -39,6 +40,7 @@ struct SiblingView {
QImage name;
QPoint namePosition;
float64 nameOpacity = 0.;
float64 scale = 1.;
[[nodiscard]] bool valid() const {
return !image.isNull();

View File

@ -488,7 +488,9 @@ void OverlayWidget::RendererGL::paintTransformedContent(
not_null<QOpenGLShaderProgram*> program,
ContentGeometry geometry,
bool fillTransparentBackground) {
const auto rect = transformRect(geometry.rect);
const auto rect = scaleRect(
transformRect(geometry.rect),
geometry.scale);
const auto centerx = rect.x() + rect.width() / 2;
const auto centery = rect.y() + rect.height() / 2;
const auto rsin = float(std::sin(geometry.rotation * M_PI / 180.));
@ -1066,4 +1068,17 @@ Rect OverlayWidget::RendererGL::transformRect(const QRect &raster) const {
return TransformRect(Rect(raster), _viewport, _factor);
}
Rect OverlayWidget::RendererGL::scaleRect(
const Rect &unscaled,
float64 scale) const {
const auto added = scale - 1.;
const auto addw = unscaled.width() * added;
const auto addh = unscaled.height() * added;
return Rect(
unscaled.x() - addw / 2,
unscaled.y() - addh / 2,
unscaled.width() + addw,
unscaled.height() + addh);
}
} // namespace Media::View

View File

@ -97,6 +97,9 @@ private:
[[nodiscard]] Ui::GL::Rect transformRect(const QRectF &raster) const;
[[nodiscard]] Ui::GL::Rect transformRect(
const Ui::GL::Rect &raster) const;
[[nodiscard]] Ui::GL::Rect scaleRect(
const Ui::GL::Rect &unscaled,
float64 scale) const;
void uploadTexture(
GLint internalformat,

View File

@ -1795,11 +1795,13 @@ OverlayWidget::ContentGeometry OverlayWidget::contentGeometry() const {
}
OverlayWidget::ContentGeometry OverlayWidget::storiesContentGeometry(
const Stories::ContentLayout &layout) const {
const Stories::ContentLayout &layout,
float64 scale) const {
return {
.rect = QRectF(layout.geometry),
.controlsOpacity = kStoriesControlsOpacity,
.fade = layout.fade,
.scale = scale,
.roundRadius = layout.radius,
.topShadowShown = !layout.headerOutside,
};
@ -4458,7 +4460,7 @@ void OverlayWidget::paint(not_null<Renderer*> renderer) {
const auto paint = [&](const SiblingView &view, int index) {
renderer->paintTransformedStaticContent(
view.image,
storiesContentGeometry(view.layout),
storiesContentGeometry(view.layout, view.scale),
false, // semi-transparent
false, // fill transparent background
index);

View File

@ -180,6 +180,7 @@ private:
// Stories.
qreal fade = 0.;
qreal scale = 1.;
int bottomShadowSkip = 0;
int roundRadius = 0;
bool topShadowShown = false;
@ -421,7 +422,8 @@ private:
[[nodiscard]] QRect finalContentRect() const;
[[nodiscard]] ContentGeometry contentGeometry() const;
[[nodiscard]] ContentGeometry storiesContentGeometry(
const Stories::ContentLayout &layout) const;
const Stories::ContentLayout &layout,
float64 scale = 1.) const;
void updateContentRect();
void contentSizeChanged();