gamnit: intro basic input event supports for iOS
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 12 Dec 2017 18:20:11 +0000 (13:20 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 17 Jan 2018 20:30:11 +0000 (15:30 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/gamnit/gamnit.nit
lib/gamnit/input_ios.nit [new file with mode: 0644]

index d4f6830..a967461 100644 (file)
@@ -24,6 +24,7 @@ import programs
 import gamnit_android is conditional(android)
 import gamnit_linux is conditional(linux)
 import gamnit_ios is conditional(ios)
+import input_ios is conditional(ios)
 
 redef class App
 
diff --git a/lib/gamnit/input_ios.nit b/lib/gamnit/input_ios.nit
new file mode 100644 (file)
index 0000000..cb3d463
--- /dev/null
@@ -0,0 +1,59 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Gamnit event support for iOS
+module input_ios
+
+intrude import ios::glkit
+import display_ios
+import gamnit_ios
+
+# Pointer/touch event on iOS
+class GamnitIOSPointerEvent
+       super PointerEvent
+
+       private var native: UIEvent
+
+       private var native_touch: UITouch
+
+       private var content_scale_factor: Float
+
+       redef fun x do return native_touch.x * content_scale_factor
+
+       redef fun y do return native_touch.y * content_scale_factor
+
+       redef var pressed
+
+       redef var is_move
+
+       redef var pointer_id = native_touch.to_i is lazy
+end
+
+redef class NitGLKView
+
+       redef var content_scale_factor = super is lazy
+
+       redef fun touches_began(touches, event)
+       do app.accept_event(new GamnitIOSPointerEvent(event, touches.any_object, content_scale_factor, true, false))
+
+       redef fun touches_moved(touches, event)
+       do app.accept_event(new GamnitIOSPointerEvent(event, touches.any_object, content_scale_factor, true, true))
+
+       redef fun touches_ended(touches, event)
+       do app.accept_event(new GamnitIOSPointerEvent(event, touches.any_object, content_scale_factor, false, false))
+
+       # TODO handle cancel
+       #redef fun touches_cancelled(touches_event) do
+       #do app.accept_event(new GamnitIOSPointerEvent(event, false, false))
+end