2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _TVG_SHAPE_IMPL_H_
18 #define _TVG_SHAPE_IMPL_H_
20 #include "tvgCommon.h"
21 #include "tvgShapePath.h"
23 /************************************************************************/
24 /* Internal Class Implementation */
25 /************************************************************************/
30 uint8_t color[4] = {0, 0, 0, 0};
31 float* dashPattern = nullptr;
33 StrokeCap cap = StrokeCap::Square;
34 StrokeJoin join = StrokeJoin::Bevel;
38 if (dashPattern) free(dashPattern);
45 ShapePath *path = nullptr;
47 ShapeStroke *stroke = nullptr;
48 uint8_t color[4] = {0, 0, 0, 0}; //r, g, b, a
49 void *edata = nullptr; //engine data
50 Shape *shape = nullptr;
51 uint32_t flag = RenderUpdateFlag::None;
53 Impl(Shape* s) : path(new ShapePath), shape(s)
59 if (path) delete(path);
60 if (fill) delete(fill);
61 if (stroke) delete(stroke);
64 bool dispose(RenderMethod& renderer)
66 return renderer.dispose(*shape, edata);
69 bool render(RenderMethod& renderer)
71 return renderer.render(*shape, edata);
74 bool update(RenderMethod& renderer, const RenderTransform* transform, RenderUpdateFlag pFlag)
76 edata = renderer.prepare(*shape, edata, transform, static_cast<RenderUpdateFlag>(pFlag | flag));
78 flag = RenderUpdateFlag::None;
80 if (edata) return true;
84 bool bounds(float* x, float* y, float* w, float* h)
86 if (!path) return false;
87 return path->bounds(x, y, w, h);
90 bool strokeWidth(float width)
92 //TODO: Size Exception?
94 if (!stroke) stroke = new ShapeStroke();
95 if (!stroke) return false;
97 stroke->width = width;
98 flag |= RenderUpdateFlag::Stroke;
103 bool strokeCap(StrokeCap cap)
105 if (!stroke) stroke = new ShapeStroke();
106 if (!stroke) return false;
109 flag |= RenderUpdateFlag::Stroke;
114 bool strokeJoin(StrokeJoin join)
116 if (!stroke) stroke = new ShapeStroke();
117 if (!stroke) return false;
120 flag |= RenderUpdateFlag::Stroke;
125 bool strokeColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
127 if (!stroke) stroke = new ShapeStroke();
128 if (!stroke) return false;
130 stroke->color[0] = r;
131 stroke->color[1] = g;
132 stroke->color[2] = b;
133 stroke->color[3] = a;
135 flag |= RenderUpdateFlag::Stroke;
140 bool strokeDash(const float* pattern, uint32_t cnt)
144 if (!stroke) stroke = new ShapeStroke();
145 if (!stroke) return false;
147 if (stroke->dashCnt != cnt) {
148 if (stroke->dashPattern) free(stroke->dashPattern);
149 stroke->dashPattern = nullptr;
152 if (!stroke->dashPattern) stroke->dashPattern = static_cast<float*>(malloc(sizeof(float) * cnt));
153 assert(stroke->dashPattern);
155 for (uint32_t i = 0; i < cnt; ++i)
156 stroke->dashPattern[i] = pattern[i];
158 stroke->dashCnt = cnt;
159 flag |= RenderUpdateFlag::Stroke;
165 #endif //_TVG_SHAPE_IMPL_H_