src/core/android/SDL_android.c
changeset 11931 d479188e0155
parent 11921 88a2982221ec
child 11932 a05a909eeddb
     1.1 --- a/src/core/android/SDL_android.c	Mon Mar 12 18:41:06 2018 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Thu Mar 15 18:22:48 2018 -0700
     1.3 @@ -223,6 +223,9 @@
     1.4  static jmethodID midOpenAPKExpansionInputStream;
     1.5  static jmethodID midGetManifestEnvironmentVariables;
     1.6  static jmethodID midGetDisplayDPI;
     1.7 +static jmethodID midCreateCustomCursor;
     1.8 +static jmethodID midSetCustomCursor;
     1.9 +static jmethodID midSetSystemCursor;
    1.10  
    1.11  /* audio manager */
    1.12  static jclass mAudioManagerClass;
    1.13 @@ -332,7 +335,11 @@
    1.14                                  "getManifestEnvironmentVariables", "()Z");
    1.15  
    1.16      midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
    1.17 -    midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
    1.18 +
    1.19 +    /* Custom cursor implementation is only available on API 24 and above */
    1.20 +    midCreateCustomCursor = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "createCustomCursor", "([IIIII)I");
    1.21 +    midSetCustomCursor = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setCustomCursor", "(I)V");
    1.22 +    midSetSystemCursor = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "setSystemCursor", "(I)V");
    1.23  
    1.24      if (!midGetNativeSurface ||
    1.25         !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
    1.26 @@ -2167,6 +2174,40 @@
    1.27      }
    1.28  }
    1.29  
    1.30 +int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y)
    1.31 +{
    1.32 +    JNIEnv *mEnv = Android_JNI_GetEnv();
    1.33 +    int custom_cursor = 0;
    1.34 +    if (midCreateCustomCursor) {
    1.35 +        jintArray pixels;
    1.36 +        pixels = (*mEnv)->NewIntArray(mEnv, surface->w * surface->h);
    1.37 +        if (!pixels) {
    1.38 +            return 0;
    1.39 +        }
    1.40 +        (*mEnv)->SetIntArrayRegion(mEnv, pixels, 0, surface->w * surface->h, (int *)surface->pixels);
    1.41 +        custom_cursor = (*mEnv)->CallStaticIntMethod(mEnv, mActivityClass, midCreateCustomCursor, pixels, surface->w, surface->h, hot_x, hot_y);
    1.42 +        (*mEnv)->DeleteLocalRef(mEnv, pixels);
    1.43 +    }
    1.44 +    return custom_cursor;
    1.45 +}
    1.46 +
    1.47 +
    1.48 +void Android_JNI_SetCustomCursor(int cursorID)
    1.49 +{
    1.50 +    JNIEnv *mEnv = Android_JNI_GetEnv();
    1.51 +    if (midSetCustomCursor) {
    1.52 +        (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetCustomCursor, cursorID);
    1.53 +    }
    1.54 +}
    1.55 +
    1.56 +void Android_JNI_SetSystemCursor(int cursorID)
    1.57 +{
    1.58 +    JNIEnv *mEnv = Android_JNI_GetEnv();
    1.59 +    if (midSetSystemCursor) {
    1.60 +        (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetSystemCursor, cursorID);
    1.61 +    }
    1.62 +}
    1.63 +
    1.64  #endif /* __ANDROID__ */
    1.65  
    1.66  /* vi: set ts=4 sw=4 expandtab: */