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_CHECKBOXGROUP_CHECKBOXGROUP_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOXGROUP_CHECKBOXGROUP_MODIFIER_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components_ng/base/modifier.h" 22 #include "core/components_ng/pattern/checkboxgroup/checkboxgroup_paint_property.h" 23 #include "core/components_ng/pattern/radio/radio_paint_method.h" 24 #include "core/components_ng/property/property.h" 25 #include "core/components_ng/render/animation_utils.h" 26 #include "core/components_ng/render/drawing_forward.h" 27 #include "core/pipeline_ng/pipeline_context.h" 28 29 namespace OHOS::Ace::NG { 30 class CheckBoxGroupModifier : public ContentModifier { 31 DECLARE_ACE_TYPE(CheckBoxGroupModifier, ContentModifier); 32 33 public: 34 struct Parameters { 35 float borderWidth; 36 float borderRadius; 37 float checkStroke; 38 float checkMarkPaintSize; 39 float hoverDuration; 40 float hoverToTouchDuration; 41 Color pointColor; 42 Color activeColor; 43 Color inactiveColor; 44 Color shadowColor; 45 Color clickEffectColor; 46 Color hoverColor; 47 Color inactivePointColor; 48 Dimension hoverRadius; 49 Dimension hotZoneHorizontalPadding; 50 Dimension hotZoneVerticalPadding; 51 Dimension shadowWidth; 52 UIStatus uiStatus; 53 Dimension defaultPaddingSize; 54 Dimension hoverPaddingSize; 55 bool showCircleDial; 56 CheckBoxGroupPaintProperty::SelectStatus status; 57 }; 58 59 explicit CheckBoxGroupModifier(const Parameters& parameters); 60 ~CheckBoxGroupModifier() override = default; onDraw(DrawingContext & context)61 void onDraw(DrawingContext& context) override 62 { 63 PaintCheckBox(context, offset_->Get(), size_->Get()); 64 } 65 UpdateAnimatableProperty(const RefPtr<FrameNode> & host)66 void UpdateAnimatableProperty(const RefPtr<FrameNode>& host) 67 { 68 switch (touchHoverType_) { 69 case TouchHoverAnimationType::HOVER: 70 SetBoardColor(LinearColor(hoverColor_), hoverDuration_, Curves::FRICTION, host); 71 break; 72 case TouchHoverAnimationType::PRESS_TO_HOVER: 73 SetBoardColor(LinearColor(hoverColor_), hoverToTouchDuration_, Curves::SHARP, host); 74 break; 75 case TouchHoverAnimationType::NONE: 76 SetBoardColor(LinearColor(hoverColor_.BlendOpacity(0)), hoverDuration_, Curves::FRICTION, host); 77 break; 78 case TouchHoverAnimationType::HOVER_TO_PRESS: 79 SetBoardColor(LinearColor(clickEffectColor_), hoverToTouchDuration_, Curves::SHARP, host); 80 break; 81 case TouchHoverAnimationType::PRESS: 82 SetBoardColor(LinearColor(clickEffectColor_), hoverDuration_, Curves::FRICTION, host); 83 break; 84 default: 85 break; 86 } 87 } 88 SetBoardColor(LinearColor color,int32_t duration,const RefPtr<CubicCurve> & curve,const RefPtr<FrameNode> & host)89 void SetBoardColor( 90 LinearColor color, int32_t duration, const RefPtr<CubicCurve>& curve, const RefPtr<FrameNode>& host) 91 { 92 CHECK_NULL_VOID(host); 93 if (animateTouchHoverColor_) { 94 AnimationOption option = AnimationOption(); 95 option.SetDuration(duration); 96 option.SetCurve(curve); 97 AnimationUtils::Animate( 98 option, [&]() { animateTouchHoverColor_->Set(color); }, nullptr, nullptr, host->GetContextRefPtr()); 99 } 100 } 101 102 void PaintCheckBox(DrawingContext& context, const OffsetF& paintOffset, const SizeF& contentSize) const; 103 void PaintCheckBoxGroupPartStatus( 104 RSCanvas& canvas, const OffsetF& paintOffset, RSBrush& brush, RSPen& pen, const SizeF& paintSize) const; 105 void DrawCheck(RSCanvas& canvas, const OffsetF& origin, RSPen& pen, RSPen& shadowPen, const SizeF& paintSize) const; 106 void DrawUnselected(RSCanvas& canvas, const OffsetF& origin, RSPen& pen, const SizeF& paintSize) const; 107 void DrawActiveBorder(RSCanvas& canvas, const OffsetF& paintOffset, RSBrush& brush, const SizeF& paintSize) const; 108 void DrawUnselectedBorder( 109 RSCanvas& canvas, const OffsetF& paintOffset, RSBrush& brush, const SizeF& paintSize) const; 110 void DrawPart(RSCanvas& canvas, const OffsetF& origin, RSPen& pen, const SizeF& paintSize) const; 111 void DrawTouchAndHoverBoard(RSCanvas& canvas, const SizeF& contentSize, const OffsetF& offset) const; 112 void DrawRectOrCircle(RSCanvas& canvas, const RSRoundRect& rrect) const; 113 SetBorderWidth(float borderWidth)114 void SetBorderWidth(float borderWidth) 115 { 116 borderWidth_ = borderWidth; 117 } 118 SetBorderRadius(float borderRadius)119 void SetBorderRadius(float borderRadius) 120 { 121 borderRadius_ = borderRadius; 122 } 123 SetCheckStroke(float checkStroke)124 void SetCheckStroke(float checkStroke) 125 { 126 checkStroke_->Set(checkStroke); 127 } 128 SetCheckMarkPaintSize(float checkMarkPaintSize)129 void SetCheckMarkPaintSize(float checkMarkPaintSize) 130 { 131 checkMarkPaintSize_->Set(checkMarkPaintSize); 132 } 133 SetPointColor(Color pointColor)134 void SetPointColor(Color pointColor) 135 { 136 pointColor_->Set(LinearColor(pointColor)); 137 } 138 SetActiveColor(Color activeColor)139 void SetActiveColor(Color activeColor) 140 { 141 activeColor_->Set(LinearColor(activeColor)); 142 } 143 SetInactiveColor(Color inactiveColor)144 void SetInactiveColor(Color inactiveColor) 145 { 146 inactiveColor_->Set(LinearColor(inactiveColor)); 147 } 148 SetShadowColor(Color shadowColor)149 void SetShadowColor(Color shadowColor) 150 { 151 shadowColor_ = shadowColor; 152 } 153 SetClickEffectColor(Color clickEffectColor)154 void SetClickEffectColor(Color clickEffectColor) 155 { 156 clickEffectColor_ = clickEffectColor; 157 } 158 SetHoverColor(Color hoverColor)159 void SetHoverColor(Color hoverColor) 160 { 161 hoverColor_ = hoverColor; 162 } 163 SetInactivePointColor(Color inactivePointColor)164 void SetInactivePointColor(Color inactivePointColor) 165 { 166 if (inactivePointColor_) { 167 inactivePointColor_->Set(inactivePointColor); 168 } 169 } 170 SetHoverRadius(Dimension hoverRadius)171 void SetHoverRadius(Dimension hoverRadius) 172 { 173 hoverRadius_ = hoverRadius; 174 } 175 SetHotZoneHorizontalPadding(Dimension hotZoneHorizontalPadding)176 void SetHotZoneHorizontalPadding(Dimension hotZoneHorizontalPadding) 177 { 178 hotZoneHorizontalPadding_ = hotZoneHorizontalPadding; 179 } 180 SetHotZoneVerticalPadding(Dimension hotZoneVerticalPadding)181 void SetHotZoneVerticalPadding(Dimension hotZoneVerticalPadding) 182 { 183 hotZoneVerticalPadding_ = hotZoneVerticalPadding; 184 } 185 SetShadowWidth(Dimension shadowWidth)186 void SetShadowWidth(Dimension shadowWidth) 187 { 188 shadowWidth_ = shadowWidth; 189 } 190 SetEnabled(bool value)191 void SetEnabled(bool value) 192 { 193 enabled_->Set(value); 194 } 195 SetTouchHoverAnimationType(const TouchHoverAnimationType touchHoverType)196 void SetTouchHoverAnimationType(const TouchHoverAnimationType touchHoverType) 197 { 198 touchHoverType_ = touchHoverType; 199 } 200 SetUiStatus(UIStatus uiStatus)201 void SetUiStatus(UIStatus uiStatus) 202 { 203 if (uiStatus_) { 204 uiStatus_->Set(static_cast<int>(uiStatus)); 205 } 206 } 207 SetSelectStatus(CheckBoxGroupPaintProperty::SelectStatus status)208 void SetSelectStatus(CheckBoxGroupPaintProperty::SelectStatus status) 209 { 210 if (status_) { 211 status_->Set(static_cast<int>(status)); 212 } 213 } 214 GetBorderWidth()215 float GetBorderWidth() const 216 { 217 return borderWidth_; 218 } 219 SetOffset(OffsetF & offset)220 void SetOffset(OffsetF& offset) 221 { 222 if (offset_) { 223 offset_->Set(offset); 224 } 225 } 226 SetSize(SizeF & size)227 void SetSize(SizeF& size) 228 { 229 if (size_) { 230 size_->Set(size); 231 } 232 } 233 SetHoverEffectType(HoverEffectType hoverEffectType)234 void SetHoverEffectType(HoverEffectType hoverEffectType) 235 { 236 hoverEffectType_ = hoverEffectType; 237 } 238 SetCheckboxGroupStyle(CheckBoxStyle checkBoxGroupStyle)239 void SetCheckboxGroupStyle(CheckBoxStyle checkBoxGroupStyle) 240 { 241 checkBoxGroupStyle_ = checkBoxGroupStyle; 242 CHECK_NULL_VOID(checkBoxGroupShape_); 243 checkBoxGroupShape_->Set(static_cast<int32_t>(checkBoxGroupStyle)); 244 } 245 246 private: 247 RefPtr<AnimatablePropertyColor> activeColor_; 248 RefPtr<AnimatablePropertyColor> pointColor_; 249 RefPtr<AnimatablePropertyColor> inactiveColor_; 250 RefPtr<AnimatablePropertyFloat> checkMarkPaintSize_; 251 RefPtr<AnimatablePropertyFloat> checkStroke_; 252 RefPtr<AnimatablePropertyColor> animateTouchHoverColor_; 253 TouchHoverAnimationType touchHoverType_ = TouchHoverAnimationType::NONE; 254 HoverEffectType hoverEffectType_ = HoverEffectType::AUTO; 255 RefPtr<PropertyBool> enabled_; 256 RefPtr<PropertyInt> uiStatus_; 257 RefPtr<PropertyInt> status_; 258 RefPtr<PropertyOffsetF> offset_; 259 RefPtr<PropertySizeF> size_; 260 RefPtr<PropertyInt> checkBoxGroupShape_; 261 CheckBoxStyle checkBoxGroupStyle_ = CheckBoxStyle::CIRCULAR_STYLE; 262 float borderWidth_; 263 float borderRadius_; 264 Color shadowColor_; 265 Color clickEffectColor_; 266 Color hoverColor_; 267 RefPtr<PropertyColor> inactivePointColor_; 268 Dimension hoverRadius_; 269 Dimension hotZoneHorizontalPadding_; 270 Dimension hotZoneVerticalPadding_; 271 Dimension shadowWidth_; 272 float hoverDuration_ = 0.0f; 273 float hoverToTouchDuration_ = 0.0f; 274 Dimension defaultPaddingSize_; 275 Dimension hoverPaddingSize_; 276 bool showCircleDial_; 277 ACE_DISALLOW_COPY_AND_MOVE(CheckBoxGroupModifier); 278 }; 279 } // namespace OHOS::Ace::NG 280 281 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOXGROUP_CHECKBOXGROUP_MODIFIER_H 282