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 #include "effect/path_effect.h"
17
18 #include "impl_factory.h"
19
20 #include "impl_interface/path_effect_impl.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
PathEffect(PathEffectType t,const scalar intervals[],int count,scalar phase)25 PathEffect::PathEffect(PathEffectType t, const scalar intervals[], int count, scalar phase) noexcept : PathEffect()
26 {
27 type_ = t;
28 impl_->InitWithDash(intervals, count, phase);
29 }
30
PathEffect(PathEffectType t,const Path & path,scalar advance,scalar phase,PathDashStyle style)31 PathEffect::PathEffect(PathEffectType t, const Path& path, scalar advance, scalar phase, PathDashStyle style) noexcept
32 : PathEffect()
33 {
34 type_ = t;
35 impl_->InitWithPathDash(path, advance, phase, style);
36 }
37
PathEffect(PathEffectType t,scalar radius)38 PathEffect::PathEffect(PathEffectType t, scalar radius) noexcept : PathEffect()
39 {
40 type_ = t;
41 impl_->InitWithCorner(radius);
42 }
43
PathEffect(PathEffectType t,PathEffect & e1,PathEffect & e2)44 PathEffect::PathEffect(PathEffectType t, PathEffect& e1, PathEffect& e2) noexcept : PathEffect()
45 {
46 type_ = t;
47 if (type_ == PathEffect::PathEffectType::SUM) {
48 impl_->InitWithSum(e1, e2);
49 } else if (type_ == PathEffect::PathEffectType::COMPOSE) {
50 impl_->InitWithCompose(e1, e2);
51 }
52 }
53
PathEffect()54 PathEffect::PathEffect() noexcept
55 : type_(PathEffect::PathEffectType::NO_TYPE), impl_(ImplFactory::CreatePathEffectImpl())
56 {}
57
GetType() const58 PathEffect::PathEffectType PathEffect::GetType() const
59 {
60 return type_;
61 }
62
CreateDashPathEffect(const scalar intervals[],int count,scalar phase)63 std::shared_ptr<PathEffect> PathEffect::CreateDashPathEffect(const scalar intervals[], int count, scalar phase)
64 {
65 return std::make_shared<PathEffect>(PathEffect::PathEffectType::DASH, intervals, count, phase);
66 }
67
CreatePathDashEffect(const Path & path,scalar advance,scalar phase,PathDashStyle style)68 std::shared_ptr<PathEffect> PathEffect::CreatePathDashEffect(
69 const Path& path, scalar advance, scalar phase, PathDashStyle style)
70 {
71 return std::make_shared<PathEffect>(PathEffect::PathEffectType::PATH_DASH, path, advance, phase, style);
72 }
73
CreateCornerPathEffect(scalar radius)74 std::shared_ptr<PathEffect> PathEffect::CreateCornerPathEffect(scalar radius)
75 {
76 return std::make_shared<PathEffect>(PathEffect::PathEffectType::CORNER, radius);
77 }
78
CreateSumPathEffect(PathEffect & e1,PathEffect & e2)79 std::shared_ptr<PathEffect> PathEffect::CreateSumPathEffect(PathEffect& e1, PathEffect& e2)
80 {
81 return std::make_shared<PathEffect>(PathEffect::PathEffectType::SUM, e1, e2);
82 }
83
CreateComposePathEffect(PathEffect & e1,PathEffect & e2)84 std::shared_ptr<PathEffect> PathEffect::CreateComposePathEffect(PathEffect& e1, PathEffect& e2)
85 {
86 return std::make_shared<PathEffect>(PathEffect::PathEffectType::COMPOSE, e1, e2);
87 }
88 } // namespace Drawing
89 } // namespace Rosen
90 } // namespace OHOS