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_PAINTS_CHECKBOX_CHECKBOX_PAINT_METHOD_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_CHECKBOX_CHECKBOX_PAINT_METHOD_H 18 19 #include "base/memory/ace_type.h" 20 #include "base/utils/macros.h" 21 #include "core/components_ng/pattern/checkbox/checkbox_modifier.h" 22 #include "core/components_ng/pattern/checkbox/checkbox_paint_property.h" 23 #include "core/components_ng/render/canvas.h" 24 #include "core/components_ng/render/drawing.h" 25 #include "core/components_ng/render/node_paint_method.h" 26 namespace OHOS::Ace::NG { 27 class CheckBoxPaintMethod : public NodePaintMethod { DECLARE_ACE_TYPE(CheckBoxPaintMethod,NodePaintMethod)28 DECLARE_ACE_TYPE(CheckBoxPaintMethod, NodePaintMethod) 29 30 public: 31 explicit CheckBoxPaintMethod(const RefPtr<CheckBoxModifier>& checkboxModifier) : checkboxModifier_(checkboxModifier) 32 {} 33 34 ~CheckBoxPaintMethod() override = default; 35 GetContentModifier(PaintWrapper * paintWrapper)36 RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override 37 { 38 CHECK_NULL_RETURN(checkboxModifier_, nullptr); 39 return checkboxModifier_; 40 } 41 UpdateContentModifier(PaintWrapper * paintWrapper)42 void UpdateContentModifier(PaintWrapper* paintWrapper) override 43 { 44 CHECK_NULL_VOID(checkboxModifier_); 45 checkboxModifier_->InitializeParam(); 46 auto paintProperty = DynamicCast<CheckBoxPaintProperty>(paintWrapper->GetPaintProperty()); 47 if (paintProperty->GetCheckBoxSelect().has_value()) { 48 checkboxModifier_->SetIsSelect(paintProperty->GetCheckBoxSelectValue()); 49 } 50 if (paintProperty->HasCheckBoxSelectedColor()) { 51 checkboxModifier_->SetUserActiveColor(paintProperty->GetCheckBoxSelectedColorValue()); 52 } 53 auto size = paintWrapper->GetContentSize(); 54 auto offset = paintWrapper->GetContentOffset(); 55 checkboxModifier_->SetSize(size); 56 checkboxModifier_->SetOffset(offset); 57 checkboxModifier_->SetEnabled(enabled_); 58 checkboxModifier_->SetIsHover(isHover_); 59 checkboxModifier_->UpdateAnimatableProperty(); 60 } 61 SetHotZoneOffset(OffsetF & hotZoneOffset)62 void SetHotZoneOffset(OffsetF& hotZoneOffset) 63 { 64 hotZoneOffset_ = hotZoneOffset; 65 } 66 SetHotZoneSize(SizeF & hotZoneSize)67 void SetHotZoneSize(SizeF& hotZoneSize) 68 { 69 hotZoneSize_ = hotZoneSize; 70 } 71 SetEnabled(bool enabled)72 void SetEnabled(bool enabled) 73 { 74 enabled_ = enabled; 75 } 76 SetIsHover(bool isHover)77 void SetIsHover(bool isHover) 78 { 79 isHover_ = isHover; 80 } 81 SetTotalScale(float totalScale)82 void SetTotalScale(float totalScale) 83 { 84 totalScale_ = totalScale; 85 } 86 SetPointScale(float pointScale)87 void SetPointScale(float pointScale) 88 { 89 pointScale_ = pointScale; 90 } 91 92 private: 93 bool enabled_ = true; 94 bool isHover_ = false; 95 float totalScale_ = 1.0f; 96 float pointScale_ = 0.5f; 97 OffsetF hotZoneOffset_; 98 SizeF hotZoneSize_; 99 100 RefPtr<CheckBoxModifier> checkboxModifier_; 101 ACE_DISALLOW_COPY_AND_MOVE(CheckBoxPaintMethod); 102 }; 103 } // namespace OHOS::Ace::NG 104 105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_CHECKBOX_CHECKBOX_PAINT_METHOD_H 106