1 /* 2 * Copyright (c) 2023 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 REGION_H 17 #define REGION_H 18 19 #include "impl_interface/region_impl.h" 20 #include "utils/drawing_macros.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 enum class RegionOp { 26 DIFFERENCE, 27 INTERSECT, 28 UNION, 29 XOR, 30 REVERSE_DIFFERENCE, 31 REPLACE, 32 }; 33 class DRAWING_API Region { 34 public: 35 Region(); 36 Region(const Region& other); 37 Region& operator=(const Region& other); 38 virtual ~Region() = default; 39 GetDrawingType()40 virtual DrawingType GetDrawingType() const 41 { 42 return DrawingType::COMMON; 43 } 44 45 /* 46 * @brief Constructs a rectangular Region matching the bounds of rect. 47 * @param rectI Bounds of constructed Region. 48 * @return If rectI is empty, constructs empty and returns false. 49 */ 50 virtual bool SetRect(const RectI& rectI); 51 52 /* 53 * @brief Constructs Region to match outline of path within clip. 54 * @param &path Providing outline. 55 * @param &clip Containing path. 56 * @return Return true if constructed Region is not empty. 57 */ 58 virtual bool SetPath(const Path& path, const Region& clip); 59 60 /* 61 * @brief Appends outline of Region to path. 62 * @param path Path to append to. 63 * @return Return true if path changed. 64 */ 65 bool GetBoundaryPath(Path* path) const; 66 67 /* 68 * @brief Determines whether it intersects other. 69 * @param &other Other Region object. 70 * @return If true indicates that other and Region have area in common. 71 */ 72 bool IsIntersects(const Region& other) const; 73 74 /* 75 * @brief Determines whether Region is empty. 76 * @return If true indicates that bounds has no width or height. 77 */ 78 bool IsEmpty() const; 79 80 /* 81 * @brief Determines whether Region is one Rect with positive dimensions. 82 * @return If true indicates that Region contains one Rect. 83 */ 84 bool IsRect() const; 85 86 /* 87 * @brief Replaces Region with the result of Region op region. 88 * @param ®ion Operand. 89 * @param op Operation type. 90 * @return Returns true if replaced Region is not empty. 91 */ 92 virtual bool Op(const Region& region, RegionOp op); 93 94 /* 95 * @brief Get the adaptation layer instance, called in the adaptation layer. 96 * @return Adaptation Layer instance. 97 */ 98 std::shared_ptr<Data> Serialize() const; 99 bool Deserialize(std::shared_ptr<Data> data); 100 101 template<typename T> GetImpl()102 T* GetImpl() const 103 { 104 return impl_->DowncastingTo<T>(); 105 } 106 107 private: 108 std::shared_ptr<RegionImpl> impl_; 109 }; 110 } // namespace Drawing 111 } // namespace Rosen 112 } // namespace OHOS 113 #endif 114