From 6b4284633be66102bd2f9112b8d2934cac01d81c Mon Sep 17 00:00:00 2001 From: luigi-rosso Date: Tue, 12 Sep 2023 16:41:39 +0000 Subject: [PATCH] add artboards shapes to updates when RenderOpacity has dirt Fixes nested artboards not applying inherited opacity to their backgrounds Issue #5887 Diffs= 0dcbdade4 add artboards shapes to updates when RenderOpacity has dirt (#5971) Co-authored-by: hernan --- .rive_head | 2 +- include/rive/shapes/shape_paint_container.hpp | 4 +++ src/artboard.cpp | 4 +++ test/assets/nested_artboard_opacity.riv | Bin 0 -> 155 bytes test/nested_artboard_opacity_test.cpp | 26 ++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/assets/nested_artboard_opacity.riv create mode 100644 test/nested_artboard_opacity_test.cpp diff --git a/.rive_head b/.rive_head index b5177a62..ea5fdcd5 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -85b2b6ed1965d66f5f268993e54f5f89f30a2e29 +0dcbdade49885fcae4de304972ae37f6283f19d1 diff --git a/include/rive/shapes/shape_paint_container.hpp b/include/rive/shapes/shape_paint_container.hpp index f5200fa7..ceccbf4e 100644 --- a/include/rive/shapes/shape_paint_container.hpp +++ b/include/rive/shapes/shape_paint_container.hpp @@ -38,6 +38,10 @@ class ShapePaintContainer std::unique_ptr makeCommandPath(PathSpace space); void propagateOpacity(float opacity); + + #ifdef TESTING + const std::vector& shapePaints() const { return m_ShapePaints; } + #endif }; } // namespace rive diff --git a/src/artboard.cpp b/src/artboard.cpp index 4f09ab02..8b372155 100644 --- a/src/artboard.cpp +++ b/src/artboard.cpp @@ -427,6 +427,10 @@ void Artboard::update(ComponentDirt value) m_ClipPath = factory()->makeRenderPath(clip); m_BackgroundPath = factory()->makeRenderPath(bg); } + if (hasDirt(value, ComponentDirt::RenderOpacity)) + { + propagateOpacity(childOpacity()); + } } bool Artboard::updateComponents() diff --git a/test/assets/nested_artboard_opacity.riv b/test/assets/nested_artboard_opacity.riv new file mode 100644 index 0000000000000000000000000000000000000000..128cc95cd122ad10daf3d33e582fd75510f980cc GIT binary patch literal 155 zcmWIY40B~?xSev8kpTq685mjk0}_i;^GXyPi%OF66N^&V85n*!bASkj7#2yt)Z&uV z6oo{nq(X9jUP)qRUTP65gOJF&<#xP4g-(1R;wU2{gAgmT>VF1?7Yrh-3?QS?bOVj9 Y0vTQ9%*ntY<^ojCq{_hX|36qc0Je1}TmS$7 literal 0 HcmV?d00001 diff --git a/test/nested_artboard_opacity_test.cpp b/test/nested_artboard_opacity_test.cpp new file mode 100644 index 00000000..e3c2b73b --- /dev/null +++ b/test/nested_artboard_opacity_test.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include "rive_file_reader.hpp" + +TEST_CASE("Nested artboard background renders with opacity", "[file]") +{ + auto file = ReadRiveFile("../../test/assets/nested_artboard_opacity.riv"); + + auto mainArtboard = file->artboard()->instance(); + REQUIRE(mainArtboard->find("Parent Artboard") != nullptr); + auto artboard = mainArtboard->find("Parent Artboard"); + artboard->updateComponents(); + REQUIRE(artboard->is()); + REQUIRE(artboard->find("Nested artboard container") != nullptr); + auto nestedArtboardContainer = artboard->find("Nested artboard container"); + REQUIRE(nestedArtboardContainer->artboard() != nullptr); + auto nestedArtboard = nestedArtboardContainer->artboard(); + nestedArtboard->updateComponents(); + auto paints = nestedArtboard->shapePaints(); + REQUIRE(paints.size() == 1); + auto paint = paints[0]; + REQUIRE(paint->is()); + REQUIRE(paint->renderOpacity() == 0.3275f); +}