os_javascript.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*************************************************************************/
  2. /* os_javascript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. #ifndef OS_JAVASCRIPT_H
  31. #define OS_JAVASCRIPT_H
  32. #include "audio_driver_javascript.h"
  33. #include "drivers/unix/os_unix.h"
  34. #include "javascript_eval.h"
  35. #include "main/input_default.h"
  36. #include "os/input.h"
  37. #include "os/main_loop.h"
  38. #include "power_javascript.h"
  39. #include "servers/audio_server.h"
  40. #include "servers/visual/rasterizer.h"
  41. #include <emscripten/html5.h>
  42. typedef String (*GetDataDirFunc)();
  43. class OS_JavaScript : public OS_Unix {
  44. bool idbfs_available;
  45. int64_t time_to_save_sync;
  46. int64_t last_sync_time;
  47. VisualServer *visual_server;
  48. AudioDriverJavaScript audio_driver_javascript;
  49. const char *gl_extensions;
  50. InputDefault *input;
  51. Vector2 windowed_size;
  52. bool window_maximized;
  53. bool soft_fs_enabled;
  54. bool canvas_size_adjustment_requested;
  55. VideoMode video_mode;
  56. CursorShape cursor_shape;
  57. MainLoop *main_loop;
  58. GetDataDirFunc get_data_dir_func;
  59. PowerJavascript *power_manager;
  60. #ifdef JAVASCRIPT_EVAL_ENABLED
  61. JavaScript *javascript_eval;
  62. #endif
  63. static void _close_notification_funcs(const String &p_file, int p_flags);
  64. void process_joypads();
  65. void set_css_cursor(const char *);
  66. const char *get_css_cursor() const;
  67. public:
  68. // functions used by main to initialize/deintialize the OS
  69. virtual int get_video_driver_count() const;
  70. virtual const char *get_video_driver_name(int p_driver) const;
  71. virtual int get_audio_driver_count() const;
  72. virtual const char *get_audio_driver_name(int p_driver) const;
  73. virtual void initialize_logger();
  74. virtual void initialize_core();
  75. virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
  76. virtual void set_main_loop(MainLoop *p_main_loop);
  77. virtual void delete_main_loop();
  78. virtual void finalize();
  79. typedef int64_t ProcessID;
  80. //static OS* get_singleton();
  81. virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
  82. virtual void set_mouse_mode(MouseMode p_mode);
  83. virtual MouseMode get_mouse_mode() const;
  84. virtual Point2 get_mouse_position() const;
  85. virtual int get_mouse_button_state() const;
  86. virtual void set_window_title(const String &p_title);
  87. //virtual void set_clipboard(const String& p_text);
  88. //virtual String get_clipboard() const;
  89. virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
  90. virtual VideoMode get_video_mode(int p_screen = 0) const;
  91. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
  92. virtual Size2 get_screen_size(int p_screen = -1) const;
  93. virtual void set_window_size(const Size2);
  94. virtual Size2 get_window_size() const;
  95. virtual void set_window_maximized(bool p_enabled);
  96. virtual bool is_window_maximized() const { return window_maximized; }
  97. virtual void set_window_fullscreen(bool p_enable);
  98. virtual bool is_window_fullscreen() const;
  99. void request_canvas_size_adjustment();
  100. virtual String get_name();
  101. virtual MainLoop *get_main_loop() const;
  102. virtual bool can_draw() const;
  103. virtual bool is_userfs_persistent() const;
  104. virtual void set_cursor_shape(CursorShape p_shape);
  105. void main_loop_begin();
  106. bool main_loop_iterate();
  107. void main_loop_request_quit();
  108. void main_loop_end();
  109. void main_loop_focusout();
  110. void main_loop_focusin();
  111. virtual bool has_touchscreen_ui_hint() const;
  112. void set_opengl_extensions(const char *p_gl_extensions);
  113. virtual Error shell_open(String p_uri);
  114. virtual String get_data_dir() const;
  115. String get_executable_path() const;
  116. virtual String get_resource_dir() const;
  117. void process_accelerometer(const Vector3 &p_accelerometer);
  118. void push_input(const Ref<InputEvent> &p_ev);
  119. virtual bool is_joy_known(int p_device);
  120. virtual String get_joy_guid(int p_device) const;
  121. bool joy_connection_changed(int p_type, const EmscriptenGamepadEvent *p_event);
  122. virtual OS::PowerState get_power_state();
  123. virtual int get_power_seconds_left();
  124. virtual int get_power_percent_left();
  125. virtual bool _check_internal_feature_support(const String &p_feature);
  126. void set_idbfs_available(bool p_idbfs_available);
  127. OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_dir_func);
  128. ~OS_JavaScript();
  129. };
  130. #endif