lib/mnit & implementations: move up `is_move` from Android to abstract
[nit.git] / lib / mnit / input.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2013 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Defines abstract classes for user and general inputs to the application.
18 # Implemented independantly for each platforms and technologies.
19 module input
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 fun depressed: Bool is abstract
38
39 # Is this a movement event?
40 fun is_move: Bool is abstract
41 end
42
43 # A motion event on screen composed of many `PointerEvent`
44 #
45 # Example of a `MotionEvent` a gesture such as pinching using two fingers.
46 interface MotionEvent
47 super InputEvent
48
49 # A pointer just went down?
50 fun just_went_down: Bool is abstract
51
52 # Which pointer is down, if any
53 fun down_pointer: nullable PointerEvent is abstract
54 end
55
56 # Specific touch event
57 interface TouchEvent
58 super PointerEvent
59
60 # Pressure level of input
61 fun pressure: Float is abstract
62 end
63
64 # Keyboard or other keys event
65 interface KeyEvent
66 super InputEvent
67
68 # Key is currently down?
69 fun is_down: Bool is abstract
70
71 # Key is currently up?
72 fun is_up: Bool do return not is_down
73
74 # Key is the up arrow key?
75 fun is_arrow_up: Bool is abstract
76
77 # Key is the left arrow key?
78 fun is_arrow_left: Bool is abstract
79
80 # Key is the down arrow key?
81 fun is_arrow_down: Bool is abstract
82
83 # Key is the right arrow key?
84 fun is_arrow_right: Bool is abstract
85
86 # Key code, is plateform specific
87 fun code: Int is abstract
88
89 # Get Char value of key, if any
90 fun to_c: nullable Char is abstract
91
92 # Name of the key that raised `self`
93 #
94 # Use mainly for debug since it is implementation dependent.
95 fun name: String is abstract
96 end
97
98 # Mobile hardware (or pseudo hardware) event
99 interface MobileKeyEvent
100 super KeyEvent
101
102 # Key is back button? (mostly for Android)
103 fun is_back_key: Bool is abstract
104
105 # Key is menu button? (mostly for Android)
106 fun is_menu_key: Bool is abstract
107
108 # Key is search button? (mostly for Android)
109 fun is_search_key: Bool is abstract
110
111 # Key is home button? (mostly for Android)
112 fun is_home_key: Bool is abstract
113 end
114
115 # Sensor events like accelerometer, gyroscope etc for mobile apps
116 interface SensorEvent
117 super InputEvent
118 end
119
120 # Quit event, used for window close button
121 interface QuitEvent
122 super InputEvent
123 end