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