1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SHAPE_POLYGON_PAINT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SHAPE_POLYGON_PAINT_PROPERTY_H 18 19 #include <array> 20 #include <string> 21 #include <vector> 22 #include "core/components/shape/shape_component.h" 23 #include "core/components_ng/base/inspector_filter.h" 24 #include "core/components_ng/layout/layout_property.h" 25 #include "core/components_ng/pattern/shape/shape_paint_property.h" 26 #include "core/components_ng/property/property.h" 27 #include "core/components_ng/render/paint_property.h" 28 29 namespace OHOS::Ace::NG { 30 31 class ACE_EXPORT PolygonPaintProperty : public ShapePaintProperty { 32 DECLARE_ACE_TYPE(PolygonPaintProperty, ShapePaintProperty); 33 34 public: 35 PolygonPaintProperty() = default; 36 ~PolygonPaintProperty() override = default; Clone()37 RefPtr<PaintProperty> Clone() const override 38 { 39 auto value = MakeRefPtr<PolygonPaintProperty>(); 40 value->PaintProperty::UpdatePaintProperty(DynamicCast<PaintProperty>(this)); 41 value->propPoints_ = ClonePoints(); 42 value->propFill_ = CloneFill(); 43 value->propFillOpacity_ = CloneFillOpacity(); 44 value->propStroke_ = CloneStroke(); 45 value->propStrokeWidth_ = CloneStrokeWidth(); 46 value->propStrokeOpacity_ = CloneStrokeOpacity(); 47 value->propStrokeDashArray_ = CloneStrokeDashArray(); 48 value->propStrokeDashOffset_ = CloneStrokeDashOffset(); 49 value->propStrokeLineCap_ = CloneStrokeLineCap(); 50 value->propStrokeLineJoin_ = CloneStrokeLineJoin(); 51 value->propStrokeMiterLimit_ = CloneStrokeMiterLimit(); 52 value->propAntiAlias_ = CloneAntiAlias(); 53 return value; 54 } 55 Reset()56 void Reset() override 57 { 58 ShapePaintProperty::Reset(); 59 ResetPoints(); 60 } 61 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)62 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 63 { 64 ShapePaintProperty::ToJsonValue(json, filter); 65 /* no fixed attr below, just return */ 66 if (filter.IsFastFilter()) { 67 return; 68 } 69 if (propPoints_.has_value()) { 70 const auto size = static_cast<int32_t>(propPoints_.value().size()); 71 std::vector<std::array<float, 2>> point(size); 72 for (int i = 0; i < size; i++) { 73 point[i][0] = propPoints_.value()[i].first.ConvertToPx(); 74 point[i][1] = propPoints_.value()[i].second.ConvertToPx(); 75 } 76 json->PutExtAttr("points", point.data(), filter); 77 } 78 } 79 80 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Points, ShapePoints, PROPERTY_UPDATE_RENDER); 81 82 private: 83 ACE_DISALLOW_COPY_AND_MOVE(PolygonPaintProperty); 84 }; 85 86 } // namespace OHOS::Ace::NG 87 88 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SHAPE_POLYGON_PAINT_PROPERTY_H 89