submodule: add rive-cpp to rive-tizen as submodule
[platform/core/uifw/rive-tizen.git] / submodule / src / shapes / shape.cpp
1 #include "shapes/shape.hpp"
2 #include "shapes/clipping_shape.hpp"
3 #include "shapes/paint/blend_mode.hpp"
4 #include "shapes/paint/shape_paint.hpp"
5 #include "shapes/path_composer.hpp"
6 #include <algorithm>
7
8 using namespace rive;
9
10 void Shape::addPath(Path* path)
11 {
12         // Make sure the path is not already in the shape.
13         assert(std::find(m_Paths.begin(), m_Paths.end(), path) == m_Paths.end());
14         m_Paths.push_back(path);
15 }
16
17 void Shape::update(ComponentDirt value)
18 {
19         Super::update(value);
20
21         if (hasDirt(value, ComponentDirt::RenderOpacity))
22         {
23                 for (auto shapePaint : m_ShapePaints)
24                 {
25                         shapePaint->renderOpacity(renderOpacity());
26                 }
27         }
28 }
29
30 void Shape::pathChanged()
31 {
32         m_PathComposer->addDirt(ComponentDirt::Path, true);
33         invalidateStrokeEffects();
34 }
35
36 void Shape::pathComposer(PathComposer* value) { m_PathComposer = value; }
37 void Shape::draw(Renderer* renderer)
38 {
39         auto shouldRestore = clip(renderer);
40
41         for (auto shapePaint : m_ShapePaints)
42         {
43                 if (!shapePaint->isVisible())
44                 {
45                         continue;
46                 }
47                 renderer->save();
48                 bool paintsInLocal =
49                     (shapePaint->pathSpace() & PathSpace::Local) == PathSpace::Local;
50                 if (paintsInLocal)
51                 {
52                         const Mat2D& transform = worldTransform();
53                         renderer->transform(transform);
54                 }
55                 shapePaint->draw(renderer,
56                                  paintsInLocal ? m_PathComposer->localPath()
57                                                : m_PathComposer->worldPath());
58                 renderer->restore();
59         }
60
61         if (shouldRestore)
62         {
63                 renderer->restore();
64         }
65 }
66
67 void Shape::buildDependencies()
68 {
69         Super::buildDependencies();
70
71         // Set the blend mode on all the shape paints. If we ever animate this
72         // property, we'll need to update it in the update cycle/mark dirty when the
73         // blend mode changes.
74         for (auto paint : m_ShapePaints)
75         {
76                 paint->blendMode((BlendMode)blendModeValue());
77         }
78 }
79
80 void Shape::addDefaultPathSpace(PathSpace space)
81 {
82         m_DefaultPathSpace |= space;
83 }