common: code refactoring.
[platform/core/graphics/tizenvg.git] / src / lib / tvgPaint.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 #ifndef _TVG_PAINT_H_
18 #define _TVG_PAINT_H_
19
20 namespace tvg
21 {
22     struct StrategyMethod
23     {
24         virtual ~StrategyMethod(){}
25
26         virtual bool dispose(RenderMethod& renderer) = 0;
27         virtual bool update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t pFlag) = 0;
28         virtual bool render(RenderMethod& renderer) = 0;
29
30         virtual bool rotate(float degree) = 0;
31         virtual bool scale(float factor) = 0;
32         virtual bool translate(float x, float y) = 0;
33         virtual bool transform(const Matrix& m) = 0;
34         virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
35
36     };
37
38     struct Paint::Impl
39     {
40         StrategyMethod* smethod = nullptr;
41
42         ~Impl() {
43             if (smethod) delete(smethod);
44         }
45
46         void method(StrategyMethod* method)
47         {
48             smethod = method;
49         }
50
51         StrategyMethod* method()
52         {
53             return smethod;
54         }
55     };
56
57
58     template<class T>
59     struct PaintMethod : StrategyMethod
60     {
61         T* inst = nullptr;
62
63         PaintMethod(T* _inst) : inst(_inst) {}
64         ~PaintMethod(){}
65
66         bool rotate(float degree) override
67         {
68             return inst->rotate(degree);
69         }
70
71         bool scale(float factor) override
72         {
73             return inst->scale(factor);
74         }
75
76         bool translate(float x, float y) override
77         {
78             return inst->translate(x, y);
79         }
80
81         bool transform(const Matrix& m) override
82         {
83             return inst->transform(m);
84         }
85
86         bool bounds(float* x, float* y, float* w, float* h) const override
87         {
88             return inst->bounds(x, y, w, h);
89         }
90
91         bool dispose(RenderMethod& renderer)
92         {
93             return inst->dispose(renderer);
94         }
95
96         bool update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t pFlag)
97         {
98             return inst->update(renderer, pTransform, pFlag);
99         }
100
101         bool render(RenderMethod& renderer)
102         {
103             return inst->render(renderer);
104         }
105     };
106 }
107
108 #endif //_TVG_PAINT_H_