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_SWIPER_SWIPER_PAINT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_SWIPER_PAINT_PROPERTY_H
18 
19 #include "core/animation/curve.h"
20 #include "core/animation/curves.h"
21 #include "core/components/common/layout/constants.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components_ng/render/paint_property.h"
24 
25 namespace OHOS::Ace::NG {
26 class InspectorFilter;
27 
28 struct SwiperAnimationStyle {
29     ACE_DEFINE_PROPERTY_GROUP_ITEM(AutoPlay, bool);
30     ACE_DEFINE_PROPERTY_GROUP_ITEM(AutoPlayInterval, int32_t);
31     ACE_DEFINE_PROPERTY_GROUP_ITEM(Duration, int32_t);
32     ACE_DEFINE_PROPERTY_GROUP_ITEM(Curve, RefPtr<Curve>);
33 
34     static const int32_t DEFAULT_INTERVAL;
35     static const int32_t DEFAULT_DURATION;
36 };
37 
38 class SwiperPaintProperty : public PaintProperty {
39     DECLARE_ACE_TYPE(SwiperPaintProperty, PaintProperty)
40 
41 public:
42     SwiperPaintProperty() = default;
43     ~SwiperPaintProperty() override = default;
44 
Clone()45     RefPtr<PaintProperty> Clone() const override
46     {
47         auto paintProperty = MakeRefPtr<SwiperPaintProperty>();
48         paintProperty->UpdatePaintProperty(this);
49         paintProperty->propSwiperAnimationStyle_ = CloneSwiperAnimationStyle();
50         paintProperty->propEnabled_ = CloneEnabled();
51         paintProperty->propEdgeEffect_ = CloneEdgeEffect();
52         paintProperty->propFadeColor_ = CloneFadeColor();
53         return paintProperty;
54     }
55 
Reset()56     void Reset() override
57     {
58         PaintProperty::Reset();
59         ResetSwiperAnimationStyle();
60         ResetEnabled();
61         ResetEdgeEffect();
62         ResetFadeColor();
63     }
64 
65     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
66 
67     void FromJson(const std::unique_ptr<JsonValue>& json) override;
68 
69     ACE_DEFINE_PROPERTY_GROUP(SwiperAnimationStyle, SwiperAnimationStyle);
70     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(SwiperAnimationStyle, AutoPlay, bool, PROPERTY_UPDATE_RENDER);
71     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(SwiperAnimationStyle, AutoPlayInterval, int32_t, PROPERTY_UPDATE_RENDER);
72     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(SwiperAnimationStyle, Duration, int32_t, PROPERTY_UPDATE_RENDER);
73     ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(SwiperAnimationStyle, Curve, RefPtr<Curve>, PROPERTY_UPDATE_RENDER);
74 
75     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Enabled, bool, PROPERTY_UPDATE_RENDER);
76     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EdgeEffect, EdgeEffect, PROPERTY_UPDATE_RENDER);
77     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(FadeColor, Color, PROPERTY_UPDATE_RENDER);
78 };
79 
80 } // namespace OHOS::Ace::NG
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_SWIPER_PAINT_PROPERTY_H
83