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