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_PATTERNLOCK_PATTERNLOCK_PAINT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_PAINT_PROPERTY_H 18 19 #include "core/components_ng/base/inspector_filter.h" 20 #include "core/components_ng/render/paint_property.h" 21 #include "core/components_v2/pattern_lock/pattern_lock_theme.h" 22 #include "core/pipeline/pipeline_base.h" 23 24 namespace OHOS::Ace::NG { 25 26 class PatternLockPaintProperty : public PaintProperty { 27 DECLARE_ACE_TYPE(PatternLockPaintProperty, PaintProperty) 28 29 public: 30 PatternLockPaintProperty() = default; 31 ~PatternLockPaintProperty() override = default; 32 Clone()33 RefPtr<PaintProperty> Clone() const override 34 { 35 auto paintProperty = MakeRefPtr<PatternLockPaintProperty>(); 36 paintProperty->UpdatePaintProperty(this); 37 paintProperty->propCircleRadius_ = CloneCircleRadius(); 38 paintProperty->propRegularColor_ = CloneRegularColor(); 39 paintProperty->propSelectedColor_ = CloneSelectedColor(); 40 paintProperty->propActiveColor_ = CloneActiveColor(); 41 paintProperty->propPathColor_ = ClonePathColor(); 42 paintProperty->propPathStrokeWidth_ = ClonePathStrokeWidth(); 43 paintProperty->propAutoReset_ = CloneAutoReset(); 44 paintProperty->propActiveCircleColor_ = CloneActiveCircleColor(); 45 paintProperty->propActiveCircleRadius_ = CloneActiveCircleRadius(); 46 paintProperty->propEnableWaveEffect_ = CloneEnableWaveEffect(); 47 return paintProperty; 48 } 49 Reset()50 void Reset() override 51 { 52 PaintProperty::Reset(); 53 ResetCircleRadius(); 54 ResetRegularColor(); 55 ResetSelectedColor(); 56 ResetActiveColor(); 57 ResetPathColor(); 58 ResetPathStrokeWidth(); 59 ResetAutoReset(); 60 ResetActiveCircleColor(); 61 ResetActiveCircleRadius(); 62 ResetEnableWaveEffect(); 63 } 64 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)65 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 66 { 67 PaintProperty::ToJsonValue(json, filter); 68 auto pipeline = PipelineBase::GetCurrentContext(); 69 CHECK_NULL_VOID(pipeline); 70 auto patternLockTheme = pipeline->GetTheme<V2::PatternLockTheme>(); 71 CHECK_NULL_VOID(patternLockTheme); 72 /* no fixed attr below, just return */ 73 if (filter.IsFastFilter()) { 74 return; 75 } 76 json->PutExtAttr("circleRadius", 77 GetCircleRadius().value_or(patternLockTheme->GetCircleRadius()).ToString().c_str(), filter); 78 json->PutExtAttr("regularColor", 79 GetRegularColor().value_or(patternLockTheme->GetRegularColor()).ColorToString().c_str(), filter); 80 json->PutExtAttr("selectedColor", 81 GetSelectedColor().value_or(patternLockTheme->GetSelectedColor()).ColorToString().c_str(), filter); 82 json->PutExtAttr("activeColor", 83 GetActiveColor().value_or(patternLockTheme->GetActiveColor()).ColorToString().c_str(), filter); 84 json->PutExtAttr("pathColor", 85 GetPathColor().value_or(patternLockTheme->GetPathColor()).ColorToString().c_str(), filter); 86 json->PutExtAttr("pathStrokeWidth", 87 GetPathStrokeWidth().value_or(patternLockTheme->GetPathStrokeWidth()).ToString().c_str(), filter); 88 json->PutExtAttr("autoReset", GetAutoReset().value_or(true) ? "true" : "false", filter); 89 json->PutExtAttr("activeCircleColor", 90 GetActiveCircleColor().value_or(patternLockTheme->GetPathColor()).ColorToString().c_str(), filter); 91 json->PutExtAttr("activeCircleRadius", 92 GetActiveCircleRadius().value_or(Dimension(0.0f, DimensionUnit::VP)).ToString().c_str(), filter); 93 json->PutExtAttr("enableWaveEffect", GetEnableWaveEffect().value_or(true) ? "true" : "false", filter); 94 } 95 96 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CircleRadius, Dimension, PROPERTY_UPDATE_RENDER); 97 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RegularColor, Color, PROPERTY_UPDATE_RENDER); 98 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedColor, Color, PROPERTY_UPDATE_RENDER); 99 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ActiveColor, Color, PROPERTY_UPDATE_RENDER); 100 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PathColor, Color, PROPERTY_UPDATE_RENDER); 101 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PathStrokeWidth, Dimension, PROPERTY_UPDATE_RENDER); 102 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(AutoReset, bool, PROPERTY_UPDATE_RENDER); 103 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ActiveCircleColor, Color, PROPERTY_UPDATE_RENDER); 104 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ActiveCircleRadius, Dimension, PROPERTY_UPDATE_RENDER); 105 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableWaveEffect, bool, PROPERTY_UPDATE_RENDER); 106 }; 107 108 } // namespace OHOS::Ace::NG 109 110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PATTERNLOCK_PATTERNLOCK_PAINT_PROPERTY_H 111