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