java_godot_wrapper.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*************************************************************************/
  2. /* java_godot_wrapper.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. // note, swapped java and godot around in the file name so all the java
  31. // wrappers are together
  32. #ifndef JAVA_GODOT_WRAPPER_H
  33. #define JAVA_GODOT_WRAPPER_H
  34. #include <android/log.h>
  35. #include <jni.h>
  36. #include "string_android.h"
  37. // Class that makes functions in java/src/org/godotengine/godot/Godot.java callable from C++
  38. class GodotJavaWrapper {
  39. private:
  40. jobject godot_instance;
  41. jobject activity;
  42. jclass godot_class;
  43. jclass activity_class;
  44. jmethodID _on_video_init = 0;
  45. jmethodID _restart = 0;
  46. jmethodID _finish = 0;
  47. jmethodID _set_keep_screen_on = 0;
  48. jmethodID _alert = 0;
  49. jmethodID _get_GLES_version_code = 0;
  50. jmethodID _get_clipboard = 0;
  51. jmethodID _set_clipboard = 0;
  52. jmethodID _request_permission = 0;
  53. jmethodID _request_permissions = 0;
  54. jmethodID _get_granted_permissions = 0;
  55. jmethodID _init_input_devices = 0;
  56. jmethodID _get_surface = 0;
  57. jmethodID _is_activity_resumed = 0;
  58. jmethodID _vibrate = 0;
  59. jmethodID _get_input_fallback_mapping = 0;
  60. jmethodID _on_godot_setup_completed = 0;
  61. jmethodID _on_godot_main_loop_started = 0;
  62. jmethodID _get_class_loader = 0;
  63. public:
  64. GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance);
  65. ~GodotJavaWrapper();
  66. jobject get_activity();
  67. jobject get_member_object(const char *p_name, const char *p_class, JNIEnv *p_env = NULL);
  68. jobject get_class_loader();
  69. void gfx_init(bool gl2);
  70. void on_video_init(JNIEnv *p_env = NULL);
  71. void on_godot_setup_completed(JNIEnv *p_env = NULL);
  72. void on_godot_main_loop_started(JNIEnv *p_env = NULL);
  73. void restart(JNIEnv *p_env = NULL);
  74. void force_quit(JNIEnv *p_env = NULL);
  75. void set_keep_screen_on(bool p_enabled);
  76. void alert(const String &p_message, const String &p_title);
  77. int get_gles_version_code();
  78. bool has_get_clipboard();
  79. String get_clipboard();
  80. bool has_set_clipboard();
  81. void set_clipboard(const String &p_text);
  82. bool request_permission(const String &p_name);
  83. bool request_permissions();
  84. Vector<String> get_granted_permissions() const;
  85. void init_input_devices();
  86. jobject get_surface();
  87. bool is_activity_resumed();
  88. void vibrate(int p_duration_ms);
  89. String get_input_fallback_mapping();
  90. };
  91. #endif /* !JAVA_GODOT_WRAPPER_H */