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_SCENE_IMPL_H_
18 #define _TVG_SCENE_IMPL_H_
20 #include "tvgCommon.h"
22 /************************************************************************/
23 /* Internal Class Implementation */
24 /************************************************************************/
28 vector<Paint*> paints;
29 RenderTransform *transform = nullptr;
30 uint32_t flag = RenderUpdateFlag::None;
34 //Are you sure clear() prior to this?
35 assert(paints.empty());
36 if (transform) delete(transform);
39 bool clear(RenderMethod& renderer)
41 for (auto paint : paints) {
42 if (paint->id() == PAINT_ID_SCENE) {
43 //We know renderer type, avoid dynamic_cast for performance.
44 auto scene = static_cast<Scene*>(paint);
45 if (!SCENE_IMPL->clear(renderer)) return false;
47 auto shape = static_cast<Shape*>(paint);
48 if (!SHAPE_IMPL->dispose(*shape, renderer)) return false;
57 bool updateInternal(RenderMethod &renderer, const RenderTransform* transform, uint32_t flag)
59 for(auto paint: paints) {
60 if (paint->id() == PAINT_ID_SCENE) {
61 //We know renderer type, avoid dynamic_cast for performance.
62 auto scene = static_cast<Scene*>(paint);
63 if (!SCENE_IMPL->update(renderer, transform, flag)) return false;
65 auto shape = static_cast<Shape*>(paint);
66 if (!SHAPE_IMPL->update(*shape, renderer, transform, flag)) return false;
72 bool update(RenderMethod &renderer, const RenderTransform* pTransform = nullptr, uint32_t pFlag = 0)
74 if (flag & RenderUpdateFlag::Transform) {
75 if (!transform) return false;
76 if (!transform->update()) {
84 if (transform && pTransform) {
85 RenderTransform outTransform(pTransform, transform);
86 ret = updateInternal(renderer, &outTransform, pFlag | flag);
88 auto outTransform = pTransform ? pTransform : transform;
89 ret = updateInternal(renderer, outTransform, pFlag | flag);
92 flag = RenderUpdateFlag::None;
97 bool render(RenderMethod &renderer)
99 for(auto paint: paints) {
100 if (paint->id() == PAINT_ID_SCENE) {
101 //We know renderer type, avoid dynamic_cast for performance.
102 auto scene = static_cast<Scene*>(paint);
103 if(!SCENE_IMPL->render(renderer)) return false;
105 auto shape = static_cast<Shape*>(paint);
106 if(!SHAPE_IMPL->render(*shape, renderer)) return false;
112 bool bounds(float* px, float* py, float* pw, float* ph)
119 for(auto paint: paints) {
125 if (paint->id() == PAINT_ID_SCENE) {
126 //We know renderer type, avoid dynamic_cast for performance.
127 auto scene = static_cast<Scene*>(paint);
128 if (!SCENE_IMPL->bounds(&x2, &y2, &w2, &h2)) return false;
130 auto shape = static_cast<Shape*>(paint);
131 if (!SHAPE_IMPL->bounds(&x2, &y2, &w2, &h2)) return false;
136 if (x + w < x2 + w2) w = (x2 + w2) - x;
138 if (y + h < y2 + h2) h = (y2 + h2) - y;
149 bool scale(float factor)
152 if (fabsf(factor - transform->factor) <= FLT_EPSILON) return true;
154 if (fabsf(factor) <= FLT_EPSILON) return true;
155 transform = new RenderTransform();
156 if (!transform) return false;
158 transform->factor = factor;
159 flag |= RenderUpdateFlag::Transform;
164 bool rotate(float degree)
167 if (fabsf(degree - transform->degree) <= FLT_EPSILON) return true;
169 if (fabsf(degree) <= FLT_EPSILON) return true;
170 transform = new RenderTransform();
171 if (!transform) return false;
173 transform->degree = degree;
174 flag |= RenderUpdateFlag::Transform;
179 bool translate(float x, float y)
182 if (fabsf(x - transform->x) <= FLT_EPSILON && fabsf(y - transform->y) <= FLT_EPSILON) return true;
184 if (fabsf(x) <= FLT_EPSILON && fabsf(y) <= FLT_EPSILON) return true;
185 transform = new RenderTransform();
186 if (!transform) return false;
190 flag |= RenderUpdateFlag::Transform;
196 #endif //_TVG_SCENE_IMPL_H_