| 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 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | #define GLFW_INCLUDE_NONE |
| 50 | |
| 51 | #include "GLFW/glfw3.h" |
| 52 | |
| 53 | |
| 54 | |
| 55 | #if defined(_WIN32) |
| 56 | #if !defined(HWND) && !defined(_MSVC_LANG) |
| 57 | #define HWND void* |
| 58 | #elif !defined(HWND) && defined(_MSVC_LANG) |
| 59 | typedef struct HWND__ *HWND; |
| 60 | #endif |
| 61 | |
| 62 | #include "../external/win32_clipboard.h" |
| 63 | |
| 64 | #define GLFW_EXPOSE_NATIVE_WIN32 |
| 65 | #define GLFW_NATIVE_INCLUDE_NONE |
| 66 | #include "GLFW/glfw3native.h" |
| 67 | |
| 68 | #if SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP |
| 69 | |
| 70 | |
| 71 | __declspec(dllimport) unsigned int __stdcall timeEndPeriod(unsigned int uPeriod); |
| 72 | |
| 73 | #endif |
| 74 | #endif |
| 75 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
| 76 | #include <sys/time.h> |
| 77 | |
| 78 | #if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) |
| 79 | |
| 80 | #if defined(_GLFW_X11) |
| 81 | #define GLFW_EXPOSE_NATIVE_X11 |
| 82 | #define Font X11Font |
| 83 | |
| 84 | |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | #if defined(_GLFW_WAYLAND) |
| 89 | #define GLFW_EXPOSE_NATIVE_WAYLAND |
| 90 | #endif |
| 91 | |
| 92 | #include "GLFW/glfw3native.h" |
| 93 | |
| 94 | #if defined(_GLFW_X11) |
| 95 | #undef Font |
| 96 | #endif |
| 97 | #endif |
| 98 | #endif |
| 99 | #if defined(__APPLE__) |
| 100 | #include <unistd.h> |
| 101 | |
| 102 | |
| 103 | void *glfwGetCocoaWindow(GLFWwindow *handle); |
| 104 | #include "GLFW/glfw3native.h" |
| 105 | #endif |
| 106 | |
| 107 | #include <stddef.h> |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | typedef struct { |
| 113 | GLFWwindow *handle; |
| 114 | } PlatformData; |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | extern CoreData CORE; |
| 120 | |
| 121 | static PlatformData platform = { 0 }; |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | int InitPlatform(void); |
| 127 | void ClosePlatform(void); |
| 128 | |
| 129 | |
| 130 | static void ErrorCallback(int error, const char *description); |
| 131 | |
| 132 | |
| 133 | static void WindowSizeCallback(GLFWwindow *window, int width, int height); |
| 134 | static void FramebufferSizeCallback(GLFWwindow *window, int width, int height); |
| 135 | static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley); |
| 136 | static void WindowPosCallback(GLFWwindow *window, int x, int y); |
| 137 | static void WindowIconifyCallback(GLFWwindow *window, int iconified); |
| 138 | static void WindowMaximizeCallback(GLFWwindow *window, int maximized); |
| 139 | static void WindowFocusCallback(GLFWwindow *window, int focused); |
| 140 | static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); |
| 141 | |
| 142 | |
| 143 | static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); |
| 144 | static void CharCallback(GLFWwindow *window, unsigned int codepoint); |
| 145 | static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); |
| 146 | static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); |
| 147 | static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); |
| 148 | static void CursorEnterCallback(GLFWwindow *window, int enter); |
| 149 | static void JoystickCallback(int jid, int event); |
| 150 | |
| 151 | |
| 152 | static void *AllocateWrapper(size_t size, void *user); |
| 153 | static void *ReallocateWrapper(void *block, size_t size, void *user); |
| 154 | static void DeallocateWrapper(void *block, void *user); |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | bool WindowShouldClose(void) |
| 168 | { |
| 169 | if (CORE.Window.ready) return CORE.Window.shouldClose; |
| 170 | else return true; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void ToggleFullscreen(void) |
| 175 | { |
| 176 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 177 | { |
| 178 | |
| 179 | CORE.Window.previousPosition = CORE.Window.position; |
| 180 | CORE.Window.previousScreen = CORE.Window.screen; |
| 181 | |
| 182 | |
| 183 | int monitorCount = 0; |
| 184 | int monitorIndex = GetCurrentMonitor(); |
| 185 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 186 | GLFWmonitor *monitor = (monitorIndex < monitorCount)? monitors[monitorIndex] : NULL; |
| 187 | |
| 188 | if (monitor != NULL) |
| 189 | { |
| 190 | |
| 191 | const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitorIndex]); |
| 192 | CORE.Window.display.width = mode->width; |
| 193 | CORE.Window.display.height = mode->height; |
| 194 | |
| 195 | CORE.Window.position = (Point){ 0, 0 }; |
| 196 | CORE.Window.screen = CORE.Window.display; |
| 197 | |
| 198 | |
| 199 | FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE); |
| 200 | |
| 201 | #if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) |
| 202 | |
| 203 | |
| 204 | glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE); |
| 205 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED); |
| 206 | #endif |
| 207 | |
| 208 | glfwSetWindowMonitor(platform.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); |
| 209 | } |
| 210 | else TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor"); |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | |
| 215 | CORE.Window.position = CORE.Window.previousPosition; |
| 216 | CORE.Window.screen = CORE.Window.previousScreen; |
| 217 | |
| 218 | |
| 219 | |
| 220 | FLAG_CLEAR(CORE.Window.flags, FLAG_FULLSCREEN_MODE); |
| 221 | |
| 222 | #if !defined(__APPLE__) && !defined(_GLFW_WAYLAND) |
| 223 | |
| 224 | |
| 225 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 226 | { |
| 227 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 228 | CORE.Window.screen.width = (unsigned int)(CORE.Window.screen.width*scaleDpi.x); |
| 229 | CORE.Window.screen.height = (unsigned int)(CORE.Window.screen.height*scaleDpi.y); |
| 230 | } |
| 231 | #endif |
| 232 | |
| 233 | |
| 234 | glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, |
| 235 | CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE); |
| 236 | |
| 237 | #if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) |
| 238 | |
| 239 | |
| 240 | glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE); |
| 241 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNDECORATED); |
| 242 | #endif |
| 243 | } |
| 244 | |
| 245 | |
| 246 | |
| 247 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) glfwSwapInterval(1); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | void ToggleBorderlessWindowed(void) |
| 252 | { |
| 253 | |
| 254 | |
| 255 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) ToggleFullscreen(); |
| 256 | |
| 257 | int monitorCount = 0; |
| 258 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 259 | const int monitor = GetCurrentMonitor(); |
| 260 | |
| 261 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 262 | { |
| 263 | const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); |
| 264 | |
| 265 | if (mode != NULL) |
| 266 | { |
| 267 | if (!FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 268 | { |
| 269 | |
| 270 | |
| 271 | CORE.Window.previousPosition = CORE.Window.position; |
| 272 | CORE.Window.previousScreen = CORE.Window.screen; |
| 273 | |
| 274 | |
| 275 | glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE); |
| 276 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED); |
| 277 | |
| 278 | |
| 279 | glfwGetMonitorPos(monitors[monitor], &CORE.Window.position.x, &CORE.Window.position.y); |
| 280 | CORE.Window.screen.width = mode->width; |
| 281 | CORE.Window.screen.height = mode->height; |
| 282 | |
| 283 | |
| 284 | glfwSetWindowMonitor(platform.handle, monitors[monitor], CORE.Window.position.x, CORE.Window.position.y, |
| 285 | CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate); |
| 286 | |
| 287 | |
| 288 | glfwFocusWindow(platform.handle); |
| 289 | |
| 290 | FLAG_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE); |
| 291 | } |
| 292 | else |
| 293 | { |
| 294 | |
| 295 | CORE.Window.position = CORE.Window.previousPosition; |
| 296 | CORE.Window.screen = CORE.Window.previousScreen; |
| 297 | |
| 298 | |
| 299 | glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE); |
| 300 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNDECORATED); |
| 301 | |
| 302 | #if !defined(__APPLE__) && !defined(_GLFW_WAYLAND) |
| 303 | |
| 304 | |
| 305 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 306 | { |
| 307 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 308 | CORE.Window.screen.width = (unsigned int)(CORE.Window.screen.width*scaleDpi.x); |
| 309 | CORE.Window.screen.height = (unsigned int)(CORE.Window.screen.height*scaleDpi.y); |
| 310 | } |
| 311 | #endif |
| 312 | |
| 313 | |
| 314 | glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, |
| 315 | CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate); |
| 316 | |
| 317 | |
| 318 | glfwFocusWindow(platform.handle); |
| 319 | |
| 320 | FLAG_CLEAR(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE); |
| 321 | } |
| 322 | } |
| 323 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); |
| 324 | } |
| 325 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 326 | } |
| 327 | |
| 328 | |
| 329 | void MaximizeWindow(void) |
| 330 | { |
| 331 | if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) |
| 332 | { |
| 333 | glfwMaximizeWindow(platform.handle); |
| 334 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | |
| 339 | void MinimizeWindow(void) |
| 340 | { |
| 341 | |
| 342 | glfwIconifyWindow(platform.handle); |
| 343 | } |
| 344 | |
| 345 | |
| 346 | void RestoreWindow(void) |
| 347 | { |
| 348 | if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) |
| 349 | { |
| 350 | |
| 351 | glfwRestoreWindow(platform.handle); |
| 352 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 353 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void SetWindowState(unsigned int flags) |
| 359 | { |
| 360 | if (!CORE.Window.ready) TRACELOG(LOG_WARNING, "WINDOW: SetWindowState does nothing before window initialization, Use \"SetConfigFlags\" instead"); |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT) != FLAG_IS_SET(flags, FLAG_VSYNC_HINT)) && FLAG_IS_SET(flags, FLAG_VSYNC_HINT)) |
| 367 | { |
| 368 | glfwSwapInterval(1); |
| 369 | FLAG_SET(CORE.Window.flags, FLAG_VSYNC_HINT); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | |
| 374 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE) != FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE)) && FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE)) |
| 375 | { |
| 376 | ToggleBorderlessWindowed(); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE) != FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE)) && FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE)) |
| 381 | { |
| 382 | ToggleFullscreen(); |
| 383 | } |
| 384 | |
| 385 | |
| 386 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE) != FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)) && FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE)) |
| 387 | { |
| 388 | glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_TRUE); |
| 389 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE); |
| 390 | } |
| 391 | |
| 392 | |
| 393 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED) != FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED)) && FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED)) |
| 394 | { |
| 395 | glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE); |
| 396 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED); |
| 397 | } |
| 398 | |
| 399 | |
| 400 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN) != FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN)) && FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN)) |
| 401 | { |
| 402 | glfwHideWindow(platform.handle); |
| 403 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN); |
| 404 | } |
| 405 | |
| 406 | |
| 407 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED) != FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED)) && FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED)) |
| 408 | { |
| 409 | |
| 410 | MinimizeWindow(); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED) != FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)) && FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED)) |
| 415 | { |
| 416 | |
| 417 | MaximizeWindow(); |
| 418 | } |
| 419 | |
| 420 | |
| 421 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED) != FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED)) && FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED)) |
| 422 | { |
| 423 | glfwSetWindowAttrib(platform.handle, GLFW_FOCUS_ON_SHOW, GLFW_FALSE); |
| 424 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TOPMOST) != FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST)) && FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST)) |
| 429 | { |
| 430 | glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_TRUE); |
| 431 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_TOPMOST); |
| 432 | } |
| 433 | |
| 434 | |
| 435 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_ALWAYS_RUN) != FLAG_IS_SET(flags, FLAG_WINDOW_ALWAYS_RUN)) && FLAG_IS_SET(flags, FLAG_WINDOW_ALWAYS_RUN)) |
| 436 | { |
| 437 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_ALWAYS_RUN); |
| 438 | } |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TRANSPARENT) != FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT)) && FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT)) |
| 444 | { |
| 445 | TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization"); |
| 446 | } |
| 447 | |
| 448 | |
| 449 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) != FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI)) && FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI)) |
| 450 | { |
| 451 | TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization"); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MOUSE_PASSTHROUGH) != FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH)) && FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH)) |
| 456 | { |
| 457 | glfwSetWindowAttrib(platform.handle, GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE); |
| 458 | FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MOUSE_PASSTHROUGH); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT) != FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT)) && FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT)) |
| 463 | { |
| 464 | TRACELOG(LOG_WARNING, "WINDOW: MSAA can only be configured before window initialization"); |
| 465 | } |
| 466 | |
| 467 | |
| 468 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_INTERLACED_HINT) != FLAG_IS_SET(flags, FLAG_INTERLACED_HINT)) && FLAG_IS_SET(flags, FLAG_INTERLACED_HINT)) |
| 469 | { |
| 470 | TRACELOG(LOG_WARNING, "WINDOW: Interlaced mode can only be configured before window initialization"); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | |
| 475 | void ClearWindowState(unsigned int flags) |
| 476 | { |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) && (FLAG_IS_SET(flags, FLAG_VSYNC_HINT))) |
| 482 | { |
| 483 | glfwSwapInterval(0); |
| 484 | FLAG_CLEAR(CORE.Window.flags, FLAG_VSYNC_HINT); |
| 485 | } |
| 486 | |
| 487 | |
| 488 | |
| 489 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_BORDERLESS_WINDOWED_MODE)) && (FLAG_IS_SET(flags, FLAG_BORDERLESS_WINDOWED_MODE))) |
| 490 | { |
| 491 | ToggleBorderlessWindowed(); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) && (FLAG_IS_SET(flags, FLAG_FULLSCREEN_MODE))) |
| 496 | { |
| 497 | ToggleFullscreen(); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) && (FLAG_IS_SET(flags, FLAG_WINDOW_RESIZABLE))) |
| 502 | { |
| 503 | glfwSetWindowAttrib(platform.handle, GLFW_RESIZABLE, GLFW_FALSE); |
| 504 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_RESIZABLE); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) && (FLAG_IS_SET(flags, FLAG_WINDOW_HIDDEN))) |
| 509 | { |
| 510 | glfwShowWindow(platform.handle); |
| 511 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_HIDDEN); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) && (FLAG_IS_SET(flags, FLAG_WINDOW_MINIMIZED))) |
| 516 | { |
| 517 | RestoreWindow(); |
| 518 | } |
| 519 | |
| 520 | |
| 521 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)) && (FLAG_IS_SET(flags, FLAG_WINDOW_MAXIMIZED))) |
| 522 | { |
| 523 | RestoreWindow(); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED)) && (FLAG_IS_SET(flags, FLAG_WINDOW_UNDECORATED))) |
| 528 | { |
| 529 | glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE); |
| 530 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNDECORATED); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) && (FLAG_IS_SET(flags, FLAG_WINDOW_UNFOCUSED))) |
| 535 | { |
| 536 | glfwSetWindowAttrib(platform.handle, GLFW_FOCUS_ON_SHOW, GLFW_TRUE); |
| 537 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 538 | } |
| 539 | |
| 540 | |
| 541 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TOPMOST)) && (FLAG_IS_SET(flags, FLAG_WINDOW_TOPMOST))) |
| 542 | { |
| 543 | glfwSetWindowAttrib(platform.handle, GLFW_FLOATING, GLFW_FALSE); |
| 544 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_TOPMOST); |
| 545 | } |
| 546 | |
| 547 | |
| 548 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_ALWAYS_RUN)) && (FLAG_IS_SET(flags, FLAG_WINDOW_ALWAYS_RUN))) |
| 549 | { |
| 550 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_ALWAYS_RUN); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TRANSPARENT)) && (FLAG_IS_SET(flags, FLAG_WINDOW_TRANSPARENT))) |
| 557 | { |
| 558 | TRACELOG(LOG_WARNING, "WINDOW: Framebuffer transparency can only be configured before window initialization"); |
| 559 | } |
| 560 | |
| 561 | |
| 562 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) && (FLAG_IS_SET(flags, FLAG_WINDOW_HIGHDPI))) |
| 563 | { |
| 564 | TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization"); |
| 565 | } |
| 566 | |
| 567 | |
| 568 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MOUSE_PASSTHROUGH)) && (FLAG_IS_SET(flags, FLAG_WINDOW_MOUSE_PASSTHROUGH))) |
| 569 | { |
| 570 | glfwSetWindowAttrib(platform.handle, GLFW_MOUSE_PASSTHROUGH, GLFW_FALSE); |
| 571 | FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MOUSE_PASSTHROUGH); |
| 572 | } |
| 573 | |
| 574 | |
| 575 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT)) && (FLAG_IS_SET(flags, FLAG_MSAA_4X_HINT))) |
| 576 | { |
| 577 | TRACELOG(LOG_WARNING, "WINDOW: MSAA can only be configured before window initialization"); |
| 578 | } |
| 579 | |
| 580 | |
| 581 | if ((FLAG_IS_SET(CORE.Window.flags, FLAG_INTERLACED_HINT)) && (FLAG_IS_SET(flags, FLAG_INTERLACED_HINT))) |
| 582 | { |
| 583 | TRACELOG(LOG_WARNING, "RPI: Interlaced mode can only be configured before window initialization"); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | void SetWindowIcon(Image image) |
| 591 | { |
| 592 | if (image.data == NULL) |
| 593 | { |
| 594 | |
| 595 | glfwSetWindowIcon(platform.handle, 0, NULL); |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | if (image.format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) |
| 600 | { |
| 601 | GLFWimage icon[1] = { 0 }; |
| 602 | |
| 603 | icon[0].width = image.width; |
| 604 | icon[0].height = image.height; |
| 605 | icon[0].pixels = (unsigned char *)image.data; |
| 606 | |
| 607 | |
| 608 | |
| 609 | glfwSetWindowIcon(platform.handle, 1, icon); |
| 610 | } |
| 611 | else TRACELOG(LOG_WARNING, "GLFW: Window icon image must be in R8G8B8A8 pixel format"); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | void SetWindowIcons(Image *images, int count) |
| 620 | { |
| 621 | if ((images == NULL) || (count <= 0)) |
| 622 | { |
| 623 | |
| 624 | glfwSetWindowIcon(platform.handle, 0, NULL); |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | int valid = 0; |
| 629 | GLFWimage *icons = (GLFWimage *)RL_CALLOC(count, sizeof(GLFWimage)); |
| 630 | |
| 631 | for (int i = 0; i < count; i++) |
| 632 | { |
| 633 | if (images[i].format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) |
| 634 | { |
| 635 | icons[valid].width = images[i].width; |
| 636 | icons[valid].height = images[i].height; |
| 637 | icons[valid].pixels = (unsigned char *)images[i].data; |
| 638 | |
| 639 | valid++; |
| 640 | } |
| 641 | else TRACELOG(LOG_WARNING, "GLFW: Window icon image must be in R8G8B8A8 pixel format"); |
| 642 | } |
| 643 | |
| 644 | glfwSetWindowIcon(platform.handle, valid, icons); |
| 645 | |
| 646 | RL_FREE(icons); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | |
| 651 | void SetWindowTitle(const char *title) |
| 652 | { |
| 653 | CORE.Window.title = title; |
| 654 | glfwSetWindowTitle(platform.handle, title); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | void SetWindowPosition(int x, int y) |
| 659 | { |
| 660 | |
| 661 | CORE.Window.position.x = x; |
| 662 | CORE.Window.position.y = y; |
| 663 | glfwSetWindowPos(platform.handle, x, y); |
| 664 | } |
| 665 | |
| 666 | |
| 667 | void SetWindowMonitor(int monitor) |
| 668 | { |
| 669 | int monitorCount = 0; |
| 670 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 671 | |
| 672 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 673 | { |
| 674 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 675 | { |
| 676 | TRACELOG(LOG_INFO, "GLFW: Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor])); |
| 677 | |
| 678 | const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); |
| 679 | glfwSetWindowMonitor(platform.handle, monitors[monitor], 0, 0, mode->width, mode->height, mode->refreshRate); |
| 680 | } |
| 681 | else |
| 682 | { |
| 683 | TRACELOG(LOG_INFO, "GLFW: Selected monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor])); |
| 684 | |
| 685 | |
| 686 | const int screenWidth = CORE.Window.render.width; |
| 687 | const int screenHeight = CORE.Window.render.height; |
| 688 | int monitorWorkareaX = 0; |
| 689 | int monitorWorkareaY = 0; |
| 690 | int monitorWorkareaWidth = 0; |
| 691 | int monitorWorkareaHeight = 0; |
| 692 | glfwGetMonitorWorkarea(monitors[monitor], &monitorWorkareaX, &monitorWorkareaY, &monitorWorkareaWidth, &monitorWorkareaHeight); |
| 693 | |
| 694 | |
| 695 | if ((screenWidth >= monitorWorkareaWidth) || (screenHeight >= monitorWorkareaHeight)) glfwSetWindowPos(platform.handle, monitorWorkareaX, monitorWorkareaY); |
| 696 | else |
| 697 | { |
| 698 | const int x = monitorWorkareaX + (monitorWorkareaWidth/2) - (screenWidth/2); |
| 699 | const int y = monitorWorkareaY + (monitorWorkareaHeight/2) - (screenHeight/2); |
| 700 | glfwSetWindowPos(platform.handle, x, y); |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | void SetWindowMinSize(int width, int height) |
| 709 | { |
| 710 | CORE.Window.screenMin.width = width; |
| 711 | CORE.Window.screenMin.height = height; |
| 712 | |
| 713 | int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.width; |
| 714 | int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.height; |
| 715 | int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.width; |
| 716 | int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.height; |
| 717 | |
| 718 | glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight); |
| 719 | } |
| 720 | |
| 721 | |
| 722 | void SetWindowMaxSize(int width, int height) |
| 723 | { |
| 724 | CORE.Window.screenMax.width = width; |
| 725 | CORE.Window.screenMax.height = height; |
| 726 | |
| 727 | int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.width; |
| 728 | int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.height; |
| 729 | int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.width; |
| 730 | int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.height; |
| 731 | |
| 732 | glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight); |
| 733 | } |
| 734 | |
| 735 | |
| 736 | void SetWindowSize(int width, int height) |
| 737 | { |
| 738 | CORE.Window.screen.width = width; |
| 739 | CORE.Window.screen.height = height; |
| 740 | |
| 741 | glfwSetWindowSize(platform.handle, width, height); |
| 742 | } |
| 743 | |
| 744 | |
| 745 | void SetWindowOpacity(float opacity) |
| 746 | { |
| 747 | if (opacity >= 1.0f) opacity = 1.0f; |
| 748 | else if (opacity <= 0.0f) opacity = 0.0f; |
| 749 | glfwSetWindowOpacity(platform.handle, opacity); |
| 750 | } |
| 751 | |
| 752 | |
| 753 | void SetWindowFocused(void) |
| 754 | { |
| 755 | glfwFocusWindow(platform.handle); |
| 756 | } |
| 757 | |
| 758 | #if defined(__linux__) && defined(_GLFW_X11) |
| 759 | |
| 760 | |
| 761 | |
| 762 | static XID X11WindowHandle; |
| 763 | #endif |
| 764 | |
| 765 | void *GetWindowHandle(void) |
| 766 | { |
| 767 | #if defined(_WIN32) |
| 768 | |
| 769 | return glfwGetWin32Window(platform.handle); |
| 770 | #endif |
| 771 | #if defined(__linux__) |
| 772 | #if defined(_GLFW_WAYLAND) |
| 773 | #if defined(_GLFW_X11) |
| 774 | int platformID = glfwGetPlatform(); |
| 775 | if (platformID == GLFW_PLATFORM_WAYLAND) |
| 776 | { |
| 777 | return glfwGetWaylandWindow(platform.handle); |
| 778 | } |
| 779 | else |
| 780 | { |
| 781 | X11WindowHandle = glfwGetX11Window(platform.handle); |
| 782 | return &X11WindowHandle; |
| 783 | } |
| 784 | #else |
| 785 | return glfwGetWaylandWindow(platform.handle); |
| 786 | #endif |
| 787 | #elif defined(_GLFW_X11) |
| 788 | |
| 789 | |
| 790 | X11WindowHandle = glfwGetX11Window(platform.handle); |
| 791 | return &X11WindowHandle; |
| 792 | #endif |
| 793 | #endif |
| 794 | #if defined(__APPLE__) |
| 795 | |
| 796 | return (void *)glfwGetCocoaWindow(platform.handle); |
| 797 | #endif |
| 798 | |
| 799 | return NULL; |
| 800 | } |
| 801 | |
| 802 | |
| 803 | int GetMonitorCount(void) |
| 804 | { |
| 805 | int monitorCount = 0; |
| 806 | |
| 807 | glfwGetMonitors(&monitorCount); |
| 808 | |
| 809 | return monitorCount; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | int GetCurrentMonitor(void) |
| 814 | { |
| 815 | int index = 0; |
| 816 | int monitorCount = 0; |
| 817 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 818 | GLFWmonitor *monitor = NULL; |
| 819 | |
| 820 | if (monitorCount >= 1) |
| 821 | { |
| 822 | if (IsWindowFullscreen()) |
| 823 | { |
| 824 | |
| 825 | monitor = glfwGetWindowMonitor(platform.handle); |
| 826 | |
| 827 | for (int i = 0; i < monitorCount; i++) |
| 828 | { |
| 829 | if (monitors[i] == monitor) |
| 830 | { |
| 831 | index = i; |
| 832 | break; |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | else |
| 837 | { |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | int closestDist = 0x7FFFFFFF; |
| 844 | |
| 845 | |
| 846 | int wcx = 0; |
| 847 | int wcy = 0; |
| 848 | |
| 849 | glfwGetWindowPos(platform.handle, &wcx, &wcy); |
| 850 | wcx += (int)CORE.Window.screen.width/2; |
| 851 | wcy += (int)CORE.Window.screen.height/2; |
| 852 | |
| 853 | for (int i = 0; i < monitorCount; i++) |
| 854 | { |
| 855 | |
| 856 | int mx = 0; |
| 857 | int my = 0; |
| 858 | |
| 859 | monitor = monitors[i]; |
| 860 | glfwGetMonitorPos(monitor, &mx, &my); |
| 861 | const GLFWvidmode *mode = glfwGetVideoMode(monitor); |
| 862 | |
| 863 | if (mode) |
| 864 | { |
| 865 | const int right = mx + mode->width - 1; |
| 866 | const int bottom = my + mode->height - 1; |
| 867 | |
| 868 | if ((wcx >= mx) && |
| 869 | (wcx <= right) && |
| 870 | (wcy >= my) && |
| 871 | (wcy <= bottom)) |
| 872 | { |
| 873 | index = i; |
| 874 | break; |
| 875 | } |
| 876 | |
| 877 | int xclosest = wcx; |
| 878 | if (wcx < mx) xclosest = mx; |
| 879 | else if (wcx > right) xclosest = right; |
| 880 | |
| 881 | int yclosest = wcy; |
| 882 | if (wcy < my) yclosest = my; |
| 883 | else if (wcy > bottom) yclosest = bottom; |
| 884 | |
| 885 | int dx = wcx - xclosest; |
| 886 | int dy = wcy - yclosest; |
| 887 | int dist = (dx*dx) + (dy*dy); |
| 888 | if (dist < closestDist) |
| 889 | { |
| 890 | index = i; |
| 891 | closestDist = dist; |
| 892 | } |
| 893 | } |
| 894 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | return index; |
| 900 | } |
| 901 | |
| 902 | |
| 903 | Vector2 GetMonitorPosition(int monitor) |
| 904 | { |
| 905 | int monitorCount = 0; |
| 906 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 907 | |
| 908 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 909 | { |
| 910 | int x = 0; |
| 911 | int y = 0; |
| 912 | glfwGetMonitorPos(monitors[monitor], &x, &y); |
| 913 | |
| 914 | return (Vector2){ (float)x, (float)y }; |
| 915 | } |
| 916 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 917 | return (Vector2){ 0, 0 }; |
| 918 | } |
| 919 | |
| 920 | |
| 921 | int GetMonitorWidth(int monitor) |
| 922 | { |
| 923 | int width = 0; |
| 924 | int monitorCount = 0; |
| 925 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 926 | |
| 927 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 928 | { |
| 929 | const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); |
| 930 | |
| 931 | if (mode) width = mode->width; |
| 932 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); |
| 933 | } |
| 934 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 935 | |
| 936 | return width; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | int GetMonitorHeight(int monitor) |
| 941 | { |
| 942 | int height = 0; |
| 943 | int monitorCount = 0; |
| 944 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 945 | |
| 946 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 947 | { |
| 948 | const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); |
| 949 | |
| 950 | if (mode) height = mode->height; |
| 951 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); |
| 952 | } |
| 953 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 954 | |
| 955 | return height; |
| 956 | } |
| 957 | |
| 958 | |
| 959 | int GetMonitorPhysicalWidth(int monitor) |
| 960 | { |
| 961 | int width = 0; |
| 962 | int monitorCount = 0; |
| 963 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 964 | |
| 965 | if ((monitor >= 0) && (monitor < monitorCount)) glfwGetMonitorPhysicalSize(monitors[monitor], &width, NULL); |
| 966 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 967 | |
| 968 | return width; |
| 969 | } |
| 970 | |
| 971 | |
| 972 | int GetMonitorPhysicalHeight(int monitor) |
| 973 | { |
| 974 | int height = 0; |
| 975 | int monitorCount = 0; |
| 976 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 977 | |
| 978 | if ((monitor >= 0) && (monitor < monitorCount)) glfwGetMonitorPhysicalSize(monitors[monitor], NULL, &height); |
| 979 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 980 | |
| 981 | return height; |
| 982 | } |
| 983 | |
| 984 | |
| 985 | int GetMonitorRefreshRate(int monitor) |
| 986 | { |
| 987 | int refresh = 0; |
| 988 | int monitorCount = 0; |
| 989 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 990 | |
| 991 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 992 | { |
| 993 | const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]); |
| 994 | |
| 995 | if (mode) refresh = mode->refreshRate; |
| 996 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor"); |
| 997 | |
| 998 | } |
| 999 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 1000 | |
| 1001 | return refresh; |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | const char *GetMonitorName(int monitor) |
| 1006 | { |
| 1007 | int monitorCount = 0; |
| 1008 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 1009 | |
| 1010 | if ((monitor >= 0) && (monitor < monitorCount)) |
| 1011 | { |
| 1012 | return glfwGetMonitorName(monitors[monitor]); |
| 1013 | } |
| 1014 | else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor"); |
| 1015 | return ""; |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | Vector2 GetWindowPosition(void) |
| 1020 | { |
| 1021 | return (Vector2){ (float)CORE.Window.position.x, (float)CORE.Window.position.y }; |
| 1022 | } |
| 1023 | |
| 1024 | |
| 1025 | Vector2 GetWindowScaleDPI(void) |
| 1026 | { |
| 1027 | Vector2 scale = { 1.0f, 1.0f }; |
| 1028 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI) && !FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 1029 | glfwGetWindowContentScale(platform.handle, &scale.x, &scale.y); |
| 1030 | return scale; |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | void SetClipboardText(const char *text) |
| 1035 | { |
| 1036 | glfwSetClipboardString(platform.handle, text); |
| 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | const char *GetClipboardText(void) |
| 1042 | { |
| 1043 | return glfwGetClipboardString(platform.handle); |
| 1044 | } |
| 1045 | |
| 1046 | #if SUPPORT_CLIPBOARD_IMAGE && defined(__linux__) && defined(_GLFW_X11) |
| 1047 | #include <X11/Xlib.h> |
| 1048 | #include <X11/Xatom.h> |
| 1049 | #endif |
| 1050 | |
| 1051 | |
| 1052 | Image GetClipboardImage(void) |
| 1053 | { |
| 1054 | Image image = { 0 }; |
| 1055 | |
| 1056 | #if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES |
| 1057 | #if defined(_WIN32) |
| 1058 | unsigned long long int dataSize = 0; |
| 1059 | void *bmpData = NULL; |
| 1060 | int width = 0; |
| 1061 | int height = 0; |
| 1062 | |
| 1063 | bmpData = (void *)Win32GetClipboardImageData(&width, &height, &dataSize); |
| 1064 | |
| 1065 | if (bmpData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); |
| 1066 | else image = LoadImageFromMemory(".bmp", (const unsigned char *)bmpData, (int)dataSize); |
| 1067 | |
| 1068 | #elif defined(__linux__) && defined(_GLFW_X11) |
| 1069 | |
| 1070 | |
| 1071 | Display *dpy = XOpenDisplay(NULL); |
| 1072 | if (!dpy) return image; |
| 1073 | |
| 1074 | Window root = DefaultRootWindow(dpy); |
| 1075 | Window win = XCreateSimpleWindow( |
| 1076 | dpy, |
| 1077 | root, |
| 1078 | 0, 0, |
| 1079 | 1, 1, |
| 1080 | 0, |
| 1081 | 0, |
| 1082 | 0 |
| 1083 | ); |
| 1084 | |
| 1085 | Atom clipboard = XInternAtom(dpy, "CLIPBOARD", False); |
| 1086 | Atom targetType = XInternAtom(dpy, "image/png", False); |
| 1087 | Atom property = XInternAtom(dpy, "RAYLIB_CLIPBOARD_MANAGER", False); |
| 1088 | |
| 1089 | |
| 1090 | XConvertSelection(dpy, clipboard, targetType, property, win, CurrentTime); |
| 1091 | |
| 1092 | |
| 1093 | XEvent ev = { 0 }; |
| 1094 | XNextEvent(dpy, &ev); |
| 1095 | |
| 1096 | Atom actualType = { 0 }; |
| 1097 | int actualFormat = 0; |
| 1098 | unsigned long nitems = 0; |
| 1099 | unsigned long bytesAfter = 0; |
| 1100 | unsigned char *data = NULL; |
| 1101 | |
| 1102 | |
| 1103 | XGetWindowProperty(dpy, win, property, 0, ~0L, False, AnyPropertyType, |
| 1104 | &actualType, &actualFormat, &nitems, &bytesAfter, &data); |
| 1105 | |
| 1106 | if (data != NULL) |
| 1107 | { |
| 1108 | image = LoadImageFromMemory(".png", data, (int)nitems); |
| 1109 | XFree(data); |
| 1110 | } |
| 1111 | |
| 1112 | XDestroyWindow(dpy, win); |
| 1113 | XCloseDisplay(dpy); |
| 1114 | #else |
| 1115 | TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); |
| 1116 | #endif |
| 1117 | #else |
| 1118 | TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly"); |
| 1119 | #endif |
| 1120 | |
| 1121 | return image; |
| 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | void ShowCursor(void) |
| 1126 | { |
| 1127 | glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL); |
| 1128 | |
| 1129 | CORE.Input.Mouse.cursorHidden = false; |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | void HideCursor(void) |
| 1134 | { |
| 1135 | glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); |
| 1136 | |
| 1137 | CORE.Input.Mouse.cursorHidden = true; |
| 1138 | } |
| 1139 | |
| 1140 | |
| 1141 | void EnableCursor(void) |
| 1142 | { |
| 1143 | glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL); |
| 1144 | |
| 1145 | |
| 1146 | SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); |
| 1147 | |
| 1148 | if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); |
| 1149 | |
| 1150 | CORE.Input.Mouse.cursorHidden = false; |
| 1151 | CORE.Input.Mouse.cursorLocked = false; |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | void DisableCursor(void) |
| 1156 | { |
| 1157 | |
| 1158 | SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2); |
| 1159 | |
| 1160 | glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED); |
| 1161 | |
| 1162 | if (glfwRawMouseMotionSupported()) glfwSetInputMode(platform.handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE); |
| 1163 | |
| 1164 | CORE.Input.Mouse.cursorHidden = true; |
| 1165 | CORE.Input.Mouse.cursorLocked = true; |
| 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | void SwapScreenBuffer(void) |
| 1170 | { |
| 1171 | glfwSwapBuffers(platform.handle); |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | double GetTime(void) |
| 1180 | { |
| 1181 | double time = glfwGetTime(); |
| 1182 | |
| 1183 | return time; |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | void OpenURL(const char *url) |
| 1192 | { |
| 1193 | |
| 1194 | if (strchr(url, '\'') != NULL) TRACELOG(LOG_WARNING, "SYSTEM: Provided URL could be potentially malicious, avoid [\'] character"); |
| 1195 | else |
| 1196 | { |
| 1197 | char *cmd = (char *)RL_CALLOC(strlen(url) + 32, sizeof(char)); |
| 1198 | #if defined(_WIN32) |
| 1199 | sprintf(cmd, "explorer \"%s\"", url); |
| 1200 | #endif |
| 1201 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
| 1202 | sprintf(cmd, "xdg-open '%s'", url); |
| 1203 | #endif |
| 1204 | #if defined(__APPLE__) |
| 1205 | sprintf(cmd, "open '%s'", url); |
| 1206 | #endif |
| 1207 | int result = system(cmd); |
| 1208 | if (result == -1) TRACELOG(LOG_WARNING, "OpenURL() child process could not be created"); |
| 1209 | RL_FREE(cmd); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | int SetGamepadMappings(const char *mappings) |
| 1219 | { |
| 1220 | return glfwUpdateGamepadMappings(mappings); |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration) |
| 1225 | { |
| 1226 | TRACELOG(LOG_WARNING, "SetGamepadVibration() not available on target platform"); |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | void SetMousePosition(int x, int y) |
| 1231 | { |
| 1232 | CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y }; |
| 1233 | CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; |
| 1234 | |
| 1235 | |
| 1236 | glfwSetCursorPos(platform.handle, CORE.Input.Mouse.currentPosition.x, CORE.Input.Mouse.currentPosition.y); |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | void SetMouseCursor(int cursor) |
| 1241 | { |
| 1242 | CORE.Input.Mouse.cursor = cursor; |
| 1243 | if (cursor == MOUSE_CURSOR_DEFAULT) glfwSetCursor(platform.handle, NULL); |
| 1244 | else |
| 1245 | { |
| 1246 | |
| 1247 | glfwSetCursor(platform.handle, glfwCreateStandardCursor(0x00036000 + cursor)); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | const char *GetKeyName(int key) |
| 1253 | { |
| 1254 | return glfwGetKeyName(key, glfwGetKeyScancode(key)); |
| 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | void PollInputEvents(void) |
| 1259 | { |
| 1260 | #if SUPPORT_GESTURES_SYSTEM |
| 1261 | |
| 1262 | |
| 1263 | UpdateGestures(); |
| 1264 | #endif |
| 1265 | |
| 1266 | |
| 1267 | CORE.Input.Keyboard.keyPressedQueueCount = 0; |
| 1268 | CORE.Input.Keyboard.charPressedQueueCount = 0; |
| 1269 | |
| 1270 | |
| 1271 | CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_UNKNOWN; |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | for (int i = 0; i < MAX_KEYBOARD_KEYS; i++) |
| 1278 | { |
| 1279 | CORE.Input.Keyboard.previousKeyState[i] = CORE.Input.Keyboard.currentKeyState[i]; |
| 1280 | CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | for (int i = 0; i < MAX_MOUSE_BUTTONS; i++) CORE.Input.Mouse.previousButtonState[i] = CORE.Input.Mouse.currentButtonState[i]; |
| 1285 | |
| 1286 | |
| 1287 | CORE.Input.Mouse.previousWheelMove = CORE.Input.Mouse.currentWheelMove; |
| 1288 | CORE.Input.Mouse.currentWheelMove = (Vector2){ 0.0f, 0.0f }; |
| 1289 | |
| 1290 | |
| 1291 | CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; |
| 1292 | |
| 1293 | |
| 1294 | for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i]; |
| 1295 | |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | |
| 1304 | CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | for (int i = 0; i < MAX_GAMEPADS; i++) |
| 1309 | { |
| 1310 | if (glfwJoystickPresent(i)) CORE.Input.Gamepad.ready[i] = true; |
| 1311 | else CORE.Input.Gamepad.ready[i] = false; |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | for (int i = 0; i < MAX_GAMEPADS; i++) |
| 1316 | { |
| 1317 | if (CORE.Input.Gamepad.ready[i]) |
| 1318 | { |
| 1319 | |
| 1320 | for (int k = 0; k < MAX_GAMEPAD_BUTTONS; k++) CORE.Input.Gamepad.previousButtonState[i][k] = CORE.Input.Gamepad.currentButtonState[i][k]; |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | GLFWgamepadstate state = { 0 }; |
| 1325 | int result = glfwGetGamepadState(i, &state); |
| 1326 | if (result == GLFW_FALSE) |
| 1327 | { |
| 1328 | |
| 1329 | state.axes[GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; |
| 1330 | state.axes[GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; |
| 1331 | } |
| 1332 | |
| 1333 | const unsigned char *buttons = state.buttons; |
| 1334 | |
| 1335 | for (int k = 0; (buttons != NULL) && (k < MAX_GAMEPAD_BUTTONS); k++) |
| 1336 | { |
| 1337 | int button = -1; |
| 1338 | |
| 1339 | switch (k) |
| 1340 | { |
| 1341 | case GLFW_GAMEPAD_BUTTON_Y: button = GAMEPAD_BUTTON_RIGHT_FACE_UP; break; |
| 1342 | case GLFW_GAMEPAD_BUTTON_B: button = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; break; |
| 1343 | case GLFW_GAMEPAD_BUTTON_A: button = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; break; |
| 1344 | case GLFW_GAMEPAD_BUTTON_X: button = GAMEPAD_BUTTON_RIGHT_FACE_LEFT; break; |
| 1345 | |
| 1346 | case GLFW_GAMEPAD_BUTTON_LEFT_BUMPER: button = GAMEPAD_BUTTON_LEFT_TRIGGER_1; break; |
| 1347 | case GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER: button = GAMEPAD_BUTTON_RIGHT_TRIGGER_1; break; |
| 1348 | |
| 1349 | case GLFW_GAMEPAD_BUTTON_BACK: button = GAMEPAD_BUTTON_MIDDLE_LEFT; break; |
| 1350 | case GLFW_GAMEPAD_BUTTON_GUIDE: button = GAMEPAD_BUTTON_MIDDLE; break; |
| 1351 | case GLFW_GAMEPAD_BUTTON_START: button = GAMEPAD_BUTTON_MIDDLE_RIGHT; break; |
| 1352 | |
| 1353 | case GLFW_GAMEPAD_BUTTON_DPAD_UP: button = GAMEPAD_BUTTON_LEFT_FACE_UP; break; |
| 1354 | case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT: button = GAMEPAD_BUTTON_LEFT_FACE_RIGHT; break; |
| 1355 | case GLFW_GAMEPAD_BUTTON_DPAD_DOWN: button = GAMEPAD_BUTTON_LEFT_FACE_DOWN; break; |
| 1356 | case GLFW_GAMEPAD_BUTTON_DPAD_LEFT: button = GAMEPAD_BUTTON_LEFT_FACE_LEFT; break; |
| 1357 | |
| 1358 | case GLFW_GAMEPAD_BUTTON_LEFT_THUMB: button = GAMEPAD_BUTTON_LEFT_THUMB; break; |
| 1359 | case GLFW_GAMEPAD_BUTTON_RIGHT_THUMB: button = GAMEPAD_BUTTON_RIGHT_THUMB; break; |
| 1360 | default: break; |
| 1361 | } |
| 1362 | |
| 1363 | if (button != -1) |
| 1364 | { |
| 1365 | if (buttons[k] == GLFW_PRESS) |
| 1366 | { |
| 1367 | CORE.Input.Gamepad.currentButtonState[i][button] = 1; |
| 1368 | CORE.Input.Gamepad.lastButtonPressed = button; |
| 1369 | } |
| 1370 | else CORE.Input.Gamepad.currentButtonState[i][button] = 0; |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | |
| 1375 | const float *axes = state.axes; |
| 1376 | |
| 1377 | for (int k = 0; (axes != NULL) && (k < GLFW_GAMEPAD_AXIS_LAST + 1); k++) |
| 1378 | { |
| 1379 | CORE.Input.Gamepad.axisState[i][k] = axes[k]; |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | if (CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1f) |
| 1384 | { |
| 1385 | CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = 1; |
| 1386 | CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_LEFT_TRIGGER_2; |
| 1387 | } |
| 1388 | else CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = 0; |
| 1389 | if (CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.1f) |
| 1390 | { |
| 1391 | CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = 1; |
| 1392 | CORE.Input.Gamepad.lastButtonPressed = GAMEPAD_BUTTON_RIGHT_TRIGGER_2; |
| 1393 | } |
| 1394 | else CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = 0; |
| 1395 | |
| 1396 | CORE.Input.Gamepad.axisCount[i] = GLFW_GAMEPAD_AXIS_LAST + 1; |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | CORE.Window.resizedLastFrame = false; |
| 1401 | |
| 1402 | if ((CORE.Window.eventWaiting) || |
| 1403 | (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED) && !FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_ALWAYS_RUN))) |
| 1404 | { |
| 1405 | glfwWaitEvents(); |
| 1406 | CORE.Time.previous = GetTime(); |
| 1407 | } |
| 1408 | else glfwPollEvents(); |
| 1409 | |
| 1410 | CORE.Window.shouldClose = glfwWindowShouldClose(platform.handle); |
| 1411 | |
| 1412 | |
| 1413 | glfwSetWindowShouldClose(platform.handle, GLFW_FALSE); |
| 1414 | } |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | static void *AllocateWrapper(size_t size, void *user) |
| 1423 | { |
| 1424 | (void)user; |
| 1425 | return RL_CALLOC(size, 1); |
| 1426 | } |
| 1427 | static void *ReallocateWrapper(void *block, size_t size, void *user) |
| 1428 | { |
| 1429 | (void)user; |
| 1430 | return RL_REALLOC(block, size); |
| 1431 | } |
| 1432 | static void DeallocateWrapper(void *block, void *user) |
| 1433 | { |
| 1434 | (void)user; |
| 1435 | RL_FREE(block); |
| 1436 | } |
| 1437 | |
| 1438 | |
| 1439 | int InitPlatform(void) |
| 1440 | { |
| 1441 | glfwSetErrorCallback(ErrorCallback); |
| 1442 | |
| 1443 | const GLFWallocator allocator = { |
| 1444 | .allocate = AllocateWrapper, |
| 1445 | .reallocate = ReallocateWrapper, |
| 1446 | .deallocate = DeallocateWrapper, |
| 1447 | .user = NULL, |
| 1448 | }; |
| 1449 | |
| 1450 | glfwInitAllocator(&allocator); |
| 1451 | |
| 1452 | #if defined(__APPLE__) |
| 1453 | glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE); |
| 1454 | #endif |
| 1455 | |
| 1456 | int result = glfwInit(); |
| 1457 | if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; } |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | glfwDefaultWindowHints(); |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | glfwWindowHint(GLFW_AUTO_ICONIFY, 0); |
| 1475 | |
| 1476 | |
| 1477 | unsigned int requestedWindowFlags = CORE.Window.flags; |
| 1478 | |
| 1479 | |
| 1480 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIDDEN)) glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
| 1481 | else glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); |
| 1482 | |
| 1483 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNDECORATED)) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); |
| 1484 | else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); |
| 1485 | |
| 1486 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_RESIZABLE)) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); |
| 1487 | else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); |
| 1488 | |
| 1489 | |
| 1490 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 1491 | |
| 1492 | |
| 1493 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED)) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 1494 | |
| 1495 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED)) glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE); |
| 1496 | else glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE); |
| 1497 | |
| 1498 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TOPMOST)) glfwWindowHint(GLFW_FLOATING, GLFW_TRUE); |
| 1499 | else glfwWindowHint(GLFW_FLOATING, GLFW_FALSE); |
| 1500 | |
| 1501 | |
| 1502 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_TRANSPARENT)) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); |
| 1503 | else glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); |
| 1504 | |
| 1505 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1506 | { |
| 1507 | #if defined(__APPLE__) |
| 1508 | glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_FALSE); |
| 1509 | #endif |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); |
| 1515 | #if defined(__APPLE__) |
| 1516 | glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE); |
| 1517 | #endif |
| 1518 | } |
| 1519 | else |
| 1520 | { |
| 1521 | glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE); |
| 1522 | #if defined(__APPLE__) |
| 1523 | glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_FALSE); |
| 1524 | #endif |
| 1525 | #if defined(_GLFW_WAYLAND) && !defined(_GLFW_X11) |
| 1526 | |
| 1527 | |
| 1528 | glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_FALSE); |
| 1529 | #endif |
| 1530 | } |
| 1531 | |
| 1532 | |
| 1533 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MOUSE_PASSTHROUGH)) glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE); |
| 1534 | else glfwWindowHint(GLFW_MOUSE_PASSTHROUGH, GLFW_FALSE); |
| 1535 | |
| 1536 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_MSAA_4X_HINT)) |
| 1537 | { |
| 1538 | |
| 1539 | TRACELOG(LOG_INFO, "DISPLAY: Trying to enable MSAA x4"); |
| 1540 | glfwWindowHint(GLFW_SAMPLES, 4); |
| 1541 | } |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | |
| 1548 | if (rlGetVersion() == RL_OPENGL_21) |
| 1549 | { |
| 1550 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); |
| 1551 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); |
| 1552 | } |
| 1553 | else if (rlGetVersion() == RL_OPENGL_33) |
| 1554 | { |
| 1555 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
| 1556 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 1557 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 1558 | |
| 1559 | #if defined(__APPLE__) |
| 1560 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); |
| 1561 | #else |
| 1562 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE); |
| 1563 | #endif |
| 1564 | |
| 1565 | } |
| 1566 | else if (rlGetVersion() == RL_OPENGL_43) |
| 1567 | { |
| 1568 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); |
| 1569 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 1570 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 1571 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE); |
| 1572 | #if RLGL_ENABLE_OPENGL_DEBUG_CONTEXT |
| 1573 | glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); |
| 1574 | #endif |
| 1575 | } |
| 1576 | else if (rlGetVersion() == RL_OPENGL_ES_20) |
| 1577 | { |
| 1578 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); |
| 1579 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); |
| 1580 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); |
| 1581 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); |
| 1582 | } |
| 1583 | else if (rlGetVersion() == RL_OPENGL_ES_30) |
| 1584 | { |
| 1585 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
| 1586 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); |
| 1587 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); |
| 1588 | glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); |
| 1589 | } |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | glfwSetJoystickCallback(NULL); |
| 1596 | |
| 1597 | if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0)) FLAG_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE); |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 1602 | { |
| 1603 | |
| 1604 | GLFWmonitor *monitor = glfwGetPrimaryMonitor(); |
| 1605 | if (!monitor) |
| 1606 | { |
| 1607 | TRACELOG(LOG_WARNING, "GLFW: Failed to get primary monitor"); |
| 1608 | return -1; |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | const GLFWvidmode *mode = glfwGetVideoMode(monitor); |
| 1613 | |
| 1614 | |
| 1615 | CORE.Window.display.width = mode->width; |
| 1616 | CORE.Window.display.height = mode->height; |
| 1617 | |
| 1618 | |
| 1619 | if ((CORE.Window.screen.width == 0) || (CORE.Window.screen.height == 0)) |
| 1620 | { |
| 1621 | |
| 1622 | CORE.Window.previousScreen.width = 800; |
| 1623 | CORE.Window.previousScreen.height = 450; |
| 1624 | CORE.Window.previousPosition.x = CORE.Window.display.width/2 - 800/2; |
| 1625 | CORE.Window.previousPosition.y = CORE.Window.display.height/2 - 450/2; |
| 1626 | |
| 1627 | |
| 1628 | if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width; |
| 1629 | if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height; |
| 1630 | } |
| 1631 | else |
| 1632 | { |
| 1633 | CORE.Window.previousScreen = CORE.Window.screen; |
| 1634 | CORE.Window.screen = CORE.Window.display; |
| 1635 | } |
| 1636 | |
| 1637 | platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", monitor, NULL); |
| 1638 | if (!platform.handle) |
| 1639 | { |
| 1640 | glfwTerminate(); |
| 1641 | TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window"); |
| 1642 | return -1; |
| 1643 | } |
| 1644 | } |
| 1645 | else |
| 1646 | { |
| 1647 | |
| 1648 | if (CORE.Window.screen.width == 0) CORE.Window.screen.width = 1; |
| 1649 | if (CORE.Window.screen.height == 0) CORE.Window.screen.height = 1; |
| 1650 | |
| 1651 | platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL); |
| 1652 | if (!platform.handle) |
| 1653 | { |
| 1654 | glfwTerminate(); |
| 1655 | TRACELOG(LOG_WARNING, "GLFW: Failed to initialize Window"); |
| 1656 | return -1; |
| 1657 | } |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | int monitorCount = 0; |
| 1663 | int monitorIndex = GetCurrentMonitor(); |
| 1664 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 1665 | |
| 1666 | if (monitorIndex < monitorCount) |
| 1667 | { |
| 1668 | GLFWmonitor *monitor = monitors[monitorIndex]; |
| 1669 | const GLFWvidmode *mode = glfwGetVideoMode(monitor); |
| 1670 | |
| 1671 | |
| 1672 | CORE.Window.display.width = mode->width; |
| 1673 | CORE.Window.display.height = mode->height; |
| 1674 | |
| 1675 | |
| 1676 | if (CORE.Window.screen.width == 0) CORE.Window.screen.width = CORE.Window.display.width; |
| 1677 | if (CORE.Window.screen.height == 0) CORE.Window.screen.height = CORE.Window.display.height; |
| 1678 | |
| 1679 | glfwSetWindowSize(platform.handle, CORE.Window.screen.width, CORE.Window.screen.height); |
| 1680 | } |
| 1681 | else |
| 1682 | { |
| 1683 | |
| 1684 | glfwTerminate(); |
| 1685 | TRACELOG(LOG_WARNING, "GLFW: Failed to determine Monitor to center Window"); |
| 1686 | return -1; |
| 1687 | } |
| 1688 | |
| 1689 | |
| 1690 | CORE.Window.render.width = CORE.Window.screen.width; |
| 1691 | CORE.Window.render.height = CORE.Window.screen.height; |
| 1692 | } |
| 1693 | |
| 1694 | glfwMakeContextCurrent(platform.handle); |
| 1695 | result = glfwGetError(NULL); |
| 1696 | if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR)) CORE.Window.ready = true; |
| 1697 | |
| 1698 | if (CORE.Window.ready) |
| 1699 | { |
| 1700 | |
| 1701 | |
| 1702 | glfwSwapInterval(0); |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) |
| 1708 | { |
| 1709 | |
| 1710 | glfwSwapInterval(1); |
| 1711 | TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC"); |
| 1712 | } |
| 1713 | |
| 1714 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1715 | { |
| 1716 | |
| 1717 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 1718 | CORE.Window.render.width = (int)(CORE.Window.screen.width*scaleDpi.x); |
| 1719 | CORE.Window.render.height = (int)(CORE.Window.screen.height*scaleDpi.y); |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f); |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | #if !defined(__APPLE__) |
| 1729 | if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) |
| 1730 | { |
| 1731 | |
| 1732 | |
| 1733 | int fbWidth = 0; |
| 1734 | int fbHeight = 0; |
| 1735 | glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight); |
| 1736 | |
| 1737 | CORE.Window.render.width = fbWidth; |
| 1738 | CORE.Window.render.height = fbHeight; |
| 1739 | } |
| 1740 | else |
| 1741 | { |
| 1742 | |
| 1743 | SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y); |
| 1744 | |
| 1745 | |
| 1746 | glfwSetWindowSize(platform.handle, CORE.Window.render.width, CORE.Window.render.height); |
| 1747 | } |
| 1748 | #endif |
| 1749 | } |
| 1750 | else CORE.Window.render = CORE.Window.screen; |
| 1751 | |
| 1752 | |
| 1753 | CORE.Window.currentFbo = CORE.Window.render; |
| 1754 | |
| 1755 | TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully %s", |
| 1756 | FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)? "(HighDPI)" : ""); |
| 1757 | TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height); |
| 1758 | TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height); |
| 1759 | TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height); |
| 1760 | TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y); |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | int monitorCount = 0; |
| 1765 | int monitorIndex = GetCurrentMonitor(); |
| 1766 | GLFWmonitor **monitors = glfwGetMonitors(&monitorCount); |
| 1767 | GLFWmonitor *monitor = monitors[monitorIndex]; |
| 1768 | |
| 1769 | int monitorX = 0; |
| 1770 | int monitorY = 0; |
| 1771 | int monitorWidth = 0; |
| 1772 | int monitorHeight = 0; |
| 1773 | glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight); |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | #if defined(__APPLE__) |
| 1780 | CORE.Window.position.x = monitorX + (monitorWidth - CORE.Window.screen.width)/2; |
| 1781 | CORE.Window.position.y = monitorY + (monitorHeight - CORE.Window.screen.height)/2; |
| 1782 | #else |
| 1783 | CORE.Window.position.x = monitorX + (monitorWidth - CORE.Window.render.width)/2; |
| 1784 | CORE.Window.position.y = monitorY + (monitorHeight - CORE.Window.render.height)/2; |
| 1785 | #endif |
| 1786 | SetWindowPosition(CORE.Window.position.x, CORE.Window.position.y); |
| 1787 | |
| 1788 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow(); |
| 1789 | } |
| 1790 | else |
| 1791 | { |
| 1792 | TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device"); |
| 1793 | return -1; |
| 1794 | } |
| 1795 | |
| 1796 | |
| 1797 | SetWindowState(requestedWindowFlags); |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | rlLoadExtensions(glfwGetProcAddress); |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback); |
| 1808 | glfwSetFramebufferSizeCallback(platform.handle, FramebufferSizeCallback); |
| 1809 | glfwSetWindowPosCallback(platform.handle, WindowPosCallback); |
| 1810 | glfwSetWindowMaximizeCallback(platform.handle, WindowMaximizeCallback); |
| 1811 | glfwSetWindowIconifyCallback(platform.handle, WindowIconifyCallback); |
| 1812 | glfwSetWindowFocusCallback(platform.handle, WindowFocusCallback); |
| 1813 | glfwSetDropCallback(platform.handle, WindowDropCallback); |
| 1814 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) glfwSetWindowContentScaleCallback(platform.handle, WindowContentScaleCallback); |
| 1815 | |
| 1816 | |
| 1817 | glfwSetKeyCallback(platform.handle, KeyCallback); |
| 1818 | glfwSetCharCallback(platform.handle, CharCallback); |
| 1819 | glfwSetMouseButtonCallback(platform.handle, MouseButtonCallback); |
| 1820 | glfwSetCursorPosCallback(platform.handle, MouseCursorPosCallback); |
| 1821 | glfwSetScrollCallback(platform.handle, MouseScrollCallback); |
| 1822 | glfwSetCursorEnterCallback(platform.handle, CursorEnterCallback); |
| 1823 | glfwSetJoystickCallback(JoystickCallback); |
| 1824 | glfwSetInputMode(platform.handle, GLFW_LOCK_KEY_MODS, GLFW_TRUE); |
| 1825 | |
| 1826 | |
| 1827 | for (int i = 0; i < MAX_GAMEPADS; i++) |
| 1828 | { |
| 1829 | |
| 1830 | |
| 1831 | if (glfwJoystickPresent(i)) |
| 1832 | { |
| 1833 | CORE.Input.Gamepad.ready[i] = true; |
| 1834 | CORE.Input.Gamepad.axisCount[i] = GLFW_GAMEPAD_AXIS_LAST + 1; |
| 1835 | strncpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i), MAX_GAMEPAD_NAME_LENGTH - 1); |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | InitTimer(); |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | CORE.Storage.basePath = GetWorkingDirectory(); |
| 1848 | |
| 1849 | |
| 1850 | #if defined(__NetBSD__) |
| 1851 | |
| 1852 | char *glfwPlatform = "X11 (NetBSD)"; |
| 1853 | #else |
| 1854 | char *glfwPlatform = ""; |
| 1855 | switch (glfwGetPlatform()) |
| 1856 | { |
| 1857 | case GLFW_PLATFORM_WIN32: glfwPlatform = "Win32"; break; |
| 1858 | case GLFW_PLATFORM_COCOA: glfwPlatform = "Cocoa"; break; |
| 1859 | case GLFW_PLATFORM_WAYLAND: glfwPlatform = "Wayland"; break; |
| 1860 | case GLFW_PLATFORM_X11: glfwPlatform = "X11"; break; |
| 1861 | case GLFW_PLATFORM_NULL: glfwPlatform = "Null"; break; |
| 1862 | default: break; |
| 1863 | } |
| 1864 | #endif |
| 1865 | |
| 1866 | TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (GLFW - %s): Initialized successfully", glfwPlatform); |
| 1867 | |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | |
| 1872 | void ClosePlatform(void) |
| 1873 | { |
| 1874 | glfwDestroyWindow(platform.handle); |
| 1875 | glfwTerminate(); |
| 1876 | |
| 1877 | #if defined(_WIN32) && SUPPORT_WINMM_HIGHRES_TIMER && !SUPPORT_BUSY_WAIT_LOOP |
| 1878 | timeEndPeriod(1); |
| 1879 | #endif |
| 1880 | } |
| 1881 | |
| 1882 | |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | static void ErrorCallback(int error, const char *description) |
| 1889 | { |
| 1890 | TRACELOG(LOG_WARNING, "GLFW: Error: %i Description: %s", error, description); |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | |
| 1895 | static void WindowSizeCallback(GLFWwindow *window, int width, int height) |
| 1896 | { |
| 1897 | |
| 1898 | |
| 1899 | } |
| 1900 | |
| 1901 | |
| 1902 | |
| 1903 | static void FramebufferSizeCallback(GLFWwindow *window, int width, int height) |
| 1904 | { |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | if ((width == 0) || (height == 0)) return; |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | SetupViewport(width, height); |
| 1914 | |
| 1915 | |
| 1916 | CORE.Window.render.width = width; |
| 1917 | CORE.Window.render.height = height; |
| 1918 | CORE.Window.currentFbo = CORE.Window.render; |
| 1919 | CORE.Window.resizedLastFrame = true; |
| 1920 | |
| 1921 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE)) |
| 1922 | { |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | |
| 1927 | CORE.Window.screen.width = width; |
| 1928 | CORE.Window.screen.height = height; |
| 1929 | CORE.Window.screenScale = MatrixScale(1.0f, 1.0f, 1.0f); |
| 1930 | SetMouseScale(1.0f, 1.0f); |
| 1931 | |
| 1932 | |
| 1933 | #if defined(_GLFW_WAYLAND) && !defined(_GLFW_X11) |
| 1934 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1935 | { |
| 1936 | int winWidth = 0; |
| 1937 | int winHeight = 0; |
| 1938 | glfwGetWindowSize(platform.handle, &winWidth, &winHeight); |
| 1939 | |
| 1940 | if ((winWidth != width) || (winHeight != height)) |
| 1941 | { |
| 1942 | CORE.Window.screen.width = winWidth; |
| 1943 | CORE.Window.screen.height = winHeight; |
| 1944 | float scaleX = (float)width/winWidth; |
| 1945 | float scaleY = (float)height/winHeight; |
| 1946 | |
| 1947 | CORE.Window.screenScale = MatrixScale(scaleX, scaleY, 1.0f); |
| 1948 | } |
| 1949 | } |
| 1950 | #endif |
| 1951 | } |
| 1952 | else |
| 1953 | { |
| 1954 | |
| 1955 | if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) |
| 1956 | { |
| 1957 | |
| 1958 | Vector2 scaleDpi = GetWindowScaleDPI(); |
| 1959 | CORE.Window.screen.width = (int)((float)width/scaleDpi.x); |
| 1960 | CORE.Window.screen.height = (int)((float)height/scaleDpi.y); |
| 1961 | CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f); |
| 1962 | #if !defined(__APPLE__) && !defined(_GLFW_WAYLAND) |
| 1963 | |
| 1964 | SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y); |
| 1965 | #endif |
| 1966 | } |
| 1967 | else |
| 1968 | { |
| 1969 | |
| 1970 | CORE.Window.screen.width = width; |
| 1971 | CORE.Window.screen.height = height; |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | |
| 1976 | } |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float scaley) |
| 1981 | { |
| 1982 | |
| 1983 | |
| 1984 | CORE.Window.render.width = (int)((float)CORE.Window.screen.width*scalex); |
| 1985 | CORE.Window.render.height = (int)((float)CORE.Window.screen.height*scaley); |
| 1986 | CORE.Window.currentFbo = CORE.Window.render; |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | CORE.Window.screenScale = MatrixScale(scalex, scaley, 1.0f); |
| 1991 | |
| 1992 | #if !defined(__APPLE__) && !defined(_GLFW_WAYLAND) |
| 1993 | |
| 1994 | SetMouseScale(1.0f/scalex, 1.0f/scaley); |
| 1995 | #endif |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | static void WindowPosCallback(GLFWwindow *window, int x, int y) |
| 2000 | { |
| 2001 | |
| 2002 | CORE.Window.position.x = x; |
| 2003 | CORE.Window.position.y = y; |
| 2004 | } |
| 2005 | |
| 2006 | |
| 2007 | static void WindowIconifyCallback(GLFWwindow *window, int iconified) |
| 2008 | { |
| 2009 | if (iconified) FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 2010 | else FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MINIMIZED); |
| 2011 | } |
| 2012 | |
| 2013 | |
| 2014 | static void WindowMaximizeCallback(GLFWwindow *window, int maximized) |
| 2015 | { |
| 2016 | if (maximized) FLAG_SET(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 2017 | else FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_MAXIMIZED); |
| 2018 | } |
| 2019 | |
| 2020 | |
| 2021 | static void WindowFocusCallback(GLFWwindow *window, int focused) |
| 2022 | { |
| 2023 | if (focused) FLAG_CLEAR(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 2024 | else FLAG_SET(CORE.Window.flags, FLAG_WINDOW_UNFOCUSED); |
| 2025 | } |
| 2026 | |
| 2027 | |
| 2028 | static void WindowDropCallback(GLFWwindow *window, int count, const char **paths) |
| 2029 | { |
| 2030 | if (count > 0) |
| 2031 | { |
| 2032 | |
| 2033 | if (CORE.Window.dropFileCount > 0) |
| 2034 | { |
| 2035 | for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]); |
| 2036 | |
| 2037 | RL_FREE(CORE.Window.dropFilepaths); |
| 2038 | |
| 2039 | CORE.Window.dropFileCount = 0; |
| 2040 | CORE.Window.dropFilepaths = NULL; |
| 2041 | } |
| 2042 | |
| 2043 | |
| 2044 | CORE.Window.dropFileCount = count; |
| 2045 | CORE.Window.dropFilepaths = (char **)RL_CALLOC(CORE.Window.dropFileCount, sizeof(char *)); |
| 2046 | |
| 2047 | for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) |
| 2048 | { |
| 2049 | CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char)); |
| 2050 | strncpy(CORE.Window.dropFilepaths[i], paths[i], MAX_FILEPATH_LENGTH - 1); |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | |
| 2056 | static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) |
| 2057 | { |
| 2058 | if (key < 0) return; |
| 2059 | |
| 2060 | |
| 2061 | |
| 2062 | if (action == GLFW_RELEASE) CORE.Input.Keyboard.currentKeyState[key] = 0; |
| 2063 | else if (action == GLFW_PRESS) CORE.Input.Keyboard.currentKeyState[key] = 1; |
| 2064 | else if (action == GLFW_REPEAT) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1; |
| 2065 | |
| 2066 | |
| 2067 | if (((key == KEY_CAPS_LOCK) && (FLAG_IS_SET(mods, GLFW_MOD_CAPS_LOCK))) || |
| 2068 | ((key == KEY_NUM_LOCK) && (FLAG_IS_SET(mods, GLFW_MOD_NUM_LOCK)))) CORE.Input.Keyboard.currentKeyState[key] = 1; |
| 2069 | |
| 2070 | |
| 2071 | if ((CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) && (action == GLFW_PRESS)) |
| 2072 | { |
| 2073 | |
| 2074 | CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = key; |
| 2075 | CORE.Input.Keyboard.keyPressedQueueCount++; |
| 2076 | } |
| 2077 | |
| 2078 | |
| 2079 | if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE); |
| 2080 | } |
| 2081 | |
| 2082 | |
| 2083 | static void CharCallback(GLFWwindow *window, unsigned int codepoint) |
| 2084 | { |
| 2085 | |
| 2086 | |
| 2087 | |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) |
| 2092 | { |
| 2093 | |
| 2094 | CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = codepoint; |
| 2095 | CORE.Input.Keyboard.charPressedQueueCount++; |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | |
| 2100 | static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) |
| 2101 | { |
| 2102 | |
| 2103 | |
| 2104 | CORE.Input.Mouse.currentButtonState[button] = action; |
| 2105 | CORE.Input.Touch.currentTouchState[button] = action; |
| 2106 | |
| 2107 | #if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES |
| 2108 | |
| 2109 | GestureEvent gestureEvent = { 0 }; |
| 2110 | |
| 2111 | |
| 2112 | if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) gestureEvent.touchAction = TOUCH_ACTION_DOWN; |
| 2113 | else if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) gestureEvent.touchAction = TOUCH_ACTION_UP; |
| 2114 | |
| 2115 | |
| 2116 | |
| 2117 | |
| 2118 | gestureEvent.pointId[0] = 0; |
| 2119 | |
| 2120 | |
| 2121 | gestureEvent.pointCount = 1; |
| 2122 | |
| 2123 | |
| 2124 | gestureEvent.position[0] = GetMousePosition(); |
| 2125 | |
| 2126 | |
| 2127 | gestureEvent.position[0].x /= (float)GetScreenWidth(); |
| 2128 | gestureEvent.position[0].y /= (float)GetScreenHeight(); |
| 2129 | |
| 2130 | |
| 2131 | ProcessGestureEvent(gestureEvent); |
| 2132 | #endif |
| 2133 | } |
| 2134 | |
| 2135 | |
| 2136 | static void MouseCursorPosCallback(GLFWwindow *window, double x, double y) |
| 2137 | { |
| 2138 | CORE.Input.Mouse.currentPosition.x = (float)x; |
| 2139 | CORE.Input.Mouse.currentPosition.y = (float)y; |
| 2140 | CORE.Input.Touch.position[0] = CORE.Input.Mouse.currentPosition; |
| 2141 | |
| 2142 | #if SUPPORT_GESTURES_SYSTEM && SUPPORT_MOUSE_GESTURES |
| 2143 | |
| 2144 | GestureEvent gestureEvent = { 0 }; |
| 2145 | |
| 2146 | gestureEvent.touchAction = TOUCH_ACTION_MOVE; |
| 2147 | |
| 2148 | |
| 2149 | gestureEvent.pointId[0] = 0; |
| 2150 | |
| 2151 | |
| 2152 | gestureEvent.pointCount = 1; |
| 2153 | |
| 2154 | |
| 2155 | gestureEvent.position[0] = CORE.Input.Touch.position[0]; |
| 2156 | |
| 2157 | |
| 2158 | gestureEvent.position[0].x /= (float)GetScreenWidth(); |
| 2159 | gestureEvent.position[0].y /= (float)GetScreenHeight(); |
| 2160 | |
| 2161 | |
| 2162 | ProcessGestureEvent(gestureEvent); |
| 2163 | #endif |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset) |
| 2168 | { |
| 2169 | CORE.Input.Mouse.currentWheelMove = (Vector2){ (float)xoffset, (float)yoffset }; |
| 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | static void CursorEnterCallback(GLFWwindow *window, int enter) |
| 2174 | { |
| 2175 | if (enter) CORE.Input.Mouse.cursorOnScreen = true; |
| 2176 | else CORE.Input.Mouse.cursorOnScreen = false; |
| 2177 | } |
| 2178 | |
| 2179 | |
| 2180 | static void JoystickCallback(int jid, int event) |
| 2181 | { |
| 2182 | if (jid < MAX_GAMEPADS) |
| 2183 | { |
| 2184 | if (event == GLFW_CONNECTED) |
| 2185 | { |
| 2186 | |
| 2187 | |
| 2188 | memset(CORE.Input.Gamepad.name[jid], 0, MAX_GAMEPAD_NAME_LENGTH); |
| 2189 | strncpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid), MAX_GAMEPAD_NAME_LENGTH - 1); |
| 2190 | } |
| 2191 | else if (event == GLFW_DISCONNECTED) |
| 2192 | { |
| 2193 | memset(CORE.Input.Gamepad.name[jid], 0, MAX_GAMEPAD_NAME_LENGTH); |
| 2194 | } |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | #ifdef _WIN32 |
| 2199 | # define WIN32_CLIPBOARD_IMPLEMENTATION |
| 2200 | # include "../external/win32_clipboard.h" |
| 2201 | #endif |
| 2202 | |