Merge pull request #21621 from AlexHolly/android-pen-hover-support
Adds Pen support for Android
This commit is contained in:
commit
98497ff719
|
@ -94,6 +94,11 @@ public class GodotLib {
|
||||||
*/
|
*/
|
||||||
public static native void touch(int what, int pointer, int howmany, int[] arr);
|
public static native void touch(int what, int pointer, int howmany, int[] arr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forward hover events from the main thread to the GL thread.
|
||||||
|
*/
|
||||||
|
public static native void hover(int type, int x, int y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward accelerometer sensor events from the main thread to the GL thread.
|
* Forward accelerometer sensor events from the main thread to the GL thread.
|
||||||
* @see android.hardware.SensorEventListener#onSensorChanged(SensorEvent)
|
* @see android.hardware.SensorEventListener#onSensorChanged(SensorEvent)
|
||||||
|
|
|
@ -188,7 +188,18 @@ public class GodotInputHandler implements InputDeviceListener {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
} else if ((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) {
|
||||||
|
final int x = Math.round(event.getX());
|
||||||
|
final int y = Math.round(event.getY());
|
||||||
|
final int type = event.getAction();
|
||||||
|
queueEvent(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GodotLib.hover(type, x, y);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -826,6 +826,13 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jo
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jobject obj, jint p_type, jint p_x, jint p_y) {
|
||||||
|
if (step == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
os_android->process_hover(p_type, Point2(p_x, p_y));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Android Key codes.
|
* Android Key codes.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -45,6 +45,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
|
||||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jobject obj);
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jobject obj);
|
||||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj);
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj);
|
||||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jobject obj, jint ev, jint pointer, jint count, jintArray positions);
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jobject obj, jint ev, jint pointer, jint count, jintArray positions);
|
||||||
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jobject obj, jint p_type, jint p_x, jint p_y);
|
||||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed);
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed);
|
||||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jobject obj, jint p_device, jint p_button, jboolean p_pressed);
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jobject obj, jint p_device, jint p_button, jboolean p_pressed);
|
||||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value);
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value);
|
||||||
|
|
|
@ -477,6 +477,23 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OS_Android::process_hover(int p_type, Point2 p_pos) {
|
||||||
|
// https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_HOVER_ENTER
|
||||||
|
switch (p_type) {
|
||||||
|
case 7: // hover move
|
||||||
|
case 9: // hover enter
|
||||||
|
case 10: { // hover exit
|
||||||
|
Ref<InputEventMouseMotion> ev;
|
||||||
|
ev.instance();
|
||||||
|
ev->set_position(p_pos);
|
||||||
|
ev->set_global_position(p_pos);
|
||||||
|
ev->set_relative(p_pos - hover_prev_pos);
|
||||||
|
input->parse_input_event(ev);
|
||||||
|
hover_prev_pos = p_pos;
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OS_Android::process_accelerometer(const Vector3 &p_accelerometer) {
|
void OS_Android::process_accelerometer(const Vector3 &p_accelerometer) {
|
||||||
|
|
||||||
input->set_accelerometer(p_accelerometer);
|
input->set_accelerometer(p_accelerometer);
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<TouchPos> touch;
|
Vector<TouchPos> touch;
|
||||||
|
Point2 hover_prev_pos; // needed to calculate the relative position on hover events
|
||||||
|
|
||||||
bool use_gl2;
|
bool use_gl2;
|
||||||
bool use_apk_expansion;
|
bool use_apk_expansion;
|
||||||
|
@ -186,6 +187,7 @@ public:
|
||||||
void process_magnetometer(const Vector3 &p_magnetometer);
|
void process_magnetometer(const Vector3 &p_magnetometer);
|
||||||
void process_gyroscope(const Vector3 &p_gyroscope);
|
void process_gyroscope(const Vector3 &p_gyroscope);
|
||||||
void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
|
void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
|
||||||
|
void process_hover(int p_type, Point2 p_pos);
|
||||||
void process_joy_event(JoypadEvent p_event);
|
void process_joy_event(JoypadEvent p_event);
|
||||||
void process_event(Ref<InputEvent> p_event);
|
void process_event(Ref<InputEvent> p_event);
|
||||||
void init_video_mode(int p_video_width, int p_video_height);
|
void init_video_mode(int p_video_width, int p_video_height);
|
||||||
|
|
Loading…
Reference in a new issue