Debian Codegraph @

src/platforms/rcore_web.c

raw symbols SCIP
1 /**********************************************************************************************
2 *
3 * rcore_web - Functions to manage window, graphics device and inputs
4 *
5 * PLATFORM: WEB
6 * - HTML5 (WebAssembly)
7 *
8 * LIMITATIONS:
9 * - Limitation 01
10 * - Limitation 02
11 *
12 * POSSIBLE IMPROVEMENTS:
13 * - Replace glfw3 dependency by direct browser API calls (same as library_glfw3.js)
14 *
15 * CONFIGURATION:
16 * #define RCORE_PLATFORM_CUSTOM_FLAG
17 * Custom flag for rcore on target platform -not used-
18 *
19 * DEPENDENCIES:
20 * - emscripten: Allow interaction between browser API and C
21 * - gestures: Gestures system for touch-ready devices (or simulated from mouse inputs)
22 *
23 *
24 * LICENSE: zlib/libpng
25 *
26 * Copyright (c) 2013-2026 Ramon Santamaria (@raysan5) and contributors
27 *
28 * This software is provided "as-is", without any express or implied warranty. In no event
29 * will the authors be held liable for any damages arising from the use of this software.
30 *
31 * Permission is granted to anyone to use this software for any purpose, including commercial
32 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
33 *
34 * 1. The origin of this software must not be misrepresented; you must not claim that you
35 * wrote the original software. If you use this software in a product, an acknowledgment
36 * in the product documentation would be appreciated but is not required.
37 *
38 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
39 * as being the original software.
40 *
41 * 3. This notice may not be removed or altered from any source distribution.
42 *
43 **********************************************************************************************/
44
45 #define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
46 // NOTE: Already provided by rlgl implementation (on glad.h)
47 #include "GLFW/glfw3.h" // GLFW3: Windows, OpenGL context and Input management
48
49 #include <emscripten/emscripten.h> // Emscripten functionality for C
50 #include <emscripten/html5.h> // Emscripten HTML5 library
51
52 #include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
53
54 //----------------------------------------------------------------------------------
55 // Defines and Macros
56 //----------------------------------------------------------------------------------
57 // TODO: HACK: Added flag if not provided by GLFW when using external library
58 // Latest GLFW release (GLFW 3.3.8) does not implement this flag, it was added for 3.4.0-dev
59 #if !defined(GLFW_MOUSE_PASSTHROUGH)
60 #define GLFW_MOUSE_PASSTHROUGH 0x0002000D
61 #endif
62
63 #if (_POSIX_C_SOURCE < 199309L)
64 #undef _POSIX_C_SOURCE
65 #define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext.
66 #endif
67
68 //----------------------------------------------------------------------------------
69 // Types and Structures Definition
70 //----------------------------------------------------------------------------------
71 typedef struct {
72 GLFWwindow *handle; // GLFW window handle (graphic device)
73 bool ourFullscreen; // Internal var to filter our handling of fullscreen vs the user handling of fullscreen
74 int unmaximizedWidth; // Internal var to store the unmaximized window (canvas) width
75 int unmaximizedHeight; // Internal var to store the unmaximized window (canvas) height
76
77 char canvasId[64]; // Keep current canvas id where wasm app is running
78 // NOTE: Useful when trying to run multiple wasms in different canvases in same webpage
79
80 #if defined(GRAPHICS_API_OPENGL_SOFTWARE)
81 unsigned int *pixels; // Pointer to pixel data buffer (RGBA 32bit format)
82 #endif
83 } PlatformData;
84
85 //----------------------------------------------------------------------------------
86 // Global Variables Definition
87 //----------------------------------------------------------------------------------
88 extern CoreData CORE; // Global CORE state context
89
90 static PlatformData platform = { 0 }; // Platform specific data
91
92 //----------------------------------------------------------------------------------
93 // Global Variables Definition
94 //----------------------------------------------------------------------------------
95 static const char cursorLUT[11][12] = {
96 "default", // 0 MOUSE_CURSOR_DEFAULT
97 "default", // 1 MOUSE_CURSOR_ARROW
98 "text", // 2 MOUSE_CURSOR_IBEAM
99 "crosshair", // 3 MOUSE_CURSOR_CROSSHAIR
100 "pointer", // 4 MOUSE_CURSOR_POINTING_HAND
101 "ew-resize", // 5 MOUSE_CURSOR_RESIZE_EW
102 "ns-resize", // 6 MOUSE_CURSOR_RESIZE_NS
103 "nwse-resize", // 7 MOUSE_CURSOR_RESIZE_NWSE
104 "nesw-resize", // 8 MOUSE_CURSOR_RESIZE_NESW
105 "move", // 9 MOUSE_CURSOR_RESIZE_ALL
106 "not-allowed" // 10 MOUSE_CURSOR_NOT_ALLOWED
107 };
108
109 //----------------------------------------------------------------------------------
110 // Module Internal Functions Declaration
111 //----------------------------------------------------------------------------------
112 int InitPlatform(void); // Initialize platform (graphics, inputs and more)
113 void ClosePlatform(void); // Close platform
114
115 // Error callback event
116 static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
117
118 // Window callbacks events
119 static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 Window Size Callback, runs when window is resized
120 static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 Window Iconify Callback, runs when window is minimized/restored
121 //static void WindowMaximizeCallback(GLFWwindow *window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized
122 static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 Window Focus Callback, runs when window get/lose focus
123 static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
124 static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); // GLFW3 Window Content Scale Callback, runs when window changes scale
125
126 // Input callbacks events
127 static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
128 static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
129 static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
130 static void MouseMoveCallback(GLFWwindow *window, double x, double y); // GLFW3 Mouse Move Callback, runs on mouse move
131 static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Mouse Scrolling Callback, runs on mouse wheel
132 static void MouseEnterCallback(GLFWwindow *window, int enter); // GLFW3 Mouse Enter Callback, cursor enters client area
133
134 // Emscripten window callback events
135 static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData);
136 //static EM_BOOL EmscriptenWindowResizedCallback(int eventType, const EmscriptenUiEvent *event, void *userData);
137 static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData);
138 static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData);
139 static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const EmscriptenVisibilityChangeEvent *visibilityChangeEvent, void *userData);
140
141 // Emscripten input callback events
142 //static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboardEvent *keyboardEvent, void *userData);
143 static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
144 static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
145 static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData);
146 static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData);
147 static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData);
148
149 // JS: Set the canvas id provided by the module configuration
150 EM_JS(void, SetCanvasIdJs, (char *out, int outSize), {
151 var canvasId = "#" + Module.canvas.id;
152 stringToUTF8(canvasId, out, outSize);
153 });
154
155 //----------------------------------------------------------------------------------
156 // Module Functions Declaration
157 //----------------------------------------------------------------------------------
158 // NOTE: Functions declaration is provided by raylib.h
159
160 //----------------------------------------------------------------------------------
161 // Module Functions Definition: Window and Graphics Device
162 //----------------------------------------------------------------------------------
163
164 // Check if application should close
165 // This will always return false on a web-build as web builds have no control over this functionality
166 // Sleep is handled in EndDrawing() for synchronous code
167 bool WindowShouldClose(void)
168 {
169 // Emscripten Asyncify is required to run synchronous code in asynchronous JS
170 // REF: https://emscripten.org/docs/porting/asyncify.html
171
172 // WindowShouldClose() is not called on a web-ready raylib application if using emscripten_set_main_loop()
173 // and encapsulating one frame execution on a UpdateDrawFrame() function,
174 // allowing the browser to manage execution asynchronously
175
176 // Optionally, time to give-control-back-to-browser can be managed here,
177 // but it seems below line could generate stuttering on some browsers
178 emscripten_sleep(12);
179
180 return false;
181 }
182
183 // Toggle fullscreen mode
184 void ToggleFullscreen(void)
185 {
186 platform.ourFullscreen = true;
187 bool enterFullscreen = false;
188
189 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
190 if (wasFullscreen)
191 {
192 if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) enterFullscreen = false;
193 else if (FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) enterFullscreen = true;
194 else
195 {
196 const int canvasWidth = EM_ASM_INT( { return Module.canvas.width; }, 0);
197 const int canvasStyleWidth = EM_ASM_INT( { return parseInt(Module.canvas.style.width); }, 0);
198 if (canvasStyleWidth > canvasWidth) enterFullscreen = false;
199 else enterFullscreen = true;
200 }
201
202 EM_ASM(document.exitFullscreen(););
203
204 FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
205 FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
206 }
207 else enterFullscreen = true;
208
209 if (enterFullscreen)
210 {
211 // NOTE: The setTimeouts handle the browser mode change delay
212 EM_ASM(
213 setTimeout(function(){
214 Module.requestFullscreen(false, false);
215 }, 100);
216 );
217
218 FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
219 }
220
221 // NOTE: Old notes below:
222 /*
223 EM_ASM
224 (
225 // This strategy works well while using raylib minimal web shell for emscripten,
226 // it re-scales the canvas to fullscreen using monitor resolution, for tools this
227 // is a good strategy but maybe games prefer to keep current canvas resolution and
228 // display it in fullscreen, adjusting monitor resolution if possible
229 if (document.fullscreenElement) document.exitFullscreen();
230 else Module.requestFullscreen(true, true); //false, true);
231 );
232 */
233 // EM_ASM(Module.requestFullscreen(false, false););
234 /*
235 if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
236 {
237 // Option 1: Request fullscreen for the canvas element
238 // This option does not seem to work at all:
239 // emscripten_request_pointerlock() and emscripten_request_fullscreen() are affected by web security,
240 // the user must click once on the canvas to hide the pointer or transition to full screen
241 //emscripten_request_fullscreen(platform.canvasId, false);
242
243 // Option 2: Request fullscreen for the canvas element with strategy
244 // This option does not seem to work at all
245 // REF: https://github.com/emscripten-core/emscripten/issues/5124
246 // EmscriptenFullscreenStrategy strategy = {
247 // .scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH, //EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT,
248 // .canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF,
249 // .filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT,
250 // .canvasResizedCallback = EmscriptenWindowResizedCallback,
251 // .canvasResizedCallbackUserData = NULL
252 // };
253 //emscripten_request_fullscreen_strategy(platform.canvasId, EM_FALSE, &strategy);
254
255 // Option 3: Request fullscreen for the canvas element with strategy
256 // It works as expected but only inside the browser (client area)
257 EmscriptenFullscreenStrategy strategy = {
258 .scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT,
259 .canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF,
260 .filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT,
261 .canvasResizedCallback = EmscriptenWindowResizedCallback,
262 .canvasResizedCallbackUserData = NULL
263 };
264 emscripten_enter_soft_fullscreen(platform.canvasId, &strategy);
265
266 int width = 0;
267 int height = 0;
268 emscripten_get_canvas_element_size(platform.canvasId, &width, &height);
269 TRACELOG(LOG_WARNING, "Emscripten: Enter fullscreen: Canvas size: %i x %i", width, height);
270
271 FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
272 }
273 else
274 {
275 //emscripten_exit_fullscreen();
276 //emscripten_exit_soft_fullscreen();
277
278 int width, height;
279 emscripten_get_canvas_element_size(platform.canvasId, &width, &height);
280 TRACELOG(LOG_WARNING, "Emscripten: Exit fullscreen: Canvas size: %i x %i", width, height);
281
282 FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
283 }
284 */
285 }
286
287 // Toggle borderless windowed mode
288 void ToggleBorderlessWindowed(void)
289 {
290 platform.ourFullscreen = true;
291 bool enterBorderless = false;
292
293 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
294 if (wasFullscreen)
295 {
296 if (FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) enterBorderless = false;
297 else if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) enterBorderless = true;
298 else
299 {
300 const int canvasWidth = EM_ASM_INT( { return Module.canvas.width; }, 0);
301 const int screenWidth = EM_ASM_INT( { return screen.width; }, 0);
302 if (screenWidth == canvasWidth) enterBorderless = false;
303 else enterBorderless = true;
304 }
305
306 EM_ASM(document.exitFullscreen(););
307
308 FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
309 FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
310 }
311 else enterBorderless = true;
312
313 if (enterBorderless)
314 {
315 // 1. The setTimeouts handle the browser mode change delay
316 // 2. The style unset handles the possibility of a width="value%" like on the default shell.html file
317 EM_ASM
318 (
319 const canvasId = UTF8ToString($0);
320 setTimeout(function()
321 {
322 Module.requestFullscreen(false, true);
323 setTimeout(function()
324 {
325 document.querySelector(canvasId).style.width="unset";
326 }, 100);
327 }, 100);
328 , platform.canvasId);
329 FLAG_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
330 }
331 }
332
333 // Set window state: maximized, if resizable
334 void MaximizeWindow(void)
335 {
336 if ((glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) && !(FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)))
337 {
338 platform.unmaximizedWidth = CORE.Window.screen.width;
339 platform.unmaximizedHeight = CORE.Window.screen.height;
340
341 const int tabWidth = EM_ASM_INT( return window.innerWidth; );
342 const int tabHeight = EM_ASM_INT( return window.innerHeight; );
343
344 if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight);
345
346 FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED);
347 }
348 }
349
350 // Set window state: minimized
351 void MinimizeWindow(void)
352 {
353 TRACELOG(LOG_WARNING, "MinimizeWindow() not available on target platform");
354 }
355
356 // Restore window from being minimized/maximized
357 void RestoreWindow(void)
358 {
359 if ((glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) && (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)))
360 {
361 if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight);
362
363 FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED);
364 }
365 }
366
367 // Set window configuration state using flags
368 void SetWindowState(unsigned int flags)
369 {
370 if (!CORE.Window.ready) TRACELOG(LOG_WARNING, "WINDOW: SetWindowState does nothing before window initialization, Use \"SetConfigFlags\" instead");
371
372 // Check previous state and requested state to apply required changes
373 // NOTE: In most cases the functions already change the flags internally
374
375 // State change: FLAG_VSYNC_HINT
376 if (FLAG_IS_SET(flags, FLAG_VSYNC_HINT))
377 {
378 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_VSYNC_HINT) not available on target platform");
379 }
380
381 // State change: FLAG_BORDERLESS_WINDOWED_MODE
382 if (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE))
383 {
384 // NOTE: Window state flag updated inside ToggleBorderlessWindowed() function
385 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
386 if (wasFullscreen)
387 {
388 const int canvasWidth = EM_ASM_INT( { return Module.canvas.width; }, 0);
389 const int canvasStyleWidth = EM_ASM_INT( { return parseInt(Module.canvas.style.width); }, 0);
390 if ((FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) || canvasStyleWidth > canvasWidth) ToggleBorderlessWindowed();
391 }
392 else ToggleBorderlessWindowed();
393 }
394
395 // State change: FLAG_FULLSCREEN_MODE
396 if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE))
397 {
398 // NOTE: Window state flag updated inside ToggleFullscreen() function
399 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
400 if (wasFullscreen)
401 {
402 const int canvasWidth = EM_ASM_INT( { return Module.canvas.width; }, 0);
403 const int screenWidth = EM_ASM_INT( { return screen.width; }, 0);
404 if ((FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) || screenWidth == canvasWidth ) ToggleFullscreen();
405 }
406 else ToggleFullscreen();
407 }
408
409 // State change: FLAG_WINDOW_RESIZABLE
410 if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE) != FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)) && (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)))
411 {
412 glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE);
413 FLAG_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE);
414 }
415
416 // State change: FLAG_WINDOW_UNDECORATED
417 if (FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED))
418 {
419 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_UNDECORATED) not available on target platform");
420 }
421
422 // State change: FLAG_WINDOW_HIDDEN
423 if (FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN))
424 {
425 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_HIDDEN) not available on target platform");
426 }
427
428 // State change: FLAG_WINDOW_MINIMIZED
429 if (FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED))
430 {
431 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MINIMIZED) not available on target platform");
432 }
433
434 // State change: FLAG_WINDOW_MAXIMIZED
435 if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED) != FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)) && (FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)))
436 {
437 if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
438 {
439 platform.unmaximizedWidth = CORE.Window.screen.width;
440 platform.unmaximizedHeight = CORE.Window.screen.height;
441
442 const int tabWidth = EM_ASM_INT( return window.innerWidth; );
443 const int tabHeight = EM_ASM_INT( return window.innerHeight; );
444
445 if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight);
446
447 FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED);
448 }
449 }
450
451 // State change: FLAG_WINDOW_UNFOCUSED
452 if (FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED))
453 {
454 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_UNFOCUSED) not available on target platform");
455 }
456
457 // State change: FLAG_WINDOW_TOPMOST
458 if (FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST))
459 {
460 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_TOPMOST) not available on target platform");
461 }
462
463 // State change: FLAG_WINDOW_ALWAYS_RUN
464 if (FLAG_IS_SET(flags, FLAG_WINDOW_ALWAYS_RUN))
465 {
466 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_ALWAYS_RUN) not available on target platform");
467 }
468
469 // The following states can not be changed after window creation
470 // NOTE: Review for PLATFORM_WEB
471
472 // State change: FLAG_WINDOW_TRANSPARENT
473 if (FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT))
474 {
475 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_TRANSPARENT) not available on target platform");
476 }
477
478 // State change: FLAG_WINDOW_HIGHDPI
479 if (FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI))
480 {
481 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_HIGHDPI) not available on target platform");
482 }
483
484 // State change: FLAG_WINDOW_MOUSE_PASSTHROUGH
485 if (FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH))
486 {
487 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MOUSE_PASSTHROUGH) not available on target platform");
488 }
489
490 // State change: FLAG_MSAA_4X_HINT
491 if (FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT))
492 {
493 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_MSAA_4X_HINT) not available on target platform");
494 }
495
496 // State change: FLAG_INTERLACED_HINT
497 if (FLAG_IS_SET(flags, FLAG_INTERLACED_HINT))
498 {
499 TRACELOG(LOG_WARNING, "SetWindowState(FLAG_INTERLACED_HINT) not available on target platform");
500 }
501 }
502
503 // Clear window configuration state flags
504 void ClearWindowState(unsigned int flags)
505 {
506 // Check previous state and requested state to apply required changes
507 // NOTE: In most cases the functions already change the flags internally
508
509 // State change: FLAG_VSYNC_HINT
510 if (FLAG_IS_SET(flags, FLAG_VSYNC_HINT))
511 {
512 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_VSYNC_HINT) not available on target platform");
513 }
514
515 // State change: FLAG_BORDERLESS_WINDOWED_MODE
516 if (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE))
517 {
518 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
519 if (wasFullscreen)
520 {
521 const int canvasWidth = EM_ASM_INT( { return Module.canvas.width; }, 0);
522 const int screenWidth = EM_ASM_INT( { return screen.width; }, 0);
523 if (FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE) || (screenWidth == canvasWidth)) EM_ASM(document.exitFullscreen(););
524 }
525
526 FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
527 }
528
529 // State change: FLAG_FULLSCREEN_MODE
530 if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE))
531 {
532 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
533 if (wasFullscreen)
534 {
535 const int canvasWidth = EM_ASM_INT( { return Module.canvas.width; }, 0);
536 const int canvasStyleWidth = EM_ASM_INT( { return parseInt(Module.canvas.style.width); }, 0);
537 if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE) || (canvasStyleWidth > canvasWidth)) EM_ASM(document.exitFullscreen(););
538 }
539
540 FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
541 }
542
543 // State change: FLAG_WINDOW_RESIZABLE
544 if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) && (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)))
545 {
546 glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE);
547 FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_RESIZABLE);
548 }
549
550 // State change: FLAG_WINDOW_HIDDEN
551 if (FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN))
552 {
553 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_HIDDEN) not available on target platform");
554 }
555
556 // State change: FLAG_WINDOW_MINIMIZED
557 if (FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED))
558 {
559 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MINIMIZED) not available on target platform");
560 }
561
562 // State change: FLAG_WINDOW_MAXIMIZED
563 if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)) && (FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)))
564 {
565 if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
566 {
567 if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight);
568
569 FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED);
570 }
571 }
572
573 // State change: FLAG_WINDOW_UNDECORATED
574 if (FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED))
575 {
576 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_UNDECORATED) not available on target platform");
577 }
578
579 // State change: FLAG_WINDOW_UNFOCUSED
580 if (FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED))
581 {
582 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_UNFOCUSED) not available on target platform");
583 }
584
585 // State change: FLAG_WINDOW_TOPMOST
586 if (FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST))
587 {
588 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_TOPMOST) not available on target platform");
589 }
590
591 // State change: FLAG_WINDOW_ALWAYS_RUN
592 if (FLAG_IS_SET(flags, FLAG_WINDOW_ALWAYS_RUN))
593 {
594 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_ALWAYS_RUN) not available on target platform");
595 }
596
597 // The following states can not be changed after window creation
598 // NOTE: Review for PLATFORM_WEB
599
600 // State change: FLAG_WINDOW_TRANSPARENT
601 if (FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT))
602 {
603 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_TRANSPARENT) not available on target platform");
604 }
605
606 // State change: FLAG_WINDOW_HIGHDPI
607 if (FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI))
608 {
609 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_HIGHDPI) not available on target platform");
610 }
611
612 // State change: FLAG_WINDOW_MOUSE_PASSTHROUGH
613 if (FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH))
614 {
615 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MOUSE_PASSTHROUGH) not available on target platform");
616 }
617
618 // State change: FLAG_MSAA_4X_HINT
619 if (FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT))
620 {
621 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_MSAA_4X_HINT) not available on target platform");
622 }
623
624 // State change: FLAG_INTERLACED_HINT
625 if (FLAG_IS_SET(flags, FLAG_INTERLACED_HINT))
626 {
627 TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_INTERLACED_HINT) not available on target platform");
628 }
629 }
630
631 // Set icon for window
632 void SetWindowIcon(Image image)
633 {
634 TRACELOG(LOG_WARNING, "SetWindowIcon() not available on target platform");
635 }
636
637 // Set icon for window, multiple images
638 void SetWindowIcons(Image *images, int count)
639 {
640 TRACELOG(LOG_WARNING, "SetWindowIcons() not available on target platform");
641 }
642
643 // Set title for window
644 void SetWindowTitle(const char *title)
645 {
646 CORE.Window.title = title;
647 emscripten_set_window_title(title);
648 }
649
650 // Set window position on screen (windowed mode)
651 void SetWindowPosition(int x, int y)
652 {
653 TRACELOG(LOG_WARNING, "SetWindowPosition() not available on target platform");
654 }
655
656 // Set monitor for the current window
657 void SetWindowMonitor(int monitor)
658 {
659 TRACELOG(LOG_WARNING, "SetWindowMonitor() not available on target platform");
660 }
661
662 // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
663 void SetWindowMinSize(int width, int height)
664 {
665 CORE.Window.screenMin.width = width;
666 CORE.Window.screenMin.height = height;
667
668 // Trigger the resize event once to update the window minimum width and height
669 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
670 }
671
672 // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
673 void SetWindowMaxSize(int width, int height)
674 {
675 CORE.Window.screenMax.width = width;
676 CORE.Window.screenMax.height = height;
677
678 // Trigger the resize event once to update the window maximum width and height
679 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
680 }
681
682 // Set window dimensions
683 void SetWindowSize(int width, int height)
684 {
685 glfwSetWindowSize(platform.handle, width, height);
686 }
687
688 // Set window opacity, value opacity is between 0.0 and 1.0
689 void SetWindowOpacity(float opacity)
690 {
691 if (opacity >= 1.0f) opacity = 1.0f;
692 else if (opacity <= 0.0f) opacity = 0.0f;
693 EM_ASM({ Module.canvas.style.opacity = $0; }, opacity);
694 }
695
696 // Set window focused
697 void SetWindowFocused(void)
698 {
699 TRACELOG(LOG_WARNING, "SetWindowFocused() not available on target platform");
700 }
701
702 // Get native window handle
703 void *GetWindowHandle(void)
704 {
705 TRACELOG(LOG_WARNING, "GetWindowHandle() not implemented on target platform");
706 return NULL;
707 }
708
709 // Get number of monitors
710 int GetMonitorCount(void)
711 {
712 TRACELOG(LOG_WARNING, "GetMonitorCount() not implemented on target platform");
713 return 1;
714 }
715
716 // Get current monitor where window is placed
717 int GetCurrentMonitor(void)
718 {
719 TRACELOG(LOG_WARNING, "GetCurrentMonitor() not implemented on target platform");
720 return 0;
721 }
722
723 // Get selected monitor position
724 Vector2 GetMonitorPosition(int monitor)
725 {
726 TRACELOG(LOG_WARNING, "GetMonitorPosition() not implemented on target platform");
727 return (Vector2){ 0, 0 };
728 }
729
730 // Get selected monitor width (currently used by monitor)
731 int GetMonitorWidth(int monitor)
732 {
733 // NOTE: Returned value is limited to the current monitor where the browser window is located
734 int width = 0;
735 width = EM_ASM_INT( { return screen.width; }, 0);
736 return width;
737 }
738
739 // Get selected monitor height (currently used by monitor)
740 int GetMonitorHeight(int monitor)
741 {
742 // NOTE: Returned value is limited to the current monitor where the browser window is located
743 int height = 0;
744 height = EM_ASM_INT( { return screen.height; }, 0);
745 return height;
746 }
747
748 // Get selected monitor physical width in millimetres
749 int GetMonitorPhysicalWidth(int monitor)
750 {
751 TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth() not implemented on target platform");
752 return 0;
753 }
754
755 // Get selected monitor physical height in millimetres
756 int GetMonitorPhysicalHeight(int monitor)
757 {
758 TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight() not implemented on target platform");
759 return 0;
760 }
761
762 // Get selected monitor refresh rate
763 int GetMonitorRefreshRate(int monitor)
764 {
765 TRACELOG(LOG_WARNING, "GetMonitorRefreshRate() not implemented on target platform");
766 return 0;
767 }
768
769 // Get the human-readable, UTF-8 encoded name of the selected monitor
770 const char *GetMonitorName(int monitor)
771 {
772 TRACELOG(LOG_WARNING, "GetMonitorName() not implemented on target platform");
773 return "";
774 }
775
776 // Get window position XY on monitor
777 Vector2 GetWindowPosition(void)
778 {
779 // NOTE: Returned position is relative to the current monitor where the browser window is located
780 Vector2 position = { 0, 0 };
781 position.x = (float)EM_ASM_INT( { return window.screenX; }, 0);
782 position.y = (float)EM_ASM_INT( { return window.screenY; }, 0);
783 return position;
784 }
785
786 // Get window scale DPI factor for current monitor
787 Vector2 GetWindowScaleDPI(void)
788 {
789 // NOTE: Returned scale is relative to the current monitor where the browser window is located
790 Vector2 scale = { 1.0f, 1.0f };
791 scale.x = (float)EM_ASM_DOUBLE( { return window.devicePixelRatio; } );
792 scale.y = scale.x;
793 return scale;
794 }
795
796 // Set clipboard text content
797 void SetClipboardText(const char *text)
798 {
799 // Security check to (partially) avoid malicious code
800 if (strchr(text, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided Clipboard could be potentially malicious, avoid [\'] character");
801 else EM_ASM({ navigator.clipboard.writeText(UTF8ToString($0)); }, text);
802 }
803
804 // Async EM_JS to be able to await clickboard read asynchronous function
805 EM_ASYNC_JS(void, RequestClipboardData, (void), {
806 if (navigator.clipboard && window.isSecureContext)
807 {
808 let items = await navigator.clipboard.read();
809 for (const item of items)
810 {
811 // Check if this item contains plain text or image
812 if (item.types.includes("text/plain"))
813 {
814 const blob = await item.getType("text/plain");
815 const text = await blob.text();
816 window._lastClipboardString = text;
817 }
818 else if (item.types.find(t => t.startsWith("image/")))
819 {
820 const blob = await item.getType(item.types.find(t => t.startsWith("image/")));
821 const bitmap = await createImageBitmap(blob);
822
823 const canvas = document.createElement('canvas');
824 canvas.width = bitmap.width;
825 canvas.height = bitmap.height;
826 const ctx = canvas.getContext('2d');
827 ctx.drawImage(bitmap, 0, 0);
828
829 const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
830
831 // Store image and data for the Fetch function
832 window._lastImgWidth = canvas.width;
833 window._lastImgHeight = canvas.height;
834 window._lastImgData = imgData;
835 }
836 }
837 }
838 else console.warn("Clipboard read() requires HTTPS/Localhost");
839 });
840
841 // Returns the string created by RequestClipboardData from JS memory to Emscripten C memory
842 EM_JS(char *, GetLastPastedText, (void), {
843 var str = window._lastClipboardString || "";
844 var length = lengthBytesUTF8(str) + 1;
845 if (length > 1)
846 {
847 var ptr = _malloc(length);
848 stringToUTF8(str, ptr, length);
849 return ptr;
850 }
851 return 0;
852 });
853
854 // Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
855 EM_JS(unsigned char *, GetLastPastedImage, (int *width, int *height), {
856 if (window._lastImgData)
857 {
858 const data = window._lastImgData;
859 if (data.length > 0)
860 {
861 const ptr = _malloc(data.length);
862 HEAPU8.set(data, ptr);
863
864 // Set the width and height via the pointers passed from C
865 // HEAP32 handles the 4-byte integers
866 if (width) setValue(width, window._lastImgWidth, 'i32');
867 if (height) setValue(height, window._lastImgHeight, 'i32');
868
869 // Clear the JS buffer so there is no need to fetch the same image twice
870 window._lastImgData = null;
871
872 return ptr;
873 }
874 }
875
876 return 0;
877 });
878
879 // Get clipboard text content
880 // NOTE: returned string is allocated and freed by GLFW
881 const char *GetClipboardText(void)
882 {
883 RequestClipboardData();
884 return GetLastPastedText();
885 }
886
887 // Get clipboard image
888 Image GetClipboardImage(void)
889 {
890 Image image = { 0 };
891 int w = 0, h = 0;
892 RequestClipboardData();
893 unsigned char* data = GetLastPastedImage(&w, &h);
894 if (data != NULL) {
895 image.data = data;
896 image.width = w;
897 image.height = h;
898 image.mipmaps = 1;
899 image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
900 }
901
902 return image;
903 }
904
905 // Show mouse cursor
906 void ShowCursor(void)
907 {
908 if (CORE.Input.Mouse.cursorHidden)
909 {
910 EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[CORE.Input.Mouse.cursor]);
911
912 CORE.Input.Mouse.cursorHidden = false;
913 }
914 }
915
916 // Hides mouse cursor
917 void HideCursor(void)
918 {
919 if (!CORE.Input.Mouse.cursorHidden)
920 {
921 EM_ASM(Module.canvas.style.cursor = 'none';);
922
923 CORE.Input.Mouse.cursorHidden = true;
924 }
925 }
926
927 // Enables cursor (unlock cursor)
928 void EnableCursor(void)
929 {
930 emscripten_exit_pointerlock();
931
932 // Set cursor position in the middle
933 SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
934
935 // NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback()
936 }
937
938 // Disables cursor (lock cursor)
939 void DisableCursor(void)
940 {
941 emscripten_request_pointerlock(platform.canvasId, 1);
942
943 // Set cursor position in the middle
944 SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
945
946 // NOTE: CORE.Input.Mouse.cursorLocked handled by EmscriptenPointerlockCallback()
947 }
948
949 // Swap back buffer with front buffer (screen drawing)
950 void SwapScreenBuffer(void)
951 {
952 #if defined(GRAPHICS_API_OPENGL_SOFTWARE)
953 // Update framebuffer
954 rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, platform.pixels);
955
956 // Copy framebuffer data into canvas
957 EM_ASM({
958 const width = $0;
959 const height = $1;
960 const ptr = $2;
961
962 // Get canvas and 2d context created
963 const canvas = Module.canvas;
964 const ctx = canvas.getContext('2d');
965
966 if (!Module.__img || (Module.__img.width !== width) || (Module.__img.height !== height))
967 {
968 Module.__img = ctx.createImageData(width, height);
969 }
970
971 const src = HEAPU8.subarray(ptr, ptr + width*height*4); // RGBA (4 bytes)
972 Module.__img.data.set(src);
973 ctx.putImageData(Module.__img, 0, 0);
974
975 }, CORE.Window.screen.width, CORE.Window.screen.height, platform.pixels);
976 #else
977 glfwSwapBuffers(platform.handle);
978 #endif
979 }
980
981 //----------------------------------------------------------------------------------
982 // Module Functions Definition: Misc
983 //----------------------------------------------------------------------------------
984
985 // Get elapsed time measure in seconds since InitTimer()
986 double GetTime(void)
987 {
988 double time = glfwGetTime(); // Elapsed time since glfwInit()
989
990 return time;
991 }
992
993 // Open URL with default system browser (if available)
994 // NOTE: This function is only safe to use if the provided URL is safe
995 // A user could craft a malicious string performing another action
996 // Avoid calling this function with user input non-validated strings
997 void OpenURL(const char *url)
998 {
999 // Security check to (partially) avoid malicious code on target platform
1000 if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character");
1001 else emscripten_run_script(TextFormat("window.open('%s', '_blank')", url));
1002 }
1003
1004 //----------------------------------------------------------------------------------
1005 // Module Functions Definition: Inputs
1006 //----------------------------------------------------------------------------------
1007
1008 // Set internal gamepad mappings
1009 int SetGamepadMappings(const char *mappings)
1010 {
1011 TRACELOG(LOG_INFO, "SetGamepadMappings not implemented in rcore_web.c");
1012
1013 return 0;
1014 }
1015
1016 // Set gamepad vibration
1017 void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
1018 {
1019 if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (duration > 0.0f))
1020 {
1021 if (leftMotor < 0.0f) leftMotor = 0.0f;
1022 if (leftMotor > 1.0f) leftMotor = 1.0f;
1023 if (rightMotor < 0.0f) rightMotor = 0.0f;
1024 if (rightMotor > 1.0f) rightMotor = 1.0f;
1025 if (duration > MAX_GAMEPAD_VIBRATION_TIME) duration = MAX_GAMEPAD_VIBRATION_TIME;
1026 duration *= 1000.0f; // Convert duration to ms
1027
1028 // NOTE: At the moment (2024.10.21) Chrome, Edge, Opera, Safari, Android Chrome, Android Webview only support the vibrationActuator API,
1029 // and Firefox only supports the hapticActuators API
1030 EM_ASM({
1031 try
1032 {
1033 navigator.getGamepads()[$0].vibrationActuator.playEffect('dual-rumble', { startDelay: 0, duration: $3, weakMagnitude: $1, strongMagnitude: $2 });
1034 }
1035 catch (e)
1036 {
1037 try
1038 {
1039 navigator.getGamepads()[$0].hapticActuators[0].pulse($2, $3);
1040 }
1041 catch (e) { }
1042 }
1043 }, gamepad, leftMotor, rightMotor, duration);
1044 }
1045 }
1046
1047 // Set mouse position XY
1048 void SetMousePosition(int x, int y)
1049 {
1050 CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
1051 CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
1052
1053 if (CORE.Input.Mouse.cursorLocked) CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition;
1054
1055 // NOTE: emscripten not implemented
1056 glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y);
1057 }
1058
1059 // Set mouse cursor
1060 void SetMouseCursor(int cursor)
1061 {
1062 if (CORE.Input.Mouse.cursor != cursor)
1063 {
1064 if (!CORE.Input.Mouse.cursorLocked) EM_ASM( { Module.canvas.style.cursor = UTF8ToString($0); }, cursorLUT[cursor]);
1065
1066 CORE.Input.Mouse.cursor = cursor;
1067 }
1068 }
1069
1070 // Get physical key name
1071 const char *GetKeyName(int key)
1072 {
1073 TRACELOG(LOG_WARNING, "GetKeyName() not implemented on target platform");
1074 return "";
1075 }
1076
1077 // Register all input events
1078 void PollInputEvents(void)
1079 {
1080 #if SUPPORT_GESTURES_SYSTEM
1081 // NOTE: Gestures update must be called every frame to reset gestures correctly
1082 // because ProcessGestureEvent() is called on an event, not every frame
1083 UpdateGestures();
1084 #endif
1085
1086 // Reset keys/chars pressed registered
1087 CORE.Input.Keyboard.keyPressedQueueCount = 0;
1088 CORE.Input.Keyboard.charPressedQueueCount = 0;
1089
1090 // Reset last gamepad button/axis registered state
1091 CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
1092 //CORE.Input.Gamepad.axisCount = 0;
1093
1094 // Keyboard/Mouse input polling (automatically managed by GLFW3 through callback)
1095
1096 // Register previous keys states
1097 for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
1098 {
1099 CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i];
1100 CORE.Input.Keyboard.keyRepeatInFrame[i] = 0;
1101 }
1102
1103 // Register previous mouse states
1104 for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i];
1105
1106 // Register previous mouse wheel state
1107 CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove;
1108 CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f };
1109
1110 // Register previous mouse position
1111 CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
1112
1113 // Register previous touch states
1114 for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
1115
1116 // Reset touch positions
1117 // TODO: It resets on target platform the mouse position and not filled again until a move-event,
1118 // so, if mouse is not moved it returns a (0, 0) position... this behaviour should be reviewed!
1119 //for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.position[i] = (Vector2){ 0, 0 };
1120
1121 // Gamepad support using emscripten API
1122 // NOTE: GLFW3 joystick functionality not available in web
1123
1124 // Get number of gamepads connected
1125 int numGamepads = 0;
1126 if (emscripten_sample_gamepad_data() == EMSCRIPTEN_RESULT_SUCCESS) numGamepads = emscripten_get_num_gamepads();
1127
1128 for (int i = 0; (i < numGamepads) && (i < MAX_GAMEPADS); i++)
1129 {
1130 // Register previous gamepad button states
1131 for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k];
1132
1133 EmscriptenGamepadEvent gamepadState;
1134
1135 int result = emscripten_get_gamepad_status(i, &gamepadState);
1136
1137 if (result == EMSCRIPTEN_RESULT_SUCCESS)
1138 {
1139 // Register buttons data for every connected gamepad
1140 for (int j = 0; (j < gamepadState.numButtons) && (j < MAX_GAMEPAD_BUTTONS); j++)
1141 {
1142 GamepadButton button = -1;
1143
1144 // Gamepad Buttons reference: https://www.w3.org/TR/gamepad/#gamepad-interface
1145 switch (j)
1146 {
1147 case 0: button = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; break;
1148 case 1: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break;
1149 case 2: button = GAMEPAD_BUTTON_RIGHT_FACE_LEFT; break;
1150 case 3: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break;
1151 case 4: button = GAMEPAD_BUTTON_LEFT_TRIGGER_1; break;
1152 case 5: button = GAMEPAD_BUTTON_RIGHT_TRIGGER_1; break;
1153 case 6: button = GAMEPAD_BUTTON_LEFT_TRIGGER_2; break;
1154 case 7: button = GAMEPAD_BUTTON_RIGHT_TRIGGER_2; break;
1155 case 8: button = GAMEPAD_BUTTON_MIDDLE_LEFT; break;
1156 case 9: button = GAMEPAD_BUTTON_MIDDLE_RIGHT; break;
1157 case 10: button = GAMEPAD_BUTTON_LEFT_THUMB; break;
1158 case 11: button = GAMEPAD_BUTTON_RIGHT_THUMB; break;
1159 case 12: button = GAMEPAD_BUTTON_LEFT_FACE_UP; break;
1160 case 13: button = GAMEPAD_BUTTON_LEFT_FACE_DOWN; break;
1161 case 14: button = GAMEPAD_BUTTON_LEFT_FACE_LEFT; break;
1162 case 15: button = GAMEPAD_BUTTON_LEFT_FACE_RIGHT; break;
1163 default: break;
1164 }
1165
1166 if (button + 1 != 0) // Check for valid button
1167 {
1168 if (gamepadState.digitalButton[j] == 1)
1169 {
1170 CORE.Input.Gamepad.currentButtonState[i][button] = 1;
1171 CORE.Input.Gamepad.lastButtonPressed = button;
1172 }
1173 else CORE.Input.Gamepad.currentButtonState[i][button] = 0;
1174 }
1175
1176 //TRACELOG(LOG_DEBUG, "INPUT: Gamepad %d, button %d: Digital: %d, Analog: %g", gamepadState.index, j, gamepadState.digitalButton[j], gamepadState.analogButton[j]);
1177 }
1178
1179 // Register axis data for every connected gamepad
1180 for (int j = 0; (j < gamepadState.numAxes) && (j < MAX_GAMEPAD_AXES); j++)
1181 {
1182 CORE.Input.Gamepad.axisState[i][j] = gamepadState.axis[j];
1183 }
1184
1185 CORE.Input.Gamepad.axisCount[i] = gamepadState.numAxes;
1186 }
1187 }
1188
1189 CORE.Window.resizedLastFrame = false;
1190 }
1191
1192 //----------------------------------------------------------------------------------
1193 // Module Internal Functions Definition
1194 //----------------------------------------------------------------------------------
1195
1196 // Initialize platform: graphics, inputs and more
1197 int InitPlatform(void)
1198 {
1199 SetCanvasIdJs(platform.canvasId, 64); // Get the current canvas id
1200
1201 glfwSetErrorCallback(ErrorCallback);
1202
1203 // Initialize GLFW internal global state
1204 int result = glfwInit();
1205 if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; }
1206
1207 // Initialize graphic device: display/window and graphic context
1208 //----------------------------------------------------------------------------
1209 glfwDefaultWindowHints(); // Set default windows hints
1210 // glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
1211 // glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
1212 // glfwWindowHint(GLFW_BLUE_BITS, 8); // Framebuffer blue color component bits
1213 // glfwWindowHint(GLFW_ALPHA_BITS, 8); // Framebuffer alpha color component bits
1214 // glfwWindowHint(GLFW_DEPTH_BITS, 24); // Depthbuffer bits
1215 // glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window
1216 // glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); // OpenGL API to use. Alternative: GLFW_OPENGL_ES_API
1217 // glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
1218
1219 // Check window creation flags
1220 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Visible window
1221 else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); // Window initially hidden
1222
1223 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED)) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window
1224 else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window
1225
1226 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window
1227 else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable
1228
1229 // Disable FLAG_WINDOW_MINIMIZED, not supported on initialization
1230 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED);
1231
1232 // Disable FLAG_WINDOW_MAXIMIZED, not supported on initialization
1233 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED);
1234
1235 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
1236 else glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE);
1237
1238 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TOPMOST)) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
1239 else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
1240
1241 // NOTE: Some GLFW flags are not supported on HTML5
1242 // e.g.: GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_MOUSE_PASSTHROUGH
1243
1244 // Scale content area based on the monitor content scale where window is placed on
1245 // NOTE: This feature requires emscripten 3.1.51
1246 //if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
1247 //else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE);
1248
1249 if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT))
1250 {
1251 // NOTE: MSAA is only enabled for main framebuffer, not user-created FBOs
1252 TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4");
1253 glfwWindowHint(GLFW_SAMPLES, 4); // Tries to enable multisampling x4 (MSAA), default is 0
1254 }
1255
1256 // NOTE: When asking for an OpenGL context version, most drivers provide the highest supported version
1257 // with backward compatibility to older OpenGL versions
1258 // For example, if using OpenGL 1.1, driver can provide a 4.3 backwards compatible context
1259
1260 // Check selection OpenGL version
1261 if (rlGetVersion() == RL_OPENGL_21)
1262 {
1263 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // Choose OpenGL major version (just hint)
1264 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // Choose OpenGL minor version (just hint)
1265 }
1266 else if (rlGetVersion() == RL_OPENGL_33)
1267 {
1268 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Choose OpenGL major version (just hint)
1269 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint)
1270 // Profiles Hint, only OpenGL 3.3 and above
1271 // Possible values: GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE
1272 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
1273
1274 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE); // Forward Compatibility Hint: Only 3.3 and above!
1275 // glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // Request OpenGL DEBUG context
1276 }
1277 else if (rlGetVersion() == RL_OPENGL_43)
1278 {
1279 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // Choose OpenGL major version (just hint)
1280 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint)
1281 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
1282 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE);
1283 #if RLGL_ENABLE_OPENGL_DEBUG_CONTEXT
1284 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // Enable OpenGL Debug Context
1285 #endif
1286 }
1287 else if (rlGetVersion() == RL_OPENGL_ES_20) // Request OpenGL ES 2.0 context
1288 {
1289 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
1290 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
1291 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
1292 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
1293 }
1294 else if (rlGetVersion() == RL_OPENGL_ES_30) // Request OpenGL ES 3.0 context
1295 {
1296 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
1297 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
1298 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
1299 glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
1300 }
1301
1302 // NOTE: Getting video modes is not implemented in emscripten GLFW3 version
1303 CORE.Window.display.width = CORE.Window.screen.width;
1304 CORE.Window.display.height = CORE.Window.screen.height;
1305
1306 // Init fullscreen toggle required var:
1307 platform.ourFullscreen = false;
1308
1309 #if defined(GRAPHICS_API_OPENGL_SOFTWARE)
1310 // Avoid creating a WebGL canvas, avoid calling glfwCreateWindow()
1311 emscripten_set_canvas_element_size(platform.canvasId, CORE.Window.screen.width, CORE.Window.screen.height);
1312 EM_ASM({
1313 const canvas = document.querySelector(UTF8ToString($0));
1314 Module.canvas = canvas;
1315 }, platform.canvasId);
1316
1317 // Load memory framebuffer with desired screen size
1318 // NOTE: Despite using a software framebuffer for blitting, GLFW still creates a WebGL canvas,
1319 // but it is not being used, on SwapScreenBuffer() the pure software renderer is used
1320 // TODO: Consider requesting another type of canvas, not a WebGL one --> Replace GLFW-web by Emscripten?
1321 platform.pixels = (unsigned int *)RL_CALLOC(CORE.Window.screen.width*CORE.Window.screen.height, sizeof(unsigned int));
1322 #else
1323 if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
1324 {
1325 // Remember center for switchinging from fullscreen to window
1326 if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width))
1327 {
1328 // If screen width/height equal to the display, it's not possible to
1329 // calculate the window position for toggling full-screened/windowed
1330 CORE.Window.position.x = CORE.Window.display.width/4;
1331 CORE.Window.position.y = CORE.Window.display.height/4;
1332 }
1333 else
1334 {
1335 CORE.Window.position.x = CORE.Window.display.width/2 - CORE.Window.screen.width/2;
1336 CORE.Window.position.y = CORE.Window.display.height/2 - CORE.Window.screen.height/2;
1337 }
1338
1339 if (CORE.Window.position.x < 0) CORE.Window.position.x = 0;
1340 if (CORE.Window.position.y < 0) CORE.Window.position.y = 0;
1341
1342 // Obtain recommended CORE.Window.display.width/CORE.Window.display.height from a valid videomode for the monitor
1343 int count = 0;
1344 const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count);
1345
1346 // Get closest video mode to desired CORE.Window.screen.width/CORE.Window.screen.height
1347 for (int i = 0; i < count; i++)
1348 {
1349 if ((unsigned int)modes[i].width >= CORE.Window.screen.width)
1350 {
1351 if ((unsigned int)modes[i].height >= CORE.Window.screen.height)
1352 {
1353 CORE.Window.display.width = modes[i].width;
1354 CORE.Window.display.height = modes[i].height;
1355 break;
1356 }
1357 }
1358 }
1359
1360 TRACELOG(LOG_WARNING, "SYSTEM: Closest fullscreen videomode: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
1361
1362 platform.handle = glfwCreateWindow(CORE.Window.display.width, CORE.Window.display.height, (CORE.Window.title != 0)? CORE.Window.title : " ", glfwGetPrimaryMonitor(), NULL);
1363
1364 // NOTE: Full-screen change, not working properly...
1365 // glfwSetWindowMonitor(platform.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
1366 }
1367 else
1368 {
1369 // No-fullscreen window creation
1370 platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL);
1371
1372 if (platform.handle)
1373 {
1374 CORE.Window.render.width = CORE.Window.screen.width;
1375 CORE.Window.render.height = CORE.Window.screen.height;
1376 }
1377 }
1378
1379 if (!platform.handle)
1380 {
1381 glfwTerminate();
1382 TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window");
1383 return -1;
1384 }
1385 #endif
1386
1387 // WARNING: glfwCreateWindow() title doesn't work with emscripten
1388 emscripten_set_window_title((CORE.Window.title != 0)? CORE.Window.title : " ");
1389
1390 // Set window callback events
1391 glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback);
1392 glfwSetWindowIconifyCallback(platform.handle, WindowIconifyCallback);
1393 glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback);
1394 glfwSetDropCallback(platform.handle, WindowDropCallback);
1395
1396 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
1397 {
1398 // Window content (framebuffer) scale callback
1399 glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback);
1400 }
1401
1402 // Set input callback events
1403 glfwSetKeyCallback(platform.handle, KeyCallback);
1404 glfwSetCharCallback(platform.handle, CharCallback);
1405 glfwSetMouseButtonCallback(platform.handle, MouseButtonCallback);
1406 glfwSetCursorPosCallback(platform.handle, MouseMoveCallback);
1407 glfwSetScrollCallback(platform.handle, MouseScrollCallback);
1408 glfwSetCursorEnterCallback(platform.handle, MouseEnterCallback);
1409
1410 glfwMakeContextCurrent(platform.handle);
1411 result = true; // TODO: WARNING: glfwGetError(NULL); symbol can not be found in Web
1412
1413 // Check context activation
1414 if (result == true) //(result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
1415 {
1416 CORE.Window.ready = true;
1417
1418 int fbWidth = CORE.Window.screen.width;
1419 int fbHeight = CORE.Window.screen.height;
1420
1421 CORE.Window.render.width = fbWidth;
1422 CORE.Window.render.height = fbHeight;
1423 CORE.Window.currentFbo.width = fbWidth;
1424 CORE.Window.currentFbo.height = fbHeight;
1425
1426 TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully %s",
1427 FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)? "(HighDPI)" : "");
1428 TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
1429 TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
1430 TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
1431 TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
1432 }
1433 else
1434 {
1435 TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
1436 return -1;
1437 }
1438
1439 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
1440
1441 // If graphic device is no properly initialized, end program
1442 if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
1443
1444 // Load OpenGL extensions
1445 // NOTE: GL procedures address loader is required to load extensions
1446 rlLoadExtensions(glfwGetProcAddress);
1447 //----------------------------------------------------------------------------
1448
1449 // Initialize events callbacks
1450 //----------------------------------------------------------------------------
1451 // Setup window events callbacks
1452 emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenFullscreenChangeCallback);
1453 emscripten_set_blur_callback(platform.canvasId, platform.handle, 1, EmscriptenFocusCallback);
1454 emscripten_set_focus_callback(platform.canvasId, platform.handle, 1, EmscriptenFocusCallback);
1455 emscripten_set_visibilitychange_callback(NULL, 1, EmscriptenVisibilityChangeCallback);
1456
1457 // WARNING: Below resize code was breaking fullscreen mode for sample games and examples, it needs review
1458 // Check fullscreen change events(note this is done on the window since most browsers don't support this on canvas)
1459 // emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback);
1460 // Check Resize event (note this is done on the window since most browsers don't support this on canvas)
1461 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback);
1462
1463 // Trigger resize callback to force initial size
1464 EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
1465
1466 // Setup input events
1467 // NOTE: Keyboard callbacks only used to consume some events, libglfw.js takes care of the actual input
1468 //emscripten_set_keypress_callback(platform.canvasId, NULL, 1, EmscriptenKeyboardCallback); // WRNING: Breaks input
1469 //emscripten_set_keydown_callback(platform.canvasId, NULL, 1, EmscriptenKeyboardCallback);
1470 emscripten_set_click_callback(platform.canvasId, NULL, 1, EmscriptenMouseCallback);
1471 emscripten_set_pointerlockchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenPointerlockCallback);
1472 emscripten_set_mousemove_callback(platform.canvasId, NULL, 1, EmscriptenMouseMoveCallback);
1473 emscripten_set_touchstart_callback(platform.canvasId, NULL, 1, EmscriptenTouchCallback);
1474 emscripten_set_touchend_callback(platform.canvasId, NULL, 1, EmscriptenTouchCallback);
1475 emscripten_set_touchmove_callback(platform.canvasId, NULL, 1, EmscriptenTouchCallback);
1476 emscripten_set_touchcancel_callback(platform.canvasId, NULL, 1, EmscriptenTouchCallback);
1477 emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
1478 emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
1479 //----------------------------------------------------------------------------
1480
1481 // Initialize timing system
1482 //----------------------------------------------------------------------------
1483 InitTimer();
1484 //----------------------------------------------------------------------------
1485
1486 // Initialize storage system
1487 //----------------------------------------------------------------------------
1488 CORE.Storage.basePath = GetWorkingDirectory();
1489 //----------------------------------------------------------------------------
1490
1491 TRACELOG(LOG_INFO, "PLATFORM: WEB: Initialized successfully");
1492
1493 return 0;
1494 }
1495
1496 // Close platform
1497 void ClosePlatform(void)
1498 {
1499 glfwDestroyWindow(platform.handle);
1500 glfwTerminate();
1501 }
1502
1503 // GLFW3 callback functions, called on GLFW registered events
1504 //-------------------------------------------------------------------------------------------------------
1505 // GLFW3: Called on errors
1506 static void ErrorCallback(int error, const char *description)
1507 {
1508 TRACELOG(LOG_WARNING, "GLFW: Error: %i Description: %s", error, description);
1509 }
1510
1511 // GLFW3: Called on window resizing, runs when window is resizedLastFrame
1512 static void WindowSizeCallback(GLFWwindow *window, int width, int height)
1513 {
1514 // Reset viewport and projection matrix for new size
1515 SetupViewport(width, height);
1516
1517 CORE.Window.currentFbo.width = width;
1518 CORE.Window.currentFbo.height = height;
1519 CORE.Window.resizedLastFrame = true;
1520
1521 if (IsWindowFullscreen()) return;
1522
1523 // Set current screen size
1524 if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
1525 {
1526 Vector2 windowScaleDPI = GetWindowScaleDPI();
1527
1528 CORE.Window.screen.width = (unsigned int)(width/windowScaleDPI.x);
1529 CORE.Window.screen.height = (unsigned int)(height/windowScaleDPI.y);
1530 }
1531 else
1532 {
1533 CORE.Window.screen.width = width;
1534 CORE.Window.screen.height = height;
1535 }
1536
1537 // NOTE: Postprocessing texture is not scaled to new size
1538 }
1539
1540 // GLFW3: Called on window content (framebuffer) scaled
1541 static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley)
1542 {
1543 CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f);
1544 }
1545
1546 // GLFW3: Called on windows minimized/restored
1547 static void WindowIconifyCallback(GLFWwindow *window, int iconified)
1548 {
1549 if (iconified) FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); // The window was iconified
1550 else FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); // The window was restored
1551 }
1552
1553 // GLFW3: Called on windows get/lose focus
1554 static void WindowFocusCallback(GLFWwindow *window, int focused)
1555 {
1556 if (focused) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); // The window was focused
1557 else FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); // The window lost focus
1558 }
1559
1560 // GLFW3: Called on file-drop over the window
1561 static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
1562 {
1563 if (count > 0)
1564 {
1565 // In case previous dropped filepaths have not been freed, free them
1566 if (CORE.Window.dropFileCount > 0)
1567 {
1568 for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]);
1569
1570 RL_FREE(CORE.Window.dropFilepaths);
1571
1572 CORE.Window.dropFileCount = 0;
1573 CORE.Window.dropFilepaths = NULL;
1574 }
1575
1576 // WARNING: Paths are freed by GLFW when the callback returns, an internal copy must freed
1577 CORE.Window.dropFileCount = count;
1578 CORE.Window.dropFilepaths = (char **)RL_CALLOC(CORE.Window.dropFileCount, sizeof(char *));
1579
1580 for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++)
1581 {
1582 CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
1583 strncpy(CORE.Window.dropFilepaths[i], paths[i], MAX_FILEPATH_LENGTH - 1);
1584 }
1585 }
1586 }
1587
1588 // GLFW3: Called on keyboard interaction
1589 static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
1590 {
1591 if (key < 0) return; // Security check, macOS fn key generates -1
1592
1593 // WARNING: GLFW could return GLFW_REPEAT, it needs to be considered as 1
1594 // to work properly with our implementation (IsKeyDown/IsKeyUp checks)
1595 if (action == GLFW_RELEASE) CORE.Input.Keyboard.currentKeyState[key] = 0;
1596 else if (action == GLFW_PRESS) CORE.Input.Keyboard.currentKeyState[key] = 1;
1597 else if (action == GLFW_REPEAT) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1;
1598
1599 // Check if there is space available in the key queue
1600 if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS))
1601 {
1602 // Add character to the queue
1603 CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key;
1604 CORE.Input.Keyboard.keyPressedQueueCount++;
1605 }
1606
1607 // Check the exit key to set close window
1608 if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE);
1609 }
1610
1611 // GLFW3: Called on key down interaction, gets equivalent unicode char value for the key
1612 static void CharCallback(GLFWwindow *window, unsigned int key)
1613 {
1614 //TRACELOG(LOG_DEBUG, "Char Callback: KEY:%i(%c)", key, key);
1615
1616 // NOTE: Registers any key down considering OS keyboard layout but
1617 // does not detect action events, those should be managed by user...
1618 // REF: https://github.com/glfw/glfw/issues/668#issuecomment-166794907
1619 // REF: https://www.glfw.org/docs/latest/input_guide.html#input_char
1620
1621 // Check if there is space available in the queue
1622 if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE)
1623 {
1624 // Add character to the queue
1625 CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = key;
1626 CORE.Input.Keyboard.charPressedQueueCount++;
1627 }
1628 }
1629
1630 // GLFW3: Called on mouse button interaction
1631 static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
1632 {
1633 // WARNING: GLFW could only return GLFW_PRESS (1) or GLFW_RELEASE (0) for now,
1634 // but future releases may add more actions (i.e. GLFW_REPEAT)
1635 CORE.Input.Mouse.currentButtonState[button] = action;
1636 CORE.Input.Touch.currentTouchState[button] = action;
1637
1638 #if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
1639 // Process mouse events as touches to be able to use mouse-gestures
1640 GestureEvent gestureEvent = { 0 };
1641
1642 // Register touch actions
1643 if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
1644 else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP;
1645
1646 // NOTE: TOUCH_ACTION_MOVE event is registered in MouseMoveCallback()
1647
1648 // Assign a pointer ID
1649 gestureEvent.pointId[0] = 0;
1650
1651 // Register touch points count
1652 gestureEvent.pointCount = 1;
1653
1654 // Register touch points position, only one point registered
1655 gestureEvent.position[0] = GetMousePosition();
1656
1657 // Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
1658 gestureEvent.position[0].x /= (float)GetScreenWidth();
1659 gestureEvent.position[0].y /= (float)GetScreenHeight();
1660
1661 // Gesture data is sent to gestures-system for processing
1662 // Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself
1663 if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent);
1664
1665 #endif
1666 }
1667
1668 // GLFW3: Called on mouse move
1669 static void MouseMoveCallback(GLFWwindow *window, double x, double y)
1670 {
1671 // If the pointer is not locked, follow the position
1672 if (!CORE.Input.Mouse.cursorLocked)
1673 {
1674 CORE.Input.Mouse.currentPosition.x = (float)x;
1675 CORE.Input.Mouse.currentPosition.y = (float)y;
1676 CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition;
1677 }
1678
1679 #if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES
1680 // Process mouse events as touches to be able to use mouse-gestures
1681 GestureEvent gestureEvent = { 0 };
1682
1683 gestureEvent.touchAction = TOUCH_ACTION_MOVE;
1684
1685 // Assign a pointer ID
1686 gestureEvent.pointId[0] = 0;
1687
1688 // Register touch points count
1689 gestureEvent.pointCount = 1;
1690
1691 // Register touch points position, only one point registered
1692 gestureEvent.position[0] = CORE.Input.Touch.position[0];
1693
1694 // Normalize gestureEvent.position[0] for CORE.Window.screen.width and CORE.Window.screen.height
1695 gestureEvent.position[0].x /= (float)GetScreenWidth();
1696 gestureEvent.position[0].y /= (float)GetScreenHeight();
1697
1698 // Gesture data is sent to gestures-system for processing
1699 ProcessGestureEvent(gestureEvent);
1700 #endif
1701 }
1702
1703 // GLFW3: Called on mouse wheel scrolling
1704 static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset)
1705 {
1706 CORE.Input.Mouse.currentWheelMove = (Vector2){ (float)xoffset, (float)yoffset };
1707 }
1708
1709 // GLFW3: Called on mouse entering the window
1710 static void MouseEnterCallback(GLFWwindow *window, int enter)
1711 {
1712 if (enter) CORE.Input.Mouse.cursorOnScreen = true;
1713 else CORE.Input.Mouse.cursorOnScreen = false;
1714 }
1715 //-------------------------------------------------------------------------------------------------------
1716
1717 // Emscripten callback functions, called on specific browser events
1718 //-------------------------------------------------------------------------------------------------------
1719 /*
1720 // Emscripten: Called on key events
1721 static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboardEvent *keyboardEvent, void *userData)
1722 {
1723 // WARNING: Keyboard inputs already processed through GLFW callback
1724
1725 return 1; // The event was consumed by the callback handler
1726 }
1727 */
1728
1729 // Emscripten: Called on mouse input events
1730 static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
1731 {
1732 // This is only for registering mouse click events with emscripten and doesn't need to do anything
1733
1734 return 1; // The event was consumed by the callback handler
1735 }
1736
1737 // Emscripten: Called on mouse move events
1738 static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
1739 {
1740 // To emulate the GLFW_RAW_MOUSE_MOTION property
1741 if (CORE.Input.Mouse.cursorLocked)
1742 {
1743 CORE.Input.Mouse.previousPosition.x = CORE.Input.Mouse.lockedPosition.x - mouseEvent->movementX;
1744 CORE.Input.Mouse.previousPosition.y = CORE.Input.Mouse.lockedPosition.y - mouseEvent->movementY;
1745 }
1746
1747 return 1; // The event was consumed by the callback handler
1748 }
1749
1750 // Emscripten: Called on pointer lock events
1751 static EM_BOOL EmscriptenPointerlockCallback(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData)
1752 {
1753 CORE.Input.Mouse.cursorLocked = EM_ASM_INT( { if (document.pointerLockElement) return 1; }, 0);
1754
1755 if (CORE.Input.Mouse.cursorLocked)
1756 {
1757 CORE.Input.Mouse.lockedPosition = CORE.Input.Mouse.currentPosition;
1758 CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.lockedPosition;
1759 }
1760
1761 return 1; // The event was consumed by the callback handler
1762 }
1763
1764 // Emscripten: Called on connect/disconnect gamepads events
1765 static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
1766 {
1767 /*
1768 TRACELOG(LOG_DEBUG, "%s: timeStamp: %g, connected: %d, index: %ld, numAxes: %d, numButtons: %d, id: \"%s\", mapping: \"%s\"",
1769 eventType != 0? emscripten_event_type_to_string(eventType) : "Gamepad state",
1770 gamepadEvent->timestamp, gamepadEvent->connected, gamepadEvent->index, gamepadEvent->numAxes, gamepadEvent->numButtons, gamepadEvent->id, gamepadEvent->mapping);
1771
1772 for (int i = 0; i < gamepadEvent->numAxes; i++) TRACELOG(LOG_DEBUG, "Axis %d: %g", i, gamepadEvent->axis[i]);
1773 for (int i = 0; i < gamepadEvent->numButtons; i++) TRACELOG(LOG_DEBUG, "Button %d: Digital: %d, Analog: %g", i, gamepadEvent->digitalButton[i], gamepadEvent->analogButton[i]);
1774 */
1775
1776 if (gamepadEvent->connected && (gamepadEvent->index < MAX_GAMEPADS))
1777 {
1778 CORE.Input.Gamepad.ready[gamepadEvent->index] = true;
1779 snprintf(CORE.Input.Gamepad.name[gamepadEvent->index], MAX_GAMEPAD_NAME_LENGTH, "%s", gamepadEvent->id);
1780 }
1781 else CORE.Input.Gamepad.ready[gamepadEvent->index] = false;
1782
1783 return 1; // The event was consumed by the callback handler
1784 }
1785
1786 // Emscripten: Called on touch input events
1787 static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
1788 {
1789 // Register touch points count
1790 CORE.Input.Touch.pointCount = touchEvent->numTouches;
1791
1792 double canvasWidth = 0.0;
1793 double canvasHeight = 0.0;
1794 // NOTE: emscripten_get_canvas_element_size() returns canvas.width and canvas.height but
1795 // actual CSS size needs to be considered: canvas.style.width and canvas.style.height
1796 // EMSCRIPTEN_RESULT res = emscripten_get_canvas_element_size("#canvas", &canvasWidth, &canvasHeight);
1797 emscripten_get_element_css_size(platform.canvasId, &canvasWidth, &canvasHeight);
1798
1799 for (int i = 0; (i < CORE.Input.Touch.pointCount) && (i < MAX_TOUCH_POINTS); i++)
1800 {
1801 // Register touch points id
1802 CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier;
1803
1804 // Register touch points position
1805 CORE.Input.Touch.position[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY};
1806
1807 // Normalize gestureEvent.position[x] for CORE.Window.screen.width and CORE.Window.screen.height
1808 CORE.Input.Touch.position[i].x *= ((float)GetScreenWidth()/(float)canvasWidth);
1809 CORE.Input.Touch.position[i].y *= ((float)GetScreenHeight()/(float)canvasHeight);
1810
1811 if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) CORE.Input.Touch.currentTouchState[i] = 1;
1812 else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) CORE.Input.Touch.currentTouchState[i] = 0;
1813 }
1814
1815 // Update mouse position when single touch detected
1816 if (CORE.Input.Touch.pointCount == 1)
1817 {
1818 CORE.Input.Mouse.currentPosition.x = CORE.Input.Touch.position[0].x;
1819 CORE.Input.Mouse.currentPosition.y = CORE.Input.Touch.position[0].y;
1820 }
1821
1822 #if SUPPORT_GESTURES_SYSTEM
1823 GestureEvent gestureEvent = { 0 };
1824 gestureEvent.pointCount = CORE.Input.Touch.pointCount;
1825
1826 // Register touch actions
1827 if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_ACTION_DOWN;
1828 else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_ACTION_UP;
1829 else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_ACTION_MOVE;
1830 else if (eventType == EMSCRIPTEN_EVENT_TOUCHCANCEL) gestureEvent.touchAction = TOUCH_ACTION_CANCEL;
1831
1832 for (int i = 0; (i < gestureEvent.pointCount) && (i < MAX_TOUCH_POINTS); i++)
1833 {
1834 gestureEvent.pointId[i] = CORE.Input.Touch.pointId[i];
1835 gestureEvent.position[i] = CORE.Input.Touch.position[i];
1836
1837 // Normalize gestureEvent.position[i]
1838 gestureEvent.position[i].x /= (float)GetScreenWidth();
1839 gestureEvent.position[i].y /= (float)GetScreenHeight();
1840 }
1841
1842 // Gesture data is sent to gestures system for processing
1843 ProcessGestureEvent(gestureEvent);
1844 #endif
1845
1846 if (eventType == EMSCRIPTEN_EVENT_TOUCHEND)
1847 {
1848 // Identify the EMSCRIPTEN_EVENT_TOUCHEND and remove it from the list
1849 for (int i = 0; i < CORE.Input.Touch.pointCount; i++)
1850 {
1851 if (touchEvent->touches[i].isChanged)
1852 {
1853 // Move all touch points one position up
1854 for (int j = i; j < CORE.Input.Touch.pointCount - 1; j++)
1855 {
1856 CORE.Input.Touch.pointId[j] = CORE.Input.Touch.pointId[j + 1];
1857 CORE.Input.Touch.position[j] = CORE.Input.Touch.position[j + 1];
1858 }
1859 // Decrease touch points count to remove the last one
1860 CORE.Input.Touch.pointCount--;
1861 break;
1862 }
1863 }
1864 // Clamp pointCount to avoid negative values
1865 if (CORE.Input.Touch.pointCount < 0) CORE.Input.Touch.pointCount = 0;
1866 }
1867
1868 return 1; // The event was consumed by the callback handler
1869 }
1870
1871 // Emscripten: Called on fullscreen change events
1872 static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData)
1873 {
1874 // NOTE 1: Reset the fullscreen flags if the user left fullscreen manually by pressing the Escape key
1875 // NOTE 2: Which is a necessary safeguard because that case will bypass the toggles CORE.Window.flags resets
1876 if (platform.ourFullscreen) platform.ourFullscreen = false;
1877 else
1878 {
1879 const bool wasFullscreen = EM_ASM_INT( { if (document.fullscreenElement) return 1; }, 0);
1880 if (!wasFullscreen)
1881 {
1882 FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE);
1883 FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE);
1884 }
1885 }
1886
1887 return 1; // The event was consumed by the callback handler
1888 }
1889
1890 // Emscripten: Called on resize event
1891 static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData)
1892 {
1893 // Don't resize non-resizeable windows
1894 if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) return 1;
1895
1896 // This event is called whenever the window changes sizes,
1897 // so the size of the canvas object is explicitly retrieved below
1898 int width = EM_ASM_INT( return window.innerWidth; );
1899 int height = EM_ASM_INT( return window.innerHeight; );
1900
1901 if (width < (int)CORE.Window.screenMin.width) width = CORE.Window.screenMin.width;
1902 else if ((width > (int)CORE.Window.screenMax.width) && (CORE.Window.screenMax.width > 0)) width = CORE.Window.screenMax.width;
1903
1904 if (height < (int)CORE.Window.screenMin.height) height = CORE.Window.screenMin.height;
1905 else if ((height > (int)CORE.Window.screenMax.height) && (CORE.Window.screenMax.height > 0)) height = CORE.Window.screenMax.height;
1906
1907 emscripten_set_canvas_element_size(platform.canvasId, width, height);
1908
1909 SetupViewport(width, height); // Reset viewport and projection matrix for new size
1910
1911 CORE.Window.currentFbo.width = width;
1912 CORE.Window.currentFbo.height = height;
1913 CORE.Window.resizedLastFrame = true;
1914
1915 if (IsWindowFullscreen()) return 1;
1916
1917 // Set current screen size
1918 CORE.Window.screen.width = width;
1919 CORE.Window.screen.height = height;
1920
1921 glfwSetWindowSize(platform.handle, CORE.Window.screen.width, CORE.Window.screen.height);
1922
1923 // NOTE: Postprocessing texture is not scaled to new size
1924
1925 return 0;
1926 }
1927
1928 // Emscripten: Called on windows focus change events
1929 static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData)
1930 {
1931 EM_BOOL consumed = 1;
1932 switch (eventType)
1933 {
1934 case EMSCRIPTEN_EVENT_BLUR: WindowFocusCallback(userData, 0); break;
1935 case EMSCRIPTEN_EVENT_FOCUS: WindowFocusCallback(userData, 1); break;
1936 default: consumed = 0; break;
1937 }
1938 return consumed;
1939 }
1940
1941 // Emscripten: Called on visibility change events
1942 static EM_BOOL EmscriptenVisibilityChangeCallback(int eventType, const EmscriptenVisibilityChangeEvent *visibilityChangeEvent, void *userData)
1943 {
1944 if (visibilityChangeEvent->hidden) FLAG_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN); // The window was hidden
1945 else FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_HIDDEN); // The window was restored
1946 return 1; // The event was consumed by the callback handler
1947 }
1948 //-------------------------------------------------------------------------------------------------------
1949
1950 // EOF