null_window.c (18727B)
1 //======================================================================== 2 // GLFW 3.4 (modified for raylib) - www.glfw.org; www.raylib.com 3 //------------------------------------------------------------------------ 4 // Copyright (c) 2016 Google Inc. 5 // Copyright (c) 2016-2019 Camilla Löwy <elmindreda@glfw.org> 6 // Copyright (c) 2024 M374LX <wilsalx@gmail.com> 7 // 8 // This software is provided 'as-is', without any express or implied 9 // warranty. In no event will the authors be held liable for any damages 10 // arising from the use of this software. 11 // 12 // Permission is granted to anyone to use this software for any purpose, 13 // including commercial applications, and to alter it and redistribute it 14 // freely, subject to the following restrictions: 15 // 16 // 1. The origin of this software must not be misrepresented; you must not 17 // claim that you wrote the original software. If you use this software 18 // in a product, an acknowledgment in the product documentation would 19 // be appreciated but is not required. 20 // 21 // 2. Altered source versions must be plainly marked as such, and must not 22 // be misrepresented as being the original software. 23 // 24 // 3. This notice may not be removed or altered from any source 25 // distribution. 26 // 27 //======================================================================== 28 29 #include "internal.h" 30 31 #include <stdlib.h> 32 33 static void applySizeLimits(_GLFWwindow* window, int* width, int* height) 34 { 35 if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE) 36 { 37 const float ratio = (float) window->numer / (float) window->denom; 38 *height = (int) (*width / ratio); 39 } 40 41 if (window->minwidth != GLFW_DONT_CARE) 42 *width = _glfw_max(*width, window->minwidth); 43 else if (window->maxwidth != GLFW_DONT_CARE) 44 *width = _glfw_min(*width, window->maxwidth); 45 46 if (window->minheight != GLFW_DONT_CARE) 47 *height = _glfw_min(*height, window->minheight); 48 else if (window->maxheight != GLFW_DONT_CARE) 49 *height = _glfw_max(*height, window->maxheight); 50 } 51 52 static void fitToMonitor(_GLFWwindow* window) 53 { 54 GLFWvidmode mode; 55 _glfwGetVideoModeNull(window->monitor, &mode); 56 _glfwGetMonitorPosNull(window->monitor, 57 &window->null.xpos, 58 &window->null.ypos); 59 window->null.width = mode.width; 60 window->null.height = mode.height; 61 } 62 63 static void acquireMonitorNull(_GLFWwindow* window) 64 { 65 _glfwInputMonitorWindow(window->monitor, window); 66 } 67 68 static void releaseMonitorNull(_GLFWwindow* window) 69 { 70 if (window->monitor->window != window) 71 return; 72 73 _glfwInputMonitorWindow(window->monitor, NULL); 74 } 75 76 static int createNativeWindow(_GLFWwindow* window, 77 const _GLFWwndconfig* wndconfig, 78 const _GLFWfbconfig* fbconfig) 79 { 80 if (window->monitor) 81 fitToMonitor(window); 82 else 83 { 84 if (wndconfig->xpos == GLFW_ANY_POSITION && wndconfig->ypos == GLFW_ANY_POSITION) 85 { 86 window->null.xpos = 17; 87 window->null.ypos = 17; 88 } 89 else 90 { 91 window->null.xpos = wndconfig->xpos; 92 window->null.ypos = wndconfig->ypos; 93 } 94 95 window->null.width = wndconfig->width; 96 window->null.height = wndconfig->height; 97 } 98 99 window->null.visible = wndconfig->visible; 100 window->null.decorated = wndconfig->decorated; 101 window->null.maximized = wndconfig->maximized; 102 window->null.floating = wndconfig->floating; 103 window->null.transparent = fbconfig->transparent; 104 window->null.opacity = 1.f; 105 106 return GLFW_TRUE; 107 } 108 109 110 ////////////////////////////////////////////////////////////////////////// 111 ////// GLFW platform API ////// 112 ////////////////////////////////////////////////////////////////////////// 113 114 GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, 115 const _GLFWwndconfig* wndconfig, 116 const _GLFWctxconfig* ctxconfig, 117 const _GLFWfbconfig* fbconfig) 118 { 119 if (!createNativeWindow(window, wndconfig, fbconfig)) 120 return GLFW_FALSE; 121 122 if (ctxconfig->client != GLFW_NO_API) 123 { 124 if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API || 125 ctxconfig->source == GLFW_OSMESA_CONTEXT_API) 126 { 127 if (!_glfwInitOSMesa()) 128 return GLFW_FALSE; 129 if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) 130 return GLFW_FALSE; 131 } 132 else if (ctxconfig->source == GLFW_EGL_CONTEXT_API) 133 { 134 if (!_glfwInitEGL()) 135 return GLFW_FALSE; 136 if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) 137 return GLFW_FALSE; 138 } 139 140 if (!_glfwRefreshContextAttribs(window, ctxconfig)) 141 return GLFW_FALSE; 142 } 143 144 if (wndconfig->mousePassthrough) 145 _glfwSetWindowMousePassthroughNull(window, GLFW_TRUE); 146 147 if (window->monitor) 148 { 149 _glfwShowWindowNull(window); 150 _glfwFocusWindowNull(window); 151 acquireMonitorNull(window); 152 153 if (wndconfig->centerCursor) 154 _glfwCenterCursorInContentArea(window); 155 } 156 else 157 { 158 if (wndconfig->visible) 159 { 160 _glfwShowWindowNull(window); 161 if (wndconfig->focused) 162 _glfwFocusWindowNull(window); 163 } 164 } 165 166 return GLFW_TRUE; 167 } 168 169 void _glfwDestroyWindowNull(_GLFWwindow* window) 170 { 171 if (window->monitor) 172 releaseMonitorNull(window); 173 174 if (_glfw.null.focusedWindow == window) 175 _glfw.null.focusedWindow = NULL; 176 177 if (window->context.destroy) 178 window->context.destroy(window); 179 } 180 181 void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title) 182 { 183 } 184 185 void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images) 186 { 187 } 188 189 void _glfwSetWindowMonitorNull(_GLFWwindow* window, 190 _GLFWmonitor* monitor, 191 int xpos, int ypos, 192 int width, int height, 193 int refreshRate) 194 { 195 if (window->monitor == monitor) 196 { 197 if (!monitor) 198 { 199 _glfwSetWindowPosNull(window, xpos, ypos); 200 _glfwSetWindowSizeNull(window, width, height); 201 } 202 203 return; 204 } 205 206 if (window->monitor) 207 releaseMonitorNull(window); 208 209 _glfwInputWindowMonitor(window, monitor); 210 211 if (window->monitor) 212 { 213 window->null.visible = GLFW_TRUE; 214 acquireMonitorNull(window); 215 fitToMonitor(window); 216 } 217 else 218 { 219 _glfwSetWindowPosNull(window, xpos, ypos); 220 _glfwSetWindowSizeNull(window, width, height); 221 } 222 } 223 224 void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos) 225 { 226 if (xpos) 227 *xpos = window->null.xpos; 228 if (ypos) 229 *ypos = window->null.ypos; 230 } 231 232 void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos) 233 { 234 if (window->monitor) 235 return; 236 237 if (window->null.xpos != xpos || window->null.ypos != ypos) 238 { 239 window->null.xpos = xpos; 240 window->null.ypos = ypos; 241 _glfwInputWindowPos(window, xpos, ypos); 242 } 243 } 244 245 void _glfwGetWindowSizeNull(_GLFWwindow* window, int* width, int* height) 246 { 247 if (width) 248 *width = window->null.width; 249 if (height) 250 *height = window->null.height; 251 } 252 253 void _glfwSetWindowSizeNull(_GLFWwindow* window, int width, int height) 254 { 255 if (window->monitor) 256 return; 257 258 if (window->null.width != width || window->null.height != height) 259 { 260 window->null.width = width; 261 window->null.height = height; 262 _glfwInputFramebufferSize(window, width, height); 263 _glfwInputWindowDamage(window); 264 _glfwInputWindowSize(window, width, height); 265 } 266 } 267 268 void _glfwSetWindowSizeLimitsNull(_GLFWwindow* window, 269 int minwidth, int minheight, 270 int maxwidth, int maxheight) 271 { 272 int width = window->null.width; 273 int height = window->null.height; 274 applySizeLimits(window, &width, &height); 275 _glfwSetWindowSizeNull(window, width, height); 276 } 277 278 void _glfwSetWindowAspectRatioNull(_GLFWwindow* window, int n, int d) 279 { 280 int width = window->null.width; 281 int height = window->null.height; 282 applySizeLimits(window, &width, &height); 283 _glfwSetWindowSizeNull(window, width, height); 284 } 285 286 void _glfwGetFramebufferSizeNull(_GLFWwindow* window, int* width, int* height) 287 { 288 if (width) 289 *width = window->null.width; 290 if (height) 291 *height = window->null.height; 292 } 293 294 void _glfwGetWindowFrameSizeNull(_GLFWwindow* window, 295 int* left, int* top, 296 int* right, int* bottom) 297 { 298 if (window->null.decorated && !window->monitor) 299 { 300 if (left) 301 *left = 1; 302 if (top) 303 *top = 10; 304 if (right) 305 *right = 1; 306 if (bottom) 307 *bottom = 1; 308 } 309 else 310 { 311 if (left) 312 *left = 0; 313 if (top) 314 *top = 0; 315 if (right) 316 *right = 0; 317 if (bottom) 318 *bottom = 0; 319 } 320 } 321 322 void _glfwGetWindowContentScaleNull(_GLFWwindow* window, float* xscale, float* yscale) 323 { 324 if (xscale) 325 *xscale = 1.f; 326 if (yscale) 327 *yscale = 1.f; 328 } 329 330 void _glfwIconifyWindowNull(_GLFWwindow* window) 331 { 332 if (_glfw.null.focusedWindow == window) 333 { 334 _glfw.null.focusedWindow = NULL; 335 _glfwInputWindowFocus(window, GLFW_FALSE); 336 } 337 338 if (!window->null.iconified) 339 { 340 window->null.iconified = GLFW_TRUE; 341 _glfwInputWindowIconify(window, GLFW_TRUE); 342 343 if (window->monitor) 344 releaseMonitorNull(window); 345 } 346 } 347 348 void _glfwRestoreWindowNull(_GLFWwindow* window) 349 { 350 if (window->null.iconified) 351 { 352 window->null.iconified = GLFW_FALSE; 353 _glfwInputWindowIconify(window, GLFW_FALSE); 354 355 if (window->monitor) 356 acquireMonitorNull(window); 357 } 358 else if (window->null.maximized) 359 { 360 window->null.maximized = GLFW_FALSE; 361 _glfwInputWindowMaximize(window, GLFW_FALSE); 362 } 363 } 364 365 void _glfwMaximizeWindowNull(_GLFWwindow* window) 366 { 367 if (!window->null.maximized) 368 { 369 window->null.maximized = GLFW_TRUE; 370 _glfwInputWindowMaximize(window, GLFW_TRUE); 371 } 372 } 373 374 GLFWbool _glfwWindowMaximizedNull(_GLFWwindow* window) 375 { 376 return window->null.maximized; 377 } 378 379 GLFWbool _glfwWindowHoveredNull(_GLFWwindow* window) 380 { 381 return _glfw.null.xcursor >= window->null.xpos && 382 _glfw.null.ycursor >= window->null.ypos && 383 _glfw.null.xcursor <= window->null.xpos + window->null.width - 1 && 384 _glfw.null.ycursor <= window->null.ypos + window->null.height - 1; 385 } 386 387 GLFWbool _glfwFramebufferTransparentNull(_GLFWwindow* window) 388 { 389 return window->null.transparent; 390 } 391 392 void _glfwSetWindowResizableNull(_GLFWwindow* window, GLFWbool enabled) 393 { 394 window->null.resizable = enabled; 395 } 396 397 void _glfwSetWindowDecoratedNull(_GLFWwindow* window, GLFWbool enabled) 398 { 399 window->null.decorated = enabled; 400 } 401 402 void _glfwSetWindowFloatingNull(_GLFWwindow* window, GLFWbool enabled) 403 { 404 window->null.floating = enabled; 405 } 406 407 void _glfwSetWindowMousePassthroughNull(_GLFWwindow* window, GLFWbool enabled) 408 { 409 } 410 411 float _glfwGetWindowOpacityNull(_GLFWwindow* window) 412 { 413 return window->null.opacity; 414 } 415 416 void _glfwSetWindowOpacityNull(_GLFWwindow* window, float opacity) 417 { 418 window->null.opacity = opacity; 419 } 420 421 void _glfwSetRawMouseMotionNull(_GLFWwindow *window, GLFWbool enabled) 422 { 423 } 424 425 GLFWbool _glfwRawMouseMotionSupportedNull(void) 426 { 427 return GLFW_TRUE; 428 } 429 430 void _glfwShowWindowNull(_GLFWwindow* window) 431 { 432 window->null.visible = GLFW_TRUE; 433 } 434 435 void _glfwRequestWindowAttentionNull(_GLFWwindow* window) 436 { 437 } 438 439 void _glfwHideWindowNull(_GLFWwindow* window) 440 { 441 if (_glfw.null.focusedWindow == window) 442 { 443 _glfw.null.focusedWindow = NULL; 444 _glfwInputWindowFocus(window, GLFW_FALSE); 445 } 446 447 window->null.visible = GLFW_FALSE; 448 } 449 450 void _glfwFocusWindowNull(_GLFWwindow* window) 451 { 452 _GLFWwindow* previous; 453 454 if (_glfw.null.focusedWindow == window) 455 return; 456 457 if (!window->null.visible) 458 return; 459 460 previous = _glfw.null.focusedWindow; 461 _glfw.null.focusedWindow = window; 462 463 if (previous) 464 { 465 _glfwInputWindowFocus(previous, GLFW_FALSE); 466 if (previous->monitor && previous->autoIconify) 467 _glfwIconifyWindowNull(previous); 468 } 469 470 _glfwInputWindowFocus(window, GLFW_TRUE); 471 } 472 473 GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window) 474 { 475 return _glfw.null.focusedWindow == window; 476 } 477 478 GLFWbool _glfwWindowIconifiedNull(_GLFWwindow* window) 479 { 480 return window->null.iconified; 481 } 482 483 GLFWbool _glfwWindowVisibleNull(_GLFWwindow* window) 484 { 485 return window->null.visible; 486 } 487 488 void _glfwPollEventsNull(void) 489 { 490 } 491 492 void _glfwWaitEventsNull(void) 493 { 494 } 495 496 void _glfwWaitEventsTimeoutNull(double timeout) 497 { 498 } 499 500 void _glfwPostEmptyEventNull(void) 501 { 502 } 503 504 void _glfwGetCursorPosNull(_GLFWwindow* window, double* xpos, double* ypos) 505 { 506 if (xpos) 507 *xpos = _glfw.null.xcursor - window->null.xpos; 508 if (ypos) 509 *ypos = _glfw.null.ycursor - window->null.ypos; 510 } 511 512 void _glfwSetCursorPosNull(_GLFWwindow* window, double x, double y) 513 { 514 _glfw.null.xcursor = window->null.xpos + (int) x; 515 _glfw.null.ycursor = window->null.ypos + (int) y; 516 } 517 518 void _glfwSetCursorModeNull(_GLFWwindow* window, int mode) 519 { 520 } 521 522 GLFWbool _glfwCreateCursorNull(_GLFWcursor* cursor, 523 const GLFWimage* image, 524 int xhot, int yhot) 525 { 526 return GLFW_TRUE; 527 } 528 529 GLFWbool _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape) 530 { 531 return GLFW_TRUE; 532 } 533 534 void _glfwDestroyCursorNull(_GLFWcursor* cursor) 535 { 536 } 537 538 void _glfwSetCursorNull(_GLFWwindow* window, _GLFWcursor* cursor) 539 { 540 } 541 542 void _glfwSetClipboardStringNull(const char* string) 543 { 544 char* copy = _glfw_strdup(string); 545 _glfw_free(_glfw.null.clipboardString); 546 _glfw.null.clipboardString = copy; 547 } 548 549 const char* _glfwGetClipboardStringNull(void) 550 { 551 return _glfw.null.clipboardString; 552 } 553 554 EGLenum _glfwGetEGLPlatformNull(EGLint** attribs) 555 { 556 return 0; 557 } 558 559 EGLNativeDisplayType _glfwGetEGLNativeDisplayNull(void) 560 { 561 return 0; 562 } 563 564 EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window) 565 { 566 return 0; 567 } 568 569 const char* _glfwGetScancodeNameNull(int scancode) 570 { 571 if (scancode < GLFW_NULL_SC_FIRST || scancode > GLFW_NULL_SC_LAST) 572 { 573 _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); 574 return NULL; 575 } 576 577 switch (scancode) 578 { 579 case GLFW_NULL_SC_APOSTROPHE: 580 return "'"; 581 case GLFW_NULL_SC_COMMA: 582 return ","; 583 case GLFW_NULL_SC_MINUS: 584 case GLFW_NULL_SC_KP_SUBTRACT: 585 return "-"; 586 case GLFW_NULL_SC_PERIOD: 587 case GLFW_NULL_SC_KP_DECIMAL: 588 return "."; 589 case GLFW_NULL_SC_SLASH: 590 case GLFW_NULL_SC_KP_DIVIDE: 591 return "/"; 592 case GLFW_NULL_SC_SEMICOLON: 593 return ";"; 594 case GLFW_NULL_SC_EQUAL: 595 case GLFW_NULL_SC_KP_EQUAL: 596 return "="; 597 case GLFW_NULL_SC_LEFT_BRACKET: 598 return "["; 599 case GLFW_NULL_SC_RIGHT_BRACKET: 600 return "]"; 601 case GLFW_NULL_SC_KP_MULTIPLY: 602 return "*"; 603 case GLFW_NULL_SC_KP_ADD: 604 return "+"; 605 case GLFW_NULL_SC_BACKSLASH: 606 case GLFW_NULL_SC_WORLD_1: 607 case GLFW_NULL_SC_WORLD_2: 608 return "\\"; 609 case GLFW_NULL_SC_0: 610 case GLFW_NULL_SC_KP_0: 611 return "0"; 612 case GLFW_NULL_SC_1: 613 case GLFW_NULL_SC_KP_1: 614 return "1"; 615 case GLFW_NULL_SC_2: 616 case GLFW_NULL_SC_KP_2: 617 return "2"; 618 case GLFW_NULL_SC_3: 619 case GLFW_NULL_SC_KP_3: 620 return "3"; 621 case GLFW_NULL_SC_4: 622 case GLFW_NULL_SC_KP_4: 623 return "4"; 624 case GLFW_NULL_SC_5: 625 case GLFW_NULL_SC_KP_5: 626 return "5"; 627 case GLFW_NULL_SC_6: 628 case GLFW_NULL_SC_KP_6: 629 return "6"; 630 case GLFW_NULL_SC_7: 631 case GLFW_NULL_SC_KP_7: 632 return "7"; 633 case GLFW_NULL_SC_8: 634 case GLFW_NULL_SC_KP_8: 635 return "8"; 636 case GLFW_NULL_SC_9: 637 case GLFW_NULL_SC_KP_9: 638 return "9"; 639 case GLFW_NULL_SC_A: 640 return "a"; 641 case GLFW_NULL_SC_B: 642 return "b"; 643 case GLFW_NULL_SC_C: 644 return "c"; 645 case GLFW_NULL_SC_D: 646 return "d"; 647 case GLFW_NULL_SC_E: 648 return "e"; 649 case GLFW_NULL_SC_F: 650 return "f"; 651 case GLFW_NULL_SC_G: 652 return "g"; 653 case GLFW_NULL_SC_H: 654 return "h"; 655 case GLFW_NULL_SC_I: 656 return "i"; 657 case GLFW_NULL_SC_J: 658 return "j"; 659 case GLFW_NULL_SC_K: 660 return "k"; 661 case GLFW_NULL_SC_L: 662 return "l"; 663 case GLFW_NULL_SC_M: 664 return "m"; 665 case GLFW_NULL_SC_N: 666 return "n"; 667 case GLFW_NULL_SC_O: 668 return "o"; 669 case GLFW_NULL_SC_P: 670 return "p"; 671 case GLFW_NULL_SC_Q: 672 return "q"; 673 case GLFW_NULL_SC_R: 674 return "r"; 675 case GLFW_NULL_SC_S: 676 return "s"; 677 case GLFW_NULL_SC_T: 678 return "t"; 679 case GLFW_NULL_SC_U: 680 return "u"; 681 case GLFW_NULL_SC_V: 682 return "v"; 683 case GLFW_NULL_SC_W: 684 return "w"; 685 case GLFW_NULL_SC_X: 686 return "x"; 687 case GLFW_NULL_SC_Y: 688 return "y"; 689 case GLFW_NULL_SC_Z: 690 return "z"; 691 } 692 693 return NULL; 694 } 695 696 int _glfwGetKeyScancodeNull(int key) 697 { 698 return _glfw.null.scancodes[key]; 699 } 700 701 void _glfwGetRequiredInstanceExtensionsNull(char** extensions) 702 { 703 } 704 705 GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, 706 VkPhysicalDevice device, 707 uint32_t queuefamily) 708 { 709 return GLFW_FALSE; 710 } 711 712 VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, 713 _GLFWwindow* window, 714 const VkAllocationCallbacks* allocator, 715 VkSurfaceKHR* surface) 716 { 717 // This seems like the most appropriate error to return here 718 return VK_ERROR_EXTENSION_NOT_PRESENT; 719 } 720