• 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_TEXT_DRAG_TEXT_DRAG_OVERLAY_MODIFIER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_DRAG_TEXT_DRAG_OVERLAY_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/image/image_pattern.h"
23 #include "core/components_ng/pattern/pattern.h"
24 
25 namespace OHOS::Ace::NG {
26 constexpr int32_t TEXT_ANIMATION_DURATION = 300;
27 constexpr Dimension TEXT_DRAG_DEFAULT_OFFSET = 8.0_vp;
28 constexpr int32_t TEXT_FLOATING_ANIMATE_HANDLE_OPACITY_DURATION = 150;
29 
30 class TextDragPattern;
31 enum class DragAnimType { FLOATING, FLOATING_CANCEL, DEFAULT };
32 
33 class TextDragOverlayModifier : public OverlayModifier {
34     DECLARE_ACE_TYPE(TextDragOverlayModifier, OverlayModifier);
35 
36 public:
37     explicit TextDragOverlayModifier(const WeakPtr<OHOS::Ace::NG::Pattern>& pattern);
38     ~TextDragOverlayModifier() override = default;
39 
40     virtual void StartFloatingAnimate();
41     void StartFloatingSelBackgroundAnimate();
42 
IsHandlesShow()43     bool IsHandlesShow()
44     {
45         return isHandlesShow_;
46     }
47 
UpdateHandlesShowFlag(bool isHandlesShow)48     void UpdateHandlesShowFlag(bool isHandlesShow)
49     {
50         isHandlesShow_ = isHandlesShow;
51     }
52 
53     void SetAnimateFlag(bool isAnimate);
54 
SetShadowOpacity(float opacity)55     void SetShadowOpacity(float opacity)
56     {
57         CHECK_NULL_VOID(shadowOpacity_);
58         shadowOpacity_->Set(opacity);
59     }
60 
SetHandleOpacity(float opacity)61     void SetHandleOpacity(float opacity)
62     {
63         CHECK_NULL_VOID(handleOpacity_);
64         handleOpacity_->Set(opacity);
65     }
66 
SetFirstHandle(const RectF & handle)67     void SetFirstHandle(const RectF& handle)
68     {
69         CHECK_NULL_VOID(firstHandle_);
70         firstHandle_->Set(handle);
71     }
72 
SetSecondHandle(const RectF & handle)73     void SetSecondHandle(const RectF& handle)
74     {
75         CHECK_NULL_VOID(secondHandle_);
76         secondHandle_->Set(handle);
77     }
78 
SetHandleRadius(float radius)79     void SetHandleRadius(float radius)
80     {
81         CHECK_NULL_VOID(handleRadius_);
82         handleRadius_->Set(radius);
83     }
84 
SetInnerHandleRadius(float radius)85     void SetInnerHandleRadius(float radius)
86     {
87         CHECK_NULL_VOID(innerHandleRadius_);
88         innerHandleRadius_->Set(radius);
89     }
90 
SetInnerHandleColor(const Color & color)91     void SetInnerHandleColor(const Color& color)
92     {
93         CHECK_NULL_VOID(innerHandleColor_);
94         innerHandleColor_->Set(color);
95     }
96 
SetHandleColor(const Color & color)97     void SetHandleColor(const Color& color)
98     {
99         CHECK_NULL_VOID(handleColor_);
100         handleColor_->Set(color);
101     }
102 
SetSelectedColor(uint32_t selectedColor)103     void SetSelectedColor(uint32_t selectedColor)
104     {
105         CHECK_NULL_VOID(selectedColor_);
106         selectedColor_->Set(static_cast<int32_t>(selectedColor));
107     }
108 
SetIsFirstHandleAnimated(bool isFirstHandleAnimated)109     void SetIsFirstHandleAnimated(bool isFirstHandleAnimated)
110     {
111         isFirstHandleAnimated_ = isFirstHandleAnimated;
112     }
113 
SetIsSecondHandleAnimated(bool isSecondHandleAnimated)114     void SetIsSecondHandleAnimated(bool isSecondHandleAnimated)
115     {
116         isSecondHandleAnimated_ = isSecondHandleAnimated;
117     }
118 
119     void PaintBackground(const RSPath& path, RSCanvas& canvas, RefPtr<TextDragPattern> textDragPattern);
120     void PaintShadow(const RSPath& path, const Shadow& shadow, RSCanvas& canvas);
121     void onDraw(DrawingContext& context) override;
122     void SetBackgroundOffset(float offset);
123     void SetSelectedBackgroundOpacity(float opacity);
124     void PaintHandle(RSCanvas& canvas, const RectF& handleRect, bool isFirstHandle, float startX, float startY);
125     void PaintHandleRing(RSCanvas& canvas);
126     void PaintHandleHold(RSCanvas& canvas, const RectF& handleRect, const OffsetF& startPoint,
127         const OffsetF& endPoint);
128     void PaintSelBackground(RSCanvas& canvas, const RefPtr<TextDragPattern>& textDragPattern);
129     void PaintImage(RSCanvas& canvas);
IsAnimating()130     bool IsAnimating()
131     {
132         return isAnimating_;
133     }
134 
135 protected:
136     WeakPtr<Pattern> pattern_;
137     bool isAnimating_ = false;
138     bool isHandlesShow_ = false;
139     bool isFirstHandleAnimated_ = true;
140     bool isSecondHandleAnimated_ = true;
141     RefPtr<AnimatablePropertyFloat> backgroundOffset_;
142     RefPtr<AnimatablePropertyFloat> selectedBackgroundOpacity_;
143     RefPtr<AnimatablePropertyFloat> handleOpacity_;
144     RefPtr<PropertyRectF> firstHandle_;
145     RefPtr<PropertyRectF> secondHandle_;
146     RefPtr<PropertyFloat> handleRadius_;
147     RefPtr<PropertyColor> innerHandleColor_;
148     RefPtr<PropertyColor> handleColor_;
149     RefPtr<PropertyFloat> innerHandleRadius_;
150     RefPtr<PropertyInt> selectedColor_;
151 private:
152     DragAnimType type_ = DragAnimType::DEFAULT;
153     RefPtr<AnimatablePropertyFloat> shadowOpacity_;
154 
155     ACE_DISALLOW_COPY_AND_MOVE(TextDragOverlayModifier);
156 };
157 } // namespace OHOS::Ace::NG
158 
159 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_DRAG_TEXT_DRAG_OVERLAY_MODIFIER_H
160