瀏覽代碼

Implement HTML5 cancel/ok button swap on Windows.

Platform is detected on init via the `navigator.platform` string.

(cherry picked from commit 0b286a287ca35275988f22a60f307521c5b08437)
Fabio Alessandrelli 5 年之前
父節點
當前提交
31c21b9750
共有 2 個文件被更改,包括 18 次插入0 次删除
  1. 16 0
      platform/javascript/os_javascript.cpp
  2. 2 0
      platform/javascript/os_javascript.h

+ 16 - 0
platform/javascript/os_javascript.cpp

@@ -916,6 +916,17 @@ void OS_JavaScript::initialize_core() {
 
 Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
 
+	/* clang-format off */
+	swap_ok_cancel = EM_ASM_INT({
+		const win = (['Windows', 'Win64', 'Win32', 'WinCE']);
+		const plat = navigator.platform || "";
+		if (win.indexOf(plat) !== -1) {
+			return 1;
+		}
+		return 0;
+	}) == 1;
+	/* clang-format on */
+
 	EmscriptenWebGLContextAttributes attributes;
 	emscripten_webgl_init_context_attributes(&attributes);
 	attributes.alpha = GLOBAL_GET("display/window/per_pixel_transparency/allowed");
@@ -1084,6 +1095,10 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
 	return OK;
 }
 
+bool OS_JavaScript::get_swap_ok_cancel() {
+	return swap_ok_cancel;
+}
+
 void OS_JavaScript::swap_buffers() {
 	emscripten_webgl_commit_frame();
 }
@@ -1428,6 +1443,7 @@ OS_JavaScript::OS_JavaScript(int p_argc, char *p_argv[]) {
 	visual_server = NULL;
 	audio_driver_javascript = NULL;
 
+	swap_ok_cancel = false;
 	idb_available = false;
 	sync_wait_time = -1;
 

+ 2 - 0
platform/javascript/os_javascript.h

@@ -69,6 +69,7 @@ class OS_JavaScript : public OS_Unix {
 	AudioDriverJavaScript *audio_driver_javascript;
 	VisualServer *visual_server;
 
+	bool swap_ok_cancel;
 	bool idb_available;
 	int64_t sync_wait_time;
 	int64_t last_sync_check_time;
@@ -115,6 +116,7 @@ public:
 	// Override return type to make writing static callbacks less tedious.
 	static OS_JavaScript *get_singleton();
 
+	virtual bool get_swap_ok_cancel();
 	virtual void swap_buffers();
 	virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
 	virtual VideoMode get_video_mode(int p_screen = 0) const;