[HTML5] Implement fullscreenchange in JS library.
Removes more emscripten HTML5 library dependencies.
This commit is contained in:
parent
b2d30c725d
commit
b6315afc9a
@ -62,20 +62,13 @@ bool DisplayServerJavaScript::check_size_force_redraw() {
|
||||
return godot_js_display_size_update() != 0;
|
||||
}
|
||||
|
||||
EM_BOOL DisplayServerJavaScript::fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data) {
|
||||
void DisplayServerJavaScript::fullscreen_change_callback(int p_fullscreen) {
|
||||
DisplayServerJavaScript *display = get_singleton();
|
||||
// Empty ID is canvas.
|
||||
String target_id = String::utf8(p_event->id);
|
||||
if (target_id.is_empty() || target_id == String::utf8(&(display->canvas_id[1]))) {
|
||||
// This event property is the only reliable data on
|
||||
// browser fullscreen state.
|
||||
if (p_event->isFullscreen) {
|
||||
display->window_mode = WINDOW_MODE_FULLSCREEN;
|
||||
} else {
|
||||
display->window_mode = WINDOW_MODE_WINDOWED;
|
||||
}
|
||||
if (p_fullscreen) {
|
||||
display->window_mode = WINDOW_MODE_FULLSCREEN;
|
||||
} else {
|
||||
display->window_mode = WINDOW_MODE_WINDOWED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Drag and drop callback.
|
||||
@ -736,7 +729,6 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
|
||||
// These callbacks from Emscripten's html5.h suffice to access most
|
||||
// JavaScript APIs.
|
||||
SET_EM_WINDOW_CALLBACK(blur, blur_callback)
|
||||
SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, fullscreenchange, fullscreen_change_callback)
|
||||
#undef SET_EM_CALLBACK
|
||||
#undef EM_CHECK
|
||||
|
||||
@ -745,9 +737,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
|
||||
godot_js_display_mouse_wheel_cb(&DisplayServerJavaScript::mouse_wheel_callback);
|
||||
godot_js_display_touch_cb(&DisplayServerJavaScript::touch_callback, touch_event.identifier, touch_event.coords);
|
||||
godot_js_display_key_cb(&DisplayServerJavaScript::key_callback, key_event.code, key_event.key);
|
||||
|
||||
// For APIs that are not (sufficiently) exposed, a
|
||||
// library is used below (implemented in library_godot_display.js).
|
||||
godot_js_display_fullscreen_cb(&DisplayServerJavaScript::fullscreen_change_callback);
|
||||
godot_js_display_notification_cb(&send_window_event_callback,
|
||||
WINDOW_EVENT_MOUSE_ENTER,
|
||||
WINDOW_EVENT_MOUSE_EXIT,
|
||||
|
@ -78,8 +78,7 @@ private:
|
||||
static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape);
|
||||
|
||||
// events
|
||||
static EM_BOOL fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data);
|
||||
|
||||
static void fullscreen_change_callback(int p_fullscreen);
|
||||
static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers);
|
||||
static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers);
|
||||
static int mouse_wheel_callback(double p_delta_x, double p_delta_y);
|
||||
|
@ -94,6 +94,7 @@ extern void godot_js_display_mouse_move_cb(void (*p_callback)(double p_x, double
|
||||
extern void godot_js_display_mouse_wheel_cb(int (*p_callback)(double p_delta_x, double p_delta_y));
|
||||
extern void godot_js_display_touch_cb(void (*p_callback)(int p_type, int p_count), uint32_t *r_identifiers, double *r_coords);
|
||||
extern void godot_js_display_key_cb(void (*p_callback)(int p_type, int p_repeat, int p_modifiers), char r_code[32], char r_key[32]);
|
||||
extern void godot_js_display_fullscreen_cb(void (*p_callback)(int p_fullscreen));
|
||||
extern void godot_js_display_notification_cb(void (*p_callback)(int p_notification), int p_enter, int p_exit, int p_in, int p_out);
|
||||
extern void godot_js_display_paste_cb(void (*p_callback)(const char *p_text));
|
||||
extern void godot_js_display_drop_files_cb(void (*p_callback)(char **p_filev, int p_filec));
|
||||
|
@ -853,6 +853,20 @@ const GodotDisplay = {
|
||||
/*
|
||||
* Listeners
|
||||
*/
|
||||
godot_js_display_fullscreen_cb__sig: 'vi',
|
||||
godot_js_display_fullscreen_cb: function (callback) {
|
||||
const canvas = GodotConfig.canvas;
|
||||
const func = GodotRuntime.get_func(callback);
|
||||
function change_cb(evt) {
|
||||
if (evt.target === canvas) {
|
||||
func(GodotDisplayScreen.isFullscreen());
|
||||
}
|
||||
}
|
||||
GodotDisplayListeners.add(document, 'fullscreenchange', change_cb, false);
|
||||
GodotDisplayListeners.add(document, 'mozfullscreenchange', change_cb, false);
|
||||
GodotDisplayListeners.add(document, 'webkitfullscreenchange', change_cb, false);
|
||||
},
|
||||
|
||||
godot_js_display_notification_cb__sig: 'viiiii',
|
||||
godot_js_display_notification_cb: function (callback, p_enter, p_exit, p_in, p_out) {
|
||||
const canvas = GodotConfig.canvas;
|
||||
|
Loading…
Reference in New Issue
Block a user