Merge: nitc: check pkg-config packages availability later
[nit.git] / lib / gamnit / input_ios.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 # Gamnit event support for iOS
16 module input_ios
17
18 intrude import ios::glkit
19 import display_ios
20 import gamnit_ios
21
22 # Pointer/touch event on iOS
23 class GamnitIOSPointerEvent
24 super PointerEvent
25
26 private var native: UIEvent
27
28 private var native_touch: UITouch
29
30 private var content_scale_factor: Float
31
32 redef fun x do return native_touch.x * content_scale_factor
33
34 redef fun y do return native_touch.y * content_scale_factor
35
36 redef var pressed
37
38 redef var is_move
39
40 redef var pointer_id = native_touch.to_i is lazy
41 end
42
43 redef class NitGLKView
44
45 redef var content_scale_factor = super is lazy
46
47 redef fun touches_began(touches, event)
48 do app.accept_event(new GamnitIOSPointerEvent(event, touches.any_object, content_scale_factor, true, false))
49
50 redef fun touches_moved(touches, event)
51 do app.accept_event(new GamnitIOSPointerEvent(event, touches.any_object, content_scale_factor, true, true))
52
53 redef fun touches_ended(touches, event)
54 do app.accept_event(new GamnitIOSPointerEvent(event, touches.any_object, content_scale_factor, false, false))
55
56 # TODO handle cancel
57 #redef fun touches_cancelled(touches_event) do
58 #do app.accept_event(new GamnitIOSPointerEvent(event, false, false))
59 end