1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file depict_transform.h
18  *
19  * @brief Defines Building vertex matrix transformation pipeline
20  * ransformation matrix. Through the operation of vertex coordinates and matrix, we can get new coordinates
21  * @since 1.0
22  * @version 1.0
23  */
24 
25 #ifndef GRAPHIC_LITE_DEPICT_TRANSFORM_H
26 #define GRAPHIC_LITE_DEPICT_TRANSFORM_H
27 
28 #include "gfx_utils/diagram/common/common_basics.h"
29 #include "gfx_utils/trans_affine.h"
30 namespace OHOS {
31 /**
32  * @template<VertexSource,TransAffine> class DepictTransform
33  * @brief The depicttransform class forms a 2 * 3 matrix through six variables,
34  * A new coordinate is obtained after calculation with the coordinate.
35  * @since 1.0
36  * @version 1.0
37  */
38 template <class VertexSource>
39 class DepictTransform {
40 public:
41     /**
42      * @brief DepictTransform Class constructor
43      * The construction parameters are VertexSource and TransAffine attributes,
44      * which determine the vertex source of the curve.
45      * @since 1.0
46      * @version 1.0
47      */
DepictTransform(VertexSource & source,TransAffine & tr)48     DepictTransform(VertexSource& source, TransAffine& tr)
49         : source_(&source), trans_(&tr) {}
50 
Attach(VertexSource & source)51     void Attach(VertexSource& source)
52     {
53         source_ = &source;
54     }
55 
Rewind(uint32_t pathId)56     void Rewind(uint32_t pathId)
57     {
58         source_->Rewind(pathId);
59     }
60 
GenerateVertex(float * x,float * y)61     uint32_t GenerateVertex(float* x, float* y)
62     {
63         uint32_t cmd = source_->GenerateVertex(x, y);
64         if (IsVertex(cmd)) {
65             trans_->Transform(x, y);
66         }
67         return cmd;
68     }
69 
GetTransformer(TransAffine & tr)70     void GetTransformer(TransAffine& tr)
71     {
72         trans_ = &tr;
73     }
74 
75 private:
76 
77     VertexSource* source_;
78     TransAffine* trans_;
79 };
80 } // namespace OHOS
81 #endif
82