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 virtual ~PathEffect() {} 50 PathEffectType GetType() const; GetDrawingType()51 virtual DrawingType GetDrawingType() const 52 { 53 return DrawingType::COMMON; 54 } 55 PathEffect(PathEffectType t, const scalar intervals[], int count, scalar phase) noexcept; 56 PathEffect(PathEffectType t, const Path& path, scalar advance, scalar phase, PathDashStyle style) noexcept; 57 PathEffect(PathEffectType t, scalar radius) noexcept; 58 PathEffect(PathEffectType t, PathEffect& e1, PathEffect& e2) noexcept; 59 60 template<typename T> GetImpl()61 const std::shared_ptr<T> GetImpl() const 62 { 63 return impl_->DowncastingTo<T>(); 64 } 65 66 protected: 67 PathEffect() noexcept; 68 69 private: 70 PathEffectType type_; 71 std::shared_ptr<PathEffectImpl> impl_; 72 }; 73 } // namespace Drawing 74 } // namespace Rosen 75 } // namespace OHOS 76 #endif