lib/android: add the gamepad module
[nit.git] / lib / android / gamepad.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 # Support for gamepad events (over Bluetooth or USB)
16 module gamepad
17
18 import input_events
19
20 redef class AndroidKeyEvent
21
22 # Was `self` raised by the A button?
23 fun is_a: Bool do return key_code == 96
24
25 # Was `self` raised by the B button?
26 fun is_b: Bool do return key_code == 97
27
28 # Was `self` raised by the X button?
29 fun is_x: Bool do return key_code == 99
30
31 # Was `self` raised by the Y button?
32 fun is_y: Bool do return key_code == 100
33
34 # Was `self` raised by the directional pad?
35 fun is_dpad: Bool
36 do
37 return is_dpad_up or is_dpad_down or is_dpad_left or is_dpad_right
38 end
39
40 # Was `self` raised by the up key on the directional pad?
41 fun is_dpad_up: Bool do return key_code == 19
42
43 # Was `self` raised by the down key on the directional pad?
44 fun is_dpad_down: Bool do return key_code == 20
45
46 # Was `self` raised by the left key on the directional pad?
47 fun is_dpad_left: Bool do return key_code == 21
48
49 # Was `self` raised by the right key on the directional pad?
50 fun is_dpad_right: Bool do return key_code == 22
51
52 # Was `self` raised by the start button?
53 fun is_start: Bool do return key_code == 108
54
55 # Was `self` raised by the select button?
56 fun is_select: Bool do return key_code == 109
57
58 # Was `self` raised by the right bumper button?
59 fun is_bumper_right: Bool do return key_code == 103
60
61 # Was `self` raised by the right trigger?
62 fun is_trigger_right: Bool do return key_code == 105
63
64 # Was `self` raised by the left bumper?
65 fun is_bumper_left: Bool do return key_code == 102
66
67 # Was `self` raised by the left trigger?
68 fun is_trigger_left: Bool do return key_code == 101
69
70 # Was `self` raised by the media button 'previous'?
71 fun is_media_previous: Bool do return key_code == 87
72
73 # Was `self` raised by the media button 'pause'?
74 fun is_media_pause: Bool do return key_code == 85
75
76 # Was `self` raised by the media button 'next'?
77 fun is_media_next: Bool do return key_code == 88
78 end