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_PATTERN_MARQUEE_PAINT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MARQUEE_PAINT_PROPERTY_H
18 
19 #include "base/geometry/dimension.h"
20 #include "base/utils/macros.h"
21 #include "core/components/common/layout/constants.h"
22 #include "core/components_ng/base/inspector_filter.h"
23 #include "core/components_ng/render/paint_property.h"
24 
25 namespace OHOS::Ace::NG {
26 constexpr Dimension DEFAULT_MARQUEE_SCROLL_AMOUNT = 6.0_vp;
27 class ACE_EXPORT MarqueePaintProperty : public PaintProperty {
28     DECLARE_ACE_TYPE(MarqueePaintProperty, PaintProperty);
29 
30 public:
31     MarqueePaintProperty() = default;
32 
33     ~MarqueePaintProperty() override = default;
34 
Clone()35     RefPtr<PaintProperty> Clone() const override
36     {
37         auto value = MakeRefPtr<MarqueePaintProperty>();
38         value->PaintProperty::UpdatePaintProperty(this);
39         value->propPlayerStatus_ = ClonePlayerStatus();
40         value->propScrollAmount_ = CloneScrollAmount();
41         value->propDirection_ = CloneDirection();
42         value->propLoop_ = CloneLoop();
43         return value;
44     }
45 
Reset()46     void Reset() override
47     {
48         PaintProperty::Reset();
49         ResetPlayerStatus();
50         ResetScrollAmount();
51         ResetDirection();
52         ResetLoop();
53     }
54 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)55     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
56     {
57         PaintProperty::ToJsonValue(json, filter);
58         /* no fixed attr below, just return */
59         if (filter.IsFastFilter()) {
60             return;
61         }
62         json->PutExtAttr("step",
63             std::to_string(propScrollAmount_.value_or(DEFAULT_MARQUEE_SCROLL_AMOUNT.ConvertToPx())).c_str(), filter);
64         json->PutExtAttr("loop", std::to_string(propLoop_.value_or(-1)).c_str(), filter);
65         json->PutExtAttr("start", propPlayerStatus_.value_or(true) ? "true" : "false", filter);
66         json->PutExtAttr("fromStart",
67             propDirection_.value_or(MarqueeDirection::RIGHT) == MarqueeDirection::LEFT ? "true" : "false", filter);
68     }
69     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PlayerStatus, bool, PROPERTY_UPDATE_MEASURE);
70     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollAmount, double, PROPERTY_UPDATE_MEASURE);
71     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Loop, int32_t, PROPERTY_UPDATE_MEASURE);
72     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Direction, MarqueeDirection, PROPERTY_UPDATE_MEASURE);
73 
74 private:
75     ACE_DISALLOW_COPY_AND_MOVE(MarqueePaintProperty);
76 };
77 } // namespace OHOS::Ace::NG
78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MARQUEE_PAINT_PROPERTY_H
79