• 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 #include "core/components_ng/pattern/text_drag/text_drag_paint_method.h"
16 #include "core/components_ng/pattern/text_drag/text_drag_pattern.h"
17 #include "core/components/text/text_theme.h"
18 
19 namespace OHOS::Ace::NG {
20 constexpr float CONSTANT_DOUBLE = 2.0f;
TextDragPaintMethod(const WeakPtr<Pattern> & pattern,const RefPtr<TextDragOverlayModifier> & textDragOverlayModifier)21 TextDragPaintMethod::TextDragPaintMethod(const WeakPtr<Pattern>& pattern,
22     const RefPtr<TextDragOverlayModifier>& textDragOverlayModifier) : pattern_(pattern),
23     overlayModifier_(textDragOverlayModifier) {}
24 
GetOverlayModifier(PaintWrapper * paintWrapper)25 RefPtr<Modifier> TextDragPaintMethod::GetOverlayModifier(PaintWrapper* paintWrapper)
26 {
27     return overlayModifier_;
28 }
29 
UpdateHandleInfo(const TextDragInfo & info)30 void TextDragPaintMethod::UpdateHandleInfo(const TextDragInfo& info)
31 {
32     auto pipleline = PipelineContext::GetCurrentContext();
33     CHECK_NULL_VOID(pipleline);
34     auto textOverlayTheme = pipleline->GetTheme<TextOverlayTheme>();
35     CHECK_NULL_VOID(textOverlayTheme);
36     auto modifier = DynamicCast<TextDragOverlayModifier>(overlayModifier_);
37     CHECK_NULL_VOID(modifier);
38     auto handleDiameter = textOverlayTheme->GetHandleDiameter().ConvertToPx();
39     modifier->SetHandleRadius(handleDiameter / CONSTANT_DOUBLE);
40     if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
41         modifier->SetHandleColor(textOverlayTheme->GetHandleColor());
42     } else {
43         modifier->SetHandleColor(info.handleColor.value_or(textOverlayTheme->GetHandleColor()));
44     }
45     modifier->SetInnerHandleRadius(textOverlayTheme->GetHandleDiameterInner().ConvertToPx() / CONSTANT_DOUBLE);
46     modifier->SetInnerHandleColor(textOverlayTheme->GetHandleColorInner());
47     modifier->SetFirstHandle(info.firstHandle);
48     modifier->SetSecondHandle(info.secondHandle);
49     auto pattern = DynamicCast<TextDragPattern>(pattern_.Upgrade());
50     CHECK_NULL_VOID(pattern);
51     auto screenWdith = SystemProperties::GetDevicePhysicalWidth();
52     auto screenHeight = SystemProperties::GetDevicePhysicalHeight();
53     RectF boundsRect(-handleDiameter - screenWdith, -handleDiameter - screenHeight,
54         pattern->GetFrameWidth() + (screenWdith + handleDiameter) * CONSTANT_DOUBLE,
55         pattern->GetFrameHeight() + (screenHeight + handleDiameter) * CONSTANT_DOUBLE);
56     modifier->SetBoundsRect(boundsRect);
57     modifier->SetIsFirstHandleAnimated(info.isFirstHandleAnimation);
58     modifier->SetIsSecondHandleAnimated(info.isSecondHandleAnimation);
59     auto textTheme = pipleline->GetTheme<TextTheme>();
60     CHECK_NULL_VOID(textTheme);
61     auto selectorColor = info.selectedBackgroundColor.value_or(textTheme->GetSelectedColor());
62     modifier->SetSelectedColor(selectorColor.GetValue());
63 }
64 } // namespace OHOS::Ace::NG
65