Merge: nitc: check pkg-config packages availability later
[nit.git] / lib / mnit / input.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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 # Defines abstract classes for user and general inputs to the application.
16 # Implemented independantly for each platforms and technologies.
17 module input
18
19 import android::input_events is conditional(android)
20
21 # Input to the App, propagated through `App::input`.
22 interface InputEvent
23 end
24
25 # Mouse and touch input events
26 interface PointerEvent
27 super InputEvent
28
29 # X position on screen (in pixels)
30 fun x: Float is abstract
31
32 # Y position on screen (in pixels)
33 fun y: Float is abstract
34
35 # Is down? either going down or already down
36 fun pressed: Bool is abstract
37
38 # Is it not currently pressed down? The opposite of `pressed`.
39 fun depressed: Bool do return not pressed
40
41 # Is this a movement event?
42 fun is_move: Bool is abstract
43
44 # Unique identifier of this pointer among other active pointers
45 #
46 # This value is useful to differentiate between pointers (or fingers) on
47 # multi-touch systems. This value does not change for the same pointer
48 # while it touches the screen.
49 fun pointer_id: Int do return 0
50 end
51
52 # A motion event on screen composed of many `PointerEvent`
53 #
54 # Example of a `MotionEvent` a gesture such as pinching using two fingers.
55 interface MotionEvent
56 super InputEvent
57
58 # A pointer just went down?
59 fun just_went_down: Bool is abstract
60
61 # Which pointer is down, if any
62 fun down_pointer: nullable PointerEvent is abstract
63 end
64
65 # Specific touch event
66 interface TouchEvent
67 super PointerEvent
68
69 # Pressure level of input
70 fun pressure: Float is abstract
71 end
72
73 # Keyboard or other keys event
74 interface KeyEvent
75 super InputEvent
76
77 # Key is currently down?
78 fun is_down: Bool is abstract
79
80 # Key is currently up?
81 fun is_up: Bool do return not is_down
82
83 # Key is the up arrow key?
84 fun is_arrow_up: Bool is abstract
85
86 # Key is the left arrow key?
87 fun is_arrow_left: Bool is abstract
88
89 # Key is the down arrow key?
90 fun is_arrow_down: Bool is abstract
91
92 # Key is the right arrow key?
93 fun is_arrow_right: Bool is abstract
94
95 # Key code, is plateform specific
96 fun code: Int is abstract
97
98 # Get Char value of key, if any
99 fun to_c: nullable Char is abstract
100
101 # Name of the key that raised `self`
102 #
103 # Use mainly for debug since it is implementation dependent.
104 fun name: String is abstract
105 end
106
107 # Mobile hardware (or pseudo hardware) event
108 interface MobileKeyEvent
109 super KeyEvent
110
111 # Key is back button? (mostly for Android)
112 fun is_back_key: Bool is abstract
113
114 # Key is menu button? (mostly for Android)
115 fun is_menu_key: Bool is abstract
116
117 # Key is search button? (mostly for Android)
118 fun is_search_key: Bool is abstract
119
120 # Key is home button? (mostly for Android)
121 fun is_home_key: Bool is abstract
122 end
123
124 # Sensor events like accelerometer, gyroscope etc for mobile apps
125 interface SensorEvent
126 super InputEvent
127 end
128
129 # Quit event, used for window close button
130 interface QuitEvent
131 super InputEvent
132 end