|
@@ -43,8 +43,13 @@ import org.godotengine.godot.xr.regular.RegularFallbackConfigChooser;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.Context;
|
|
|
+import android.content.res.AssetManager;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.graphics.PixelFormat;
|
|
|
import android.os.Build;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.SparseArray;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.PointerIcon;
|
|
@@ -52,6 +57,8 @@ import android.view.SurfaceView;
|
|
|
|
|
|
import androidx.annotation.Keep;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
+
|
|
|
/**
|
|
|
* A simple GLSurfaceView sub-class that demonstrate how to perform
|
|
|
* OpenGL ES 2.0 rendering into a GL Surface. Note the following important
|
|
@@ -74,6 +81,7 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView
|
|
|
private final Godot godot;
|
|
|
private final GodotInputHandler inputHandler;
|
|
|
private final GodotRenderer godotRenderer;
|
|
|
+ private final SparseArray<PointerIcon> customPointerIcons = new SparseArray<>();
|
|
|
|
|
|
public GodotGLRenderView(Context context, Godot godot, XRMode xrMode, boolean p_use_debug_opengl) {
|
|
|
super(context);
|
|
@@ -168,13 +176,50 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView
|
|
|
inputHandler.onPointerCaptureChange(false);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Used to configure the PointerIcon for the given type.
|
|
|
+ *
|
|
|
+ * Called from JNI
|
|
|
+ */
|
|
|
+ @Keep
|
|
|
+ @Override
|
|
|
+ public void configurePointerIcon(int pointerType, String imagePath, float hotSpotX, float hotSpotY) {
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
|
|
+ try {
|
|
|
+ Bitmap bitmap = null;
|
|
|
+ if (!TextUtils.isEmpty(imagePath)) {
|
|
|
+ if (godot.directoryAccessHandler.filesystemFileExists(imagePath)) {
|
|
|
+ // Try to load the bitmap from the file system
|
|
|
+ bitmap = BitmapFactory.decodeFile(imagePath);
|
|
|
+ } else if (godot.directoryAccessHandler.assetsFileExists(imagePath)) {
|
|
|
+ // Try to load the bitmap from the assets directory
|
|
|
+ AssetManager am = getContext().getAssets();
|
|
|
+ InputStream imageInputStream = am.open(imagePath);
|
|
|
+ bitmap = BitmapFactory.decodeStream(imageInputStream);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PointerIcon customPointerIcon = PointerIcon.create(bitmap, hotSpotX, hotSpotY);
|
|
|
+ customPointerIcons.put(pointerType, customPointerIcon);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // Reset the custom pointer icon
|
|
|
+ customPointerIcons.delete(pointerType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* called from JNI to change pointer icon
|
|
|
*/
|
|
|
@Keep
|
|
|
+ @Override
|
|
|
public void setPointerIcon(int pointerType) {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
- setPointerIcon(PointerIcon.getSystemIcon(getContext(), pointerType));
|
|
|
+ PointerIcon pointerIcon = customPointerIcons.get(pointerType);
|
|
|
+ if (pointerIcon == null) {
|
|
|
+ pointerIcon = PointerIcon.getSystemIcon(getContext(), pointerType);
|
|
|
+ }
|
|
|
+ setPointerIcon(pointerIcon);
|
|
|
}
|
|
|
}
|
|
|
|