Skip to content

Commit

Permalink
add support for paths as holes
Browse files Browse the repository at this point in the history
add support for paths as holes

Diffs=
7a6019fb97 add support for paths as holes (#9030)

Co-authored-by: Alex Gibson <[email protected]>
Co-authored-by: Maxwell Talbot <[email protected]>
Co-authored-by: Philip Chung <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: hernan <[email protected]>
  • Loading branch information
6 people committed Feb 14, 2025
1 parent 2e1edc3 commit e5ede9c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
50d49d051e99672c6a1dfe4b844460ad4cfde794
7a6019fb974ed415d8531980b0b1516ff9f095c8
10 changes: 10 additions & 0 deletions dev/defs/shapes/path.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"string": "pathflags"
},
"coop": false
},
"isHole": {
"type": "bool",
"animates": true,
"key": {
"int": 770,
"string": "ishole"
},
"description": "With clockwise fill rule, this marks the path as a hole.",
"bindable": true
}
}
}
8 changes: 8 additions & 0 deletions include/rive/generated/core_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ class CoreRegistry
case FeatherBase::innerPropertyKey:
object->as<FeatherBase>()->inner(value);
break;
case PathBase::isHolePropertyKey:
object->as<PathBase>()->isHole(value);
break;
case PointsPathBase::isClosedPropertyKey:
object->as<PointsPathBase>()->isClosed(value);
break;
Expand Down Expand Up @@ -2149,6 +2152,8 @@ class CoreRegistry
return object->as<StrokeBase>()->transformAffectsStroke();
case FeatherBase::innerPropertyKey:
return object->as<FeatherBase>()->inner();
case PathBase::isHolePropertyKey:
return object->as<PathBase>()->isHole();
case PointsPathBase::isClosedPropertyKey:
return object->as<PointsPathBase>()->isClosed();
case RectangleBase::linkCornerRadiusPropertyKey:
Expand Down Expand Up @@ -3130,6 +3135,7 @@ class CoreRegistry
case DashBase::lengthIsPercentagePropertyKey:
case StrokeBase::transformAffectsStrokePropertyKey:
case FeatherBase::innerPropertyKey:
case PathBase::isHolePropertyKey:
case PointsPathBase::isClosedPropertyKey:
case RectangleBase::linkCornerRadiusPropertyKey:
case ClippingShapeBase::isVisiblePropertyKey:
Expand Down Expand Up @@ -3640,6 +3646,8 @@ class CoreRegistry
return object->is<StrokeBase>();
case FeatherBase::innerPropertyKey:
return object->is<FeatherBase>();
case PathBase::isHolePropertyKey:
return object->is<PathBase>();
case PointsPathBase::isClosedPropertyKey:
return object->is<PointsPathBase>();
case RectangleBase::linkCornerRadiusPropertyKey:
Expand Down
19 changes: 19 additions & 0 deletions include/rive/generated/shapes/path_base.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef _RIVE_PATH_BASE_HPP_
#define _RIVE_PATH_BASE_HPP_
#include "rive/core/field_types/core_bool_type.hpp"
#include "rive/core/field_types/core_uint_type.hpp"
#include "rive/node.hpp"
namespace rive
Expand Down Expand Up @@ -33,9 +34,11 @@ class PathBase : public Node
uint16_t coreType() const override { return typeKey; }

static const uint16_t pathFlagsPropertyKey = 128;
static const uint16_t isHolePropertyKey = 770;

protected:
uint32_t m_PathFlags = 0;
bool m_IsHole = false;

public:
inline uint32_t pathFlags() const { return m_PathFlags; }
Expand All @@ -49,9 +52,21 @@ class PathBase : public Node
pathFlagsChanged();
}

inline bool isHole() const { return m_IsHole; }
void isHole(bool value)
{
if (m_IsHole == value)
{
return;
}
m_IsHole = value;
isHoleChanged();
}

void copy(const PathBase& object)
{
m_PathFlags = object.m_PathFlags;
m_IsHole = object.m_IsHole;
Node::copy(object);
}

Expand All @@ -62,12 +77,16 @@ class PathBase : public Node
case pathFlagsPropertyKey:
m_PathFlags = CoreUintType::deserialize(reader);
return true;
case isHolePropertyKey:
m_IsHole = CoreBoolType::deserialize(reader);
return true;
}
return Node::deserialize(propertyKey, reader);
}

protected:
virtual void pathFlagsChanged() {}
virtual void isHoleChanged() {}
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/shapes/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Path : public PathBase
PathFlags m_pathFlags = PathFlags::none;
RawPath m_rawPath;
RenderPathDeformer* deformer() const;
void isHoleChanged() override;

public:
Shape* shape() const { return m_Shape; }
Expand Down
2 changes: 2 additions & 0 deletions src/shapes/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ void Path::update(ComponentDirt value)
// }
}

void Path::isHoleChanged() { markPathDirty(); }

bool Path::collapse(bool value)
{
bool changed = Super::collapse(value);
Expand Down
4 changes: 3 additions & 1 deletion src/shapes/path_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ void PathComposer::update(ComponentDirt value)
(path->as<PointsPath>()->isClockwise() ? 1.0f
: -1.0f) <
0);
if (isNotClockwise)
bool isHole = path->isHole();
// Only draw backwards if values are different
if (isNotClockwise != isHole)
{
m_localClockwisePath.addPathBackwards(path->rawPath(),
&localTransform);
Expand Down

0 comments on commit e5ede9c

Please sign in to comment.