Skip to content

Commit

Permalink
ignore paths that are inactive in solos when calculating hit test
Browse files Browse the repository at this point in the history
we were not skipping collapsed shapes and paths for hit testing, so pointer events were triggering on elements that were inactive.
This PR skips those paths to fix it.
Note: there might be some performance improvements that can be done in the future skipping shapes that are fully hidden, but this PR most likely covers the majority of the usual cases.

Diffs=
2c2d332e0 ignore paths that are inactive in solos when calculating hit test (#6276)

Co-authored-by: hernan <[email protected]>
  • Loading branch information
bodymovin and bodymovin committed Nov 23, 2023
1 parent d19868f commit 42773ea
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c37a28468472c8bd33beaa1b31bf190ecaa6ce06
2c2d332e0254b56f5512de65251cbd80b891aa15
7 changes: 5 additions & 2 deletions src/shapes/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ bool Shape::hitTest(const IAABB& area) const

for (auto path : m_Paths)
{
tester.setXform(path->pathTransform());
path->buildPath(tester);
if (!path->isCollapsed())
{
tester.setXform(path->pathTransform());
path->buildPath(tester);
}
}
return tester.wasHit();
}
Expand Down
Binary file added test/assets/hit_test_solos.riv
Binary file not shown.
64 changes: 64 additions & 0 deletions test/solo_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <rive/solo.hpp>
#include <rive/shapes/shape.hpp>
#include <rive/animation/state_machine_instance.hpp>
#include <rive/animation/state_machine_input_instance.hpp>
#include "rive_file_reader.hpp"
#include <catch.hpp>
#include <cstdio>
Expand Down Expand Up @@ -150,3 +151,66 @@ TEST_CASE("nested solos work", "[solo]")
REQUIRE(h->isCollapsed() == true);
REQUIRE(i->isCollapsed() == true);
}

TEST_CASE("hit test on solos", "[solo]")
{
auto file = ReadRiveFile("../../test/assets/hit_test_solos.riv");

auto artboard = file->artboard()->instance();

REQUIRE(artboard != nullptr);
REQUIRE(artboard->stateMachineCount() == 1);

auto stateMachine = artboard->stateMachineAt(0);
REQUIRE(stateMachine != nullptr);

stateMachine->advance(0.0f);
artboard->advance(0.0f);

auto toggle = stateMachine->getBool("hovered");
REQUIRE(toggle != nullptr);

// Inactive shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 100.0f));
REQUIRE(toggle->value() == true);

// // Active shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 300.0f));
REQUIRE(toggle->value() == false);

// // Inactive shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 400.0f));
REQUIRE(toggle->value() == false);

// Switches active shape to middle one
stateMachine->advance(1.5f);
artboard->advance(1.5f);

// Inactive shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 100.0f));
REQUIRE(toggle->value() == false);

// // Active shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 300.0f));
REQUIRE(toggle->value() == true);

// // Inactive shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 400.0f));
REQUIRE(toggle->value() == false);

// Switches active shape to last one
stateMachine->advance(1.0f);
artboard->advance(1.0f);

// Inactive shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 100.0f));
REQUIRE(toggle->value() == false);

// // Inactive shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 300.0f));
REQUIRE(toggle->value() == false);

// // Active shape position
stateMachine->pointerMove(rive::Vec2D(200.0f, 400.0f));
REQUIRE(toggle->value() == true);
}

0 comments on commit 42773ea

Please sign in to comment.