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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RADIO_RADIO_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RADIO_RADIO_MODIFIER_H 18 19 #include <vector> 20 21 #include "base/geometry/ng/offset_t.h" 22 #include "base/memory/ace_type.h" 23 #include "core/components_ng/base/modifier.h" 24 #include "core/components_ng/render/drawing_forward.h" 25 26 namespace OHOS::Ace::NG { 27 enum class UIStatus { 28 SELECTED = 0, 29 UNSELECTED, 30 FOCUS, 31 ON_TO_OFF, 32 OFF_TO_ON, 33 PART, 34 PART_TO_OFF, 35 OFF_TO_PART, 36 PART_TO_ON, 37 ON_TO_PART, 38 }; 39 40 enum class TouchHoverAnimationType { 41 NONE = 0, 42 HOVER, 43 PRESS, 44 HOVER_TO_PRESS, 45 PRESS_TO_HOVER, 46 }; 47 48 class RadioModifier : public ContentModifier { 49 DECLARE_ACE_TYPE(RadioModifier, ContentModifier); 50 51 public: 52 RadioModifier(); 53 ~RadioModifier() override = default; 54 onDraw(DrawingContext & context)55 void onDraw(DrawingContext& context) override 56 { 57 RSCanvas& canvas = context.canvas; 58 PaintRadio(canvas, isCheck_->Get(), size_->Get(), offset_->Get()); 59 } 60 61 void UpdateAnimatableProperty(); 62 void UpdateIsOnAnimatableProperty(bool isCheck); 63 void SetBoardColor(LinearColor color, int32_t duratuion, const RefPtr<CubicCurve>& curve); 64 void InitializeParam(); 65 void PaintRadio(RSCanvas& canvas, bool checked, const SizeF& contentSize, const OffsetF& contentOffset) const; 66 void DrawTouchAndHoverBoard(RSCanvas& canvas, const SizeF& contentSize, const OffsetF& contentOffset) const; 67 SetPointColor(const Color & pointColor)68 void SetPointColor(const Color& pointColor) 69 { 70 pointColor_->Set(LinearColor(pointColor)); 71 } SetactiveColor(const Color & activeColor)72 void SetactiveColor(const Color& activeColor) 73 { 74 activeColor_->Set(LinearColor(activeColor)); 75 } SetinactiveColor(const Color & inactiveColor)76 void SetinactiveColor(const Color& inactiveColor) 77 { 78 inactiveColor_->Set(LinearColor(inactiveColor)); 79 } SetHotZoneOffset(const OffsetF & hotZoneOffset)80 void SetHotZoneOffset(const OffsetF& hotZoneOffset) 81 { 82 hotZoneOffset_ = hotZoneOffset; 83 } 84 SetHotZoneSize(const SizeF & hotZoneSize)85 void SetHotZoneSize(const SizeF& hotZoneSize) 86 { 87 hotZoneSize_ = hotZoneSize; 88 } 89 SetEnabled(bool enabled)90 void SetEnabled(bool enabled) 91 { 92 if (enabled_) { 93 enabled_->Set(enabled); 94 } 95 } 96 SetIsCheck(bool isCheck)97 void SetIsCheck(bool isCheck) 98 { 99 if (isCheck_) { 100 isCheck_->Set(isCheck); 101 } 102 } 103 GetIsCheck()104 bool GetIsCheck() 105 { 106 if (isCheck_) { 107 return isCheck_->Get(); 108 } 109 return false; 110 } 111 SetIsOnAnimationFlag(bool isOnAnimationFlag)112 void SetIsOnAnimationFlag(bool isOnAnimationFlag) 113 { 114 if (isOnAnimationFlag_) { 115 isOnAnimationFlag_->Set(isOnAnimationFlag); 116 } 117 } 118 SetTotalScale(const float totalScale)119 void SetTotalScale(const float totalScale) 120 { 121 if (totalScale_) { 122 totalScale_->Set(totalScale); 123 } 124 } 125 SetPointScale(const float pointScale)126 void SetPointScale(const float pointScale) 127 { 128 if (pointScale_) { 129 pointScale_->Set(pointScale); 130 } 131 } 132 SetRingPointScale(const float ringPointScale)133 void SetRingPointScale(const float ringPointScale) 134 { 135 if (ringPointScale_) { 136 ringPointScale_->Set(ringPointScale); 137 } 138 } 139 SetOffset(OffsetF & offset)140 void SetOffset(OffsetF& offset) 141 { 142 if (offset_) { 143 offset_->Set(offset); 144 } 145 } 146 SetSize(SizeF & size)147 void SetSize(SizeF& size) 148 { 149 if (size_) { 150 size_->Set(size); 151 } 152 } 153 SetUIStatus(const UIStatus & uiStatus)154 void SetUIStatus(const UIStatus& uiStatus) 155 { 156 if (uiStatus_) { 157 uiStatus_->Set(static_cast<int32_t>(uiStatus)); 158 } 159 } 160 SetTouchHoverAnimationType(const TouchHoverAnimationType touchHoverType)161 void SetTouchHoverAnimationType(const TouchHoverAnimationType touchHoverType) 162 { 163 touchHoverType_ = touchHoverType; 164 } 165 166 private: 167 float shadowWidth_ = 1.5f; 168 float borderWidth_ = 1.5f; 169 Color inactivePointColor_; 170 Color shadowColor_; 171 Color clickEffectColor_; 172 Color hoverColor_; 173 Dimension hotZoneHorizontalPadding_; 174 float hoverDuration_ = 0.0f; 175 float hoverToTouchDuration_ = 0.0f; 176 float touchDuration_ = 0.0f; 177 OffsetF hotZoneOffset_; 178 SizeF hotZoneSize_; 179 RefPtr<PropertyBool> isOnAnimationFlag_; 180 RefPtr<PropertyBool> enabled_; 181 RefPtr<PropertyBool> isCheck_; 182 RefPtr<PropertyInt> uiStatus_; 183 184 RefPtr<AnimatablePropertyColor> pointColor_; 185 RefPtr<AnimatablePropertyColor> activeColor_; 186 RefPtr<AnimatablePropertyColor> inactiveColor_; 187 RefPtr<AnimatablePropertyOffsetF> offset_; 188 RefPtr<AnimatablePropertySizeF> size_; 189 RefPtr<RadioModifier> radioModifier_; 190 RefPtr<AnimatablePropertyFloat> totalScale_; 191 RefPtr<AnimatablePropertyFloat> pointScale_; 192 RefPtr<AnimatablePropertyFloat> ringPointScale_; 193 RefPtr<AnimatablePropertyColor> animateTouchHoverColor_; 194 TouchHoverAnimationType touchHoverType_ = TouchHoverAnimationType::NONE; 195 196 ACE_DISALLOW_COPY_AND_MOVE(RadioModifier); 197 }; 198 } // namespace OHOS::Ace::NG 199 200 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RADIO_RADIO_MODIFIER_H 201