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 int32_t ProcessUpEvent(bool isNeedUpAnimation); 78 #else 79 void CreateCanvasNode(); 80 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC 81 82 private: 83 std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ { nullptr }; 84 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC 85 std::shared_ptr<Rosen::RSCanvasDrawingNode> brushCanvasNode_ { nullptr }; 86 std::shared_ptr<Rosen::RSCanvasDrawingNode> trackCanvasNode_ { nullptr }; 87 #else 88 std::shared_ptr<Rosen::RSCanvasDrawingNode> canvasNode_ { nullptr }; 89 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC 90 std::vector<PointerInfo> pointerInfos_; 91 Rosen::Drawing::Paint paint_; 92 Rosen::Drawing::Path path_; 93 DisplayInfo displayInfo_ {}; 94 uint64_t screenId_ { 0 }; 95 bool isActionUp_ { false }; 96 bool isNeedInitParticleEmitter_ { true }; 97 PointerInfo lastDownPointer_ {}; 98 int64_t lastUpTime_ { 0 }; 99 bool isRotate_ { false }; 100 int32_t scaleW_ { 0 }; 101 int32_t scaleH_ { 0 }; 102 int64_t firstDownTime_ { 0 }; 103 bool hasScreenReadObserver_ { false }; 104 ScreenReadState screenReadState_ { }; 105 int32_t pointerNum_ { 0 }; 106 #ifdef OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC 107 std::vector<Rosen::Drawing::Path> pathInfos_; 108 float pathLength_ { 0.0f }; 109 float brushPathLength_ { 0.0f }; 110 uint32_t trackColorR_ { 0x00 }; 111 uint32_t trackColorG_ { 0x00 }; 112 uint32_t trackColorB_ { 0x00 }; 113 #endif // OHOS_BUILD_ENABLE_NEW_KNUCKLE_DYNAMIC 114 }; 115 } // namespace MMI 116 } // namespace OHOS 117 #endif // KNUCKLE_DRAWING_MANAGER_H 118