• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 KNUCKLE_DRAWING_MANAGER_H
17 #define KNUCKLE_DRAWING_MANAGER_H
18 
19 #include "transaction/rs_transaction.h"
20 #include "ui/rs_canvas_drawing_node.h"
21 #include "ui/rs_surface_node.h"
22 
23 #include "pointer_event.h"
24 #include "window_info.h"
25 
26 namespace OHOS {
27 namespace MMI {
28 struct PointerInfo {
29     float x { 0.0F };
30     float y { 0.0F };
31 };
32 
33 struct ScreenReadState {
34     std::string switchName;
35     std::string state;
36 };
37 
38 class KnuckleDrawingManager {
39 public:
40     void KnuckleDrawHandler(std::shared_ptr<PointerEvent> touchEvent);
41     void UpdateDisplayInfo(const DisplayInfo& displayInfo);
42     KnuckleDrawingManager();
43     ~KnuckleDrawingManager() = default;
44     void RotationCanvasNode(std::shared_ptr<Rosen::RSCanvasNode> canvasNode, const DisplayInfo& displayInfo);
45     std::string GetScreenReadState();
46 private:
47     bool IsValidAction(int32_t action);
48     void CreateTouchWindow(int32_t displayId);
49     void StartTouchDraw(std::shared_ptr<PointerEvent> touchEvent);
50     int32_t DrawGraphic(std::shared_ptr<PointerEvent> touchEvent);
51     int32_t GetPointerPos(std::shared_ptr<PointerEvent> touchEvent);
52     bool IsSingleKnuckle(std::shared_ptr<PointerEvent> touchEvent);
53     bool IsSingleKnuckleDoubleClick(std::shared_ptr<PointerEvent> touchEvent);
54     int32_t DestoryWindow();
55     void CreateObserver();
56     template <class T>
57     void CreateScreenReadObserver(T& item);
58 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
59     void CreateBrushWorkCanvasNode();
60     void CreateTrackCanvasNode();
61     void InitParticleEmitter();
62     void UpdateEmitter();
63     void DrawTrackCanvas();
64     void DrawBrushCanvas();
65     int32_t ClearTrackCanvas();
66     int32_t ClearBrushCanvas();
67     void ActionUpAnimation();
68     uint32_t GetDeltaColor(uint32_t deltaSource, uint32_t deltaTarget);
69     uint32_t DrawTrackColorBlue(int32_t pathValue);
70     uint32_t DrawTrackColorPink(int32_t pathValue);
71     uint32_t DrawTrackColorOrangeRed(int32_t pathValue);
72     uint32_t DrawTrackColorYellow(int32_t pathValue);
73     int32_t ProcessUpEvent(bool isNeedUpAnimation);
74 #else
75     void CreateCanvasNode();
76 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
77 
78 private:
79     std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ { nullptr };
80 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
81     std::shared_ptr<Rosen::RSCanvasDrawingNode> brushCanvasNode_ { nullptr };
82     std::shared_ptr<Rosen::RSCanvasDrawingNode> trackCanvasNode_ { nullptr };
83 #else
84     std::shared_ptr<Rosen::RSCanvasDrawingNode> canvasNode_ { nullptr };
85 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
86     std::vector<PointerInfo> pointerInfos_;
87     Rosen::Drawing::Paint paint_;
88     Rosen::Drawing::Path path_;
89     DisplayInfo displayInfo_ {};
90     uint64_t screenId_ { 0 };
91     bool isActionUp_ { false };
92     bool isNeedInitParticleEmitter_ { true };
93     PointerInfo lastDownPointer_ {};
94     int64_t lastUpTime_ { 0 };
95     bool isRotate_ { false };
96     int32_t scaleW_ { 0 };
97     int32_t scaleH_ { 0 };
98     int64_t firstDownTime_ { 0 };
99     bool hasScreenReadObserver_ { false };
100     ScreenReadState screenReadState_ { };
101     int32_t pointerNum_ { 0 };
102 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
103     std::vector<Rosen::Drawing::Path> pathInfos_;
104     float pathLength_ { 0.0f };
105     float brushPathLength_ { 0.0f };
106     uint32_t trackColorR_ { 0x00 };
107     uint32_t trackColorG_ { 0x00 };
108     uint32_t trackColorB_ { 0x00 };
109 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC
110 };
111 } // namespace MMI
112 } // namespace OHOS
113 #endif // KNUCKLE_DRAWING_MANAGER_H
114