• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SCENE_INTERFACE_IINPUT_RECEIVER_H
16 #define SCENE_INTERFACE_IINPUT_RECEIVER_H
17 
18 #include <scene/base/types.h>
19 
20 #include <meta/base/interface_macros.h>
21 #include <meta/base/time_span.h>
22 #include <meta/base/types.h>
23 #include <meta/interface/interface_macros.h>
24 
25 SCENE_BEGIN_NAMESPACE()
26 
27 /**
28  * @brief The PointerEvent class defines a set of pointer events
29  */
30 struct PointerEvent {
31     using PointerId = uint32_t;
32 
33     /// Pointer state
34     enum class PointerState : uint8_t {
35         /// The pointer is not pressed.
36         POINTER_UP = 0,
37         /// The pointer is pressed.
38         POINTER_DOWN,
39     };
40     /// A struct representing one input pointer
41     struct Pointer {
42         /// Id of the pointer
43         PointerId id;
44         /// Normalized input position between [0,0]..[1,1] in view space.
45         BASE_NS::Math::Vec2 position;
46         /// Pointer state
47         PointerState state { PointerState::POINTER_UP };
48     };
49     /// List of pointer ids that changed as a result of this event
50     BASE_NS::vector<Pointer> pointers;
51     /// Event timestamp
52     META_NS::TimeSpan time { META_NS::TimeSpan::Zero() };
53     /// If true after receiver handling, no further IInputReceivers should receive the event.
54     bool handled {};
55 };
56 
57 /**
58  * @brief The IInputReceiver interface can be implemented by attachments that want to receive input events.
59  * @see ICamera::SendInputEvent
60  */
61 class IInputReceiver : public CORE_NS::IInterface {
62     META_INTERFACE(CORE_NS::IInterface, IInputReceiver, "17390f1d-e8d9-46b2-a8e3-661832f5dc5b")
63 public:
64     /**
65      * @brief Invoked when an input event has been sent.
66      * @see ICamera::SendInputEvent
67      * @param event The input event information.
68      */
69     virtual void OnInput(PointerEvent& event) = 0;
70 };
71 
72 SCENE_END_NAMESPACE()
73 
74 #endif // SCENE_INTERFACE_IINPUT_RECEIVER_H
75