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/scalar.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 enum class PathDashStyle { 27 TRANSLATE, 28 ROTATE, 29 MORPH, 30 }; 31 class PathEffect { 32 public: 33 enum class PathEffectType { 34 NO_TYPE, 35 DASH, 36 PATH_DASH, 37 CORNER, 38 SUM, 39 COMPOSE, 40 }; 41 42 static std::shared_ptr<PathEffect> CreateDashPathEffect(const scalar intervals[], int count, scalar phase); 43 static std::shared_ptr<PathEffect> CreatePathDashEffect( 44 const Path& path, scalar advance, scalar phase, PathDashStyle style); 45 static std::shared_ptr<PathEffect> CreateCornerPathEffect(scalar radius); 46 static std::shared_ptr<PathEffect> CreateSumPathEffect(PathEffect& e1, PathEffect& e2); 47 static std::shared_ptr<PathEffect> CreateComposePathEffect(PathEffect& e1, PathEffect& e2); 48 ~PathEffect()49 ~PathEffect() {} 50 PathEffectType GetType() const; 51 52 PathEffect(PathEffectType t, const scalar intervals[], int count, scalar phase) noexcept; 53 PathEffect(PathEffectType t, const Path& path, scalar advance, scalar phase, PathDashStyle style) noexcept; 54 PathEffect(PathEffectType t, scalar radius) noexcept; 55 PathEffect(PathEffectType t, PathEffect& e1, PathEffect& e2) noexcept; 56 57 template<typename T> GetImpl()58 const std::shared_ptr<T> GetImpl() const 59 { 60 return impl_->DowncastingTo<T>(); 61 } 62 63 protected: 64 PathEffect() noexcept; 65 66 private: 67 PathEffectType type_; 68 std::shared_ptr<PathEffectImpl> impl_; 69 }; 70 } // namespace Drawing 71 } // namespace Rosen 72 } // namespace OHOS 73 #endif