1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_TOUCH_HANDLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_TOUCH_HANDLER_H 18 19 #include <functional> 20 #include <unordered_map> 21 22 #include "data_type/pointer_event.h" 23 24 #include "base/memory/referenced.h" 25 #include "core/components_ng/event/touch_event.h" 26 27 namespace OHOS::Ace::NG { 28 29 using ModelEventCallback = std::function<void(const Render3D::PointerEvent&)>; 30 31 class ModelTouchHandler : public Referenced { 32 public: ModelTouchHandler()33 explicit ModelTouchHandler() {} 34 ~ModelTouchHandler() override = default; 35 36 bool HandleTouchEvent(const TouchEventInfo& info, uint32_t viewWidth, uint32_t viewHeight); 37 SetCameraEventCallback(const ModelEventCallback & eventCallback)38 void SetCameraEventCallback(const ModelEventCallback& eventCallback) 39 { 40 cameraEventCallback_ = std::move(eventCallback); 41 } 42 SetClickEventCallback(const ModelEventCallback & eventCallback)43 void SetClickEventCallback(const ModelEventCallback& eventCallback) 44 { 45 clickEventCallback_ = std::move(eventCallback); 46 } 47 SetCoordinateOffset(const Offset & coordinateOffset)48 void SetCoordinateOffset(const Offset& coordinateOffset) 49 { 50 coordinateOffset_ = coordinateOffset; 51 } 52 HandleCameraEvents(bool handle)53 void HandleCameraEvents(bool handle) 54 { 55 isHandleCameraMove_ = handle; 56 } 57 58 private: 59 Render3D::PointerEvent CreateSceneTouchEvent(const TouchEvent& event, uint32_t viewWidth, 60 uint32_t viewHeight) const; 61 TouchEvent CreateTouchEvent(const TouchEventInfo& info) const; 62 ModelEventCallback cameraEventCallback_; 63 ModelEventCallback clickEventCallback_; 64 std::unordered_map<int32_t, TouchEvent> touches_; 65 Offset coordinateOffset_; 66 67 bool isClicked_ = false; 68 int32_t touchCount_ = 0; 69 bool isHandleCameraMove_ = true; 70 }; 71 72 } // namespace OHOS::Ace::NG 73 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_TOUCH_HANDLER_H 75