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 SetAnimateFlag(bool isAnimate)53 void SetAnimateFlag(bool isAnimate) 54 { 55 isAnimating_ = isAnimate; 56 } 57 SetShadowOpacity(float opacity)58 void SetShadowOpacity(float opacity) 59 { 60 CHECK_NULL_VOID(shadowOpacity_); 61 shadowOpacity_->Set(opacity); 62 } 63 SetHandleOpacity(float opacity)64 void SetHandleOpacity(float opacity) 65 { 66 CHECK_NULL_VOID(handleOpacity_); 67 handleOpacity_->Set(opacity); 68 } 69 SetFirstHandle(const RectF & handle)70 void SetFirstHandle(const RectF& handle) 71 { 72 CHECK_NULL_VOID(firstHandle_); 73 firstHandle_->Set(handle); 74 } 75 SetSecondHandle(const RectF & handle)76 void SetSecondHandle(const RectF& handle) 77 { 78 CHECK_NULL_VOID(secondHandle_); 79 secondHandle_->Set(handle); 80 } 81 SetHandleRadius(float radius)82 void SetHandleRadius(float radius) 83 { 84 CHECK_NULL_VOID(handleRadius_); 85 handleRadius_->Set(radius); 86 } 87 SetInnerHandleRadius(float radius)88 void SetInnerHandleRadius(float radius) 89 { 90 CHECK_NULL_VOID(innerHandleRadius_); 91 innerHandleRadius_->Set(radius); 92 } 93 SetInnerHandleColor(const Color & color)94 void SetInnerHandleColor(const Color& color) 95 { 96 CHECK_NULL_VOID(innerHandleColor_); 97 innerHandleColor_->Set(color); 98 } 99 SetHandleColor(const Color & color)100 void SetHandleColor(const Color& color) 101 { 102 CHECK_NULL_VOID(handleColor_); 103 handleColor_->Set(color); 104 } 105 SetSelectedColor(uint32_t selectedColor)106 void SetSelectedColor(uint32_t selectedColor) 107 { 108 CHECK_NULL_VOID(selectedColor_); 109 selectedColor_->Set(static_cast<int32_t>(selectedColor)); 110 } 111 SetIsFirstHandleAnimated(bool isFirstHandleAnimated)112 void SetIsFirstHandleAnimated(bool isFirstHandleAnimated) 113 { 114 isFirstHandleAnimated_ = isFirstHandleAnimated; 115 } 116 SetIsSecondHandleAnimated(bool isSecondHandleAnimated)117 void SetIsSecondHandleAnimated(bool isSecondHandleAnimated) 118 { 119 isSecondHandleAnimated_ = isSecondHandleAnimated; 120 } 121 122 void PaintBackground(const RSPath& path, RSCanvas& canvas, RefPtr<TextDragPattern> textDragPattern); 123 void PaintShadow(const RSPath& path, const Shadow& shadow, RSCanvas& canvas); 124 void onDraw(DrawingContext& context) override; 125 void SetBackgroundOffset(float offset); 126 void SetSelectedBackgroundOpacity(float opacity); 127 void PaintHandle(RSCanvas& canvas, const RectF& handleRect, bool isFirstHandle, float startX, float startY); 128 void PaintHandleRing(RSCanvas& canvas); 129 void PaintHandleHold(RSCanvas& canvas, const RectF& handleRect, const OffsetF& startPoint, 130 const OffsetF& endPoint); 131 void PaintSelBackground(RSCanvas& canvas, const RefPtr<TextDragPattern>& textDragPattern); 132 void PaintImage(RSCanvas& canvas); 133 134 protected: 135 WeakPtr<Pattern> pattern_; 136 bool isAnimating_ = false; 137 bool isHandlesShow_ = false; 138 bool isFirstHandleAnimated_ = true; 139 bool isSecondHandleAnimated_ = true; 140 RefPtr<AnimatablePropertyFloat> backgroundOffset_; 141 RefPtr<AnimatablePropertyFloat> selectedBackgroundOpacity_; 142 RefPtr<AnimatablePropertyFloat> handleOpacity_; 143 RefPtr<PropertyRectF> firstHandle_; 144 RefPtr<PropertyRectF> secondHandle_; 145 RefPtr<PropertyFloat> handleRadius_; 146 RefPtr<PropertyColor> innerHandleColor_; 147 RefPtr<PropertyColor> handleColor_; 148 RefPtr<PropertyFloat> innerHandleRadius_; 149 RefPtr<PropertyInt> selectedColor_; 150 private: 151 DragAnimType type_ = DragAnimType::DEFAULT; 152 RefPtr<AnimatablePropertyFloat> shadowOpacity_; 153 154 ACE_DISALLOW_COPY_AND_MOVE(TextDragOverlayModifier); 155 }; 156 } // namespace OHOS::Ace::NG 157 158 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_DRAG_TEXT_DRAG_OVERLAY_MODIFIER_H 159