diff --git a/.github/workflows/fix-formatting.yml b/.github/workflows/fix-formatting.yml index b73191d53cc..9fa5b450832 100644 --- a/.github/workflows/fix-formatting.yml +++ b/.github/workflows/fix-formatting.yml @@ -23,13 +23,21 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- - - name: Apply formatter + - name: Generate MobiVM MetalANGLE backend + run: ./gradlew :backends:gdx-backend-robovm-metalangle:generate :backends:gdx-backend-robovm-metalangle:spotlessApply + - name: Commit generation changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add backends/gdx-backend-robovm-metalangle/src + git commit -m "Generate MobiVM MetalANGLE backend" -a + continue-on-error: true + - name: Apply formater run: ./gradlew spotlessApply - name: Commit formatting changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git add . git commit -m "Apply formatter" -a continue-on-error: true - name: Push formatting changes diff --git a/.gitignore b/.gitignore index 6a647141a2f..016a0f151ad 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,7 @@ libgdx-*.zip.MD5 #the LWJGL3 libs are pulled via fetch.xml /backends/gdx-backend-lwjgl3/libs/lwjgl*.jar +/backends/gdx-backend-robovm-metalangle/res/META-INF/robovm/ios/libs #ensure gdx-setup.jar works properly !/extensions/gdx-setup/src/com/badlogic/gdx/setup/resources/gwt/war diff --git a/CHANGES b/CHANGES index 58421c3bf21..1984d045b57 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +[1.11.1] +- iOS: Add new MobiVM MetalANGLE backend + [1.11.0] - [BREAKING CHANGE] iOS: Increased min supported iOS version to 9.0. Update your Info.plist file if necessary. - [BREAKING CHANGE] Removed Maven and Ant build systems. libGDX is now solely built with Gradle. See https://libgdx.com/dev/from-source/ for updated build instructions. diff --git a/THIRDPARTY b/THIRDPARTY new file mode 100644 index 00000000000..8bbf42373bc --- /dev/null +++ b/THIRDPARTY @@ -0,0 +1,33 @@ +ANGLE/MetalANGLE: + // Copyright 2018 The ANGLE Project Authors. + // All rights reserved. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // + // Redistributions in binary form must reproduce the above + // copyright notice, this list of conditions and the following + // disclaimer in the documentation and/or other materials provided + // with the distribution. + // + // Neither the name of TransGaming Inc., Google Inc., 3DLabs Inc. + // Ltd., nor the names of their contributors may be used to endorse + // or promote products derived from this software without specific + // prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + // POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/backends/gdx-backend-robovm-metalangle/build.gradle b/backends/gdx-backend-robovm-metalangle/build.gradle new file mode 100644 index 00000000000..a89c968544a --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/build.gradle @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * 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. + ******************************************************************************/ +import org.gradle.internal.os.OperatingSystem + +sourceSets { + generator { + java { + srcDir 'generator' + } + resources { + srcDir 'generator' + } + } + main { + java { + srcDir 'src' + } + resources { + srcDir 'res' + } + } +} +configurations { + generatorCompile.extendsFrom testCompile + generatorRuntime.extendsFrom testRuntime +} + +configurations { generator } + +dependencies { + api libraries.robovm + generatorImplementation 'com.github.javaparser:javaparser-core:3.24.2' +} + +task generate(type: JavaExec) { + dependsOn configurations.generator + + main = 'JavaCodeGenerator' + classpath = sourceSets.generator.runtimeClasspath + + inputs.dir '../gdx-backend-robovm/src/' + outputs.dir 'src/' +} + +task fetchMetalANGLE(type: Download) { + doFirst { + file("build/tmp").mkdirs(); + } + src 'https://github.com/kakashidinho/metalangle/releases/download/gles3-0.0.7/MetalANGLE.framework.ios.zip' + dest 'build/tmp/MetalANGLE.framework.ios.zip' + onlyIfModified true + useETag "all" +} + +task fetchMetalANGLESimulator(type: Download) { + doFirst { + file("build/tmp").mkdirs(); + } + src 'https://github.com/kakashidinho/metalangle/releases/download/gles3-0.0.7/MetalANGLE.framework.ios.simulator.zip' + dest 'build/tmp/MetalANGLE.framework.ios.simulator.zip' + onlyIfModified true + useETag "all" +} + +task verifyMetalANGLE(dependsOn: fetchMetalANGLE, type: Verify) { + src 'build/tmp/MetalANGLE.framework.ios.zip' + algorithm 'SHA-256' + checksum '66fcf9eed2ede9e5725bf64e5b3169e0f39d1a515fe425447354c41968fc7999' +} + +task verifyMetalANGLESimulator(dependsOn: fetchMetalANGLESimulator, type: Verify) { + src 'build/tmp/MetalANGLE.framework.ios.simulator.zip' + algorithm 'SHA-256' + checksum 'e9aa526d2f19c57e1efbae4ec04d76701da4cf596bf8c6fb6ef6c507dbc2fdc4' +} + +task extractMetalANGLE(dependsOn: verifyMetalANGLE, type: Copy) { + doFirst { + file("build/tmp/real").mkdirs(); + } + from zipTree('build/tmp/MetalANGLE.framework.ios.zip') + into 'build/tmp/real' +} + +task extractMetalANGLESimulator(dependsOn: verifyMetalANGLESimulator, type: Copy) { + doFirst { + file("build/tmp/sim").mkdirs(); + } + from zipTree('build/tmp/MetalANGLE.framework.ios.simulator.zip') + into 'build/tmp/sim' +} + +task buildMetalANGLE(dependsOn: [ + extractMetalANGLE, + extractMetalANGLESimulator +], type: Exec) { + doFirst { + file("res/META-INF/robovm/ios/libs").mkdirs(); + } + commandLine 'xcodebuild', '-create-xcframework', '-framework', 'build/tmp/real/MetalANGLE.framework', '-framework', 'build/tmp/sim/MetalANGLE.framework', '-output', 'res/META-INF/robovm/ios/libs/MetalANGLE.xcframework' + standardOutput = new ByteArrayOutputStream() + ext.output = { + return standardOutput.toString() + } + + inputs.dir 'build/tmp/real/MetalANGLE.framework' + inputs.dir 'build/tmp/sim/MetalANGLE.framework' + outputs.dir 'res/META-INF/robovm/ios/libs/MetalANGLE.xcframework' +} + +task jnigenBuildIOS(dependsOn: buildMetalANGLE) { +} + +task jnigenBuild() { +} + +//Dummy task to make compatible with publish +task jnigen() { +} + +if(OperatingSystem.current() == OperatingSystem.MAC_OS) { + jnigenBuild.dependsOn jnigenBuildIOS +} \ No newline at end of file diff --git a/backends/gdx-backend-robovm-metalangle/generator/JavaCodeGenerator.java b/backends/gdx-backend-robovm-metalangle/generator/JavaCodeGenerator.java new file mode 100644 index 00000000000..84e8b7e806e --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/generator/JavaCodeGenerator.java @@ -0,0 +1,142 @@ +import java.io.File; +import java.io.FileWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.expr.Name; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import com.github.javaparser.ast.visitor.ModifierVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; + +public class JavaCodeGenerator { + /** This would allow us to keep exact formatting, but it's broken for FieldDeclarations for some reason. Potential related to + * https://github.com/javaparser/javaparser/issues/1601 */ + private static boolean LEXICAL_PRESERVING_PRINTER = false; + + private static File BASE_PROJECT_SRC = new File("../gdx-backend-robovm/src"); + + private static Map IMPORT_REPLACEMENTS = new HashMap<>(); + private static Map CLASS_REPLACEMENTS = new HashMap<>(); + + static { + IMPORT_REPLACEMENTS.put("org.robovm.apple.opengles.EAGLContext", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLContext"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.opengles.EAGLRenderingAPI", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLRenderingAPI"); + + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKView", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKView"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewController", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewController"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewControllerDelegate", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewControllerDelegate"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDelegate", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewDelegate"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableColorFormat", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableColorFormat"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableDepthFormat", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableDepthFormat"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableMultisample", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableMultisample"); + IMPORT_REPLACEMENTS.put("org.robovm.apple.glkit.GLKViewDrawableStencilFormat", + "com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableStencilFormat"); + + for (Entry e : IMPORT_REPLACEMENTS.entrySet()) { + String o = e.getKey().substring(e.getKey().lastIndexOf('.') + 1); + String n = e.getValue().substring(e.getValue().lastIndexOf('.') + 1); + CLASS_REPLACEMENTS.put(o, n); + } + } + + public static void main (String[] args) throws Exception { + search(BASE_PROJECT_SRC); + } + + private static void search (File f) throws Exception { + if (f.isDirectory()) { + for (File child : f.listFiles()) + search(child); + return; + } + + if (!f.getName().endsWith(".java")) { + return; + } + + parse(f); + } + + private static void parse (File f) throws Exception { + CompilationUnit cu = StaticJavaParser.parse(f); + + if (LEXICAL_PRESERVING_PRINTER) cu = LexicalPreservingPrinter.setup(cu); + + cu.setBlockComment("DO NOT EDIT THIS FILE - it is machine generated"); + + final JavaParser javaParser = new JavaParser(); + + ModifierVisitor visitor = new ModifierVisitor() { + @Override + public Name visit (Name n, final Object arg) { + n = (Name)super.visit(n, arg); + if (IMPORT_REPLACEMENTS.containsKey(n.asString())) { + n = new Name(IMPORT_REPLACEMENTS.get(n.asString())); + } + return n; + } + + @Override + public Visitable visit (SimpleName n, Object arg) { + n = (SimpleName)super.visit(n, arg); + if (CLASS_REPLACEMENTS.containsKey(n.asString())) { + n = new SimpleName(CLASS_REPLACEMENTS.get(n.asString())); + } + return n; + } + + @Override + public Visitable visit (ClassOrInterfaceType n, final Object arg) { + n = (ClassOrInterfaceType)super.visit(n, arg); + + if (CLASS_REPLACEMENTS.containsKey(n.asString())) { + n = javaParser.parseClassOrInterfaceType(CLASS_REPLACEMENTS.get(n.asString())).getResult().get(); + } + return n; + } + + @Override + public Visitable visit (ClassOrInterfaceDeclaration n, Object arg) { + n = (ClassOrInterfaceDeclaration)super.visit(n, arg); + + String base = n.getJavadocComment().isPresent() ? n.getJavadocComment().get().getContent() : ""; + + n.setJavadocComment("DO NOT EDIT THIS FILE - it is machine generated\n" + base); + + if (n.getNameAsString().equals("IOSViewDelegate")) { + for (MethodDeclaration m : n.getMethodsByName("willPause")) + m.remove(); + } + + return n; + } + }; + + cu.accept(visitor, null); + + File out = new File("src", f.getCanonicalPath().substring(BASE_PROJECT_SRC.getCanonicalPath().length())); + try (FileWriter writer = new FileWriter(out)) { + if (LEXICAL_PRESERVING_PRINTER) + LexicalPreservingPrinter.print(cu, writer); + else + writer.append(cu.toString()); + } + } +} diff --git a/backends/gdx-backend-robovm-metalangle/gradle.properties b/backends/gdx-backend-robovm-metalangle/gradle.properties new file mode 100644 index 00000000000..31bd48a9143 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/gradle.properties @@ -0,0 +1 @@ +POM_NAME=libGDX iOS RoboVM Backend (MetalANGLE) diff --git a/backends/gdx-backend-robovm-metalangle/res/META-INF/robovm/ios/robovm.xml b/backends/gdx-backend-robovm-metalangle/res/META-INF/robovm/ios/robovm.xml new file mode 100644 index 00000000000..aa3746e88ce --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/res/META-INF/robovm/ios/robovm.xml @@ -0,0 +1,10 @@ + + + MetalANGLE + Metal + + + libs/MetalANGLE.xcframework/ios-arm64_armv7/ + libs/MetalANGLE.xcframework/ios-arm64_i386_x86_64-simulator/ + + \ No newline at end of file diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/DefaultIOSInput.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/DefaultIOSInput.java new file mode 100644 index 00000000000..a3f16900094 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/DefaultIOSInput.java @@ -0,0 +1,1183 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.AbstractInput; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.InputProcessor; +import com.badlogic.gdx.backends.iosrobovm.custom.UIAcceleration; +import com.badlogic.gdx.backends.iosrobovm.custom.UIAccelerometer; +import com.badlogic.gdx.backends.iosrobovm.custom.UIAccelerometerDelegate; +import com.badlogic.gdx.backends.iosrobovm.custom.UIAccelerometerDelegateAdapter; +import com.badlogic.gdx.graphics.glutils.HdpiMode; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.GdxRuntimeException; +import com.badlogic.gdx.utils.Pool; +import org.robovm.apple.audiotoolbox.AudioServices; +import org.robovm.apple.coregraphics.CGPoint; +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.Foundation; +import org.robovm.apple.foundation.NSExtensions; +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.foundation.NSRange; +import org.robovm.apple.gamecontroller.GCKeyboard; +import org.robovm.apple.uikit.UIAlertAction; +import org.robovm.apple.uikit.UIAlertActionStyle; +import org.robovm.apple.uikit.UIAlertController; +import org.robovm.apple.uikit.UIAlertControllerStyle; +import org.robovm.apple.uikit.UIDevice; +import org.robovm.apple.uikit.UIForceTouchCapability; +import org.robovm.apple.uikit.UIKey; +import org.robovm.apple.uikit.UIKeyboardHIDUsage; +import org.robovm.apple.uikit.UIKeyboardType; +import org.robovm.apple.uikit.UIReturnKeyType; +import org.robovm.apple.uikit.UIScreen; +import org.robovm.apple.uikit.UITextAutocapitalizationType; +import org.robovm.apple.uikit.UITextAutocorrectionType; +import org.robovm.apple.uikit.UITextField; +import org.robovm.apple.uikit.UITextFieldDelegate; +import org.robovm.apple.uikit.UITextFieldDelegateAdapter; +import org.robovm.apple.uikit.UITextSpellCheckingType; +import org.robovm.apple.uikit.UITouch; +import org.robovm.apple.uikit.UITouchPhase; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.block.VoidBlock1; +import org.robovm.rt.VM; +import org.robovm.rt.bro.NativeObject; +import org.robovm.rt.bro.annotation.MachineSizedUInt; +import org.robovm.rt.bro.annotation.Pointer; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class DefaultIOSInput extends AbstractInput implements IOSInput { + + static final int MAX_TOUCHES = 20; + + private static final int POINTER_NOT_FOUND = -1; + + /** DO NOT EDIT THIS FILE - it is machine generated */ + private static class NSObjectWrapper { + + private static final long HANDLE_OFFSET; + + static { + try { + HANDLE_OFFSET = VM.getInstanceFieldOffset(VM.getFieldAddress(NativeObject.class.getDeclaredField("handle"))); + } catch (Throwable t) { + throw new Error(t); + } + } + + private final T instance; + + public NSObjectWrapper (Class cls) { + instance = VM.allocateObject(cls); + } + + public T wrap (long handle) { + VM.setLong(VM.getObjectAddress(instance) + HANDLE_OFFSET, handle); + return instance; + } + } + + private static final NSObjectWrapper UI_TOUCH_WRAPPER = new NSObjectWrapper(UITouch.class); + + static final NSObjectWrapper UI_ACCELERATION_WRAPPER = new NSObjectWrapper( + UIAcceleration.class); + + IOSApplication app; + + IOSApplicationConfiguration config; + + int[] deltaX = new int[MAX_TOUCHES]; + + int[] deltaY = new int[MAX_TOUCHES]; + + int[] touchX = new int[MAX_TOUCHES]; + + int[] touchY = new int[MAX_TOUCHES]; + + float[] pressures = new float[MAX_TOUCHES]; + + boolean pressureSupported; + + // we store the pointer to the UITouch struct here, or 0 + long[] touchDown = new long[MAX_TOUCHES]; + + int numTouched = 0; + + boolean justTouched = false; + + Pool touchEventPool = new Pool() { + + @Override + protected TouchEvent newObject () { + return new TouchEvent(); + } + }; + + Array touchEvents = new Array(); + + private final Pool keyEventPool = new Pool(16, 1000) { + + protected KeyEvent newObject () { + return new KeyEvent(); + } + }; + + private final Array keyEvents = new Array(); + + private long currentEventTimeStamp = 0; + + float[] acceleration = new float[3]; + + float[] rotation = new float[3]; + + float[] R = new float[9]; + + InputProcessor inputProcessor = null; + + boolean hasVibrator; + + // CMMotionManager motionManager; + protected UIAccelerometerDelegate accelerometerDelegate; + + boolean compassSupported; + + boolean keyboardCloseOnReturn; + + boolean softkeyboardActive = false; + + private boolean hadHardwareKeyEvent = false; + + public DefaultIOSInput (IOSApplication app) { + this.app = app; + this.config = app.config; + this.keyboardCloseOnReturn = app.config.keyboardCloseOnReturn; + } + + @Override + public void setupPeripherals () { + // motionManager = new CMMotionManager(); + setupAccelerometer(); + setupCompass(); + UIDevice device = UIDevice.getCurrentDevice(); + if (device.getModel().equalsIgnoreCase("iphone")) hasVibrator = true; + if (app.getVersion() >= 9) { + UIForceTouchCapability forceTouchCapability = UIScreen.getMainScreen().getTraitCollection().getForceTouchCapability(); + pressureSupported = forceTouchCapability == UIForceTouchCapability.Available; + } + } + + protected void setupCompass () { + if (config.useCompass) { + // setupMagnetometer(); + } + } + + protected void setupAccelerometer () { + if (config.useAccelerometer) { + accelerometerDelegate = new UIAccelerometerDelegateAdapter() { + + @Method(selector = "accelerometer:didAccelerate:") + public void didAccelerate (UIAccelerometer accelerometer, @Pointer long valuesPtr) { + UIAcceleration values = UI_ACCELERATION_WRAPPER.wrap(valuesPtr); + float x = (float)values.getX() * 10; + float y = (float)values.getY() * 10; + float z = (float)values.getZ() * 10; + acceleration[0] = -x; + acceleration[1] = -y; + acceleration[2] = -z; + } + }; + UIAccelerometer.getSharedAccelerometer().setDelegate(accelerometerDelegate); + UIAccelerometer.getSharedAccelerometer().setUpdateInterval(config.accelerometerUpdate); + } + } + + // need to retain a reference so GC doesn't get right of the + // object passed to the native thread + // VoidBlock2 accelVoid = null; + // private void setupAccelerometer () { + // if (config.useAccelerometer) { + // motionManager.setAccelerometerUpdateInterval(config.accelerometerUpdate); + // accelVoid = new VoidBlock2() { + // @Override + // public void invoke(CMAccelerometerData accelData, NSError error) { + // updateAccelerometer(accelData); + // } + // }; + // motionManager.startAccelerometerUpdates(new NSOperationQueue(), accelVoid); + // } + // } + // need to retain a reference so GC doesn't get right of the + // object passed to the native thread + // VoidBlock2 magnetVoid = null; + // private void setupMagnetometer () { + // if (motionManager.isMagnetometerAvailable() && config.useCompass) compassSupported = true; + // else return; + // motionManager.setMagnetometerUpdateInterval(config.magnetometerUpdate); + // magnetVoid = new VoidBlock2() { + // @Override + // public void invoke(CMMagnetometerData magnetData, NSError error) { + // updateRotation(magnetData); + // } + // }; + // motionManager.startMagnetometerUpdates(new NSOperationQueue(), magnetVoid); + // } + // private void updateAccelerometer (CMAccelerometerData data) { + // float x = (float) data.getAcceleration().x() * 10f; + // float y = (float) data.getAcceleration().y() * 10f; + // float z = (float) data.getAcceleration().z() * 10f; + // acceleration[0] = -x; + // acceleration[1] = -y; + // acceleration[2] = -z; + // } + // + // private void updateRotation (CMMagnetometerData data) { + // final float eX = (float) data.getMagneticField().x(); + // final float eY = (float) data.getMagneticField().y(); + // final float eZ = (float) data.getMagneticField().z(); + // + // float gX = acceleration[0]; + // float gY = acceleration[1]; + // float gZ = acceleration[2]; + // + // float cX = eY * gZ - eZ * gY; + // float cY = eZ * gX - eX * gZ; + // float cZ = eX * gY - eY * gX; + // + // final float normal = (float) Math.sqrt(cX * cX + cY * cY + cZ * cZ); + // final float invertC = 1.0f / normal; + // cX *= invertC; + // cY *= invertC; + // cZ *= invertC; + // final float invertG = 1.0f / (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ); + // gX *= invertG; + // gY *= invertG; + // gZ *= invertG; + // final float mX = gY * cZ - gZ * cY; + // final float mY = gZ * cX - gX * cZ; + // final float mZ = gX * cY - gY * cX; + // + // R[0] = cX; R[1] = cY; R[2] = cZ; + // R[3] = mX; R[4] = mY; R[5] = mZ; + // R[6] = gX; R[7] = gY; R[8] = gZ; + // + // rotation[0] = (float) Math.atan2(R[1], R[4]) * MathUtils.radDeg; + // rotation[1] = (float) Math.asin(-R[7]) * MathUtils.radDeg; + // rotation[2] = (float) Math.atan2(-R[6], R[8]) * MathUtils.radDeg; + // } + @Override + public float getAccelerometerX () { + return acceleration[0]; + } + + @Override + public float getAccelerometerY () { + return acceleration[1]; + } + + @Override + public float getAccelerometerZ () { + return acceleration[2]; + } + + @Override + public float getAzimuth () { + if (!compassSupported) return 0; + return rotation[0]; + } + + @Override + public float getPitch () { + if (!compassSupported) return 0; + return rotation[1]; + } + + @Override + public float getRoll () { + if (!compassSupported) return 0; + return rotation[2]; + } + + @Override + public void getRotationMatrix (float[] matrix) { + if (matrix.length != 9) return; + // TODO implement when azimuth is fixed + } + + @Override + public int getMaxPointers () { + return MAX_TOUCHES; + } + + @Override + public int getX () { + return touchX[0]; + } + + @Override + public int getX (int pointer) { + return touchX[pointer]; + } + + @Override + public int getDeltaX () { + return deltaX[0]; + } + + @Override + public int getDeltaX (int pointer) { + return deltaX[pointer]; + } + + @Override + public int getY () { + return touchY[0]; + } + + @Override + public int getY (int pointer) { + return touchY[pointer]; + } + + @Override + public int getDeltaY () { + return deltaY[0]; + } + + @Override + public int getDeltaY (int pointer) { + return deltaY[pointer]; + } + + @Override + public boolean isTouched () { + for (int pointer = 0; pointer < MAX_TOUCHES; pointer++) { + if (touchDown[pointer] != 0) { + return true; + } + } + return false; + } + + @Override + public boolean justTouched () { + return justTouched; + } + + @Override + public boolean isTouched (int pointer) { + return touchDown[pointer] != 0; + } + + @Override + public float getPressure () { + return pressures[0]; + } + + @Override + public float getPressure (int pointer) { + return pressures[pointer]; + } + + @Override + public boolean isButtonPressed (int button) { + return button == Buttons.LEFT && numTouched > 0; + } + + @Override + public boolean isButtonJustPressed (int button) { + return button == Buttons.LEFT && justTouched; + } + + @Override + public void getTextInput (TextInputListener listener, String title, String text, String hint) { + getTextInput(listener, title, text, hint, OnscreenKeyboardType.Default); + } + + @Override + public void getTextInput (TextInputListener listener, String title, String text, String hint, OnscreenKeyboardType type) { + UIAlertController uiAlertController = buildUIAlertController(listener, title, text, hint, type); + app.getUIViewController().presentViewController(uiAlertController, true, null); + } + + // hack for software keyboard support + // uses a hidden textfield to capture input + // see: https://web.archive.org/web/20171016192705/http://www.badlogicgames.com/forum/viewtopic.php?f=17&t=11788 + private UITextField textfield = null; + + private final UITextFieldDelegate textDelegate = new UITextFieldDelegateAdapter() { + + @Override + public boolean shouldChangeCharacters (UITextField textField, NSRange range, String string) { + for (int i = 0; i < range.getLength(); i++) { + inputProcessor.keyTyped((char)8); + } + if (string.isEmpty()) { + if (range.getLength() > 0) Gdx.graphics.requestRendering(); + return false; + } + char[] chars = new char[string.length()]; + string.getChars(0, string.length(), chars, 0); + for (int i = 0; i < chars.length; i++) { + inputProcessor.keyTyped(chars[i]); + } + Gdx.graphics.requestRendering(); + return true; + } + + @Override + public boolean shouldEndEditing (UITextField textField) { + // Text field needs to have at least one symbol - so we can use backspace + textField.setText("x"); + Gdx.graphics.requestRendering(); + return true; + } + + @Override + public boolean shouldReturn (UITextField textField) { + if (keyboardCloseOnReturn) setOnscreenKeyboardVisible(false); + inputProcessor.keyDown(Keys.ENTER); + inputProcessor.keyTyped((char)13); + Gdx.graphics.requestRendering(); + return false; + } + }; + + @Override + public void setOnscreenKeyboardVisible (boolean visible) { + setOnscreenKeyboardVisible(visible, OnscreenKeyboardType.Default); + } + + @Override + public void setOnscreenKeyboardVisible (boolean visible, OnscreenKeyboardType type) { + if (textfield == null) createDefaultTextField(); + softkeyboardActive = visible; + if (visible) { + UIKeyboardType preferredInputType; + if (type == null) type = OnscreenKeyboardType.Default; + textfield.setKeyboardType(getIosInputType(type)); + textfield.becomeFirstResponder(); + textfield.setDelegate(textDelegate); + } else { + textfield.resignFirstResponder(); + } + } + + protected UIKeyboardType getIosInputType (OnscreenKeyboardType type) { + UIKeyboardType preferredInputType; + switch (type) { + case NumberPad: + preferredInputType = UIKeyboardType.NumberPad; + break; + case PhonePad: + preferredInputType = UIKeyboardType.PhonePad; + break; + case Email: + preferredInputType = UIKeyboardType.EmailAddress; + break; + case URI: + preferredInputType = UIKeyboardType.URL; + break; + // no equivalent in UIKeyboardType? + case Password: + default: + preferredInputType = UIKeyboardType.Default; + break; + } + return preferredInputType; + } + + /** Set the keyboard to close when the UITextField return key is pressed + * @param shouldClose Whether or not the keyboard should clsoe on return key press */ + public void setKeyboardCloseOnReturnKey (boolean shouldClose) { + keyboardCloseOnReturn = shouldClose; + } + + public UITextField getKeyboardTextField () { + if (textfield == null) createDefaultTextField(); + return textfield; + } + + private void createDefaultTextField () { + textfield = new UITextField(new CGRect(10, 10, 100, 50)); + // Parameters + // Setting parameters + textfield.setKeyboardType(UIKeyboardType.Default); + textfield.setReturnKeyType(UIReturnKeyType.Done); + textfield.setAutocapitalizationType(UITextAutocapitalizationType.None); + textfield.setAutocorrectionType(UITextAutocorrectionType.No); + textfield.setSpellCheckingType(UITextSpellCheckingType.No); + textfield.setHidden(true); + // Text field needs to have at least one symbol - so we can use backspace + textfield.setText("x"); + app.getUIViewController().getView().addSubview(textfield); + } + + /** Builds an {@link UIAlertController} with an added {@link UITextField} for inputting text. + * @param listener Text input listener + * @param title Dialog title + * @param text Text for text field + * @param type + * @return UIAlertController */ + private UIAlertController buildUIAlertController (final TextInputListener listener, String title, final String text, + final String placeholder, final OnscreenKeyboardType type) { + final UIAlertController uiAlertController = new UIAlertController(title, text, UIAlertControllerStyle.Alert); + uiAlertController.addTextField(new VoidBlock1() { + + @Override + public void invoke (UITextField uiTextField) { + uiTextField.setPlaceholder(placeholder); + uiTextField.setText(text); + uiTextField.setKeyboardType(getIosInputType(type)); + if (type == OnscreenKeyboardType.Password) { + uiTextField.setSecureTextEntry(true); + } + } + }); + uiAlertController.addAction(new UIAlertAction("Ok", UIAlertActionStyle.Default, new VoidBlock1() { + + @Override + public void invoke (UIAlertAction uiAlertAction) { + // user clicked "Ok" button + UITextField textField = uiAlertController.getTextFields().get(0); + listener.input(textField.getText()); + } + })); + uiAlertController.addAction(new UIAlertAction("Cancel", UIAlertActionStyle.Cancel, new VoidBlock1() { + + @Override + public void invoke (UIAlertAction uiAlertAction) { + // user clicked "Cancel" button + listener.canceled(); + } + })); + return uiAlertController; + } + + @Override + public void vibrate (int milliseconds) { + AudioServices.playSystemSound(4095); + } + + @Override + public void vibrate (long[] pattern, int repeat) { + // FIXME implement this + } + + @Override + public void cancelVibrate () { + // FIXME implement this + } + + @Override + public long getCurrentEventTime () { + return currentEventTimeStamp; + } + + @Override + public void setInputProcessor (InputProcessor processor) { + this.inputProcessor = processor; + } + + @Override + public InputProcessor getInputProcessor () { + return inputProcessor; + } + + @Override + public boolean isPeripheralAvailable (Peripheral peripheral) { + if (peripheral == Peripheral.Accelerometer && config.useAccelerometer) return true; + if (peripheral == Peripheral.MultitouchScreen) return true; + if (peripheral == Peripheral.Vibrator) return hasVibrator; + if (peripheral == Peripheral.Compass) return compassSupported; + if (peripheral == Peripheral.OnscreenKeyboard) return true; + if (peripheral == Peripheral.Pressure) return pressureSupported; + if (peripheral == Peripheral.HardwareKeyboard) + return Foundation.getMajorSystemVersion() >= 14 ? GCKeyboard.getCoalescedKeyboard() != null : hadHardwareKeyEvent; + return false; + } + + @Override + public int getRotation () { + // we measure orientation counter clockwise, just like on Android + switch (app.uiApp.getStatusBarOrientation()) { + case LandscapeLeft: + return 270; + case PortraitUpsideDown: + return 180; + case LandscapeRight: + return 90; + case Portrait: + default: + return 0; + } + } + + @Override + public Orientation getNativeOrientation () { + return Orientation.Portrait; + } + + @Override + public void setCursorCatched (boolean catched) { + } + + @Override + public boolean isCursorCatched () { + return false; + } + + @Override + public void setCursorPosition (int x, int y) { + } + + @Override + public void onTouch (long touches) { + toTouchEvents(touches); + Gdx.graphics.requestRendering(); + } + + @Override + public boolean onKey (UIKey key, boolean down) { + if (key == null) { + return false; + } + int keyCode = getGdxKeyCode(key); + if (keyCode != Keys.UNKNOWN) synchronized (keyEvents) { + hadHardwareKeyEvent = true; + KeyEvent event = keyEventPool.obtain(); + long timeStamp = System.nanoTime(); + event.timeStamp = timeStamp; + event.keyChar = 0; + event.keyCode = keyCode; + event.type = down ? KeyEvent.KEY_DOWN : KeyEvent.KEY_UP; + keyEvents.add(event); + if (!down) { + char character; + switch (keyCode) { + case Keys.DEL: + character = 8; + break; + case Keys.FORWARD_DEL: + character = 127; + break; + case Keys.ENTER: + character = 13; + break; + default: + String characters = key.getCharacters(); + // special keys return constants like "UIKeyInputF5", so we check for length 1 + character = (characters != null && characters.length() == 1) ? characters.charAt(0) : 0; + } + if (character >= 0) { + event = keyEventPool.obtain(); + event.timeStamp = timeStamp; + event.type = KeyEvent.KEY_TYPED; + event.keyCode = keyCode; + event.keyChar = character; + keyEvents.add(event); + } + if (pressedKeys[keyCode]) { + pressedKeyCount--; + pressedKeys[keyCode] = false; + } + } else { + if (!pressedKeys[event.keyCode]) { + pressedKeyCount++; + pressedKeys[event.keyCode] = true; + } + } + } + return isCatchKey(keyCode); + } + + @Override + public void processEvents () { + synchronized (touchEvents) { + justTouched = false; + for (TouchEvent event : touchEvents) { + currentEventTimeStamp = event.timestamp; + switch (event.phase) { + case Began: + if (inputProcessor != null) inputProcessor.touchDown(event.x, event.y, event.pointer, Buttons.LEFT); + if (numTouched >= 1) justTouched = true; + break; + case Cancelled: + case Ended: + if (inputProcessor != null) inputProcessor.touchUp(event.x, event.y, event.pointer, Buttons.LEFT); + break; + case Moved: + case Stationary: + if (inputProcessor != null) inputProcessor.touchDragged(event.x, event.y, event.pointer); + break; + } + } + touchEventPool.freeAll(touchEvents); + touchEvents.clear(); + } + synchronized (keyEvents) { + if (keyJustPressed) { + keyJustPressed = false; + for (int i = 0; i < justPressedKeys.length; i++) { + justPressedKeys[i] = false; + } + } + for (KeyEvent e : keyEvents) { + currentEventTimeStamp = e.timeStamp; + switch (e.type) { + case KeyEvent.KEY_DOWN: + if (inputProcessor != null) inputProcessor.keyDown(e.keyCode); + keyJustPressed = true; + justPressedKeys[e.keyCode] = true; + break; + case KeyEvent.KEY_UP: + if (inputProcessor != null) inputProcessor.keyUp(e.keyCode); + break; + case KeyEvent.KEY_TYPED: + // don't process key typed events if soft keyboard is active + // the soft keyboard hook already catches the changes + if (!softkeyboardActive && inputProcessor != null) inputProcessor.keyTyped(e.keyChar); + } + } + keyEventPool.freeAll(keyEvents); + keyEvents.clear(); + } + } + + private int getFreePointer () { + for (int i = 0; i < touchDown.length; i++) { + if (touchDown[i] == 0) return i; + } + throw new GdxRuntimeException("Couldn't find free pointer id!"); + } + + private int findPointer (UITouch touch) { + long ptr = touch.getHandle(); + for (int i = 0; i < touchDown.length; i++) { + if (touchDown[i] == ptr) return i; + } + // If pointer is not found + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < touchDown.length; i++) { + sb.append(i + ":" + touchDown[i] + " "); + } + Gdx.app.error("IOSInput", "Pointer ID lookup failed: " + ptr + ", " + sb.toString()); + return POINTER_NOT_FOUND; + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + private static class NSSetExtensions extends NSExtensions { + + @Method(selector = "allObjects") + @Pointer + public static native long allObjects (@Pointer long thiz); + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + private static class NSArrayExtensions extends NSExtensions { + + @Method(selector = "objectAtIndex:") + @Pointer + public static native long objectAtIndex$ (@Pointer long thiz, @MachineSizedUInt long index); + + @Method(selector = "count") + @MachineSizedUInt + public static native long count (@Pointer long thiz); + } + + private void toTouchEvents (long touches) { + long array = NSSetExtensions.allObjects(touches); + int length = (int)NSArrayExtensions.count(array); + final IOSScreenBounds screenBounds = app.getScreenBounds(); + for (int i = 0; i < length; i++) { + long touchHandle = NSArrayExtensions.objectAtIndex$(array, i); + UITouch touch = UI_TOUCH_WRAPPER.wrap(touchHandle); + int locX, locY; + // Get and map the location to our drawing space + { + CGPoint loc = touch.getLocationInView(app.graphics.view); + locX = (int)(loc.getX() - screenBounds.x); + locY = (int)(loc.getY() - screenBounds.y); + if (config.hdpiMode == HdpiMode.Pixels) { + locX *= app.pixelsPerPoint; + locY *= app.pixelsPerPoint; + } + // app.debug("IOSInput","pos= "+loc+" bounds= "+bounds+" x= "+locX+" locY= "+locY); + } + // if its not supported, we will simply use 1.0f when touch is present + float pressure = 1.0f; + if (pressureSupported) { + pressure = (float)touch.getForce(); + } + synchronized (touchEvents) { + UITouchPhase phase = touch.getPhase(); + TouchEvent event = touchEventPool.obtain(); + event.x = locX; + event.y = locY; + event.phase = phase; + event.timestamp = (long)(touch.getTimestamp() * 1000000000); + if (phase == UITouchPhase.Began) { + event.pointer = getFreePointer(); + touchDown[event.pointer] = touch.getHandle(); + touchX[event.pointer] = event.x; + touchY[event.pointer] = event.y; + deltaX[event.pointer] = 0; + deltaY[event.pointer] = 0; + pressures[event.pointer] = pressure; + numTouched++; + } else if (phase == UITouchPhase.Moved || phase == UITouchPhase.Stationary) { + event.pointer = findPointer(touch); + if (event.pointer != POINTER_NOT_FOUND) { + deltaX[event.pointer] = event.x - touchX[event.pointer]; + deltaY[event.pointer] = event.y - touchY[event.pointer]; + touchX[event.pointer] = event.x; + touchY[event.pointer] = event.y; + pressures[event.pointer] = pressure; + } + } else if (phase == UITouchPhase.Cancelled || phase == UITouchPhase.Ended) { + event.pointer = findPointer(touch); + if (event.pointer != POINTER_NOT_FOUND) { + touchDown[event.pointer] = 0; + touchX[event.pointer] = event.x; + touchY[event.pointer] = event.y; + deltaX[event.pointer] = 0; + deltaY[event.pointer] = 0; + pressures[event.pointer] = 0; + numTouched--; + } + } + if (event.pointer != POINTER_NOT_FOUND) { + touchEvents.add(event); + } else { + touchEventPool.free(event); + } + } + } + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + static class TouchEvent { + + UITouchPhase phase; + + long timestamp; + + int x, y; + + int pointer; + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + static class KeyEvent { + + static final int KEY_DOWN = 0; + + static final int KEY_UP = 1; + + static final int KEY_TYPED = 2; + + long timeStamp; + + int type; + + int keyCode; + + char keyChar; + } + + @Override + public float getGyroscopeX () { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getGyroscopeY () { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getGyroscopeZ () { + // TODO Auto-generated method stub + return 0; + } + + protected int getGdxKeyCode (UIKey key) { + UIKeyboardHIDUsage keyCode; + try { + keyCode = key.getKeyCode(); + } catch (IllegalArgumentException e) { + return Keys.UNKNOWN; + } + switch (keyCode) { + case KeyboardA: + return Keys.A; + case KeyboardB: + return Keys.B; + case KeyboardC: + return Keys.C; + case KeyboardD: + return Keys.D; + case KeyboardE: + return Keys.E; + case KeyboardF: + return Keys.F; + case KeyboardG: + return Keys.G; + case KeyboardH: + return Keys.H; + case KeyboardI: + return Keys.I; + case KeyboardJ: + return Keys.J; + case KeyboardK: + return Keys.K; + case KeyboardL: + return Keys.L; + case KeyboardM: + return Keys.M; + case KeyboardN: + return Keys.N; + case KeyboardO: + return Keys.O; + case KeyboardP: + return Keys.P; + case KeyboardQ: + return Keys.Q; + case KeyboardR: + return Keys.R; + case KeyboardS: + return Keys.S; + case KeyboardT: + return Keys.T; + case KeyboardU: + return Keys.U; + case KeyboardV: + return Keys.V; + case KeyboardW: + return Keys.W; + case KeyboardX: + return Keys.X; + case KeyboardY: + return Keys.Y; + case KeyboardZ: + return Keys.Z; + case Keyboard1: + return Keys.NUM_1; + case Keyboard2: + return Keys.NUM_2; + case Keyboard3: + return Keys.NUM_3; + case Keyboard4: + return Keys.NUM_4; + case Keyboard5: + return Keys.NUM_5; + case Keyboard6: + return Keys.NUM_6; + case Keyboard7: + return Keys.NUM_7; + case Keyboard8: + return Keys.NUM_8; + case Keyboard9: + return Keys.NUM_9; + case Keyboard0: + return Keys.NUM_0; + case KeyboardReturnOrEnter: + return Keys.ENTER; + case KeyboardEscape: + return Keys.ESCAPE; + case KeyboardDeleteOrBackspace: + return Keys.BACKSPACE; + case KeyboardTab: + return Keys.TAB; + case KeyboardSpacebar: + return Keys.SPACE; + case KeyboardHyphen: + return Keys.MINUS; + case KeyboardEqualSign: + return Keys.EQUALS; + case KeyboardOpenBracket: + return Keys.LEFT_BRACKET; + case KeyboardCloseBracket: + return Keys.RIGHT_BRACKET; + case KeyboardBackslash: + return Keys.BACKSLASH; + case KeyboardNonUSPound: + return Keys.POUND; + case KeyboardSemicolon: + return Keys.SEMICOLON; + case KeyboardQuote: + return Keys.APOSTROPHE; + case KeyboardGraveAccentAndTilde: + return Keys.GRAVE; + case KeyboardComma: + return Keys.COMMA; + case KeyboardPeriod: + return Keys.PERIOD; + case KeyboardSlash: + return Keys.SLASH; + case KeyboardF1: + return Keys.F1; + case KeyboardF2: + return Keys.F2; + case KeyboardF3: + return Keys.F3; + case KeyboardF4: + return Keys.F4; + case KeyboardF5: + return Keys.F5; + case KeyboardF6: + return Keys.F6; + case KeyboardF7: + return Keys.F7; + case KeyboardF8: + return Keys.F8; + case KeyboardF9: + return Keys.F9; + case KeyboardF10: + return Keys.F10; + case KeyboardF11: + return Keys.F11; + case KeyboardF12: + return Keys.F12; + case KeyboardF13: + return Keys.F13; + case KeyboardF14: + return Keys.F14; + case KeyboardF15: + return Keys.F15; + case KeyboardF16: + return Keys.F16; + case KeyboardF17: + return Keys.F17; + case KeyboardF18: + return Keys.F18; + case KeyboardF19: + return Keys.F19; + case KeyboardF20: + return Keys.F20; + case KeyboardF21: + return Keys.F21; + case KeyboardF22: + return Keys.F22; + case KeyboardF23: + return Keys.F23; + case KeyboardF24: + return Keys.F24; + case KeyboardPause: + return Keys.PAUSE; + case KeyboardInsert: + return Keys.INSERT; + case KeyboardHome: + return Keys.HOME; + case KeyboardPageUp: + return Keys.PAGE_UP; + case KeyboardDeleteForward: + return Keys.FORWARD_DEL; + case KeyboardEnd: + return Keys.END; + case KeyboardPageDown: + return Keys.PAGE_DOWN; + case KeyboardRightArrow: + return Keys.RIGHT; + case KeyboardLeftArrow: + return Keys.LEFT; + case KeyboardDownArrow: + return Keys.DOWN; + case KeyboardUpArrow: + return Keys.UP; + case KeypadNumLock: + return Keys.NUM_LOCK; + case KeypadSlash: + return Keys.NUMPAD_DIVIDE; + case KeypadAsterisk: + return Keys.NUMPAD_MULTIPLY; + case KeypadHyphen: + return Keys.NUMPAD_SUBTRACT; + case KeypadPlus: + return Keys.NUMPAD_ADD; + case KeypadEnter: + return Keys.NUMPAD_ENTER; + case Keypad1: + return Keys.NUM_1; + case Keypad2: + return Keys.NUM_2; + case Keypad3: + return Keys.NUM_3; + case Keypad4: + return Keys.NUM_4; + case Keypad5: + return Keys.NUM_5; + case Keypad6: + return Keys.NUM_6; + case Keypad7: + return Keys.NUM_7; + case Keypad8: + return Keys.NUM_8; + case Keypad9: + return Keys.NUM_9; + case Keypad0: + return Keys.NUM_0; + case KeypadPeriod: + return Keys.NUMPAD_DOT; + case KeyboardNonUSBackslash: + return Keys.BACKSLASH; + case KeyboardApplication: + return Keys.MENU; + case KeyboardPower: + return Keys.POWER; + case KeypadEqualSign: + case KeypadEqualSignAS400: + return Keys.NUMPAD_EQUALS; + case KeyboardHelp: + return Keys.F1; + case KeyboardMenu: + return Keys.MENU; + case KeyboardSelect: + return Keys.BUTTON_SELECT; + case KeyboardStop: + return Keys.MEDIA_STOP; + case KeyboardFind: + return Keys.SEARCH; + case KeyboardMute: + return Keys.MUTE; + case KeyboardVolumeUp: + return Keys.VOLUME_UP; + case KeyboardVolumeDown: + return Keys.VOLUME_DOWN; + case KeypadComma: + return Keys.NUMPAD_COMMA; + case KeyboardAlternateErase: + return Keys.DEL; + case KeyboardCancel: + return Keys.ESCAPE; + case KeyboardClear: + return Keys.CLEAR; + case KeyboardReturn: + return Keys.ENTER; + case KeyboardLeftControl: + return Keys.CONTROL_LEFT; + case KeyboardLeftShift: + return Keys.SHIFT_LEFT; + case KeyboardLeftAlt: + return Keys.ALT_LEFT; + case KeyboardRightControl: + return Keys.CONTROL_RIGHT; + case KeyboardRightShift: + return Keys.SHIFT_RIGHT; + case KeyboardRightAlt: + return Keys.ALT_RIGHT; + case KeyboardCapsLock: + return Keys.CAPS_LOCK; + case KeyboardPrintScreen: + return Keys.PRINT_SCREEN; + case KeyboardScrollLock: + return Keys.SCROLL_LOCK; + default: + return Keys.UNKNOWN; + } + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplication.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplication.java new file mode 100644 index 00000000000..dcb08f0414c --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplication.java @@ -0,0 +1,445 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import java.io.File; +import com.badlogic.gdx.ApplicationLogger; +import com.badlogic.gdx.backends.iosrobovm.objectal.OALIOSAudio; +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.Foundation; +import org.robovm.apple.foundation.NSMutableDictionary; +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.foundation.NSProcessInfo; +import org.robovm.apple.foundation.NSString; +import org.robovm.apple.uikit.UIApplication; +import org.robovm.apple.uikit.UIApplicationDelegateAdapter; +import org.robovm.apple.uikit.UIApplicationLaunchOptions; +import org.robovm.apple.uikit.UIDevice; +import org.robovm.apple.uikit.UIUserInterfaceIdiom; +import org.robovm.apple.uikit.UIPasteboard; +import org.robovm.apple.uikit.UIScreen; +import org.robovm.apple.uikit.UIViewController; +import org.robovm.apple.uikit.UIWindow; +import org.robovm.rt.bro.Bro; +import com.badlogic.gdx.Application; +import com.badlogic.gdx.ApplicationListener; +import com.badlogic.gdx.Audio; +import com.badlogic.gdx.Files; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Graphics; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.LifecycleListener; +import com.badlogic.gdx.Net; +import com.badlogic.gdx.Preferences; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Clipboard; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSApplication implements Application { + + /** DO NOT EDIT THIS FILE - it is machine generated */ + public static abstract class Delegate extends UIApplicationDelegateAdapter { + + private IOSApplication app; + + protected abstract IOSApplication createApplication (); + + @Override + public boolean didFinishLaunching (UIApplication application, UIApplicationLaunchOptions launchOptions) { + // Prevent this from being GCed until the ObjC UIApplication is deallocated + application.addStrongRef(this); + this.app = createApplication(); + return app.didFinishLaunching(application, launchOptions); + } + + @Override + public void didBecomeActive (UIApplication application) { + app.didBecomeActive(application); + } + + @Override + public void willEnterForeground (UIApplication application) { + app.willEnterForeground(application); + } + + @Override + public void willResignActive (UIApplication application) { + app.willResignActive(application); + } + + @Override + public void willTerminate (UIApplication application) { + app.willTerminate(application); + } + } + + UIApplication uiApp; + + UIWindow uiWindow; + + ApplicationListener listener; + + IOSViewControllerListener viewControllerListener; + + IOSApplicationConfiguration config; + + IOSGraphics graphics; + + IOSAudio audio; + + Files files; + + IOSInput input; + + IOSNet net; + + int logLevel = Application.LOG_DEBUG; + + ApplicationLogger applicationLogger; + + /** The display scale factor (1.0f for normal; 2.0f to use retina coordinates/dimensions). */ + float pixelsPerPoint; + + private IOSScreenBounds lastScreenBounds = null; + + Array runnables = new Array(); + + Array executedRunnables = new Array(); + + Array lifecycleListeners = new Array(); + + public IOSApplication (ApplicationListener listener, IOSApplicationConfiguration config) { + this.listener = listener; + this.config = config; + } + + final boolean didFinishLaunching (UIApplication uiApp, UIApplicationLaunchOptions options) { + setApplicationLogger(new IOSApplicationLogger()); + Gdx.app = this; + this.uiApp = uiApp; + // enable or disable screen dimming + uiApp.setIdleTimerDisabled(config.preventScreenDimming); + Gdx.app.debug("IOSApplication", "iOS version: " + UIDevice.getCurrentDevice().getSystemVersion()); + Gdx.app.debug("IOSApplication", "Running in " + (Bro.IS_64BIT ? "64-bit" : "32-bit") + " mode"); + // iOS counts in "points" instead of pixels. Points are logical pixels + pixelsPerPoint = (float)UIScreen.getMainScreen().getNativeScale(); + Gdx.app.debug("IOSApplication", "Pixels per point: " + pixelsPerPoint); + this.uiWindow = new UIWindow(UIScreen.getMainScreen().getBounds()); + this.uiWindow.makeKeyAndVisible(); + uiApp.getDelegate().setWindow(uiWindow); + // setup libgdx + this.input = createInput(); + this.graphics = createGraphics(); + Gdx.gl = Gdx.gl20 = graphics.gl20; + Gdx.gl30 = graphics.gl30; + this.files = createFiles(); + this.audio = createAudio(config); + this.net = new IOSNet(this, config); + Gdx.files = this.files; + Gdx.graphics = this.graphics; + Gdx.audio = this.audio; + Gdx.input = this.input; + Gdx.net = this.net; + this.input.setupPeripherals(); + this.uiWindow.setRootViewController(this.graphics.viewController); + Gdx.app.debug("IOSApplication", "created"); + return true; + } + + protected Files createFiles () { + return new IOSFiles(); + } + + protected IOSAudio createAudio (IOSApplicationConfiguration config) { + return new OALIOSAudio(config); + } + + protected IOSGraphics createGraphics () { + return new IOSGraphics(this, config, input, config.useGL30); + } + + protected IOSUIViewController createUIViewController (IOSGraphics graphics) { + return new IOSUIViewController(this, graphics); + } + + protected IOSInput createInput () { + return new DefaultIOSInput(this); + } + + /** Returns device ppi using a best guess approach when device is unknown. Overwrite to customize strategy. */ + protected int guessUnknownPpi () { + int ppi; + if (UIDevice.getCurrentDevice().getUserInterfaceIdiom() == UIUserInterfaceIdiom.Pad) + ppi = 132 * (int)pixelsPerPoint; + else + ppi = 164 * (int)pixelsPerPoint; + error("IOSApplication", "Device PPI unknown. PPI value has been guessed to " + ppi + " but may be wrong"); + return ppi; + } + + /** Return the UI view controller of IOSApplication + * @return the view controller of IOSApplication */ + public UIViewController getUIViewController () { + return graphics.viewController; + } + + /** Return the UI Window of IOSApplication + * @return the window */ + public UIWindow getUIWindow () { + return uiWindow; + } + + /** @see IOSScreenBounds for detailed explanation + * @return logical dimensions of space we draw to, adjusted for device orientation */ + protected IOSScreenBounds computeBounds () { + CGRect screenBounds = uiWindow.getBounds(); + final CGRect statusBarFrame = uiApp.getStatusBarFrame(); + double statusBarHeight = statusBarFrame.getHeight(); + double screenWidth = screenBounds.getWidth(); + double screenHeight = screenBounds.getHeight(); + if (statusBarHeight != 0.0) { + debug("IOSApplication", "Status bar is visible (height = " + statusBarHeight + ")"); + screenHeight -= statusBarHeight; + } else { + debug("IOSApplication", "Status bar is not visible"); + } + final int offsetX = 0; + final int offsetY = (int)Math.round(statusBarHeight); + final int width = (int)Math.round(screenWidth); + final int height = (int)Math.round(screenHeight); + final int backBufferWidth = (int)Math.round(screenWidth * pixelsPerPoint); + final int backBufferHeight = (int)Math.round(screenHeight * pixelsPerPoint); + debug("IOSApplication", "Computed bounds are x=" + offsetX + " y=" + offsetY + " w=" + width + " h=" + height + " bbW= " + + backBufferWidth + " bbH= " + backBufferHeight); + return lastScreenBounds = new IOSScreenBounds(offsetX, offsetY, width, height, backBufferWidth, backBufferHeight); + } + + /** @return area of screen in UIKit points on which libGDX draws, with 0,0 being upper left corner */ + public IOSScreenBounds getScreenBounds () { + if (lastScreenBounds == null) + return computeBounds(); + else + return lastScreenBounds; + } + + final void didBecomeActive (UIApplication uiApp) { + Gdx.app.debug("IOSApplication", "resumed"); + audio.didBecomeActive(); + graphics.makeCurrent(); + graphics.resume(); + } + + final void willEnterForeground (UIApplication uiApp) { + audio.willEnterForeground(); + } + + final void willResignActive (UIApplication uiApp) { + Gdx.app.debug("IOSApplication", "paused"); + audio.willResignActive(); + graphics.makeCurrent(); + graphics.pause(); + Gdx.gl.glFinish(); + } + + final void willTerminate (UIApplication uiApp) { + Gdx.app.debug("IOSApplication", "disposed"); + audio.willTerminate(); + graphics.makeCurrent(); + Array listeners = lifecycleListeners; + synchronized (listeners) { + for (LifecycleListener listener : listeners) { + listener.pause(); + } + } + listener.dispose(); + Gdx.gl.glFinish(); + } + + @Override + public ApplicationListener getApplicationListener () { + return listener; + } + + @Override + public Graphics getGraphics () { + return graphics; + } + + @Override + public Audio getAudio () { + return audio; + } + + @Override + public Input getInput () { + return input; + } + + @Override + public Files getFiles () { + return files; + } + + @Override + public Net getNet () { + return net; + } + + @Override + public void debug (String tag, String message) { + if (logLevel >= LOG_DEBUG) getApplicationLogger().debug(tag, message); + } + + @Override + public void debug (String tag, String message, Throwable exception) { + if (logLevel >= LOG_DEBUG) getApplicationLogger().debug(tag, message, exception); + } + + @Override + public void log (String tag, String message) { + if (logLevel >= LOG_INFO) getApplicationLogger().log(tag, message); + } + + @Override + public void log (String tag, String message, Throwable exception) { + if (logLevel >= LOG_INFO) getApplicationLogger().log(tag, message, exception); + } + + @Override + public void error (String tag, String message) { + if (logLevel >= LOG_ERROR) getApplicationLogger().error(tag, message); + } + + @Override + public void error (String tag, String message, Throwable exception) { + if (logLevel >= LOG_ERROR) getApplicationLogger().error(tag, message, exception); + } + + @Override + public void setLogLevel (int logLevel) { + this.logLevel = logLevel; + } + + @Override + public int getLogLevel () { + return logLevel; + } + + @Override + public void setApplicationLogger (ApplicationLogger applicationLogger) { + this.applicationLogger = applicationLogger; + } + + @Override + public ApplicationLogger getApplicationLogger () { + return applicationLogger; + } + + @Override + public ApplicationType getType () { + return ApplicationType.iOS; + } + + @Override + public int getVersion () { + return (int)NSProcessInfo.getSharedProcessInfo().getOperatingSystemVersion().getMajorVersion(); + } + + @Override + public long getJavaHeap () { + return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); + } + + @Override + public long getNativeHeap () { + return getJavaHeap(); + } + + @Override + public Preferences getPreferences (String name) { + File libraryPath = new File(System.getenv("HOME"), "Library"); + File finalPath = new File(libraryPath, name + ".plist"); + @SuppressWarnings("unchecked") + NSMutableDictionary nsDictionary = (NSMutableDictionary)NSMutableDictionary + .read(finalPath); + // if it fails to get an existing dictionary, create a new one. + if (nsDictionary == null) { + nsDictionary = new NSMutableDictionary(); + nsDictionary.write(finalPath, false); + } + return new IOSPreferences(nsDictionary, finalPath.getAbsolutePath()); + } + + @Override + public void postRunnable (Runnable runnable) { + synchronized (runnables) { + runnables.add(runnable); + Gdx.graphics.requestRendering(); + } + } + + public void processRunnables () { + synchronized (runnables) { + executedRunnables.clear(); + executedRunnables.addAll(runnables); + runnables.clear(); + } + for (int i = 0; i < executedRunnables.size; i++) { + try { + executedRunnables.get(i).run(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + + @Override + public void exit () { + System.exit(0); + } + + @Override + public Clipboard getClipboard () { + return new Clipboard() { + + @Override + public void setContents (String content) { + UIPasteboard.getGeneralPasteboard().setString(content); + } + + @Override + public boolean hasContents () { + if (Foundation.getMajorSystemVersion() >= 10) { + return UIPasteboard.getGeneralPasteboard().hasStrings(); + } + String contents = getContents(); + return contents != null && !contents.isEmpty(); + } + + @Override + public String getContents () { + return UIPasteboard.getGeneralPasteboard().getString(); + } + }; + } + + @Override + public void addLifecycleListener (LifecycleListener listener) { + synchronized (lifecycleListeners) { + lifecycleListeners.add(listener); + } + } + + @Override + public void removeLifecycleListener (LifecycleListener listener) { + synchronized (lifecycleListeners) { + lifecycleListeners.removeValue(listener, true); + } + } + + /** Add a listener to handle events from the libGDX root view controller + * @param listener The {#link IOSViewControllerListener} to add */ + public void addViewControllerListener (IOSViewControllerListener listener) { + viewControllerListener = listener; + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplicationConfiguration.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplicationConfiguration.java new file mode 100644 index 00000000000..24cfa0dc25c --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplicationConfiguration.java @@ -0,0 +1,99 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.glutils.HdpiMode; +import com.badlogic.gdx.graphics.glutils.HdpiUtils; +import com.badlogic.gdx.utils.ObjectMap; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableColorFormat; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableDepthFormat; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableMultisample; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableStencilFormat; +import org.robovm.apple.uikit.UIRectEdge; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSApplicationConfiguration { + + /** whether to enable screen dimming. */ + public boolean preventScreenDimming = true; + + /** whether or not portrait orientation is supported. */ + public boolean orientationPortrait = true; + + /** whether or not landscape orientation is supported. */ + public boolean orientationLandscape = true; + + /** the color format, RGBA8888 is the default * */ + public MGLDrawableColorFormat colorFormat = MGLDrawableColorFormat.RGBA8888; + + /** the depth buffer format, Format16 is default * */ + public MGLDrawableDepthFormat depthFormat = MGLDrawableDepthFormat._16; + + /** the stencil buffer format, None is default * */ + public MGLDrawableStencilFormat stencilFormat = MGLDrawableStencilFormat.None; + + /** the multisample format, None is default * */ + public MGLDrawableMultisample multisample = MGLDrawableMultisample.None; + + /** number of frames per second, 60 is default * */ + public int preferredFramesPerSecond = 60; + + /** whether to use the accelerometer, default true * */ + public boolean useAccelerometer = true; + + /** the update interval to poll the accelerometer with, in seconds * */ + public float accelerometerUpdate = 0.05f; + + /** the update interval to poll the magnetometer with, in seconds * */ + public float magnetometerUpdate = 0.05f; + + /** whether to use the compass, default true * */ + public boolean useCompass = true; + + /** whether or not to allow background music from iPod * */ + public boolean allowIpod = true; + + /** whether or not the onScreenKeyboard should be closed on return key * */ + public boolean keyboardCloseOnReturn = true; + + /** Experimental, whether to enable OpenGL ES 3 if supported. If not supported it will fall-back to OpenGL ES 2.0. When GL ES 3 + * is enabled, {@link com.badlogic.gdx.Gdx#gl30} can be used to access it's functionality. + * @deprecated this option is currently experimental and not yet fully supported, expect issues. */ + @Deprecated public boolean useGL30 = false; + + /** whether the status bar should be visible or not * */ + public boolean statusBarVisible = false; + + /** whether the home indicator should be hidden or not * */ + public boolean hideHomeIndicator = true; + + /** Whether to override the ringer/mute switch, see https://github.com/libgdx/libgdx/issues/4430 */ + public boolean overrideRingerSwitch = false; + + /** Edges where app gestures must be fired over system gestures. Prior to iOS 11, UIRectEdge.All was default behaviour if + * status bar hidden, see https://github.com/libgdx/libgdx/issues/5110 * */ + public UIRectEdge screenEdgesDeferringSystemGestures = UIRectEdge.None; + + /** The maximum number of threads to use for network requests. Default is {@link Integer#MAX_VALUE}. */ + public int maxNetThreads = Integer.MAX_VALUE; + + /** whether to use audio or not. Default is true * */ + public boolean useAudio = true; + + /** This setting allows you to specify whether you want to work in logical or raw pixel units. See {@link HdpiMode} for more + * information. Note that some OpenGL functions like {@link GL20#glViewport(int, int, int, int)} and + * {@link GL20#glScissor(int, int, int, int)} require raw pixel units. Use {@link HdpiUtils} to help with the conversion if + * HdpiMode is set to {@link HdpiMode#Logical}. Defaults to {@link HdpiMode#Logical}. */ + public HdpiMode hdpiMode = HdpiMode.Logical; + + ObjectMap knownDevices = IOSDevice.populateWithKnownDevices(); + + /** adds device information for newer iOS devices, or overrides information for given ones + * @param classifier human readable device classifier + * @param machineString machine string returned by iOS + * @param ppi device's pixel per inch value */ + public void addIosDevice (String classifier, String machineString, int ppi) { + IOSDevice.addDeviceToMap(knownDevices, classifier, machineString, ppi); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplicationLogger.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplicationLogger.java new file mode 100644 index 00000000000..eb4a8263f75 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSApplicationLogger.java @@ -0,0 +1,44 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.ApplicationLogger; +import org.robovm.apple.foundation.Foundation; +import org.robovm.apple.foundation.NSString; + +/** DO NOT EDIT THIS FILE - it is machine generated Default implementation of {@link ApplicationLogger} for ios */ +public class IOSApplicationLogger implements ApplicationLogger { + + @Override + public void log (String tag, String message) { + Foundation.log("%@", new NSString("[info] " + tag + ": " + message)); + } + + @Override + public void log (String tag, String message, Throwable exception) { + Foundation.log("%@", new NSString("[info] " + tag + ": " + message)); + exception.printStackTrace(); + } + + @Override + public void error (String tag, String message) { + Foundation.log("%@", new NSString("[error] " + tag + ": " + message)); + } + + @Override + public void error (String tag, String message, Throwable exception) { + Foundation.log("%@", new NSString("[error] " + tag + ": " + message)); + exception.printStackTrace(); + } + + @Override + public void debug (String tag, String message) { + Foundation.log("%@", new NSString("[debug] " + tag + ": " + message)); + } + + @Override + public void debug (String tag, String message, Throwable exception) { + Foundation.log("%@", new NSString("[debug] " + tag + ": " + message)); + exception.printStackTrace(); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSAudio.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSAudio.java new file mode 100644 index 00000000000..ed878307d25 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSAudio.java @@ -0,0 +1,17 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.Audio; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public interface IOSAudio extends Audio { + + public void didBecomeActive (); + + public void willEnterForeground (); + + public void willResignActive (); + + public void willTerminate (); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSDevice.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSDevice.java new file mode 100644 index 00000000000..f3e9976eca0 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSDevice.java @@ -0,0 +1,134 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.utils.ObjectMap; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSDevice { + + final String classifier; + + final String machineString; + + final int ppi; + + public IOSDevice (String classifier, String machineString, int ppi) { + this.classifier = classifier; + this.machineString = machineString; + this.ppi = ppi; + } + + /** The devices information can be obtained from https://github.com/lmirosevic/GBDeviceInfo or + * https://gist.github.com/adamawolf/3048717 */ + static ObjectMap populateWithKnownDevices () { + ObjectMap deviceMap = new ObjectMap(); + addDeviceToMap(deviceMap, "IPHONE_2G", "iPhone1,1", 163); + addDeviceToMap(deviceMap, "IPHONE_3G", "iPhone1,2", 163); + addDeviceToMap(deviceMap, "IPHONE_3GS", "iPhone2,1", 163); + addDeviceToMap(deviceMap, "IPHONE_4", "iPhone3,1", 326); + addDeviceToMap(deviceMap, "IPHONE_4V", "iPhone3,2", 326); + addDeviceToMap(deviceMap, "IPHONE_4_CDMA", "iPhone3,3", 326); + addDeviceToMap(deviceMap, "IPHONE_4S", "iPhone4,1", 326); + addDeviceToMap(deviceMap, "IPHONE_5", "iPhone5,1", 326); + addDeviceToMap(deviceMap, "IPHONE_5_CDMA_GSM", "iPhone5,2", 326); + addDeviceToMap(deviceMap, "IPHONE_5C", "iPhone5,3", 326); + addDeviceToMap(deviceMap, "IPHONE_5C_CDMA_GSM", "iPhone5,4", 326); + addDeviceToMap(deviceMap, "IPHONE_5S", "iPhone6,1", 326); + addDeviceToMap(deviceMap, "IPHONE_5S_CDMA_GSM", "iPhone6,2", 326); + addDeviceToMap(deviceMap, "IPHONE_6_PLUS", "iPhone7,1", 401); + addDeviceToMap(deviceMap, "IPHONE_6", "iPhone7,2", 326); + addDeviceToMap(deviceMap, "IPHONE_6S", "iPhone8,1", 326); + addDeviceToMap(deviceMap, "IPHONE_6S_PLUS", "iPhone8,2", 401); + addDeviceToMap(deviceMap, "IPHONE_7_CDMA_GSM", "iPhone9,1", 326); + addDeviceToMap(deviceMap, "IPHONE_7_PLUS_CDMA_GSM", "iPhone9,2", 401); + addDeviceToMap(deviceMap, "IPHONE_7", "iPhone9,3", 326); + addDeviceToMap(deviceMap, "IPHONE_7_PLUS", "iPhone9,4", 401); + addDeviceToMap(deviceMap, "IPHONE_SE", "iPhone8,4", 326); + addDeviceToMap(deviceMap, "IPHONE_8_CDMA_GSM", "iPhone10,1", 326); + addDeviceToMap(deviceMap, "IPHONE_8_PLUS_CDMA_GSM", "iPhone10,2", 401); + addDeviceToMap(deviceMap, "IPHONE_X_CDMA_GSM", "iPhone10,3", 458); + addDeviceToMap(deviceMap, "IPHONE_8", "iPhone10,4", 326); + addDeviceToMap(deviceMap, "IPHONE_8_PLUS", "iPhone10,5", 401); + addDeviceToMap(deviceMap, "IPHONE_X", "iPhone10,6", 458); + addDeviceToMap(deviceMap, "IPHONE_XS", "iPhone11,2", 458); + addDeviceToMap(deviceMap, "IPHONE_XS_MAX", "iPhone11,4", 458); + addDeviceToMap(deviceMap, "IPHONE_XS_MAX_2_NANO_SIM", "iPhone11,6", 458); + addDeviceToMap(deviceMap, "IPHONE_XR", "iPhone11,8", 326); + addDeviceToMap(deviceMap, "IPHONE_11", "iPhone12,1", 326); + addDeviceToMap(deviceMap, "IPHONE_11_PRO", "iPhone12,3", 458); + addDeviceToMap(deviceMap, "IPHONE_11_PRO_MAX", "iPhone12,5", 458); + addDeviceToMap(deviceMap, "IPHONE_SE_2G", "iPhone12,8", 326); + addDeviceToMap(deviceMap, "IPOD_TOUCH_1G", "iPod1,1", 163); + addDeviceToMap(deviceMap, "IPOD_TOUCH_2G", "iPod2,1", 163); + addDeviceToMap(deviceMap, "IPOD_TOUCH_3G", "iPod3,1", 163); + addDeviceToMap(deviceMap, "IPOD_TOUCH_4G", "iPod4,1", 326); + addDeviceToMap(deviceMap, "IPOD_TOUCH_5G", "iPod5,1", 326); + addDeviceToMap(deviceMap, "IPOD_TOUCH_6G", "iPod7,1", 326); + addDeviceToMap(deviceMap, "IPOD_TOUCH_7G", "iPod9,1", 326); + addDeviceToMap(deviceMap, "IPAD", "iPad1,1", 132); + addDeviceToMap(deviceMap, "IPAD_3G", "iPad1,2", 132); + addDeviceToMap(deviceMap, "IPAD_2_WIFI", "iPad2,1", 132); + addDeviceToMap(deviceMap, "IPAD_2", "iPad2,2", 132); + addDeviceToMap(deviceMap, "IPAD_2_CDMA", "iPad2,3", 132); + addDeviceToMap(deviceMap, "IPAD_2V", "iPad2,4", 132); + addDeviceToMap(deviceMap, "IPAD_MINI_WIFI", "iPad2,5", 164); + addDeviceToMap(deviceMap, "IPAD_MINI", "iPad2,6", 164); + addDeviceToMap(deviceMap, "IPAD_MINI_WIFI_CDMA", "iPad2,7", 164); + addDeviceToMap(deviceMap, "IPAD_3_WIFI", "iPad3,1", 264); + addDeviceToMap(deviceMap, "IPAD_3_WIFI_CDMA", "iPad3,2", 264); + addDeviceToMap(deviceMap, "IPAD_3", "iPad3,3", 264); + addDeviceToMap(deviceMap, "IPAD_4_WIFI", "iPad3,4", 264); + addDeviceToMap(deviceMap, "IPAD_4", "iPad3,5", 264); + addDeviceToMap(deviceMap, "IPAD_4_GSM_CDMA", "iPad3,6", 264); + addDeviceToMap(deviceMap, "IPAD_AIR_WIFI", "iPad4,1", 264); + addDeviceToMap(deviceMap, "IPAD_AIR_WIFI_GSM", "iPad4,2", 264); + addDeviceToMap(deviceMap, "IPAD_AIR_WIFI_CDMA", "iPad4,3", 264); + addDeviceToMap(deviceMap, "IPAD_MINI_RETINA_WIFI", "iPad4,4", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_RETINA_WIFI_CDMA", "iPad4,5", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_RETINA_WIFI_CELLULAR_CN", "iPad4,6", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_3_WIFI", "iPad4,7", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_3_WIFI_CELLULAR", "iPad4,8", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_3_WIFI_CELLULAR_CN", "iPad4,9", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_4_WIFI", "iPad5,1", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_4_WIFI_CELLULAR", "iPad5,2", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_AIR_2_WIFI", "iPad5,3", 264); + addDeviceToMap(deviceMap, "IPAD_MINI_AIR_2_WIFI_CELLULAR", "iPad5,4", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_WIFI", "iPad6,7", 264); + addDeviceToMap(deviceMap, "IPAD_PRO", "iPad6,8", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_97_WIFI", "iPad6,3", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_97", "iPad6,4", 264); + addDeviceToMap(deviceMap, "IPAD_5_WIFI", "iPad6,11", 264); + addDeviceToMap(deviceMap, "IPAD_5_WIFI_CELLULAR", "iPad6,12", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_2_WIFI", "iPad7,1", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_2_WIFI_CELLULAR", "iPad7,2", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_10_5_WIFI", "iPad7,3", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_10_5_WIFI_CELLULAR", "iPad7,4", 264); + addDeviceToMap(deviceMap, "IPAD_6_WIFI", "iPad7,5", 264); + addDeviceToMap(deviceMap, "IPAD_6_WIFI_CELLULAR", "iPad7,6", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_11_WIFI", "iPad8,1", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_11_WIFI_6GB", "iPad8,2", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_11_WIFI_CELLULAR", "iPad8,3", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_11_WIFI_CELLULAR_6GB", "iPad8,4", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_3_WIFI", "iPad8,5", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_3_WIFI_6GB", "iPad8,6", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_3_WIFI_CELLULAR", "iPad8,7", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_3_WIFI_CELLULAR_6GB", "iPad8,8", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_11_2G_WIFI", "iPad8,9", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_11_2G_WIFI_CELLULAR", "iPad8,10", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_12.9_4G_WIFI", "iPad8,11", 264); + addDeviceToMap(deviceMap, "IPAD_PRO_12.9_4G_WIFI_CELLULAR", "iPad8,12", 264); + addDeviceToMap(deviceMap, "IPAD_MINI_5G_WIFI", "iPad11,1", 326); + addDeviceToMap(deviceMap, "IPAD_MINI_5G_WIFI_CELLULAR", "iPad11,2", 326); + addDeviceToMap(deviceMap, "IPAD_AIR_3G_WIFI", "iPad11,3", 264); + addDeviceToMap(deviceMap, "IPAD_AIR_3G_WIFI_CELLULAR", "iPad11,4", 264); + addDeviceToMap(deviceMap, "SIMULATOR_32", "i386", 264); + addDeviceToMap(deviceMap, "SIMULATOR_64", "x86_64", 264); + addDeviceToMap(deviceMap, "SIMULATOR_ARM64", "arm64", 264); + return deviceMap; + } + + static void addDeviceToMap (ObjectMap deviceMap, String classifier, String machineString, int ppi) { + deviceMap.put(machineString, new IOSDevice(classifier, machineString, ppi)); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSFileHandle.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSFileHandle.java new file mode 100644 index 00000000000..3d509a91aef --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSFileHandle.java @@ -0,0 +1,52 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import java.io.File; +import com.badlogic.gdx.Files.FileType; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.GdxRuntimeException; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSFileHandle extends FileHandle { + + protected IOSFileHandle (String fileName, FileType type) { + super(fileName, type); + } + + protected IOSFileHandle (File file, FileType type) { + super(file, type); + } + + @Override + public FileHandle child (String name) { + if (file.getPath().length() == 0) return new IOSFileHandle(new File(name), type); + return new IOSFileHandle(new File(file, name), type); + } + + @Override + public FileHandle parent () { + File parent = file.getParentFile(); + if (parent == null) { + if (type == FileType.Absolute) + parent = new File("/"); + else + parent = new File(""); + } + return new IOSFileHandle(parent, type); + } + + @Override + public FileHandle sibling (String name) { + if (file.getPath().length() == 0) throw new GdxRuntimeException("Cannot get the sibling of the root."); + return new IOSFileHandle(new File(file.getParent(), name), type); + } + + @Override + public File file () { + if (type == FileType.Internal) return new File(IOSFiles.internalPath, file.getPath()); + if (type == FileType.External) return new File(IOSFiles.externalPath, file.getPath()); + if (type == FileType.Local) return new File(IOSFiles.localPath, file.getPath()); + return file; + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSFiles.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSFiles.java new file mode 100644 index 00000000000..64b882fba0f --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSFiles.java @@ -0,0 +1,76 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import org.robovm.apple.foundation.NSBundle; +import com.badlogic.gdx.Files; +import com.badlogic.gdx.files.FileHandle; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSFiles implements Files { + + // TODO: Use NSSearchPathForDirectoriesInDomains instead? + // $HOME should point to the app root dir. + static final String appDir = System.getenv("HOME"); + + static final String externalPath = appDir + "/Documents/"; + + static final String localPath = appDir + "/Library/local/"; + + static final String internalPath = NSBundle.getMainBundle().getBundlePath(); + + public IOSFiles () { + new FileHandle(externalPath).mkdirs(); + new FileHandle(localPath).mkdirs(); + } + + @Override + public FileHandle getFileHandle (String fileName, FileType type) { + return new IOSFileHandle(fileName, type); + } + + @Override + public FileHandle classpath (String path) { + return new IOSFileHandle(path, FileType.Classpath); + } + + @Override + public FileHandle internal (String path) { + return new IOSFileHandle(path, FileType.Internal); + } + + @Override + public FileHandle external (String path) { + return new IOSFileHandle(path, FileType.External); + } + + @Override + public FileHandle absolute (String path) { + return new IOSFileHandle(path, FileType.Absolute); + } + + @Override + public FileHandle local (String path) { + return new IOSFileHandle(path, FileType.Local); + } + + @Override + public String getExternalStoragePath () { + return externalPath; + } + + @Override + public boolean isExternalStorageAvailable () { + return true; + } + + @Override + public String getLocalStoragePath () { + return localPath; + } + + @Override + public boolean isLocalStorageAvailable () { + return true; + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGLES20.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGLES20.java new file mode 100644 index 00000000000..dcd59170058 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGLES20.java @@ -0,0 +1,360 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import java.nio.Buffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import com.badlogic.gdx.graphics.GL20; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSGLES20 implements GL20 { + + public IOSGLES20 () { + init(); + } + + /** last viewport set, needed because GLKView resets the viewport on each call to render... amazing * */ + public static int x, y, width, height; + + private static native void init (); + + public native void glActiveTexture (int texture); + + public native void glAttachShader (int program, int shader); + + public native void glBindAttribLocation (int program, int index, String name); + + public native void glBindBuffer (int target, int buffer); + + public native void glBindFramebuffer (int target, int framebuffer); + + public native void glBindRenderbuffer (int target, int renderbuffer); + + public native void glBindTexture (int target, int texture); + + public native void glBlendColor (float red, float green, float blue, float alpha); + + public native void glBlendEquation (int mode); + + public native void glBlendEquationSeparate (int modeRGB, int modeAlpha); + + public native void glBlendFunc (int sfactor, int dfactor); + + public native void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha); + + public native void glBufferData (int target, int size, Buffer data, int usage); + + public native void glBufferSubData (int target, int offset, int size, Buffer data); + + public native int glCheckFramebufferStatus (int target); + + public native void glClear (int mask); + + public native void glClearColor (float red, float green, float blue, float alpha); + + public native void glClearDepthf (float depth); + + public native void glClearStencil (int s); + + public native void glColorMask (boolean red, boolean green, boolean blue, boolean alpha); + + public native void glCompileShader (int shader); + + public native void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border, + int imageSize, Buffer data); + + public native void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, + int format, int imageSize, Buffer data); + + public native void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, + int border); + + public native void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height); + + public native int glCreateProgram (); + + public native int glCreateShader (int type); + + public native void glCullFace (int mode); + + public native void glDeleteBuffers (int n, IntBuffer buffers); + + public native void glDeleteBuffer (int buffer); + + public native void glDeleteFramebuffers (int n, IntBuffer framebuffers); + + public native void glDeleteFramebuffer (int framebuffer); + + public native void glDeleteProgram (int program); + + public native void glDeleteRenderbuffers (int n, IntBuffer renderbuffers); + + public native void glDeleteRenderbuffer (int renderbuffer); + + public native void glDeleteShader (int shader); + + public native void glDeleteTextures (int n, IntBuffer textures); + + public native void glDeleteTexture (int texture); + + public native void glDepthFunc (int func); + + public native void glDepthMask (boolean flag); + + public native void glDepthRangef (float zNear, float zFar); + + public native void glDetachShader (int program, int shader); + + public native void glDisable (int cap); + + public native void glDisableVertexAttribArray (int index); + + public native void glDrawArrays (int mode, int first, int count); + + public native void glDrawElements (int mode, int count, int type, Buffer indices); + + public native void glDrawElements (int mode, int count, int type, int indices); + + public native void glEnable (int cap); + + public native void glEnableVertexAttribArray (int index); + + public native void glFinish (); + + public native void glFlush (); + + public native void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer); + + public native void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level); + + public native void glFrontFace (int mode); + + public native void glGenBuffers (int n, IntBuffer buffers); + + public native int glGenBuffer (); + + public native void glGenerateMipmap (int target); + + public native void glGenFramebuffers (int n, IntBuffer framebuffers); + + public native int glGenFramebuffer (); + + public native void glGenRenderbuffers (int n, IntBuffer renderbuffers); + + public native int glGenRenderbuffer (); + + public native void glGenTextures (int n, IntBuffer textures); + + public native int glGenTexture (); + + public native String glGetActiveAttrib (int program, int index, IntBuffer size, IntBuffer type); + + public native String glGetActiveUniform (int program, int index, IntBuffer size, IntBuffer type); + + public native void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders); + + public native int glGetAttribLocation (int program, String name); + + public native void glGetBooleanv (int pname, Buffer params); + + public native void glGetBufferParameteriv (int target, int pname, IntBuffer params); + + public native int glGetError (); + + public native void glGetFloatv (int pname, FloatBuffer params); + + public native void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params); + + public native void glGetIntegerv (int pname, IntBuffer params); + + public native void glGetProgramiv (int program, int pname, IntBuffer params); + + public native String glGetProgramInfoLog (int program); + + public native void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params); + + public native void glGetShaderiv (int shader, int pname, IntBuffer params); + + public native String glGetShaderInfoLog (int shader); + + public native void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision); + + public native void glGetShaderSource (int shader, int bufsize, Buffer length, String source); + + public native String glGetString (int name); + + public native void glGetTexParameterfv (int target, int pname, FloatBuffer params); + + public native void glGetTexParameteriv (int target, int pname, IntBuffer params); + + public native void glGetUniformfv (int program, int location, FloatBuffer params); + + public native void glGetUniformiv (int program, int location, IntBuffer params); + + public native int glGetUniformLocation (int program, String name); + + public native void glGetVertexAttribfv (int index, int pname, FloatBuffer params); + + public native void glGetVertexAttribiv (int index, int pname, IntBuffer params); + + public native void glGetVertexAttribPointerv (int index, int pname, Buffer pointer); + + public native void glHint (int target, int mode); + + public native boolean glIsBuffer (int buffer); + + public native boolean glIsEnabled (int cap); + + public native boolean glIsFramebuffer (int framebuffer); + + public native boolean glIsProgram (int program); + + public native boolean glIsRenderbuffer (int renderbuffer); + + public native boolean glIsShader (int shader); + + public native boolean glIsTexture (int texture); + + public native void glLineWidth (float width); + + public native void glLinkProgram (int program); + + public native void glPixelStorei (int pname, int param); + + public native void glPolygonOffset (float factor, float units); + + public native void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels); + + public native void glReleaseShaderCompiler (); + + public native void glRenderbufferStorage (int target, int internalformat, int width, int height); + + public native void glSampleCoverage (float value, boolean invert); + + public native void glScissor (int x, int y, int width, int height); + + public native void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length); + + public native void glShaderSource (int shader, String string); + + public native void glStencilFunc (int func, int ref, int mask); + + public native void glStencilFuncSeparate (int face, int func, int ref, int mask); + + public native void glStencilMask (int mask); + + public native void glStencilMaskSeparate (int face, int mask); + + public native void glStencilOp (int fail, int zfail, int zpass); + + public native void glStencilOpSeparate (int face, int fail, int zfail, int zpass); + + public native void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, + int type, Buffer pixels); + + public native void glTexParameterf (int target, int pname, float param); + + public native void glTexParameterfv (int target, int pname, FloatBuffer params); + + public native void glTexParameteri (int target, int pname, int param); + + public native void glTexParameteriv (int target, int pname, IntBuffer params); + + public native void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, + int type, Buffer pixels); + + public native void glUniform1f (int location, float x); + + public native void glUniform1fv (int location, int count, FloatBuffer v); + + public native void glUniform1fv (int location, int count, float[] v, int offset); + + public native void glUniform1i (int location, int x); + + public native void glUniform1iv (int location, int count, IntBuffer v); + + public native void glUniform1iv (int location, int count, int[] v, int offset); + + public native void glUniform2f (int location, float x, float y); + + public native void glUniform2fv (int location, int count, FloatBuffer v); + + public native void glUniform2fv (int location, int count, float[] v, int offset); + + public native void glUniform2i (int location, int x, int y); + + public native void glUniform2iv (int location, int count, IntBuffer v); + + public native void glUniform2iv (int location, int count, int[] v, int offset); + + public native void glUniform3f (int location, float x, float y, float z); + + public native void glUniform3fv (int location, int count, FloatBuffer v); + + public native void glUniform3fv (int location, int count, float[] v, int offset); + + public native void glUniform3i (int location, int x, int y, int z); + + public native void glUniform3iv (int location, int count, IntBuffer v); + + public native void glUniform3iv (int location, int count, int[] v, int offset); + + public native void glUniform4f (int location, float x, float y, float z, float w); + + public native void glUniform4fv (int location, int count, FloatBuffer v); + + public native void glUniform4fv (int location, int count, float[] v, int offset); + + public native void glUniform4i (int location, int x, int y, int z, int w); + + public native void glUniform4iv (int location, int count, IntBuffer v); + + public native void glUniform4iv (int location, int count, int[] v, int offset); + + public native void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix2fv (int location, int count, boolean transpose, float[] value, int offset); + + public native void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix3fv (int location, int count, boolean transpose, float[] value, int offset); + + public native void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix4fv (int location, int count, boolean transpose, float[] value, int offset); + + public native void glUseProgram (int program); + + public native void glValidateProgram (int program); + + public native void glVertexAttrib1f (int indx, float x); + + public native void glVertexAttrib1fv (int indx, FloatBuffer values); + + public native void glVertexAttrib2f (int indx, float x, float y); + + public native void glVertexAttrib2fv (int indx, FloatBuffer values); + + public native void glVertexAttrib3f (int indx, float x, float y, float z); + + public native void glVertexAttrib3fv (int indx, FloatBuffer values); + + public native void glVertexAttrib4f (int indx, float x, float y, float z, float w); + + public native void glVertexAttrib4fv (int indx, FloatBuffer values); + + public native void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr); + + public native void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr); + + public void glViewport (int x, int y, int width, int height) { + IOSGLES20.x = x; + IOSGLES20.y = y; + IOSGLES20.width = width; + IOSGLES20.height = height; + glViewportJni(x, y, width, height); + } + + public native void glViewportJni (int x, int y, int width, int height); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGLES30.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGLES30.java new file mode 100644 index 00000000000..745ac50ed4f --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGLES30.java @@ -0,0 +1,213 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.graphics.GL30; +import java.nio.Buffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.LongBuffer; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSGLES30 extends IOSGLES20 implements GL30 { + + public IOSGLES30 () { + init(); + } + + private static native void init (); + + public native void glReadBuffer (int mode); + + public native void glDrawRangeElements (int mode, int start, int end, int count, int type, Buffer indices); + + public native void glDrawRangeElements (int mode, int start, int end, int count, int type, int offset); + + public native void glTexImage3D (int target, int level, int internalformat, int width, int height, int depth, int border, + int format, int type, Buffer pixels); + + public native void glTexImage3D (int target, int level, int internalformat, int width, int height, int depth, int border, + int format, int type, int offset); + + public native void glTexSubImage3D (int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, + int depth, int format, int type, Buffer pixels); + + public native void glTexSubImage3D (int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, + int depth, int format, int type, int offset); + + public native void glCopyTexSubImage3D (int target, int level, int xoffset, int yoffset, int zoffset, int x, int y, int width, + int height); + + public native void glGenQueries (int n, int[] ids, int offset); + + public native void glGenQueries (int n, IntBuffer ids); + + public native void glDeleteQueries (int n, int[] ids, int offset); + + public native void glDeleteQueries (int n, IntBuffer ids); + + public native boolean glIsQuery (int id); + + public native void glBeginQuery (int target, int id); + + public native void glEndQuery (int target); + + public native void glGetQueryiv (int target, int pname, IntBuffer params); + + public native void glGetQueryObjectuiv (int id, int pname, IntBuffer params); + + public native boolean glUnmapBuffer (int target); + + public native Buffer glGetBufferPointerv (int target, int pname); + + public native void glDrawBuffers (int n, IntBuffer bufs); + + public native void glUniformMatrix2x3fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix3x2fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix2x4fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix4x2fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix3x4fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glUniformMatrix4x3fv (int location, int count, boolean transpose, FloatBuffer value); + + public native void glBlitFramebuffer (int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, + int mask, int filter); + + public native void glRenderbufferStorageMultisample (int target, int samples, int internalformat, int width, int height); + + public native void glFramebufferTextureLayer (int target, int attachment, int texture, int level, int layer); + + public native java.nio.Buffer glMapBufferRange (int target, int offset, int length, int access); + + public native void glFlushMappedBufferRange (int target, int offset, int length); + + public native void glBindVertexArray (int array); + + public native void glDeleteVertexArrays (int n, int[] arrays, int offset); + + public native void glDeleteVertexArrays (int n, IntBuffer arrays); + + public native void glGenVertexArrays (int n, int[] arrays, int offset); + + public native void glGenVertexArrays (int n, IntBuffer arrays); + + public native boolean glIsVertexArray (int array); + + public native void glBeginTransformFeedback (int primitiveMode); + + public native void glEndTransformFeedback (); + + public native void glBindBufferRange (int target, int index, int buffer, int offset, int size); + + public native void glBindBufferBase (int target, int index, int buffer); + + public native void glTransformFeedbackVaryings (int program, String[] varyings, int bufferMode); + + public native void glVertexAttribIPointer (int index, int size, int type, int stride, int offset); + + public native void glGetVertexAttribIiv (int index, int pname, IntBuffer params); + + public native void glGetVertexAttribIuiv (int index, int pname, IntBuffer params); + + public native void glVertexAttribI4i (int index, int x, int y, int z, int w); + + public native void glVertexAttribI4ui (int index, int x, int y, int z, int w); + + public native void glGetUniformuiv (int program, int location, IntBuffer params); + + public native int glGetFragDataLocation (int program, String name); + + public native void glUniform1uiv (int location, int count, IntBuffer value); + + public native void glUniform3uiv (int location, int count, IntBuffer value); + + public native void glUniform4uiv (int location, int count, IntBuffer value); + + public native void glClearBufferiv (int buffer, int drawbuffer, IntBuffer value); + + public native void glClearBufferuiv (int buffer, int drawbuffer, IntBuffer value); + + public native void glClearBufferfv (int buffer, int drawbuffer, FloatBuffer value); + + public native void glClearBufferfi (int buffer, int drawbuffer, float depth, int stencil); + + public native String glGetStringi (int name, int index); + + public native void glCopyBufferSubData (int readTarget, int writeTarget, int readOffset, int writeOffset, int size); + + public native void glGetUniformIndices (int program, String[] uniformNames, IntBuffer uniformIndices); + + public native void glGetActiveUniformsiv (int program, int uniformCount, IntBuffer uniformIndices, int pname, + IntBuffer params); + + public native int glGetUniformBlockIndex (int program, String uniformBlockName); + + public native void glGetActiveUniformBlockiv (int program, int uniformBlockIndex, int pname, IntBuffer params); + + public native void glGetActiveUniformBlockName (int program, int uniformBlockIndex, Buffer length, Buffer uniformBlockName); + + public native String glGetActiveUniformBlockName (int program, int uniformBlockIndex); + + public native void glUniformBlockBinding (int program, int uniformBlockIndex, int uniformBlockBinding); + + public native void glDrawArraysInstanced (int mode, int first, int count, int instanceCount); + + public native void glDrawElementsInstanced (int mode, int count, int type, int indicesOffset, int instanceCount); + + public native void glGetInteger64v (int pname, LongBuffer params); + + public native void glGetBufferParameteri64v (int target, int pname, LongBuffer params); + + public native void glGenSamplers (int count, int[] samplers, int offset); + + public native void glGenSamplers (int count, IntBuffer samplers); + + public native void glDeleteSamplers (int count, int[] samplers, int offset); + + public native void glDeleteSamplers (int count, IntBuffer samplers); + + public native boolean glIsSampler (int sampler); + + public native void glBindSampler (int unit, int sampler); + + public native void glSamplerParameteri (int sampler, int pname, int param); + + public native void glSamplerParameteriv (int sampler, int pname, IntBuffer param); + + public native void glSamplerParameterf (int sampler, int pname, float param); + + public native void glSamplerParameterfv (int sampler, int pname, FloatBuffer param); + + public native void glGetSamplerParameteriv (int sampler, int pname, IntBuffer params); + + public native void glGetSamplerParameterfv (int sampler, int pname, FloatBuffer params); + + public native void glVertexAttribDivisor (int index, int divisor); + + public native void glBindTransformFeedback (int target, int id); + + public native void glDeleteTransformFeedbacks (int n, int[] ids, int offset); + + public native void glDeleteTransformFeedbacks (int n, IntBuffer ids); + + public native void glGenTransformFeedbacks (int n, int[] ids, int offset); + + public native void glGenTransformFeedbacks (int n, IntBuffer ids); + + public native boolean glIsTransformFeedback (int id); + + public native void glPauseTransformFeedback (); + + public native void glResumeTransformFeedback (); + + public native void glProgramParameteri (int program, int pname, int value); + + public native void glInvalidateFramebuffer (int target, int numAttachments, IntBuffer attachments); + + public native void glInvalidateSubFramebuffer (int target, int numAttachments, IntBuffer attachments, int x, int y, int width, + int height); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGraphics.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGraphics.java new file mode 100644 index 00000000000..27169b8256c --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSGraphics.java @@ -0,0 +1,589 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.AbstractGraphics; +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.LifecycleListener; +import com.badlogic.gdx.backends.iosrobovm.custom.HWMachine; +import com.badlogic.gdx.graphics.Cursor; +import com.badlogic.gdx.graphics.Cursor.SystemCursor; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.GL30; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.glutils.GLVersion; +import com.badlogic.gdx.graphics.glutils.HdpiMode; +import com.badlogic.gdx.utils.Array; +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.Foundation; +import org.robovm.apple.foundation.NSObject; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKView; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewController; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewControllerDelegate; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewDelegate; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableColorFormat; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableDepthFormat; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableMultisample; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLDrawableStencilFormat; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLContext; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLRenderingAPI; +import org.robovm.apple.uikit.UIEdgeInsets; +import org.robovm.apple.uikit.UIEvent; +import org.robovm.objc.annotation.Method; +import org.robovm.rt.bro.annotation.Pointer; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSGraphics extends AbstractGraphics { + + private static final String tag = "IOSGraphics"; + + IOSApplication app; + + IOSInput input; + + GL20 gl20; + + GL30 gl30; + + IOSScreenBounds screenBounds; + + int safeInsetLeft, safeInsetTop, safeInsetBottom, safeInsetRight; + + long lastFrameTime; + + float deltaTime; + + long framesStart; + + int frames; + + int fps; + + BufferFormat bufferFormat; + + String extensions; + + private float ppiX = 0; + + private float ppiY = 0; + + private float ppcX = 0; + + private float ppcY = 0; + + private float density = 1; + + volatile boolean resume = false; + + volatile boolean appPaused; + + private long frameId = -1; + + private boolean isContinuous = true; + + private boolean isFrameRequested = true; + + IOSApplicationConfiguration config; + + MGLContext context; + + GLVersion glVersion; + + MGLKView view; + + IOSUIViewController viewController; + + public IOSGraphics (IOSApplication app, IOSApplicationConfiguration config, IOSInput input, boolean useGLES30) { + this.config = config; + // setup view and OpenGL + screenBounds = app.computeBounds(); + if (useGLES30) { + context = new MGLContext(MGLRenderingAPI.OpenGLES3); + if (context != null) + gl20 = gl30 = new IOSGLES30(); + else + Gdx.app.log("IOGraphics", "OpenGL ES 3.0 not supported, falling back on 2.0"); + } + if (context == null) { + context = new MGLContext(MGLRenderingAPI.OpenGLES2); + gl20 = new IOSGLES20(); + gl30 = null; + } + IOSViewDelegate viewDelegate = new IOSViewDelegate(); + view = new MGLKView(new CGRect(0, 0, screenBounds.width, screenBounds.height), context) { + + @Method(selector = "touchesBegan:withEvent:") + public void touchesBegan (@Pointer long touches, UIEvent event) { + IOSGraphics.this.input.onTouch(touches); + } + + @Method(selector = "touchesCancelled:withEvent:") + public void touchesCancelled (@Pointer long touches, UIEvent event) { + IOSGraphics.this.input.onTouch(touches); + } + + @Method(selector = "touchesEnded:withEvent:") + public void touchesEnded (@Pointer long touches, UIEvent event) { + IOSGraphics.this.input.onTouch(touches); + } + + @Method(selector = "touchesMoved:withEvent:") + public void touchesMoved (@Pointer long touches, UIEvent event) { + IOSGraphics.this.input.onTouch(touches); + } + + @Override + public void draw (CGRect rect) { + IOSGraphics.this.draw(this, rect); + } + }; + view.setDelegate(viewDelegate); + view.setDrawableColorFormat(config.colorFormat); + view.setDrawableDepthFormat(config.depthFormat); + view.setDrawableStencilFormat(config.stencilFormat); + view.setDrawableMultisample(config.multisample); + view.setMultipleTouchEnabled(true); + viewController = app.createUIViewController(this); + viewController.setView(view); + viewController.setDelegate(viewDelegate); + viewController.setPreferredFramesPerSecond(config.preferredFramesPerSecond); + this.app = app; + this.input = input; + int r = 0, g = 0, b = 0, a = 0, depth = 0, stencil = 0, samples = 0; + if (config.colorFormat == MGLDrawableColorFormat.RGB565) { + r = 5; + g = 6; + b = 5; + a = 0; + } else { + r = g = b = a = 8; + } + if (config.depthFormat == MGLDrawableDepthFormat._16) { + depth = 16; + } else if (config.depthFormat == MGLDrawableDepthFormat._24) { + depth = 24; + } else { + depth = 0; + } + if (config.stencilFormat == MGLDrawableStencilFormat._8) { + stencil = 8; + } + if (config.multisample == MGLDrawableMultisample._4X) { + samples = 4; + } + bufferFormat = new BufferFormat(r, g, b, a, depth, stencil, samples, false); + String machineString = HWMachine.getMachineString(); + IOSDevice device = config.knownDevices.get(machineString); + if (device == null) app.error(tag, "Machine ID: " + machineString + " not found, please report to libGDX"); + int ppi = device != null ? device.ppi : app.guessUnknownPpi(); + density = ppi / 160f; + ppiX = ppi; + ppiY = ppi; + ppcX = ppiX / 2.54f; + ppcY = ppiY / 2.54f; + app.debug(tag, "Display: ppi=" + ppi + ", density=" + density); + // time + FPS + lastFrameTime = System.nanoTime(); + framesStart = lastFrameTime; + appPaused = false; + } + + public void resume () { + if (!appPaused) return; + appPaused = false; + Array listeners = app.lifecycleListeners; + synchronized (listeners) { + for (LifecycleListener listener : listeners) { + listener.resume(); + } + } + resume = true; + app.listener.resume(); + } + + public void pause () { + if (appPaused) return; + appPaused = true; + Array listeners = app.lifecycleListeners; + synchronized (listeners) { + for (LifecycleListener listener : listeners) { + listener.pause(); + } + } + app.listener.pause(); + } + + boolean created = false; + + public void draw (MGLKView view, CGRect rect) { + makeCurrent(); + // massive hack, GLKView resets the viewport on each draw call, so IOSGLES20 + // stores the last known viewport and we reset it here... + gl20.glViewport(IOSGLES20.x, IOSGLES20.y, IOSGLES20.width, IOSGLES20.height); + if (!created) { + // OpenGL glViewport() function expects backbuffer coordinates instead of logical coordinates + gl20.glViewport(0, 0, screenBounds.backBufferWidth, screenBounds.backBufferHeight); + String versionString = gl20.glGetString(GL20.GL_VERSION); + String vendorString = gl20.glGetString(GL20.GL_VENDOR); + String rendererString = gl20.glGetString(GL20.GL_RENDERER); + glVersion = new GLVersion(Application.ApplicationType.iOS, versionString, vendorString, rendererString); + updateSafeInsets(); + app.listener.create(); + app.listener.resize(getWidth(), getHeight()); + created = true; + } + if (appPaused) { + return; + } + long time = System.nanoTime(); + if (!resume) { + deltaTime = (time - lastFrameTime) / 1000000000.0f; + } else { + resume = false; + deltaTime = 0; + } + lastFrameTime = time; + frames++; + if (time - framesStart >= 1000000000l) { + framesStart = time; + fps = frames; + frames = 0; + } + input.processEvents(); + frameId++; + app.listener.render(); + } + + void makeCurrent () { + MGLContext.setCurrentContext(context); + } + + public void update (MGLKViewController controller) { + makeCurrent(); + app.processRunnables(); + // pause the GLKViewController render loop if we are no longer continuous + // and if we haven't requested a frame in the last loop iteration + if (!isContinuous && !isFrameRequested) { + viewController.setPaused(true); + } + isFrameRequested = false; + } + + public void willPause (MGLKViewController controller, boolean pause) { + } + + @Override + public GL20 getGL20 () { + return gl20; + } + + @Override + public void setGL20 (GL20 gl20) { + this.gl20 = gl20; + if (gl30 == null) { + Gdx.gl = gl20; + Gdx.gl20 = gl20; + } + } + + @Override + public boolean isGL30Available () { + return gl30 != null; + } + + @Override + public GL30 getGL30 () { + return gl30; + } + + @Override + public void setGL30 (GL30 gl30) { + this.gl30 = gl30; + if (gl30 != null) { + this.gl20 = gl30; + Gdx.gl = gl20; + Gdx.gl20 = gl20; + Gdx.gl30 = gl30; + } + } + + @Override + public int getWidth () { + if (config.hdpiMode == HdpiMode.Pixels) { + return getBackBufferWidth(); + } else { + return screenBounds.width; + } + } + + @Override + public int getHeight () { + if (config.hdpiMode == HdpiMode.Pixels) { + return getBackBufferHeight(); + } else { + return screenBounds.height; + } + } + + @Override + public int getBackBufferWidth () { + return screenBounds.backBufferWidth; + } + + @Override + public int getBackBufferHeight () { + return screenBounds.backBufferHeight; + } + + @Override + public float getBackBufferScale () { + return app.pixelsPerPoint; + } + + @Override + public float getDeltaTime () { + return deltaTime; + } + + @Override + public int getFramesPerSecond () { + return fps; + } + + @Override + public GraphicsType getType () { + return GraphicsType.iOSGL; + } + + @Override + public GLVersion getGLVersion () { + return glVersion; + } + + @Override + public float getPpiX () { + return ppiX; + } + + @Override + public float getPpiY () { + return ppiY; + } + + @Override + public float getPpcX () { + return ppcX; + } + + @Override + public float getPpcY () { + return ppcY; + } + + @Override + public float getDensity () { + return density; + } + + @Override + public boolean supportsDisplayModeChange () { + return false; + } + + @Override + public DisplayMode[] getDisplayModes () { + return new DisplayMode[] {getDisplayMode()}; + } + + @Override + public DisplayMode getDisplayMode () { + return new IOSDisplayMode(getWidth(), getHeight(), config.preferredFramesPerSecond, + bufferFormat.r + bufferFormat.g + bufferFormat.b + bufferFormat.a); + } + + @Override + public Monitor getPrimaryMonitor () { + return new IOSMonitor(0, 0, "Primary Monitor"); + } + + @Override + public Monitor getMonitor () { + return getPrimaryMonitor(); + } + + @Override + public Monitor[] getMonitors () { + return new Monitor[] {getPrimaryMonitor()}; + } + + @Override + public DisplayMode[] getDisplayModes (Monitor monitor) { + return getDisplayModes(); + } + + @Override + public DisplayMode getDisplayMode (Monitor monitor) { + return getDisplayMode(); + } + + protected void updateSafeInsets () { + safeInsetTop = 0; + safeInsetLeft = 0; + safeInsetRight = 0; + safeInsetBottom = 0; + if (Foundation.getMajorSystemVersion() >= 11) { + UIEdgeInsets edgeInsets = viewController.getView().getSafeAreaInsets(); + safeInsetTop = (int)edgeInsets.getTop(); + safeInsetLeft = (int)edgeInsets.getLeft(); + safeInsetRight = (int)edgeInsets.getRight(); + safeInsetBottom = (int)edgeInsets.getBottom(); + if (config.hdpiMode == HdpiMode.Pixels) { + safeInsetTop *= app.pixelsPerPoint; + safeInsetLeft *= app.pixelsPerPoint; + safeInsetRight *= app.pixelsPerPoint; + safeInsetBottom *= app.pixelsPerPoint; + } + } + } + + @Override + public int getSafeInsetLeft () { + return safeInsetLeft; + } + + @Override + public int getSafeInsetTop () { + return safeInsetTop; + } + + @Override + public int getSafeInsetBottom () { + return safeInsetBottom; + } + + @Override + public int getSafeInsetRight () { + return safeInsetRight; + } + + @Override + public boolean setFullscreenMode (DisplayMode displayMode) { + return false; + } + + @Override + public boolean setWindowedMode (int width, int height) { + return false; + } + + @Override + public void setTitle (String title) { + } + + @Override + public void setUndecorated (boolean undecorated) { + } + + @Override + public void setResizable (boolean resizable) { + } + + @Override + public void setVSync (boolean vsync) { + } + + /** Sets the preferred framerate for the application. Default is 60. Is not generally advised to be used on mobile platforms. + * + * @param fps the preferred fps */ + @Override + public void setForegroundFPS (int fps) { + viewController.setPreferredFramesPerSecond(fps); + } + + @Override + public BufferFormat getBufferFormat () { + return bufferFormat; + } + + @Override + public boolean supportsExtension (String extension) { + if (extensions == null) extensions = Gdx.gl.glGetString(GL20.GL_EXTENSIONS); + return extensions.contains(extension); + } + + @Override + public void setContinuousRendering (boolean isContinuous) { + if (isContinuous != this.isContinuous) { + this.isContinuous = isContinuous; + // start the GLKViewController if we go from non-continuous -> continuous + if (isContinuous) viewController.setPaused(false); + } + } + + @Override + public boolean isContinuousRendering () { + return isContinuous; + } + + @Override + public void requestRendering () { + isFrameRequested = true; + // start the GLKViewController if we are in non-continuous mode + // (we should already be started in continuous mode) + if (!isContinuous) viewController.setPaused(false); + } + + @Override + public boolean isFullscreen () { + return true; + } + + @Override + public long getFrameId () { + return frameId; + } + + @Override + public Cursor newCursor (Pixmap pixmap, int xHotspot, int yHotspot) { + return null; + } + + @Override + public void setCursor (Cursor cursor) { + } + + @Override + public void setSystemCursor (SystemCursor systemCursor) { + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + private class IOSViewDelegate extends NSObject implements MGLKViewDelegate, MGLKViewControllerDelegate { + + @Override + public void update (MGLKViewController controller) { + IOSGraphics.this.update(controller); + } + + @Override + public void draw (MGLKView view, CGRect rect) { + IOSGraphics.this.draw(view, rect); + } + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + private class IOSDisplayMode extends DisplayMode { + + protected IOSDisplayMode (int width, int height, int refreshRate, int bitsPerPixel) { + super(width, height, refreshRate, bitsPerPixel); + } + } + + /** DO NOT EDIT THIS FILE - it is machine generated */ + private class IOSMonitor extends Monitor { + + protected IOSMonitor (int virtualX, int virtualY, String name) { + super(virtualX, virtualY, name); + } + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSInput.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSInput.java new file mode 100644 index 00000000000..7248baaf001 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSInput.java @@ -0,0 +1,21 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.Input; +import org.robovm.apple.uikit.UIKey; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public interface IOSInput extends Input { + + /** Initializes peripherals (such as compass or accelerometer) */ + void setupPeripherals (); + + /** Records touch events */ + void onTouch (long touches); + + /** Process all touch events that have been registered on #onTouch(). */ + void processEvents (); + + boolean onKey (UIKey key, boolean down); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSMusic.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSMusic.java new file mode 100644 index 00000000000..df79878e6a7 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSMusic.java @@ -0,0 +1,137 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import org.robovm.apple.foundation.NSObject; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.backends.iosrobovm.objectal.AVAudioPlayerDelegateAdapter; +import com.badlogic.gdx.backends.iosrobovm.objectal.OALAudioTrack; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +public class IOSMusic implements Music { + + private final OALAudioTrack track; + + private final String filePath; + + private boolean initialized; + + private boolean looping; + + OnCompletionListener onCompletionListener; + + public IOSMusic (OALAudioTrack track, String filePath) { + this.track = track; + this.filePath = filePath; + this.track.setDelegate(new AVAudioPlayerDelegateAdapter() { + + @Override + public void didFinishPlaying (NSObject player, boolean success) { + final OnCompletionListener listener = onCompletionListener; + if (listener != null) { + Gdx.app.postRunnable(new Runnable() { + + @Override + public void run () { + listener.onCompletion(IOSMusic.this); + } + }); + } + } + }); + } + + @Override + public void play () { + if (track.isPaused()) { + track.setPaused(false); + } else if (!track.isPlaying()) { + // Check https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/AudioTrack/OALAudioTrack.m + // OALAudioTrack needs to execute preloadURL() once to store the file path. From then on we avoid + // calling it again to avoid instantiating a new AVAudioPlayer every time. + if (!initialized) { + if (!looping) + initialized = track.playFile(filePath); + else + initialized = track.playFile(filePath, -1); + if (!initialized) { + Gdx.app.error("IOSMusic", "Unable to initialize music " + filePath); + } + } else { + track.play(); + } + } + } + + @Override + public void pause () { + if (track.isPlaying()) { + track.setPaused(true); + } + } + + @Override + public void stop () { + track.stop(); + } + + @Override + public boolean isPlaying () { + return track.isPlaying() && !track.isPaused(); + } + + @Override + public void setLooping (boolean isLooping) { + track.setNumberOfLoops(isLooping ? -1 : 0); + looping = isLooping; + } + + @Override + public boolean isLooping () { + return track.getNumberOfLoops() == -1; + } + + @Override + public void setVolume (float volume) { + track.setVolume(volume); + } + + @Override + public void setPosition (float position) { + track.setCurrentTime(position); + } + + @Override + public float getPosition () { + return (float)(track.getCurrentTime()); + } + + @Override + public void dispose () { + track.clear(); + } + + @Override + public float getVolume () { + return track.getVolume(); + } + + @Override + public void setPan (float pan, float volume) { + track.setPan(pan); + track.setVolume(volume); + } + + @Override + public void setOnCompletionListener (OnCompletionListener listener) { + this.onCompletionListener = listener; + } + + /** Calling this method preloads audio buffers and acquires the audio hardware necessary for playback. Can be noticeable on + * latency critical scenarios. Call with some time before {@link #play()}. */ + public boolean preload () { + return initialized = track.preloadFile(filePath); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSNet.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSNet.java new file mode 100644 index 00000000000..7078551a4bb --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSNet.java @@ -0,0 +1,62 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import org.robovm.apple.foundation.NSURL; +import org.robovm.apple.uikit.UIApplication; +import com.badlogic.gdx.Net; +import com.badlogic.gdx.net.NetJavaImpl; +import com.badlogic.gdx.net.NetJavaServerSocketImpl; +import com.badlogic.gdx.net.NetJavaSocketImpl; +import com.badlogic.gdx.net.ServerSocket; +import com.badlogic.gdx.net.ServerSocketHints; +import com.badlogic.gdx.net.Socket; +import com.badlogic.gdx.net.SocketHints; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSNet implements Net { + + NetJavaImpl netJavaImpl; + + final UIApplication uiApp; + + public IOSNet (IOSApplication app, IOSApplicationConfiguration configuration) { + uiApp = app.uiApp; + netJavaImpl = new NetJavaImpl(configuration.maxNetThreads); + } + + @Override + public void sendHttpRequest (HttpRequest httpRequest, HttpResponseListener httpResponseListener) { + netJavaImpl.sendHttpRequest(httpRequest, httpResponseListener); + } + + @Override + public void cancelHttpRequest (HttpRequest httpRequest) { + netJavaImpl.cancelHttpRequest(httpRequest); + } + + @Override + public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) { + return new NetJavaServerSocketImpl(protocol, hostname, port, hints); + } + + @Override + public ServerSocket newServerSocket (Protocol protocol, int port, ServerSocketHints hints) { + return new NetJavaServerSocketImpl(protocol, port, hints); + } + + @Override + public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) { + return new NetJavaSocketImpl(protocol, host, port, hints); + } + + @Override + public boolean openURI (String URI) { + NSURL url = new NSURL(URI); + if (uiApp.canOpenURL(url)) { + uiApp.openURL(url); + return true; + } + return false; + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSPreferences.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSPreferences.java new file mode 100644 index 00000000000..9d4af312272 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSPreferences.java @@ -0,0 +1,181 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.robovm.apple.foundation.NSAutoreleasePool; +import org.robovm.apple.foundation.NSMutableDictionary; +import org.robovm.apple.foundation.NSNumber; +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.foundation.NSString; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Preferences; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSPreferences implements Preferences { + + NSMutableDictionary nsDictionary; + + File file; + + public IOSPreferences (NSMutableDictionary nsDictionary, String filePath) { + this.nsDictionary = nsDictionary; + this.file = new File(filePath); + } + + @Override + public Preferences putBoolean (String key, boolean val) { + nsDictionary.put(convertKey(key), NSNumber.valueOf(val)); + return this; + } + + @Override + public Preferences putInteger (String key, int val) { + nsDictionary.put(convertKey(key), NSNumber.valueOf(val)); + return this; + } + + @Override + public Preferences putLong (String key, long val) { + nsDictionary.put(convertKey(key), NSNumber.valueOf(val)); + return this; + } + + @Override + public Preferences putFloat (String key, float val) { + nsDictionary.put(convertKey(key), NSNumber.valueOf(val)); + return this; + } + + @Override + public Preferences putString (String key, String val) { + nsDictionary.put(convertKey(key), new NSString(val)); + return this; + } + + @Override + public Preferences put (Map vals) { + Set keySet = vals.keySet(); + for (String key : keySet) { + Object value = vals.get(key); + if (value instanceof String) { + putString(key, (String)value); + } else if (value instanceof Boolean) { + putBoolean(key, (Boolean)value); + } else if (value instanceof Integer) { + putInteger(key, (Integer)value); + } else if (value instanceof Long) { + putLong(key, (Long)value); + } else if (value instanceof Float) { + putFloat(key, (Float)value); + } + } + return this; + } + + @Override + public boolean getBoolean (String key) { + NSNumber value = (NSNumber)nsDictionary.get(convertKey(key)); + if (value == null) return false; + return value.booleanValue(); + } + + @Override + public int getInteger (String key) { + NSNumber value = (NSNumber)nsDictionary.get(convertKey(key)); + if (value == null) return 0; + return value.intValue(); + } + + @Override + public long getLong (String key) { + NSNumber value = (NSNumber)nsDictionary.get(convertKey(key)); + if (value == null) return 0L; + return value.longValue(); + } + + @Override + public float getFloat (String key) { + NSNumber value = (NSNumber)nsDictionary.get(convertKey(key)); + if (value == null) return 0f; + return value.floatValue(); + } + + @Override + public String getString (String key) { + NSString value = (NSString)nsDictionary.get(convertKey(key)); + if (value == null) return ""; + return value.toString(); + } + + @Override + public boolean getBoolean (String key, boolean defValue) { + if (!contains(key)) return defValue; + return getBoolean(key); + } + + @Override + public int getInteger (String key, int defValue) { + if (!contains(key)) return defValue; + return getInteger(key); + } + + @Override + public long getLong (String key, long defValue) { + if (!contains(key)) return defValue; + return getLong(key); + } + + @Override + public float getFloat (String key, float defValue) { + if (!contains(key)) return defValue; + return getFloat(key); + } + + @Override + public String getString (String key, String defValue) { + if (!contains(key)) return defValue; + return getString(key); + } + + @Override + public Map get () { + Map map = new HashMap(); + for (NSString key : nsDictionary.keySet()) { + NSObject value = nsDictionary.get(key); + map.put(key.toString(), value.toString()); + } + return map; + } + + @Override + public boolean contains (String key) { + return nsDictionary.containsKey(convertKey(key)); + } + + @Override + public void clear () { + nsDictionary.clear(); + } + + @Override + public void remove (String key) { + nsDictionary.remove(convertKey(key)); + } + + private NSString convertKey (String key) { + return new NSString(key); + } + + @Override + public void flush () { + NSAutoreleasePool pool = new NSAutoreleasePool(); + if (!nsDictionary.write(file, false)) { + Gdx.app.debug("IOSPreferences", "Failed to write NSDictionary to file " + file); + } + pool.close(); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSScreenBounds.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSScreenBounds.java new file mode 100644 index 00000000000..3afa145ce29 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSScreenBounds.java @@ -0,0 +1,46 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +/** DO NOT EDIT THIS FILE - it is machine generated Represents the bounds inside GL view to which libGDX draws. These bounds may + * be same as view's dimensions, but may differ in some cases: + *
    + *
  • Status bar is visible - drawing area is not under the status bar
  • + *
  • Screen is rotated - in some iOS versions the rotation reporting behavior is different and this needs to be handled
  • + *
+ * + *

IMPLEMENTATION & WARNING - Read carefully

Accounting for status bar is not completely clean and relies on a + * coincidence, related to coordinate system origins. When status bar is present, x and y grows (in practice only y does) to + * offset the drawing area from the status bar and width and height (and their backBuffer values of course) shrink so the + * remaining surface fits the rest of the screen. + * + * When touch events arrive, IOSInput subtracts x and y from their coordinates to account for the shift. + * + * The unclean part is in the actual rendering - since the offset is essentially faked, there is no way to supply it to the libGDX + * application. But this does not become a problem, as long as Y and HEIGHT add up to the GL view's height (or X and WIDTH, + * although that is not used in practice), because GL's coordinate system (as far as the glViewport is concerned) starts in the + * LOWER left corner. So in practice, the rendering part of libGDX can be completely oblivious to any x/y offsets. + * + * This may become a problem when interfacing with UIKit, for example when placing banner ADs or using UIKit views over the + * libGDX's GL view. In such case, overriding {@link IOSApplication#computeBounds()} and providing custom, correct values is + * recommended. */ +public final class IOSScreenBounds { + + /** Offset from top left corner in points */ + public final int x, y; + + /** Dimensions of drawing surface in points */ + public final int width, height; + + /** Dimensions of drawing surface in pixels */ + public final int backBufferWidth, backBufferHeight; + + public IOSScreenBounds (int x, int y, int width, int height, int backBufferWidth, int backBufferHeight) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.backBufferWidth = backBufferWidth; + this.backBufferHeight = backBufferHeight; + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSSound.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSSound.java new file mode 100644 index 00000000000..60808e71eea --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSSound.java @@ -0,0 +1,158 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import org.robovm.apple.foundation.NSArray; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.backends.iosrobovm.objectal.ALBuffer; +import com.badlogic.gdx.backends.iosrobovm.objectal.ALChannelSource; +import com.badlogic.gdx.backends.iosrobovm.objectal.ALSource; +import com.badlogic.gdx.backends.iosrobovm.objectal.OALSimpleAudio; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.IntArray; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author tescott + * @author Tomski + * + * First pass at implementing OALSimpleAudio support. */ +public class IOSSound implements Sound { + + private ALBuffer soundBuffer; + + private String soundPath; + + private ALChannelSource channel; + + private NSArray sourcePool; + + private IntArray streamIds = new IntArray(8); + + public IOSSound (FileHandle filePath) { + soundPath = filePath.file().getPath().replace('\\', '/'); + soundBuffer = OALSimpleAudio.sharedInstance().preloadEffect(soundPath); + channel = OALSimpleAudio.sharedInstance().getChannelSource(); + sourcePool = channel.getSourcePool().getSources(); + } + + @Override + public long play () { + return play(1, 1, 0, false); + } + + @Override + public long play (float volume) { + return play(volume, 1, 0, false); + } + + @Override + public long play (float volume, float pitch, float pan) { + return play(volume, pitch, pan, false); + } + + public long play (float volume, float pitch, float pan, boolean loop) { + if (streamIds.size == 8) streamIds.pop(); + ALSource soundSource = OALSimpleAudio.sharedInstance().playBuffer(soundBuffer, volume, pitch, pan, loop); + if (soundSource == null) return -1; + if (soundSource.getSourceId() == -1) return -1; + streamIds.insert(0, soundSource.getSourceId()); + return soundSource.getSourceId(); + } + + @Override + public long loop () { + return play(1, 1, 0, true); + } + + @Override + public long loop (float volume) { + return play(volume, 1, 0, true); + } + + @Override + public long loop (float volume, float pitch, float pan) { + return play(volume, pitch, pan, true); + } + + @Override + public void stop () { + ALSource source; + for (int i = 0; i < streamIds.size; i++) { + if ((source = getSoundSource(streamIds.get(i))) != null) source.stop(); + } + } + + @Override + public void dispose () { + stop(); + OALSimpleAudio.sharedInstance().unloadEffect(soundPath); + } + + @Override + public void stop (long soundId) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) source.stop(); + } + + @Override + public void setLooping (long soundId, boolean looping) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) source.setLooping(looping); + } + + @Override + public void setPitch (long soundId, float pitch) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) source.setPitch(pitch); + } + + @Override + public void setVolume (long soundId, float volume) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) source.setVolume(volume); + } + + @Override + public void setPan (long soundId, float pan, float volume) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) { + source.setPan(pan); + source.setVolume(volume); + } + } + + @Override + public void pause () { + ALSource source; + for (int i = 0; i < streamIds.size; i++) { + if ((source = getSoundSource(streamIds.get(i))) != null) source.setPaused(true); + } + } + + @Override + public void resume () { + ALSource source; + for (int i = 0; i < streamIds.size; i++) { + if ((source = getSoundSource(streamIds.get(i))) != null) source.setPaused(false); + } + } + + @Override + public void pause (long soundId) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) source.setPaused(true); + } + + @Override + public void resume (long soundId) { + ALSource source; + if ((source = getSoundSource(soundId)) != null) source.setPaused(false); + } + + private ALSource getSoundSource (long soundId) { + for (ALSource source : sourcePool) { + if (source.getSourceId() == soundId) return source; + } + return null; + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSUIViewController.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSUIViewController.java new file mode 100644 index 00000000000..b3794800bbf --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSUIViewController.java @@ -0,0 +1,110 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +import com.badlogic.gdx.graphics.glutils.HdpiMode; +import org.robovm.apple.foundation.NSSet; +import com.badlogic.gdx.backends.iosrobovm.bindings.metalangle.MGLKViewController; +import org.robovm.apple.uikit.UIDevice; +import org.robovm.apple.uikit.UIInterfaceOrientation; +import org.robovm.apple.uikit.UIInterfaceOrientationMask; +import org.robovm.apple.uikit.UIPress; +import org.robovm.apple.uikit.UIPressesEvent; +import org.robovm.apple.uikit.UIRectEdge; +import org.robovm.apple.uikit.UIUserInterfaceIdiom; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class IOSUIViewController extends MGLKViewController { + + final IOSApplication app; + + final IOSGraphics graphics; + + protected IOSUIViewController (IOSApplication app, IOSGraphics graphics) { + this.app = app; + this.graphics = graphics; + } + + @Override + public void viewWillAppear (boolean arg0) { + super.viewWillAppear(arg0); + // start GLKViewController even though we may only draw a single frame + // (we may be in non-continuous mode) + setPaused(false); + } + + @Override + public void viewDidAppear (boolean animated) { + super.viewDidAppear(animated); + if (app.viewControllerListener != null) app.viewControllerListener.viewDidAppear(animated); + } + + @Override + public UIInterfaceOrientationMask getSupportedInterfaceOrientations () { + long mask = 0; + if (app.config.orientationLandscape) { + mask |= (1L << UIInterfaceOrientation.LandscapeLeft.value()) | (1L << UIInterfaceOrientation.LandscapeRight.value()); + } + if (app.config.orientationPortrait) { + mask |= 1L << UIInterfaceOrientation.Portrait.value(); + if (UIDevice.getCurrentDevice().getUserInterfaceIdiom() == UIUserInterfaceIdiom.Pad) { + mask |= 1L << UIInterfaceOrientation.PortraitUpsideDown.value(); + } + } + return new UIInterfaceOrientationMask(mask); + } + + @Override + public boolean shouldAutorotate () { + return true; + } + + @Override + public UIRectEdge getPreferredScreenEdgesDeferringSystemGestures () { + return app.config.screenEdgesDeferringSystemGestures; + } + + @Override + public void viewDidLayoutSubviews () { + super.viewDidLayoutSubviews(); + // get the view size and update graphics + final IOSScreenBounds oldBounds = graphics.screenBounds; + final IOSScreenBounds newBounds = app.computeBounds(); + graphics.screenBounds = newBounds; + // Layout may happen without bounds changing, don't trigger resize in that case + if (graphics.created && (newBounds.width != oldBounds.width || newBounds.height != oldBounds.height)) { + graphics.makeCurrent(); + graphics.updateSafeInsets(); + graphics.gl20.glViewport(0, 0, newBounds.backBufferWidth, newBounds.backBufferHeight); + if (graphics.config.hdpiMode == HdpiMode.Pixels) { + app.listener.resize(newBounds.backBufferWidth, newBounds.backBufferHeight); + } else { + app.listener.resize(newBounds.width, newBounds.height); + } + } + } + + @Override + public boolean prefersStatusBarHidden () { + return !app.config.statusBarVisible; + } + + @Override + public boolean prefersHomeIndicatorAutoHidden () { + return app.config.hideHomeIndicator; + } + + @Override + public void pressesBegan (NSSet presses, UIPressesEvent event) { + if (presses == null || presses.isEmpty() || !app.input.onKey(presses.getValues().first().getKey(), true)) { + super.pressesBegan(presses, event); + } + } + + @Override + public void pressesEnded (NSSet presses, UIPressesEvent event) { + if (presses == null || presses.isEmpty() || !app.input.onKey(presses.getValues().first().getKey(), false)) { + super.pressesEnded(presses, event); + } + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSViewControllerListener.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSViewControllerListener.java new file mode 100644 index 00000000000..fce1cab719e --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/IOSViewControllerListener.java @@ -0,0 +1,16 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm; + +/** DO NOT EDIT THIS FILE - it is machine generated An IOSViewControllerListener can be added to an {@link IOSApplication} via + * {@link IOSApplication#addViewControllerListener(IOSViewControllerListener)}. It will receive notification of view events. + *

+ * + * The methods will be invoked on the UI thread. + * + * @author mzechner */ +public interface IOSViewControllerListener { + + /** Called when the {@link IOSApplication} root ViewController has appeared */ + public void viewDidAppear (boolean animated); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLContext.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLContext.java new file mode 100644 index 00000000000..01399613089 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLContext.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.Pointer; +import org.robovm.rt.bro.ptr.Ptr; +import org.robovm.rt.bro.ptr.VoidPtr; +/**/ + +/**/ + +/**/ +/**/@NativeClass +/* */ +/* */public/* */ class /* */ MGLContext/* */ + extends /* */NSObject/* */ +/* *//* */ { + + /* */public static class MGLContextPtr extends Ptr { + } + + /* */ + /* */static { + ObjCRuntime.bind(MGLContext.class); + }/* */ + /* *//* */ + /* */ + + protected MGLContext () { + } + + protected MGLContext (Handle h, long handle) { + super(h, handle); + } + + protected MGLContext (SkipInit skipInit) { + super(skipInit); + } + + @Method(selector = "initWithAPI:") + public MGLContext (MGLRenderingAPI api) { + super((SkipInit)null); + initObject(initWithAPI(api)); + } + + @Method(selector = "initWithAPI:sharegroup:") + public MGLContext (MGLRenderingAPI api, MGLSharegroup sharegroup) { + super((SkipInit)null); + initObject(initWithAPISharegroup(api, sharegroup)); + } + + /* */ + /* */ + @Property(selector = "API") + public native MGLRenderingAPI getAPI (); + + @Property(selector = "sharegroup") + public native MGLSharegroup getSharegroup (); + + @Property(selector = "eglDisplay") + public native VoidPtr getEglDisplay (); + + /* */ + /* *//* */ + /* */ + @Method(selector = "initWithAPI:") + protected native @Pointer long initWithAPI (MGLRenderingAPI api); + + @Method(selector = "initWithAPI:sharegroup:") + protected native @Pointer long initWithAPISharegroup (MGLRenderingAPI api, MGLSharegroup sharegroup); + + @Method(selector = "present:") + public native boolean present (MGLLayer layer); + + @Method(selector = "currentContext") + public static native MGLContext currentContext (); + + @Method(selector = "currentLayer") + public static native MGLLayer currentLayer (); + + @Method(selector = "setCurrentContext:") + public static native boolean setCurrentContext (MGLContext context); + + @Method(selector = "setCurrentContext:forLayer:") + public static native boolean setCurrentContextForLayer (MGLContext context, MGLLayer layer); + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableColorFormat.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableColorFormat.java new file mode 100644 index 00000000000..b228e5c5240 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableColorFormat.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.rt.bro.ValuedEnum; +/**/ + +/**/ + +/**/ +/**//**/ +public enum /* */MGLDrawableColorFormat/* */ implements ValuedEnum { + /* */ + RGBA8888(32L), SRGBA8888(-32L), RGB565(16L); + /* */ + + /* */ + /* */ + /* *//* */ + /* *//* */ + + private final long n; + + private /* */ MGLDrawableColorFormat/* */ (long n) { + this.n = n; + } + + public long value () { + return n; + } + + public static /* */MGLDrawableColorFormat/* */ valueOf (long n) { + for (/* */MGLDrawableColorFormat/* */ v : values()) { + if (v.n == n) { + return v; + } + } + throw new IllegalArgumentException( + "No constant with value " + n + " found in " + /* */MGLDrawableColorFormat/* */.class.getName()); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableDepthFormat.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableDepthFormat.java new file mode 100644 index 00000000000..819711bc35d --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableDepthFormat.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.rt.bro.ValuedEnum; +/**/ + +/**/ + +/**/ +/**//**/ +public enum /* */MGLDrawableDepthFormat/* */ implements ValuedEnum { + /* */ + None(0L), _16(16L), _24(24L); + /* */ + + /* */ + /* */ + /* *//* */ + /* *//* */ + + private final long n; + + private /* */ MGLDrawableDepthFormat/* */ (long n) { + this.n = n; + } + + public long value () { + return n; + } + + public static /* */MGLDrawableDepthFormat/* */ valueOf (long n) { + for (/* */MGLDrawableDepthFormat/* */ v : values()) { + if (v.n == n) { + return v; + } + } + throw new IllegalArgumentException( + "No constant with value " + n + " found in " + /* */MGLDrawableDepthFormat/* */.class.getName()); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableMultisample.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableMultisample.java new file mode 100644 index 00000000000..7bf3d6fe1be --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableMultisample.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.rt.bro.ValuedEnum; +/**/ + +/**/ + +/**/ +/**//**/ +public enum /* */MGLDrawableMultisample/* */ implements ValuedEnum { + /* */ + None(0L), _4X(4L); + /* */ + + /* */ + /* */ + /* *//* */ + /* *//* */ + + private final long n; + + private /* */ MGLDrawableMultisample/* */ (long n) { + this.n = n; + } + + public long value () { + return n; + } + + public static /* */MGLDrawableMultisample/* */ valueOf (long n) { + for (/* */MGLDrawableMultisample/* */ v : values()) { + if (v.n == n) { + return v; + } + } + throw new IllegalArgumentException( + "No constant with value " + n + " found in " + /* */MGLDrawableMultisample/* */.class.getName()); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableStencilFormat.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableStencilFormat.java new file mode 100644 index 00000000000..b33653a94f1 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLDrawableStencilFormat.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.rt.bro.ValuedEnum; +/**/ + +/**/ + +/**/ +/**//**/ +public enum /* */MGLDrawableStencilFormat/* */ implements ValuedEnum { + /* */ + None(0L), _8(8L); + /* */ + + /* */ + /* */ + /* *//* */ + /* *//* */ + + private final long n; + + private /* */ MGLDrawableStencilFormat/* */ (long n) { + this.n = n; + } + + public long value () { + return n; + } + + public static /* */MGLDrawableStencilFormat/* */ valueOf (long n) { + for (/* */MGLDrawableStencilFormat/* */ v : values()) { + if (v.n == n) { + return v; + } + } + throw new IllegalArgumentException( + "No constant with value " + n + " found in " + /* */MGLDrawableStencilFormat/* */.class.getName()); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKView.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKView.java new file mode 100644 index 00000000000..315ced8f18b --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKView.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.coregraphics.CGSize; +import org.robovm.apple.uikit.UIImage; +import org.robovm.apple.uikit.UIView; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.ByVal; +import org.robovm.rt.bro.annotation.MachineSizedSInt; +import org.robovm.rt.bro.annotation.Pointer; +import org.robovm.rt.bro.ptr.Ptr; +/**/ + +/**/ + +/**/ +/**/@NativeClass +/* */ +/* */public/* */ class /* */ MGLKView/* */ + extends /* */UIView/* */ +/* *//* */ { + + /* */public static class MGLKViewPtr extends Ptr { + } + + /* */ + /* */static { + ObjCRuntime.bind(MGLKView.class); + }/* */ + /* *//* */ + /* */ + + protected MGLKView () { + } + + protected MGLKView (Handle h, long handle) { + super(h, handle); + } + + protected MGLKView (SkipInit skipInit) { + super(skipInit); + } + + @Method(selector = "initWithFrame:context:") + public MGLKView (@ByVal CGRect frame, MGLContext context) { + super((SkipInit)null); + initObject(initWithFrameContext(frame, context)); + } + + /* */ + /* */ + @Property(selector = "context") + public native MGLContext getContext (); + + @Property(selector = "setContext:") + public native void setContext (MGLContext v); + + @Property(selector = "delegate") + public native MGLKViewDelegate getDelegate (); + + @Property(selector = "setDelegate:", strongRef = true) + public native void setDelegate (MGLKViewDelegate v); + + @Property(selector = "retainedBacking") + public native boolean isRetainedBacking (); + + @Property(selector = "setRetainedBacking:") + public native void setRetainedBacking (boolean v); + + @Property(selector = "drawableColorFormat") + public native MGLDrawableColorFormat getDrawableColorFormat (); + + @Property(selector = "setDrawableColorFormat:") + public native void setDrawableColorFormat (MGLDrawableColorFormat v); + + @Property(selector = "drawableDepthFormat") + public native MGLDrawableDepthFormat getDrawableDepthFormat (); + + @Property(selector = "setDrawableDepthFormat:") + public native void setDrawableDepthFormat (MGLDrawableDepthFormat v); + + @Property(selector = "drawableStencilFormat") + public native MGLDrawableStencilFormat getDrawableStencilFormat (); + + @Property(selector = "setDrawableStencilFormat:") + public native void setDrawableStencilFormat (MGLDrawableStencilFormat v); + + @Property(selector = "drawableMultisample") + public native MGLDrawableMultisample getDrawableMultisample (); + + @Property(selector = "setDrawableMultisample:") + public native void setDrawableMultisample (MGLDrawableMultisample v); + + @Property(selector = "glLayer") + public native MGLLayer getGlLayer (); + + @Property(selector = "drawableSize") + public native @ByVal CGSize getDrawableSize (); + + @Property(selector = "drawableWidth") + public native @MachineSizedSInt long getDrawableWidth (); + + @Property(selector = "drawableHeight") + public native @MachineSizedSInt long getDrawableHeight (); + + @Property(selector = "defaultOpenGLFrameBufferID") + public native int getDefaultOpenGLFrameBufferID (); + + @Property(selector = "enableSetNeedsDisplay") + public native boolean isEnableSetNeedsDisplay (); + + @Property(selector = "setEnableSetNeedsDisplay:") + public native void setEnableSetNeedsDisplay (boolean v); + + @Property(selector = "snapshot") + public native UIImage getSnapshot (); + + /* */ + /* *//* */ + /* */ + @Method(selector = "initWithFrame:context:") + protected native @Pointer long initWithFrameContext (@ByVal CGRect frame, MGLContext context); + + @Method(selector = "display") + public native void display (); + + @Method(selector = "bindDrawable") + public native void bindDrawable (); + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewController.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewController.java new file mode 100644 index 00000000000..cf0e4ffc4d1 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewController.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.uikit.UIViewController; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.ByVal; +import org.robovm.rt.bro.annotation.MachineSizedSInt; +import org.robovm.rt.bro.ptr.Ptr; +/**/ + +/**/ + +/**/ +/**/@NativeClass +/* */ +/* */public/* */ class /* */ MGLKViewController/* */ + extends /* */UIViewController/* */ + /* */ implements MGLKViewDelegate/* */ { + + /* */public static class MGLKViewControllerPtr extends Ptr { + } + + /* */ + /* */static { + ObjCRuntime.bind(MGLKViewController.class); + }/* */ + /* *//* */ + /* */ + + protected MGLKViewController () { + } + + protected MGLKViewController (Handle h, long handle) { + super(h, handle); + } + + protected MGLKViewController (SkipInit skipInit) { + super(skipInit); + } + + /* */ + /* */ + @Property(selector = "delegate") + public native MGLKViewControllerDelegate getDelegate (); + + @Property(selector = "setDelegate:", strongRef = true) + public native void setDelegate (MGLKViewControllerDelegate v); + + @Property(selector = "preferredFramesPerSecond") + public native @MachineSizedSInt long getPreferredFramesPerSecond (); + + @Property(selector = "setPreferredFramesPerSecond:") + public native void setPreferredFramesPerSecond (@MachineSizedSInt long v); + + @Property(selector = "framesDisplayed") + public native @MachineSizedSInt long getFramesDisplayed (); + + @Property(selector = "timeSinceLastUpdate") + public native double getTimeSinceLastUpdate (); + + @Property(selector = "isPaused") + public native boolean isPaused (); + + @Property(selector = "setPaused:") + public native void setPaused (boolean v); + + @Property(selector = "pauseOnWillResignActive") + public native boolean isPauseOnWillResignActive (); + + @Property(selector = "setPauseOnWillResignActive:") + public native void setPauseOnWillResignActive (boolean v); + + @Property(selector = "resumeOnDidBecomeActive") + public native boolean isResumeOnDidBecomeActive (); + + @Property(selector = "setResumeOnDidBecomeActive:") + public native void setResumeOnDidBecomeActive (boolean v); + + @Property(selector = "glView") + public native MGLKView getGlView (); + + /* */ + /* *//* */ + /* */ + @Method(selector = "mglkView:drawInRect:") + public native void draw (MGLKView view, @ByVal CGRect rect); + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewControllerDelegate.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewControllerDelegate.java new file mode 100644 index 00000000000..99dcbca023b --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewControllerDelegate.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.objc.annotation.Method; +/**/ + +/**/ + +/**/ +/**//**/ +/**/public/* */ interface /* */ MGLKViewControllerDelegate/* */ + /* */extends NSObjectProtocol/* */ { + + /* */ + /* */ + /* */ + /* */ + /* *//* */ + /* */ + + /* */ + /* */ + @Method(selector = "mglkViewControllerUpdate:") + void update (MGLKViewController controller); + /* */ + /* */ + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewControllerDelegateAdapter.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewControllerDelegateAdapter.java new file mode 100644 index 00000000000..639970011ac --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewControllerDelegateAdapter.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.annotation.NotImplemented; +/**/ + +/**/ +/**/ +/**//**/ +/**/public/* */ class /* */ MGLKViewControllerDelegateAdapter/* */ + extends /* */NSObject/* */ + /* */ implements MGLKViewControllerDelegate/* */ { + + /* */ + /* */ + /* */ + /* */ + /* *//* */ + /* *//* */ + /* */ + + /* */ + /* *//* */ + /* */ + @NotImplemented("mglkViewControllerUpdate:") + public void update (MGLKViewController controller) { + } + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewDelegate.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewDelegate.java new file mode 100644 index 00000000000..99a0ea33d1a --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewDelegate.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.objc.annotation.Method; +import org.robovm.rt.bro.annotation.ByVal; +/**/ + +/**/ + +/**/ +/**//**/ +/**/public/* */ interface /* */ MGLKViewDelegate/* */ + /* */extends NSObjectProtocol/* */ { + + /* */ + /* */ + /* */ + /* */ + /* *//* */ + /* */ + + /* */ + /* */ + @Method(selector = "mglkView:drawInRect:") + void draw (MGLKView view, @ByVal CGRect rect); + /* */ + /* */ + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewDelegateAdapter.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewDelegateAdapter.java new file mode 100644 index 00000000000..0c9406fce52 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLKViewDelegateAdapter.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.coregraphics.CGRect; +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.annotation.NotImplemented; +import org.robovm.rt.bro.annotation.ByVal; +/**/ + +/**/ +/**/ +/**//**/ +/**/public/* */ class /* */ MGLKViewDelegateAdapter/* */ + extends /* */NSObject/* */ + /* */ implements MGLKViewDelegate/* */ { + + /* */ + /* */ + /* */ + /* */ + /* *//* */ + /* *//* */ + /* */ + + /* */ + /* *//* */ + /* */ + @NotImplemented("mglkView:drawInRect:") + public void draw (MGLKView view, @ByVal CGRect rect) { + } + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLLayer.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLLayer.java new file mode 100644 index 00000000000..e78237983a1 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLLayer.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.coreanimation.CALayer; +import org.robovm.apple.coregraphics.CGSize; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.ByVal; +import org.robovm.rt.bro.ptr.Ptr; +/**/ + +/**/ + +/**/ +/**/@NativeClass +/* */ +/* */public/* */ class /* */ MGLLayer/* */ + extends /* */CALayer/* */ +/* *//* */ { + + /* */public static class MGLLayerPtr extends Ptr { + } + + /* */ + /* */static { + ObjCRuntime.bind(MGLLayer.class); + }/* */ + /* *//* */ + /* */ + + protected MGLLayer () { + } + + protected MGLLayer (Handle h, long handle) { + super(h, handle); + } + + protected MGLLayer (SkipInit skipInit) { + super(skipInit); + } + + /* */ + /* */ + @Property(selector = "drawableSize") + public native @ByVal CGSize getDrawableSize (); + + @Property(selector = "defaultOpenGLFrameBufferID") + public native int getDefaultOpenGLFrameBufferID (); + + @Property(selector = "drawableColorFormat") + public native MGLDrawableColorFormat getDrawableColorFormat (); + + @Property(selector = "setDrawableColorFormat:") + public native void setDrawableColorFormat (MGLDrawableColorFormat v); + + @Property(selector = "drawableDepthFormat") + public native MGLDrawableDepthFormat getDrawableDepthFormat (); + + @Property(selector = "setDrawableDepthFormat:") + public native void setDrawableDepthFormat (MGLDrawableDepthFormat v); + + @Property(selector = "drawableStencilFormat") + public native MGLDrawableStencilFormat getDrawableStencilFormat (); + + @Property(selector = "setDrawableStencilFormat:") + public native void setDrawableStencilFormat (MGLDrawableStencilFormat v); + + @Property(selector = "drawableMultisample") + public native MGLDrawableMultisample getDrawableMultisample (); + + @Property(selector = "setDrawableMultisample:") + public native void setDrawableMultisample (MGLDrawableMultisample v); + + @Property(selector = "retainedBacking") + public native boolean isRetainedBacking (); + + @Property(selector = "setRetainedBacking:") + public native void setRetainedBacking (boolean v); + + /* */ + /* *//* */ + /* */ + @Method(selector = "present") + public native boolean present (); + + @Method(selector = "bindDefaultFrameBuffer") + public native void bindDefaultFrameBuffer (); + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLRenderingAPI.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLRenderingAPI.java new file mode 100644 index 00000000000..7d0bd93eba7 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLRenderingAPI.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.rt.bro.ValuedEnum; +/**/ + +/**/ + +/**/ +/**//**/ +public enum /* */MGLRenderingAPI/* */ implements ValuedEnum { + /* */ + OpenGLES1(1L), OpenGLES2(2L), OpenGLES3(3L); + /* */ + + /* */ + /* */ + /* *//* */ + /* *//* */ + + private final long n; + + private /* */ MGLRenderingAPI/* */ (long n) { + this.n = n; + } + + public long value () { + return n; + } + + public static /* */MGLRenderingAPI/* */ valueOf (long n) { + for (/* */MGLRenderingAPI/* */ v : values()) { + if (v.n == n) { + return v; + } + } + throw new IllegalArgumentException( + "No constant with value " + n + " found in " + /* */MGLRenderingAPI/* */.class.getName()); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLSharegroup.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLSharegroup.java new file mode 100644 index 00000000000..f954947a47c --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/MGLSharegroup.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.rt.bro.ptr.Ptr; +/**/ + +/**/ + +/**/ +/**/@NativeClass +/* */ +/* */public/* */ class /* */ MGLSharegroup/* */ + extends /* */NSObject/* */ +/* *//* */ { + + /* */public static class MGLSharegroupPtr extends Ptr { + } + + /* */ + /* */static { + ObjCRuntime.bind(MGLSharegroup.class); + }/* */ + /* *//* */ + /* */ + + protected MGLSharegroup () { + } + + protected MGLSharegroup (Handle h, long handle) { + super(h, handle); + } + + protected MGLSharegroup (SkipInit skipInit) { + super(skipInit); + } + /* */ + /* */ + + /* */ + /* *//* */ + /* */ + + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/khronos_boolean_enum_t.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/khronos_boolean_enum_t.java new file mode 100644 index 00000000000..ea5d29f4ac4 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/bindings/metalangle/khronos_boolean_enum_t.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2013-2015 RoboVM AB + * + * 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. + */ + +package com.badlogic.gdx.backends.iosrobovm.bindings.metalangle; + +/**/ + +import org.robovm.rt.bro.ValuedEnum; +/**/ + +/**/ + +/**/ +/**//**/ +public enum /* */khronos_boolean_enum_t/* */ implements ValuedEnum { + /* */ + FALSE(0L), TRUE(1L), BOOLEAN_ENUM_FORCE_SIZE(2147483647L); + /* */ + + /* */ + /* */ + /* *//* */ + /* *//* */ + + private final long n; + + private /* */ khronos_boolean_enum_t/* */ (long n) { + this.n = n; + } + + public long value () { + return n; + } + + public static /* */khronos_boolean_enum_t/* */ valueOf (long n) { + for (/* */khronos_boolean_enum_t/* */ v : values()) { + if (v.n == n) { + return v; + } + } + throw new IllegalArgumentException( + "No constant with value " + n + " found in " + /* */khronos_boolean_enum_t/* */.class.getName()); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/HWMachine.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/HWMachine.java new file mode 100644 index 00000000000..c016dde8924 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/HWMachine.java @@ -0,0 +1,34 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.custom; + +import org.robovm.rt.bro.Bro; +import org.robovm.rt.bro.Struct; +import org.robovm.rt.bro.annotation.Bridge; +import org.robovm.rt.bro.annotation.Library; +import org.robovm.rt.bro.annotation.MachineSizedSInt; +import org.robovm.rt.bro.ptr.BytePtr; +import org.robovm.rt.bro.ptr.MachineSizedUIntPtr; +import org.robovm.rt.bro.ptr.VoidPtr; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +@Library("c") +public class HWMachine { + + static { + Bro.bind(); + } + + @Bridge + public static native int sysctlbyname (BytePtr name, VoidPtr oldp, MachineSizedUIntPtr oldlenp, VoidPtr newp, + @MachineSizedSInt long newlen); + + public static String getMachineString () { + BytePtr name = BytePtr.toBytePtrAsciiZ("hw.machine"); + MachineSizedUIntPtr size = new MachineSizedUIntPtr(); + sysctlbyname(name, null, size, null, 0); + BytePtr machine = Struct.allocate(BytePtr.class, (int)size.get()); + sysctlbyname(name, machine.as(VoidPtr.class), size, null, 0); + return machine.toStringAsciiZ(); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAcceleration.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAcceleration.java new file mode 100644 index 00000000000..591255cb10c --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAcceleration.java @@ -0,0 +1,70 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.custom; + +/**/ +import org.robovm.objc.*; +import org.robovm.objc.annotation.*; +import org.robovm.rt.bro.annotation.*; +import org.robovm.rt.bro.ptr.*; +import org.robovm.apple.foundation.*; + +/**/ +/**/ +/** DO NOT EDIT THIS FILE - it is machine generated + * @since Available in iOS 2.0 and later. + * @deprecated Deprecated in iOS 5.0. */ +@Deprecated +/* */ +/* */ +@Library("UIKit") +@NativeClass +public class /* */ +/* */ +UIAcceleration extends /* */ +/* */ + NSObject { + + /* */ + /* */ + /* */ + /** DO NOT EDIT THIS FILE - it is machine generated */ + public static class UIAccelerationPtr extends Ptr { + } + + /* */ + /* */ + static { + ObjCRuntime.bind(UIAcceleration.class); + } + + /* */ + /* */ + /* */ + /* */ + public UIAcceleration () { + } + + protected UIAcceleration (SkipInit skipInit) { + super(skipInit); + } + + /* */ + /* */ + @Property(selector = "timestamp") + public native double getTimestamp (); + + @Property(selector = "x") + public native double getX (); + + @Property(selector = "y") + public native double getY (); + + @Property(selector = "z") + public native double getZ (); + /* */ + /* */ + /* */ + /* */ + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometer.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometer.java new file mode 100644 index 00000000000..3384d97a84c --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometer.java @@ -0,0 +1,73 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.custom; + +/**/ +import org.robovm.objc.*; +import org.robovm.objc.annotation.*; +import org.robovm.rt.bro.annotation.*; +import org.robovm.rt.bro.ptr.*; +import org.robovm.apple.foundation.*; + +/**/ +/**/ +/** DO NOT EDIT THIS FILE - it is machine generated + * @since Available in iOS 2.0 and later. + * @deprecated Deprecated in iOS 5.0. */ +@Deprecated +/* */ +/* */ +@Library("UIKit") +@NativeClass +public class /* */ +/* */ +UIAccelerometer extends /* */ +/* */ + NSObject { + + /* */ + /* */ + /* */ + /** DO NOT EDIT THIS FILE - it is machine generated */ + public static class UIAccelerometerPtr extends Ptr { + } + + /* */ + /* */ + static { + ObjCRuntime.bind(UIAccelerometer.class); + } + + /* */ + /* */ + /* */ + /* */ + public UIAccelerometer () { + } + + protected UIAccelerometer (SkipInit skipInit) { + super(skipInit); + } + + /* */ + /* */ + @Property(selector = "updateInterval") + public native double getUpdateInterval (); + + @Property(selector = "setUpdateInterval:") + public native void setUpdateInterval (double v); + + @Property(selector = "delegate") + public native UIAccelerometerDelegate getDelegate (); + + @Property(selector = "setDelegate:", strongRef = true) + public native void setDelegate (UIAccelerometerDelegate v); + + /* */ + /* */ + /* */ + /* */ + @Method(selector = "sharedAccelerometer") + public static native UIAccelerometer getSharedAccelerometer (); + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometerDelegate.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometerDelegate.java new file mode 100644 index 00000000000..9fa72df5ae1 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometerDelegate.java @@ -0,0 +1,39 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.custom; + +/**/ +import org.robovm.objc.annotation.*; +import org.robovm.apple.foundation.*; + +/**/ +/**/ +/**/ +/**/ +/**/ +/** DO NOT EDIT THIS FILE - it is machine generated */ +public interface /* */ +/* */ +UIAccelerometerDelegate extends /* */ +/* */ + NSObjectProtocol { + + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /** @since Available in iOS 2.0 and later. + * @deprecated Deprecated in iOS 5.0. */ + @Deprecated + @Method(selector = "accelerometer:didAccelerate:") + void didAccelerate (UIAccelerometer accelerometer, UIAcceleration acceleration); + /* */ + /* */ + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometerDelegateAdapter.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometerDelegateAdapter.java new file mode 100644 index 00000000000..c3a9bda2d86 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/custom/UIAccelerometerDelegateAdapter.java @@ -0,0 +1,45 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.custom; + +/**/ +import org.robovm.objc.annotation.*; +import org.robovm.apple.foundation.*; + +/**/ +/**/ +/**/ +/**/ +/**/ +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class /* */ +/* */ +UIAccelerometerDelegateAdapter extends /* */ +/* */ + NSObject implements /* */ +/* */ + UIAccelerometerDelegate { + + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /* */ + /** @since Available in iOS 2.0 and later. + * @deprecated Deprecated in iOS 5.0. */ + @Deprecated + @NotImplemented("accelerometer:didAccelerate:") + public void didAccelerate (UIAccelerometer accelerometer, UIAcceleration acceleration) { + throw new UnsupportedOperationException(); + } + /* */ +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALBuffer.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALBuffer.java new file mode 100644 index 00000000000..1fd6d53b0cc --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALBuffer.java @@ -0,0 +1,19 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +@Library(Library.INTERNAL) +@NativeClass +public class ALBuffer extends NSObject { + + static { + ObjCRuntime.bind(ALBuffer.class); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALChannelSource.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALChannelSource.java new file mode 100644 index 00000000000..b087b6d83da --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALChannelSource.java @@ -0,0 +1,22 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +@Library(Library.INTERNAL) +@NativeClass +public final class ALChannelSource extends NSObject { + + static { + ObjCRuntime.bind(ALChannelSource.class); + } + + @Property(selector = "sourcePool") + public native ALSoundSourcePool getSourcePool (); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALSoundSourcePool.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALSoundSourcePool.java new file mode 100644 index 00000000000..042073571ee --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALSoundSourcePool.java @@ -0,0 +1,23 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSArray; +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +@Library(Library.INTERNAL) +@NativeClass +public class ALSoundSourcePool extends NSObject { + + static { + ObjCRuntime.bind(ALSoundSourcePool.class); + } + + @Property(selector = "sources") + public native NSArray getSources (); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALSource.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALSource.java new file mode 100644 index 00000000000..43bbaef59bc --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/ALSource.java @@ -0,0 +1,48 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +@Library(Library.INTERNAL) +@NativeClass +public class ALSource extends NSObject { + + static { + ObjCRuntime.bind(ALSource.class); + } + + @Property(selector = "sourceId") + public native int getSourceId (); + + @Property(selector = "state") + public native int getState (); + + @Method(selector = "stop") + public native void stop (); + + @Property(selector = "paused") + public native boolean isPaused (); + + @Property(selector = "setPaused:") + public native void setPaused (boolean paused); + + @Method(selector = "setVolume:") + public native void setVolume (float volume); + + @Method(selector = "setPitch:") + public native void setPitch (float pitch); + + @Method(selector = "setPan:") + public native void setPan (float pan); + + @Method(selector = "setLooping:") + public native void setLooping (boolean shouldLoop); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/AVAudioPlayerDelegate.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/AVAudioPlayerDelegate.java new file mode 100644 index 00000000000..d90fb90ca67 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/AVAudioPlayerDelegate.java @@ -0,0 +1,15 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.apple.foundation.NSObjectProtocol; +import org.robovm.objc.annotation.Method; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +public interface AVAudioPlayerDelegate extends NSObjectProtocol { + + @Method(selector = "audioPlayerDidFinishPlaying:successfully:") + void didFinishPlaying (NSObject player, boolean success); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/AVAudioPlayerDelegateAdapter.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/AVAudioPlayerDelegateAdapter.java new file mode 100644 index 00000000000..0a0cc81218d --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/AVAudioPlayerDelegateAdapter.java @@ -0,0 +1,16 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.annotation.NotImplemented; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +public class AVAudioPlayerDelegateAdapter extends NSObject implements AVAudioPlayerDelegate { + + @NotImplemented("audioPlayerDidFinishPlaying:successfully:") + public void didFinishPlaying (NSObject player, boolean success) { + throw new UnsupportedOperationException(); + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALAudioSession.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALAudioSession.java new file mode 100644 index 00000000000..8f5d8a706a1 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALAudioSession.java @@ -0,0 +1,25 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +@Library(Library.INTERNAL) +@NativeClass +public final class OALAudioSession extends NSObject { + + static { + ObjCRuntime.bind(OALAudioSession.class); + } + + @Method + public native static OALAudioSession sharedInstance (); + + @Method + public native void forceEndInterruption (); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALAudioTrack.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALAudioTrack.java new file mode 100644 index 00000000000..dfbb27119fa --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALAudioTrack.java @@ -0,0 +1,81 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +@Library(Library.INTERNAL) +@NativeClass +public class OALAudioTrack extends NSObject { + + static { + ObjCRuntime.bind(OALAudioTrack.class); + } + + @Method(selector = "track") + public native static OALAudioTrack create (); + + @Method + public native boolean preloadFile (String filePath); + + @Method + public native void stop (); + + @Method + public native void clear (); + + @Method + public native boolean play (); + + @Method + public native boolean playFile (String filePath); + + @Method(selector = "playFile:loops:") + public native boolean playFile (String filePath, int numberOfLoops); + + @Property + public native boolean isPaused (); + + @Property + public native void setPaused (boolean paused); + + @Property + public native boolean isPlaying (); + + @Property + public native float getVolume (); + + @Property + public native void setVolume (float volume); + + @Property + public native float getPan (); + + @Property + public native void setPan (float pan); + + @Property + public native double getCurrentTime (); + + @Property + public native void setCurrentTime (double currentTime); + + @Property + public native int getNumberOfLoops (); + + @Property + public native void setNumberOfLoops (int numberOfLoops); + + @Property + public native AVAudioPlayerDelegate getDelegate (); + + @Property(strongRef = true) + public native void setDelegate (AVAudioPlayerDelegate delegate); +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALIOSAudio.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALIOSAudio.java new file mode 100644 index 00000000000..f85c8c4addc --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALIOSAudio.java @@ -0,0 +1,94 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.audio.AudioDevice; +import com.badlogic.gdx.audio.AudioRecorder; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; +import com.badlogic.gdx.backends.iosrobovm.IOSAudio; +import com.badlogic.gdx.backends.iosrobovm.IOSMusic; +import com.badlogic.gdx.backends.iosrobovm.IOSSound; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.GdxRuntimeException; + +/** DO NOT EDIT THIS FILE - it is machine generated */ +public class OALIOSAudio implements IOSAudio { + + private final IOSApplicationConfiguration config; + + public OALIOSAudio (IOSApplicationConfiguration config) { + this.config = config; + if (!config.useAudio) return; + OALSimpleAudio audio = OALSimpleAudio.sharedInstance(); + if (audio != null) { + audio.setAllowIpod(config.allowIpod); + audio.setHonorSilentSwitch(!config.overrideRingerSwitch); + } else + Gdx.app.error("IOSAudio", "No OALSimpleAudio instance available, audio will not be availabe"); + } + + @Override + public AudioDevice newAudioDevice (int samplingRate, boolean isMono) { + // TODO Auto-generated method stub + return null; + } + + @Override + public AudioRecorder newAudioRecorder (int samplingRate, boolean isMono) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Sound newSound (FileHandle fileHandle) { + return new IOSSound(fileHandle); + } + + @Override + public Music newMusic (FileHandle fileHandle) { + String path = fileHandle.file().getPath().replace('\\', '/'); + OALAudioTrack track = OALAudioTrack.create(); + if (track != null) { + return new IOSMusic(track, path); + } + throw new GdxRuntimeException("Error creating music audio track"); + } + + @Override + public void didBecomeActive () { + // workaround for ObjectAL crash problem + // see: https://groups.google.com/g/objectal-for-iphone/c/ubRWltp_i1Q + forceEndInterruption(); + if (config.allowIpod) { + OALSimpleAudio audio = OALSimpleAudio.sharedInstance(); + if (audio != null) { + audio.setUseHardwareIfAvailable(false); + } + } + } + + @Override + public void willEnterForeground () { + // workaround for ObjectAL crash problem + // see: https://groups.google.com/forum/?fromgroups=#!topic/objectal-for-iphone/ubRWltp_i1Q + forceEndInterruption(); + } + + @Override + public void willResignActive () { + } + + @Override + public void willTerminate () { + } + + private void forceEndInterruption () { + OALAudioSession audioSession = OALAudioSession.sharedInstance(); + if (audioSession != null) { + audioSession.forceEndInterruption(); + } + } +} diff --git a/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALSimpleAudio.java b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALSimpleAudio.java new file mode 100644 index 00000000000..00b82782fb5 --- /dev/null +++ b/backends/gdx-backend-robovm-metalangle/src/com/badlogic/gdx/backends/iosrobovm/objectal/OALSimpleAudio.java @@ -0,0 +1,57 @@ +/*DO NOT EDIT THIS FILE - it is machine generated*/ + +package com.badlogic.gdx.backends.iosrobovm.objectal; + +import org.robovm.apple.foundation.NSObject; +import org.robovm.objc.ObjCRuntime; +import org.robovm.objc.annotation.Method; +import org.robovm.objc.annotation.NativeClass; +import org.robovm.objc.annotation.Property; +import org.robovm.rt.bro.annotation.Library; + +/** DO NOT EDIT THIS FILE - it is machine generated + * @author Niklas Therning */ +@Library(Library.INTERNAL) +@NativeClass +public final class OALSimpleAudio extends NSObject { + + static { + ObjCRuntime.bind(OALSimpleAudio.class); + } + + @Method + public native static OALSimpleAudio sharedInstance (); + + @Method + public native ALBuffer preloadEffect (String filePath); + + @Method + public native boolean unloadEffect (String filePath); + + @Method(selector = "playEffect:volume:pitch:pan:loop:") + public native ALSource playEffect (String filePath, float volume, float pitch, float pan, boolean loop); + + @Method(selector = "playBuffer:volume:pitch:pan:loop:") + public native ALSource playBuffer (ALBuffer buffer, float volume, float pitch, float pan, boolean loop); + + @Property + public native boolean isAllowIpod (); + + @Property + public native void setAllowIpod (boolean allowIpod); + + @Property + public native boolean isHonorSilentSwitch (); + + @Property + public native void setHonorSilentSwitch (boolean honorSilentSwitch); + + @Property + public native boolean isUseHardwareIfAvailable (); + + @Property + public native void setUseHardwareIfAvailable (boolean useHardwareIfAvailable); + + @Property(selector = "channel") + public native ALChannelSource getChannelSource (); +} diff --git a/backends/gdx-backend-robovm/build.gradle b/backends/gdx-backend-robovm/build.gradle index ef6da18d50d..e50bda7d487 100644 --- a/backends/gdx-backend-robovm/build.gradle +++ b/backends/gdx-backend-robovm/build.gradle @@ -13,6 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ +sourceSets { + main { + resources { + srcDir 'res' + } + } +} dependencies { api libraries.robovm diff --git a/backends/gdx-backend-robovm/res/META-INF/robovm/ios/robovm.xml b/backends/gdx-backend-robovm/res/META-INF/robovm/ios/robovm.xml new file mode 100644 index 00000000000..adccdf856a9 --- /dev/null +++ b/backends/gdx-backend-robovm/res/META-INF/robovm/ios/robovm.xml @@ -0,0 +1,5 @@ + + + OpenGLES + + \ No newline at end of file diff --git a/extensions/gdx-setup/res/com/badlogic/gdx/setup/resources/ios/robovm.xml b/extensions/gdx-setup/res/com/badlogic/gdx/setup/resources/ios/robovm.xml index a75cf776e33..8a0f689bc68 100644 --- a/extensions/gdx-setup/res/com/badlogic/gdx/setup/resources/ios/robovm.xml +++ b/extensions/gdx-setup/res/com/badlogic/gdx/setup/resources/ios/robovm.xml @@ -37,7 +37,6 @@ UIKit - OpenGLES QuartzCore CoreGraphics OpenAL diff --git a/publish.gradle b/publish.gradle index a92ff90c001..c18dca0ab11 100644 --- a/publish.gradle +++ b/publish.gradle @@ -5,6 +5,7 @@ configure([ project(":backends:gdx-backend-lwjgl"), project(":backends:gdx-backend-lwjgl3"), project(":backends:gdx-backend-robovm"), + project(":backends:gdx-backend-robovm-metalangle"), project(":backends:gdx-backend-gwt"), project(":extensions:gdx-box2d-parent"), project(":extensions:gdx-box2d-parent:gdx-box2d"), diff --git a/settings.gradle b/settings.gradle index 38d617bf1db..a8ddc84c360 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,6 +21,7 @@ include ":backends:gdx-backend-headless" include ":backends:gdx-backend-lwjgl" include ":backends:gdx-backend-lwjgl3" include ":backends:gdx-backend-robovm" +include ":backends:gdx-backend-robovm-metalangle" include ":backends:gdx-backends-gwt" project(":backends:gdx-backends-gwt").name = "gdx-backend-gwt"