common: Introduced Accessor for traversing the scene-tree. 65/288765/1
authorHermet Park <chuneon.park@samsung.com>
Thu, 23 Dec 2021 02:34:31 +0000 (11:34 +0900)
committerMichal Szczecinski <m.szczecinsk@partner.samsung.com>
Wed, 22 Feb 2023 11:30:22 +0000 (12:30 +0100)
commit2988e8bea25bfb271f1f0c86f0118b50f98d6847
tree11e6c4f7c256a688fab5eb0c5a660b7bd2a8566c
parentf20cc67676bf0122203da9638592785389ea5c8c
common: Introduced Accessor for traversing the scene-tree.

Basically, this Accessor is a utility to debug the Scene structure,
by traversing the scene-tree by users.

You can search specific nodes to read the property information,
figure out the structure of the scene tree and its size.

We actually don't recommend you to touch the property unless you really
know the each paint's position and role because it's not visible, difficult to
understand its anatomy.

Also, You must underatnd that modifying the nodes of the scene will be going
well with both the art-design structure and the prorgram logic.

In this first version, Accessor only supports for the Picture class.

@example:

auto picture = tvg::Picture::gen();
picture->load("test.svg");

//The callback function from lambda expression.
//This function will be called for every paint nodes of the tree.
auto f = [](const tvg::Paint* paint) -> bool
{
    if (paint->identifier() == Shape::identifier()) {
        //override properties?
        uint8_t r, g, b, a;
        paint->fillColor(&r, &g, &b, &a);
        paint->fill(r / 2, g / 2, b / 2, a);
    }

    //You can return false, to stop traversing immediately.
    return true;
};

auto accessor = tvg::Accessor::gen();

picture = accessor->access(move(picture), f);

...

@Issue: https://github.com/Samsung/thorvg/issues/693

Change-Id: I4f46754de46dfab9bb5b14f58cc659237344822a
inc/thorvg.h
src/examples/Accessor.cpp [new file with mode: 0644]
src/examples/meson.build
src/lib/meson.build
src/lib/tvgAccessor.cpp [new file with mode: 0644]