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_SCENE_VIEWER_SCENE_VIEWER_TOUCH_HANDLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCENE_VIEWER_SCENE_VIEWER_TOUCH_HANDLER_H 18 19 #include <functional> 20 #include <unordered_map> 21 22 #include "core/event/touch_event.h" 23 #include "foundation/graphic/graphic_3d/3d_widget_adapter/include/data_type/scene_viewer_touch_event.h" 24 25 namespace OHOS::Ace { 26 27 using SceneViewerEventCallback = std::function<void(const OHOS::Render3D::SceneViewerTouchEvent&)>; 28 29 class SceneViewerTouchHandler : public TouchEventTarget { 30 DECLARE_ACE_TYPE(SceneViewerTouchHandler, TouchEventTarget); 31 public: 32 bool DispatchEvent(const TouchEvent& event) override; 33 bool HandleEvent(const TouchEvent& event) override; 34 SetEventCallback(const SceneViewerEventCallback & eventCallback)35 void SetEventCallback(const SceneViewerEventCallback& eventCallback) 36 { 37 eventCallback_ = eventCallback; 38 } 39 SetCoordinateOffset(const Offset & coordinateOffset)40 void SetCoordinateOffset(const Offset& coordinateOffset) 41 { 42 coordinateOffset_ - coordinateOffset_; 43 } 44 45 private: 46 OHOS::Render3D::SceneViewerTouchEvent CreateSceneTouchEvent(const TouchEvent& point) const; 47 48 private: 49 SceneViewerEventCallback eventCallback_; 50 std::unordered_map<int32_t, TouchEvent> touches_; 51 Offset coordinateOffset_; 52 }; 53 54 } // namespace OHOS::Ace 55 56 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCENE_VIEWER_SCENE_VIEWER_TOUCH_HANDLER_H 57