• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/memory/referenced.h"
23 #include "foundation/graphic/graphic_3d/3d_widget_adapter/include/data_type/scene_viewer_touch_event.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 using ModelEventCallback = std::function<void(const OHOS::Render3D::SceneViewerTouchEvent&)>;
28 
29 class ModelTouchHandler : public Referenced {
30 public:
ModelTouchHandler()31     explicit ModelTouchHandler() {}
32     ~ModelTouchHandler() override = default;
33 
34     bool HandleTouchEvent(const TouchEventInfo& info);
35 
SetCameraEventCallback(const ModelEventCallback & eventCallback)36     void SetCameraEventCallback(const ModelEventCallback& eventCallback)
37     {
38         cameraEventCallback_ = std::move(eventCallback);
39     }
40 
SetClickEventCallback(const ModelEventCallback & eventCallback)41     void SetClickEventCallback(const ModelEventCallback& eventCallback)
42     {
43         clickEventCallback_ = std::move(eventCallback);
44     }
45 
SetCoordinateOffset(const Offset & coordinateOffset)46     void SetCoordinateOffset(const Offset& coordinateOffset)
47     {
48         coordinateOffset_ = coordinateOffset;
49     }
50 
HandleCameraEvents(bool handle)51     void HandleCameraEvents(bool handle)
52     {
53         isHandleCameraMove_ = handle;
54     }
55 
56 private:
57     OHOS::Render3D::SceneViewerTouchEvent CreateSceneTouchEvent(const TouchEvent& event) const;
58     OHOS::Ace::TouchEvent CreateTouchEvent(const TouchEventInfo& info);
59 
60 private:
61     ModelEventCallback cameraEventCallback_;
62     ModelEventCallback clickEventCallback_;
63     std::unordered_map<int32_t, TouchEvent> touches_;
64     Offset coordinateOffset_;
65 
66     bool isClicked_ = false;
67     int32_t touchCount_ = 0;
68     bool isHandleCameraMove_ = true;
69 };
70 
71 } // namespace OHOS::Ace::NG
72 
73 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MODEL_MODEL_TOUCH_HANDLER_H
74