| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#define GLFW_INCLUDE_NONE |
| 46 |
|
| 47 |
#include "GLFW/glfw3.h" |
| 48 |
|
| 49 |
#include <emscripten/emscripten.h> |
| 50 |
#include <emscripten/html5.h> |
| 51 |
|
| 52 |
#include <sys/time.h> |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 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 |
|
| 70 |
|
| 71 |
typedef struct { |
| 72 |
GLFWwindow *handle; |
| 73 |
bool ourFullscreen; |
| 74 |
int unmaximizedWidth; |
| 75 |
int unmaximizedHeight; |
| 76 |
|
| 77 |
char canvasId[64]; |
| 78 |
|
| 79 |
|
| 80 |
#if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 81 |
unsigned int *pixels; |
| 82 |
#endif |
| 83 |
} PlatformData; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
extern CoreData CORE; |
| 89 |
|
| 90 |
static PlatformData platform = { 0 }; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
static const char cursorLUT[11][12] = { |
| 96 |
"default", |
| 97 |
"default", |
| 98 |
"text", |
| 99 |
"crosshair", |
| 100 |
"pointer", |
| 101 |
"ew-resize", |
| 102 |
"ns-resize", |
| 103 |
"nwse-resize", |
| 104 |
"nesw-resize", |
| 105 |
"move", |
| 106 |
"not-allowed" |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
int InitPlatform(void); |
| 113 |
void ClosePlatform(void); |
| 114 |
|
| 115 |
|
| 116 |
static void ErrorCallback(int error, const char *description); |
| 117 |
|
| 118 |
|
| 119 |
static void WindowSizeCallback(GLFWwindow *window, int width, int height); |
| 120 |
static void WindowIconifyCallback(GLFWwindow *window, int iconified); |
| 121 |
|
| 122 |
static void WindowFocusCallback(GLFWwindow *window, int focused); |
| 123 |
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); |
| 124 |
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); |
| 125 |
|
| 126 |
|
| 127 |
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); |
| 128 |
static void CharCallback(GLFWwindow *window, unsigned int key); |
| 129 |
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); |
| 130 |
static void MouseMoveCallback(GLFWwindow *window, double x, double y); |
| 131 |
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); |
| 132 |
static void MouseEnterCallback(GLFWwindow *window, int enter); |
| 133 |
|
| 134 |
|
| 135 |
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData); |
| 136 |
|
| 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 |
|
| 142 |
|
| 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 |
|
| 150 |
EM_JS(void, SetCanvasIdJs, (char *out, int outSize), { |
| 151 |
var canvasId = "#" + Module.canvas.id; |
| 152 |
stringToUTF8(canvasId, out, outSize); |
| 153 |
}); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
bool WindowShouldClose(void) |
| 168 |
{ |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
emscripten_sleep(12); |
| 179 |
|
| 180 |
return false; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 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 |
|
| 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 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
|
| 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 |
|
| 316 |
|
| 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 |
|
| 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 |
|
| 351 |
void MinimizeWindow(void) |
| 352 |
{ |
| 353 |
TRACELOG(LOG_WARNING, "MinimizeWindow() not available on target platform"); |
| 354 |
} |
| 355 |
|
| 356 |
|
| 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 |
|
| 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 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 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 |
|
| 382 |
if (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 383 |
{ |
| 384 |
|
| 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 |
|
| 396 |
if (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE)) |
| 397 |
{ |
| 398 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 504 |
void ClearWindowState(unsigned int flags) |
| 505 |
{ |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 632 |
void SetWindowIcon(Image image) |
| 633 |
{ |
| 634 |
TRACELOG(LOG_WARNING, "SetWindowIcon() not available on target platform"); |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
void SetWindowIcons(Image *images, int count) |
| 639 |
{ |
| 640 |
TRACELOG(LOG_WARNING, "SetWindowIcons() not available on target platform"); |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
void SetWindowTitle(const char *title) |
| 645 |
{ |
| 646 |
CORE.Window.title = title; |
| 647 |
emscripten_set_window_title(title); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
void SetWindowPosition(int x, int y) |
| 652 |
{ |
| 653 |
TRACELOG(LOG_WARNING, "SetWindowPosition() not available on target platform"); |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
void SetWindowMonitor(int monitor) |
| 658 |
{ |
| 659 |
TRACELOG(LOG_WARNING, "SetWindowMonitor() not available on target platform"); |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
void SetWindowMinSize(int width, int height) |
| 664 |
{ |
| 665 |
CORE.Window.screenMin.width = width; |
| 666 |
CORE.Window.screenMin.height = height; |
| 667 |
|
| 668 |
|
| 669 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
void SetWindowMaxSize(int width, int height) |
| 674 |
{ |
| 675 |
CORE.Window.screenMax.width = width; |
| 676 |
CORE.Window.screenMax.height = height; |
| 677 |
|
| 678 |
|
| 679 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
void SetWindowSize(int width, int height) |
| 684 |
{ |
| 685 |
glfwSetWindowSize(platform.handle, width, height); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 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 |
|
| 697 |
void SetWindowFocused(void) |
| 698 |
{ |
| 699 |
TRACELOG(LOG_WARNING, "SetWindowFocused() not available on target platform"); |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
void *GetWindowHandle(void) |
| 704 |
{ |
| 705 |
TRACELOG(LOG_WARNING, "GetWindowHandle() not implemented on target platform"); |
| 706 |
return NULL; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
int GetMonitorCount(void) |
| 711 |
{ |
| 712 |
TRACELOG(LOG_WARNING, "GetMonitorCount() not implemented on target platform"); |
| 713 |
return 1; |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
int GetCurrentMonitor(void) |
| 718 |
{ |
| 719 |
TRACELOG(LOG_WARNING, "GetCurrentMonitor() not implemented on target platform"); |
| 720 |
return 0; |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
Vector2 GetMonitorPosition(int monitor) |
| 725 |
{ |
| 726 |
TRACELOG(LOG_WARNING, "GetMonitorPosition() not implemented on target platform"); |
| 727 |
return (Vector2){ 0, 0 }; |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
int GetMonitorWidth(int monitor) |
| 732 |
{ |
| 733 |
|
| 734 |
int width = 0; |
| 735 |
width = EM_ASM_INT( { return screen.width; }, 0); |
| 736 |
return width; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
int GetMonitorHeight(int monitor) |
| 741 |
{ |
| 742 |
|
| 743 |
int height = 0; |
| 744 |
height = EM_ASM_INT( { return screen.height; }, 0); |
| 745 |
return height; |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
int GetMonitorPhysicalWidth(int monitor) |
| 750 |
{ |
| 751 |
TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth() not implemented on target platform"); |
| 752 |
return 0; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
int GetMonitorPhysicalHeight(int monitor) |
| 757 |
{ |
| 758 |
TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight() not implemented on target platform"); |
| 759 |
return 0; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
int GetMonitorRefreshRate(int monitor) |
| 764 |
{ |
| 765 |
TRACELOG(LOG_WARNING, "GetMonitorRefreshRate() not implemented on target platform"); |
| 766 |
return 0; |
| 767 |
} |
| 768 |
|
| 769 |
|
| 770 |
const char *GetMonitorName(int monitor) |
| 771 |
{ |
| 772 |
TRACELOG(LOG_WARNING, "GetMonitorName() not implemented on target platform"); |
| 773 |
return ""; |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
Vector2 GetWindowPosition(void) |
| 778 |
{ |
| 779 |
|
| 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 |
|
| 787 |
Vector2 GetWindowScaleDPI(void) |
| 788 |
{ |
| 789 |
|
| 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 |
|
| 797 |
void SetClipboardText(const char *text) |
| 798 |
{ |
| 799 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 865 |
|
| 866 |
if (width) setValue(width, window._lastImgWidth, 'i32'); |
| 867 |
if (height) setValue(height, window._lastImgHeight, 'i32'); |
| 868 |
|
| 869 |
|
| 870 |
window._lastImgData = null; |
| 871 |
|
| 872 |
return ptr; |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
return 0; |
| 877 |
}); |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
const char *GetClipboardText(void) |
| 882 |
{ |
| 883 |
RequestClipboardData(); |
| 884 |
return GetLastPastedText(); |
| 885 |
} |
| 886 |
|
| 887 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 928 |
void EnableCursor(void) |
| 929 |
{ |
| 930 |
emscripten_exit_pointerlock(); |
| 931 |
|
| 932 |
|
| 933 |
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); |
| 934 |
|
| 935 |
|
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
void DisableCursor(void) |
| 940 |
{ |
| 941 |
emscripten_request_pointerlock(platform.canvasId, 1); |
| 942 |
|
| 943 |
|
| 944 |
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); |
| 945 |
|
| 946 |
|
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
void SwapScreenBuffer(void) |
| 951 |
{ |
| 952 |
#if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 953 |
|
| 954 |
rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, platform.pixels); |
| 955 |
|
| 956 |
|
| 957 |
EM_ASM({ |
| 958 |
const width = $0; |
| 959 |
const height = $1; |
| 960 |
const ptr = $2; |
| 961 |
|
| 962 |
|
| 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); |
| 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 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
double GetTime(void) |
| 987 |
{ |
| 988 |
double time = glfwGetTime(); |
| 989 |
|
| 990 |
return time; |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
void OpenURL(const char *url) |
| 998 |
{ |
| 999 |
|
| 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 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 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 |
|
| 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; |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 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 |
|
| 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 |
|
| 1056 |
glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y); |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 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 |
|
| 1071 |
const char *GetKeyName(int key) |
| 1072 |
{ |
| 1073 |
TRACELOG(LOG_WARNING, "GetKeyName() not implemented on target platform"); |
| 1074 |
return ""; |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
void PollInputEvents(void) |
| 1079 |
{ |
| 1080 |
#if SUPPORT_GESTURES_SYSTEM |
| 1081 |
|
| 1082 |
|
| 1083 |
UpdateGestures(); |
| 1084 |
#endif |
| 1085 |
|
| 1086 |
|
| 1087 |
CORE.Input.Keyboard.keyPressedQueueCount = 0; |
| 1088 |
CORE.Input.Keyboard.charPressedQueueCount = 0; |
| 1089 |
|
| 1090 |
|
| 1091 |
CORE.Input.Gamepad.lastButtonPressed = 0; |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 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 |
|
| 1104 |
for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i]; |
| 1105 |
|
| 1106 |
|
| 1107 |
CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove; |
| 1108 |
CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f }; |
| 1109 |
|
| 1110 |
|
| 1111 |
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; |
| 1112 |
|
| 1113 |
|
| 1114 |
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i]; |
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 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 |
|
| 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 |
|
| 1140 |
for (int j = 0; (j < gamepadState.numButtons) && (j < MAX_GAMEPAD_BUTTONS); j++) |
| 1141 |
{ |
| 1142 |
GamepadButton button = -1; |
| 1143 |
|
| 1144 |
|
| 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) |
| 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 |
|
| 1177 |
} |
| 1178 |
|
| 1179 |
|
| 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 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
int InitPlatform(void) |
| 1198 |
{ |
| 1199 |
SetCanvasIdJs(platform.canvasId, 64); |
| 1200 |
|
| 1201 |
glfwSetErrorCallback(ErrorCallback); |
| 1202 |
|
| 1203 |
|
| 1204 |
int result = glfwInit(); |
| 1205 |
if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; } |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
glfwDefaultWindowHints(); |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
| 1221 |
else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); |
| 1222 |
|
| 1223 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED)) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); |
| 1224 |
else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); |
| 1225 |
|
| 1226 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); |
| 1227 |
else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); |
| 1228 |
|
| 1229 |
|
| 1230 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 1231 |
|
| 1232 |
|
| 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 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT)) |
| 1250 |
{ |
| 1251 |
|
| 1252 |
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4"); |
| 1253 |
glfwWindowHint(GLFW_SAMPLES, 4); |
| 1254 |
} |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
if (rlGetVersion() == RL_OPENGL_21) |
| 1262 |
{ |
| 1263 |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); |
| 1264 |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); |
| 1265 |
} |
| 1266 |
else if (rlGetVersion() == RL_OPENGL_33) |
| 1267 |
{ |
| 1268 |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
| 1269 |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 1270 |
|
| 1271 |
|
| 1272 |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 1273 |
|
| 1274 |
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE); |
| 1275 |
|
| 1276 |
} |
| 1277 |
else if (rlGetVersion() == RL_OPENGL_43) |
| 1278 |
{ |
| 1279 |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); |
| 1280 |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 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); |
| 1285 |
#endif |
| 1286 |
} |
| 1287 |
else if (rlGetVersion() == RL_OPENGL_ES_20) |
| 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) |
| 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 |
|
| 1303 |
CORE.Window.display.width = CORE.Window.screen.width; |
| 1304 |
CORE.Window.display.height = CORE.Window.screen.height; |
| 1305 |
|
| 1306 |
|
| 1307 |
platform.ourFullscreen = false; |
| 1308 |
|
| 1309 |
#if defined(GRAPHICS_API_OPENGL_SOFTWARE) |
| 1310 |
|
| 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 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 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 |
|
| 1326 |
if ((CORE.Window.screen.height == CORE.Window.display.height) && (CORE.Window.screen.width == CORE.Window.display.width)) |
| 1327 |
{ |
| 1328 |
|
| 1329 |
|
| 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 |
|
| 1343 |
int count = 0; |
| 1344 |
const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count); |
| 1345 |
|
| 1346 |
|
| 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 |
|
| 1365 |
|
| 1366 |
} |
| 1367 |
else |
| 1368 |
{ |
| 1369 |
|
| 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 |
|
| 1388 |
emscripten_set_window_title((CORE.Window.title != 0)? CORE.Window.title : " "); |
| 1389 |
|
| 1390 |
|
| 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 |
|
| 1399 |
glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback); |
| 1400 |
} |
| 1401 |
|
| 1402 |
|
| 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; |
| 1412 |
|
| 1413 |
|
| 1414 |
if (result == true) |
| 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 |
|
| 1442 |
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; } |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
rlLoadExtensions(glfwGetProcAddress); |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 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 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); |
| 1462 |
|
| 1463 |
|
| 1464 |
EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 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 |
|
| 1482 |
|
| 1483 |
InitTimer(); |
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
CORE.Storage.basePath = GetWorkingDirectory(); |
| 1489 |
|
| 1490 |
|
| 1491 |
TRACELOG(LOG_INFO, "PLATFORM: WEB: Initialized successfully"); |
| 1492 |
|
| 1493 |
return 0; |
| 1494 |
} |
| 1495 |
|
| 1496 |
|
| 1497 |
void ClosePlatform(void) |
| 1498 |
{ |
| 1499 |
glfwDestroyWindow(platform.handle); |
| 1500 |
glfwTerminate(); |
| 1501 |
} |
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
static void ErrorCallback(int error, const char *description) |
| 1507 |
{ |
| 1508 |
TRACELOG(LOG_WARNING, "GLFW: Error: %i Description: %s", error, description); |
| 1509 |
} |
| 1510 |
|
| 1511 |
|
| 1512 |
static void WindowSizeCallback(GLFWwindow *window, int width, int height) |
| 1513 |
{ |
| 1514 |
|
| 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 |
|
| 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 |
|
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley) |
| 1542 |
{ |
| 1543 |
CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f); |
| 1544 |
} |
| 1545 |
|
| 1546 |
|
| 1547 |
static void WindowIconifyCallback(GLFWwindow *window, int iconified) |
| 1548 |
{ |
| 1549 |
if (iconified) FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 1550 |
else FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
static void WindowFocusCallback(GLFWwindow *window, int focused) |
| 1555 |
{ |
| 1556 |
if (focused) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 1557 |
else FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths) |
| 1562 |
{ |
| 1563 |
if (count > 0) |
| 1564 |
{ |
| 1565 |
|
| 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 |
|
| 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 |
|
| 1589 |
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) |
| 1590 |
{ |
| 1591 |
if (key < 0) return; |
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 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 |
|
| 1600 |
if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS)) |
| 1601 |
{ |
| 1602 |
|
| 1603 |
CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key; |
| 1604 |
CORE.Input.Keyboard.keyPressedQueueCount++; |
| 1605 |
} |
| 1606 |
|
| 1607 |
|
| 1608 |
if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE); |
| 1609 |
} |
| 1610 |
|
| 1611 |
|
| 1612 |
static void CharCallback(GLFWwindow *window, unsigned int key) |
| 1613 |
{ |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) |
| 1623 |
{ |
| 1624 |
|
| 1625 |
CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = key; |
| 1626 |
CORE.Input.Keyboard.charPressedQueueCount++; |
| 1627 |
} |
| 1628 |
} |
| 1629 |
|
| 1630 |
|
| 1631 |
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) |
| 1632 |
{ |
| 1633 |
|
| 1634 |
|
| 1635 |
CORE.Input.Mouse.currentButtonState[button] = action; |
| 1636 |
CORE.Input.Touch.currentTouchState[button] = action; |
| 1637 |
|
| 1638 |
#if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES |
| 1639 |
|
| 1640 |
GestureEvent gestureEvent = { 0 }; |
| 1641 |
|
| 1642 |
|
| 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 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
gestureEvent.pointId[0] = 0; |
| 1650 |
|
| 1651 |
|
| 1652 |
gestureEvent.pointCount = 1; |
| 1653 |
|
| 1654 |
|
| 1655 |
gestureEvent.position[0] = GetMousePosition(); |
| 1656 |
|
| 1657 |
|
| 1658 |
gestureEvent.position[0].x /= (float)GetScreenWidth(); |
| 1659 |
gestureEvent.position[0].y /= (float)GetScreenHeight(); |
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent); |
| 1664 |
|
| 1665 |
#endif |
| 1666 |
} |
| 1667 |
|
| 1668 |
|
| 1669 |
static void MouseMoveCallback(GLFWwindow *window, double x, double y) |
| 1670 |
{ |
| 1671 |
|
| 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 |
|
| 1681 |
GestureEvent gestureEvent = { 0 }; |
| 1682 |
|
| 1683 |
gestureEvent.touchAction = TOUCH_ACTION_MOVE; |
| 1684 |
|
| 1685 |
|
| 1686 |
gestureEvent.pointId[0] = 0; |
| 1687 |
|
| 1688 |
|
| 1689 |
gestureEvent.pointCount = 1; |
| 1690 |
|
| 1691 |
|
| 1692 |
gestureEvent.position[0] = CORE.Input.Touch.position[0]; |
| 1693 |
|
| 1694 |
|
| 1695 |
gestureEvent.position[0].x /= (float)GetScreenWidth(); |
| 1696 |
gestureEvent.position[0].y /= (float)GetScreenHeight(); |
| 1697 |
|
| 1698 |
|
| 1699 |
ProcessGestureEvent(gestureEvent); |
| 1700 |
#endif |
| 1701 |
} |
| 1702 |
|
| 1703 |
|
| 1704 |
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset) |
| 1705 |
{ |
| 1706 |
CORE.Input.Mouse.currentWheelMove = (Vector2){ (float)xoffset, (float)yoffset }; |
| 1707 |
} |
| 1708 |
|
| 1709 |
|
| 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 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
| 1731 |
{ |
| 1732 |
|
| 1733 |
|
| 1734 |
return 1; |
| 1735 |
} |
| 1736 |
|
| 1737 |
|
| 1738 |
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
| 1739 |
{ |
| 1740 |
|
| 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; |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 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; |
| 1762 |
} |
| 1763 |
|
| 1764 |
|
| 1765 |
static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData) |
| 1766 |
{ |
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 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; |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData) |
| 1788 |
{ |
| 1789 |
|
| 1790 |
CORE.Input.Touch.pointCount = touchEvent->numTouches; |
| 1791 |
|
| 1792 |
double canvasWidth = 0.0; |
| 1793 |
double canvasHeight = 0.0; |
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 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 |
|
| 1802 |
CORE.Input.Touch.pointId[i] = touchEvent->touches[i].identifier; |
| 1803 |
|
| 1804 |
|
| 1805 |
CORE.Input.Touch.position[i] = (Vector2){touchEvent->touches[i].targetX, touchEvent->touches[i].targetY}; |
| 1806 |
|
| 1807 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 1838 |
gestureEvent.position[i].x /= (float)GetScreenWidth(); |
| 1839 |
gestureEvent.position[i].y /= (float)GetScreenHeight(); |
| 1840 |
} |
| 1841 |
|
| 1842 |
|
| 1843 |
ProcessGestureEvent(gestureEvent); |
| 1844 |
#endif |
| 1845 |
|
| 1846 |
if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) |
| 1847 |
{ |
| 1848 |
|
| 1849 |
for (int i = 0; i < CORE.Input.Touch.pointCount; i++) |
| 1850 |
{ |
| 1851 |
if (touchEvent->touches[i].isChanged) |
| 1852 |
{ |
| 1853 |
|
| 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 |
|
| 1860 |
CORE.Input.Touch.pointCount--; |
| 1861 |
break; |
| 1862 |
} |
| 1863 |
} |
| 1864 |
|
| 1865 |
if (CORE.Input.Touch.pointCount < 0) CORE.Input.Touch.pointCount = 0; |
| 1866 |
} |
| 1867 |
|
| 1868 |
return 1; |
| 1869 |
} |
| 1870 |
|
| 1871 |
|
| 1872 |
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData) |
| 1873 |
{ |
| 1874 |
|
| 1875 |
|
| 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; |
| 1888 |
} |
| 1889 |
|
| 1890 |
|
| 1891 |
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData) |
| 1892 |
{ |
| 1893 |
|
| 1894 |
if (!FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) return 1; |
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 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); |
| 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 |
|
| 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 |
|
| 1924 |
|
| 1925 |
return 0; |
| 1926 |
} |
| 1927 |
|
| 1928 |
|
| 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 |
|
| 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); |
| 1945 |
else FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_HIDDEN); |
| 1946 |
return 1; |
| 1947 |
} |
| 1948 |
|
| 1949 |
|
| 1950 |
|