Merge: Nitsmell : Adding new code smells and print console updated
[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
45 # Unique identifier of this pointer among other active pointers
46 #
47 # This value is useful to differentiate between pointers (or fingers) on
48 # multi-touch systems. This value does not change for the same pointer
49 # while it touches the screen.
50 fun pointer_id: Int do return 0
51 end
52
53 # A motion event on screen composed of many `PointerEvent`
54 #
55 # Example of a `MotionEvent` a gesture such as pinching using two fingers.
56 interface MotionEvent
57 super InputEvent
58
59 # A pointer just went down?
60 fun just_went_down: Bool is abstract
61
62 # Which pointer is down, if any
63 fun down_pointer: nullable PointerEvent is abstract
64 end
65
66 # Specific touch event
67 interface TouchEvent
68 super PointerEvent
69
70 # Pressure level of input
71 fun pressure: Float is abstract
72 end
73
74 # Keyboard or other keys event
75 interface KeyEvent
76 super InputEvent
77
78 # Key is currently down?
79 fun is_down: Bool is abstract
80
81 # Key is currently up?
82 fun is_up: Bool do return not is_down
83
84 # Key is the up arrow key?
85 fun is_arrow_up: Bool is abstract
86
87 # Key is the left arrow key?
88 fun is_arrow_left: Bool is abstract
89
90 # Key is the down arrow key?
91 fun is_arrow_down: Bool is abstract
92
93 # Key is the right arrow key?
94 fun is_arrow_right: Bool is abstract
95
96 # Key code, is plateform specific
97 fun code: Int is abstract
98
99 # Get Char value of key, if any
100 fun to_c: nullable Char is abstract
101
102 # Name of the key that raised `self`
103 #
104 # Use mainly for debug since it is implementation dependent.
105 fun name: String is abstract
106 end
107
108 # Mobile hardware (or pseudo hardware) event
109 interface MobileKeyEvent
110 super KeyEvent
111
112 # Key is back button? (mostly for Android)
113 fun is_back_key: Bool is abstract
114
115 # Key is menu button? (mostly for Android)
116 fun is_menu_key: Bool is abstract
117
118 # Key is search button? (mostly for Android)
119 fun is_search_key: Bool is abstract
120
121 # Key is home button? (mostly for Android)
122 fun is_home_key: Bool is abstract
123 end
124
125 # Sensor events like accelerometer, gyroscope etc for mobile apps
126 interface SensorEvent
127 super InputEvent
128 end
129
130 # Quit event, used for window close button
131 interface QuitEvent
132 super InputEvent
133 end