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_DYNAMIC_DRAWING_MANAGER_H
17 #define KNUCKLE_DYNAMIC_DRAWING_MANAGER_H
18 
19 #include "draw/canvas.h"
20 #include "include/core/SkPaint.h"
21 #include "include/core/SkPath.h"
22 #include "transaction/rs_transaction.h"
23 #include "ui/rs_canvas_drawing_node.h"
24 #include "ui/rs_surface_node.h"
25 
26 #include "knuckle_drawing_manager.h"
27 #include "knuckle_glow_trace_system.h"
28 #include "pointer_event.h"
29 #include "window_info.h"
30 
31 namespace OHOS {
32 namespace MMI {
33 class KnuckleDynamicDrawingManager {
34 public:
35     KnuckleDynamicDrawingManager();
36     ~KnuckleDynamicDrawingManager() = default;
37     void KnuckleDynamicDrawHandler(std::shared_ptr<PointerEvent> pointerEvent);
38     void UpdateDisplayInfo(const DisplayInfo& displayInfo);
39     void SetKnuckleDrawingManager(std::shared_ptr<KnuckleDrawingManager> knuckleDrawMgr);
40 
41 private:
42     void StartTouchDraw(std::shared_ptr<PointerEvent> pointerEvent);
43     void CreateTouchWindow(const int32_t displayId);
44     void CreateCanvasNode();
45     int32_t DrawGraphic(std::shared_ptr<PointerEvent> pointerEvent);
46 
47     bool CheckPointerAction(std::shared_ptr<PointerEvent> pointerEvent);
48     void ProcessUpAndCancelEvent(std::shared_ptr<PointerEvent> pointerEvent);
49     void ProcessDownEvent(std::shared_ptr<PointerEvent> pointerEvent);
50     void ProcessMoveEvent(std::shared_ptr<PointerEvent> pointerEvent);
51     void InitPointerPathPaint();
52     void UpdateTrackColors();
53     std::shared_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string &imagePath);
54     bool IsSingleKnuckle(std::shared_ptr<PointerEvent> touchEvent);
55     void DestoryWindow();
56 
57 private:
58     std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ { nullptr };
59     std::shared_ptr<Rosen::RSCanvasDrawingNode> canvasNode_ { nullptr };
60     DisplayInfo displayInfo_ {};
61     uint64_t screenId_ { 0 };
62     Rosen::Drawing::Brush brush_;
63     Rosen::Drawing::Pen pen_;
64     std::vector<Rosen::Drawing::Point> traceControlPoints_;
65 
66     int32_t pointCounter_ { 0 };
67     bool isDrawing_ { true };
68     std::shared_ptr<KnuckleGlowTraceSystem> glowTraceSystem_ { nullptr };
69     Rosen::Drawing::Path pointerPath_;
70     SkPaint pointerPathPaint_;
71     int64_t lastUpdateTimeMillis_ { 0 };
72 
73     std::shared_ptr<OHOS::Media::PixelMap> pixelMap_ { nullptr };
74     bool isStop_ { false };
75     bool isRotate_ { false };
76     int32_t lastDownX_ { 0 };
77     int32_t lastDownY_ { 0 };
78     int64_t lastUpTime_ { 0 };
79     int32_t scaleW_ { 0 };
80     int32_t scaleH_ { 0 };
81     int64_t firstDownTime_ { 0 };
82     int64_t isInDrawingTime_ { 0 };
83     std::shared_ptr<KnuckleDrawingManager> knuckleDrawMgr_ { nullptr };
84 };
85 } // namespace MMI
86 } // namespace OHOS
87 #endif // KNUCKLE_DYNAMIC_DRAWING_MANAGER_H
88