• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef PATH_EFFECT_H
17 #define PATH_EFFECT_H
18 
19 #include "draw/path.h"
20 #include "drawing/engine_adapter/impl_interface/path_effect_impl.h"
21 #include "utils/drawing_macros.h"
22 #include "utils/scalar.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 enum class PathDashStyle {
28     TRANSLATE,
29     ROTATE,
30     MORPH,
31 };
32 class DRAWING_API PathEffect {
33 public:
34     enum class PathEffectType {
35         NO_TYPE,
36         DASH,
37         PATH_DASH,
38         CORNER,
39         DISCRETE,
40         SUM,
41         COMPOSE,
42     };
43 
44     static std::shared_ptr<PathEffect> CreateDashPathEffect(const scalar intervals[], int count, scalar phase);
45     static std::shared_ptr<PathEffect> CreatePathDashEffect(
46         const Path& path, scalar advance, scalar phase, PathDashStyle style);
47     static std::shared_ptr<PathEffect> CreateCornerPathEffect(scalar radius);
48     static std::shared_ptr<PathEffect> CreateDiscretePathEffect(scalar segLength, scalar dev, uint32_t seedAssist = 0);
49     static std::shared_ptr<PathEffect> CreateSumPathEffect(PathEffect& e1, PathEffect& e2);
50     static std::shared_ptr<PathEffect> CreateComposePathEffect(PathEffect& e1, PathEffect& e2);
51 
~PathEffect()52     virtual ~PathEffect() {}
53     PathEffectType GetType() const;
GetDrawingType()54     virtual DrawingType GetDrawingType() const
55     {
56         return DrawingType::COMMON;
57     }
58     PathEffect(PathEffectType t, const scalar intervals[], int count, scalar phase) noexcept;
59     PathEffect(PathEffectType t, const Path& path, scalar advance, scalar phase, PathDashStyle style) noexcept;
60     PathEffect(PathEffectType t, scalar radius) noexcept;
61     PathEffect(PathEffectType t, scalar segLength, scalar dev, uint32_t seedAssist) noexcept;
62     PathEffect(PathEffectType t, PathEffect& e1, PathEffect& e2) noexcept;
63     PathEffect(PathEffectType t) noexcept;
64 
65     template<typename T>
GetImpl()66     T* GetImpl() const
67     {
68         return impl_->DowncastingTo<T>();
69     }
70 
71     std::shared_ptr<Data> Serialize() const;
72     bool Deserialize(std::shared_ptr<Data> data);
73 protected:
74     PathEffect() noexcept;
75 
76 private:
77     PathEffectType type_;
78     std::shared_ptr<PathEffectImpl> impl_;
79 };
80 } // namespace Drawing
81 } // namespace Rosen
82 } // namespace OHOS
83 #endif