mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 22:21:18 +00:00
Add a method for obtaining display cutouts on Android
This commit is contained in:
parent
bfc727d970
commit
71ce5857ec
8 changed files with 67 additions and 0 deletions
|
|
@ -31,6 +31,8 @@
|
|||
#include "java_godot_io_wrapper.h"
|
||||
|
||||
#include "core/error/error_list.h"
|
||||
#include "core/math/rect2.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
// JNIEnv is only valid within the thread it belongs to, in a multi threading environment
|
||||
// we can't cache it.
|
||||
|
|
@ -51,6 +53,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
|
|||
_open_URI = p_env->GetMethodID(cls, "openURI", "(Ljava/lang/String;)I");
|
||||
_get_cache_dir = p_env->GetMethodID(cls, "getCacheDir", "()Ljava/lang/String;");
|
||||
_get_data_dir = p_env->GetMethodID(cls, "getDataDir", "()Ljava/lang/String;");
|
||||
_get_display_cutouts = p_env->GetMethodID(cls, "getDisplayCutouts", "()[I"),
|
||||
_get_locale = p_env->GetMethodID(cls, "getLocale", "()Ljava/lang/String;");
|
||||
_get_model = p_env->GetMethodID(cls, "getModel", "()Ljava/lang/String;");
|
||||
_get_screen_DPI = p_env->GetMethodID(cls, "getScreenDPI", "()I");
|
||||
|
|
@ -176,6 +179,27 @@ void GodotIOJavaWrapper::screen_get_usable_rect(int (&p_rect_xywh)[4]) {
|
|||
}
|
||||
}
|
||||
|
||||
Array GodotIOJavaWrapper::get_display_cutouts() {
|
||||
Array result;
|
||||
ERR_FAIL_NULL_V(_get_display_cutouts, result);
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_NULL_V(env, result);
|
||||
jintArray returnArray = (jintArray)env->CallObjectMethod(godot_io_instance, _get_display_cutouts);
|
||||
jint arrayLength = env->GetArrayLength(returnArray);
|
||||
jint *arrayBody = env->GetIntArrayElements(returnArray, JNI_FALSE);
|
||||
int cutouts = arrayLength / 4;
|
||||
for (int i = 0; i < cutouts; i++) {
|
||||
int x = arrayBody[i * 4];
|
||||
int y = arrayBody[i * 4 + 1];
|
||||
int width = arrayBody[i * 4 + 2];
|
||||
int height = arrayBody[i * 4 + 3];
|
||||
Rect2 cutout(x, y, width, height);
|
||||
result.append(cutout);
|
||||
}
|
||||
env->ReleaseIntArrayElements(returnArray, arrayBody, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
String GodotIOJavaWrapper::get_unique_id() {
|
||||
if (_get_unique_id) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue