ScrapExplorer - window.c
Home / ext / glfw / src Lines: 1 | Size: 35145 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1//======================================================================== 2// GLFW 3.5 - www.glfw.org 3//------------------------------------------------------------------------ 4// Copyright (c) 2002-2006 Marcus Geelnard 5// Copyright (c) 2006-2019 Camilla Löwy <[email protected]> 6// Copyright (c) 2012 Torsten Walluhn <[email protected]> 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 <assert.h> 32#include <string.h> 33#include <stdlib.h> 34#include <float.h> 35 36 37////////////////////////////////////////////////////////////////////////// 38////// GLFW event API ////// 39////////////////////////////////////////////////////////////////////////// 40 41// Notifies shared code that a window has lost or received input focus 42// 43void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused) 44{ 45 assert(window != NULL); 46 assert(focused == GLFW_TRUE || focused == GLFW_FALSE); 47 48 if (window->callbacks.focus) 49 window->callbacks.focus((GLFWwindow*) window, focused); 50 51 if (!focused) 52 { 53 int key, button; 54 55 for (key = 0; key <= GLFW_KEY_LAST; key++) 56 { 57 if (window->keys[key] == GLFW_PRESS) 58 { 59 const int scancode = _glfw.platform.getKeyScancode(key); 60 _glfwInputKey(window, key, scancode, GLFW_RELEASE, 0); 61 } 62 } 63 64 for (button = 0; button <= GLFW_MOUSE_BUTTON_LAST; button++) 65 { 66 if (window->mouseButtons[button] == GLFW_PRESS) 67 _glfwInputMouseClick(window, button, GLFW_RELEASE, 0); 68 } 69 } 70} 71 72// Notifies shared code that a window has moved 73// The position is specified in content area relative screen coordinates 74// 75void _glfwInputWindowPos(_GLFWwindow* window, int x, int y) 76{ 77 assert(window != NULL); 78 79 if (window->callbacks.pos) 80 window->callbacks.pos((GLFWwindow*) window, x, y); 81} 82 83// Notifies shared code that a window has been resized 84// The size is specified in screen coordinates 85// 86void _glfwInputWindowSize(_GLFWwindow* window, int width, int height) 87{ 88 assert(window != NULL); 89 assert(width >= 0); 90 assert(height >= 0); 91 92 if (window->callbacks.size) 93 window->callbacks.size((GLFWwindow*) window, width, height); 94} 95 96// Notifies shared code that a window has been iconified or restored 97// 98void _glfwInputWindowIconify(_GLFWwindow* window, GLFWbool iconified) 99{ 100 assert(window != NULL); 101 assert(iconified == GLFW_TRUE || iconified == GLFW_FALSE); 102 103 if (window->callbacks.iconify) 104 window->callbacks.iconify((GLFWwindow*) window, iconified); 105} 106 107// Notifies shared code that a window has been maximized or restored 108// 109void _glfwInputWindowMaximize(_GLFWwindow* window, GLFWbool maximized) 110{ 111 assert(window != NULL); 112 assert(maximized == GLFW_TRUE || maximized == GLFW_FALSE); 113 114 if (window->callbacks.maximize) 115 window->callbacks.maximize((GLFWwindow*) window, maximized); 116} 117 118// Notifies shared code that a window framebuffer has been resized 119// The size is specified in pixels 120// 121void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height) 122{ 123 assert(window != NULL); 124 assert(width >= 0); 125 assert(height >= 0); 126 127 if (window->callbacks.fbsize) 128 window->callbacks.fbsize((GLFWwindow*) window, width, height); 129} 130 131// Notifies shared code that a window content scale has changed 132// The scale is specified as the ratio between the current and default DPI 133// 134void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscale) 135{ 136 assert(window != NULL); 137 assert(xscale > 0.f); 138 assert(xscale < FLT_MAX); 139 assert(yscale > 0.f); 140 assert(yscale < FLT_MAX); 141 142 if (window->callbacks.scale) 143 window->callbacks.scale((GLFWwindow*) window, xscale, yscale); 144} 145 146// Notifies shared code that the window contents needs updating 147// 148void _glfwInputWindowDamage(_GLFWwindow* window) 149{ 150 assert(window != NULL); 151 152 if (window->callbacks.refresh) 153 window->callbacks.refresh((GLFWwindow*) window); 154} 155 156// Notifies shared code that the user wishes to close a window 157// 158void _glfwInputWindowCloseRequest(_GLFWwindow* window) 159{ 160 assert(window != NULL); 161 162 window->shouldClose = GLFW_TRUE; 163 164 if (window->callbacks.close) 165 window->callbacks.close((GLFWwindow*) window); 166} 167 168// Notifies shared code that a window has changed its desired monitor 169// 170void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor) 171{ 172 assert(window != NULL); 173 window->monitor = monitor; 174} 175 176////////////////////////////////////////////////////////////////////////// 177////// GLFW public API ////// 178////////////////////////////////////////////////////////////////////////// 179 180GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, 181 const char* title, 182 GLFWmonitor* monitor, 183 GLFWwindow* share) 184{ 185 _GLFWfbconfig fbconfig; 186 _GLFWctxconfig ctxconfig; 187 _GLFWwndconfig wndconfig; 188 _GLFWwindow* window; 189 190 assert(title != NULL); 191 assert(width >= 0); 192 assert(height >= 0); 193 194 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 195 196 if (width <= 0 || height <= 0) 197 { 198 _glfwInputError(GLFW_INVALID_VALUE, 199 "Invalid window size %ix%i", 200 width, height); 201 202 return NULL; 203 } 204 205 fbconfig = _glfw.hints.framebuffer; 206 ctxconfig = _glfw.hints.context; 207 wndconfig = _glfw.hints.window; 208 209 wndconfig.width = width; 210 wndconfig.height = height; 211 ctxconfig.share = (_GLFWwindow*) share; 212 213 if (!_glfwIsValidContextConfig(&ctxconfig)) 214 return NULL; 215 216 window = _glfw_calloc(1, sizeof(_GLFWwindow)); 217 window->next = _glfw.windowListHead; 218 _glfw.windowListHead = window; 219 220 window->videoMode.width = width; 221 window->videoMode.height = height; 222 window->videoMode.redBits = fbconfig.redBits; 223 window->videoMode.greenBits = fbconfig.greenBits; 224 window->videoMode.blueBits = fbconfig.blueBits; 225 window->videoMode.refreshRate = _glfw.hints.refreshRate; 226 227 window->monitor = (_GLFWmonitor*) monitor; 228 window->resizable = wndconfig.resizable; 229 window->decorated = wndconfig.decorated; 230 window->autoIconify = wndconfig.autoIconify; 231 window->floating = wndconfig.floating; 232 window->focusOnShow = wndconfig.focusOnShow; 233 window->mousePassthrough = wndconfig.mousePassthrough; 234 window->cursorMode = GLFW_CURSOR_NORMAL; 235 236 window->doublebuffer = fbconfig.doublebuffer; 237 238 window->minwidth = GLFW_DONT_CARE; 239 window->minheight = GLFW_DONT_CARE; 240 window->maxwidth = GLFW_DONT_CARE; 241 window->maxheight = GLFW_DONT_CARE; 242 window->numer = GLFW_DONT_CARE; 243 window->denom = GLFW_DONT_CARE; 244 window->title = _glfw_strdup(title); 245 246 if (!_glfw.platform.createWindow(window, &wndconfig, &ctxconfig, &fbconfig)) 247 { 248 glfwDestroyWindow((GLFWwindow*) window); 249 return NULL; 250 } 251 252 return (GLFWwindow*) window; 253} 254 255void glfwDefaultWindowHints(void) 256{ 257 _GLFW_REQUIRE_INIT(); 258 259 // The default is OpenGL with minimum version 1.0 260 memset(&_glfw.hints.context, 0, sizeof(_glfw.hints.context)); 261 _glfw.hints.context.client = GLFW_OPENGL_API; 262 _glfw.hints.context.source = GLFW_NATIVE_CONTEXT_API; 263 _glfw.hints.context.major = 1; 264 _glfw.hints.context.minor = 0; 265 266 // The default is a focused, visible, resizable window with decorations 267 memset(&_glfw.hints.window, 0, sizeof(_glfw.hints.window)); 268 _glfw.hints.window.resizable = GLFW_TRUE; 269 _glfw.hints.window.visible = GLFW_TRUE; 270 _glfw.hints.window.decorated = GLFW_TRUE; 271 _glfw.hints.window.focused = GLFW_TRUE; 272 _glfw.hints.window.autoIconify = GLFW_TRUE; 273 _glfw.hints.window.centerCursor = GLFW_TRUE; 274 _glfw.hints.window.focusOnShow = GLFW_TRUE; 275 _glfw.hints.window.xpos = GLFW_ANY_POSITION; 276 _glfw.hints.window.ypos = GLFW_ANY_POSITION; 277 _glfw.hints.window.scaleFramebuffer = GLFW_TRUE; 278 279 // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil, 280 // double buffered 281 memset(&_glfw.hints.framebuffer, 0, sizeof(_glfw.hints.framebuffer)); 282 _glfw.hints.framebuffer.redBits = 8; 283 _glfw.hints.framebuffer.greenBits = 8; 284 _glfw.hints.framebuffer.blueBits = 8; 285 _glfw.hints.framebuffer.alphaBits = 8; 286 _glfw.hints.framebuffer.depthBits = 24; 287 _glfw.hints.framebuffer.stencilBits = 8; 288 _glfw.hints.framebuffer.doublebuffer = GLFW_TRUE; 289 290 // The default is to select the highest available refresh rate 291 _glfw.hints.refreshRate = GLFW_DONT_CARE; 292} 293 294GLFWAPI void glfwWindowHint(int hint, int value) 295{ 296 _GLFW_REQUIRE_INIT(); 297 298 switch (hint) 299 { 300 case GLFW_RED_BITS: 301 _glfw.hints.framebuffer.redBits = value; 302 return; 303 case GLFW_GREEN_BITS: 304 _glfw.hints.framebuffer.greenBits = value; 305 return; 306 case GLFW_BLUE_BITS: 307 _glfw.hints.framebuffer.blueBits = value; 308 return; 309 case GLFW_ALPHA_BITS: 310 _glfw.hints.framebuffer.alphaBits = value; 311 return; 312 case GLFW_DEPTH_BITS: 313 _glfw.hints.framebuffer.depthBits = value; 314 return; 315 case GLFW_STENCIL_BITS: 316 _glfw.hints.framebuffer.stencilBits = value; 317 return; 318 case GLFW_ACCUM_RED_BITS: 319 _glfw.hints.framebuffer.accumRedBits = value; 320 return; 321 case GLFW_ACCUM_GREEN_BITS: 322 _glfw.hints.framebuffer.accumGreenBits = value; 323 return; 324 case GLFW_ACCUM_BLUE_BITS: 325 _glfw.hints.framebuffer.accumBlueBits = value; 326 return; 327 case GLFW_ACCUM_ALPHA_BITS: 328 _glfw.hints.framebuffer.accumAlphaBits = value; 329 return; 330 case GLFW_AUX_BUFFERS: 331 _glfw.hints.framebuffer.auxBuffers = value; 332 return; 333 case GLFW_STEREO: 334 _glfw.hints.framebuffer.stereo = value ? GLFW_TRUE : GLFW_FALSE; 335 return; 336 case GLFW_DOUBLEBUFFER: 337 _glfw.hints.framebuffer.doublebuffer = value ? GLFW_TRUE : GLFW_FALSE; 338 return; 339 case GLFW_TRANSPARENT_FRAMEBUFFER: 340 _glfw.hints.framebuffer.transparent = value ? GLFW_TRUE : GLFW_FALSE; 341 return; 342 case GLFW_SAMPLES: 343 _glfw.hints.framebuffer.samples = value; 344 return; 345 case GLFW_SRGB_CAPABLE: 346 _glfw.hints.framebuffer.sRGB = value ? GLFW_TRUE : GLFW_FALSE; 347 return; 348 case GLFW_RESIZABLE: 349 _glfw.hints.window.resizable = value ? GLFW_TRUE : GLFW_FALSE; 350 return; 351 case GLFW_DECORATED: 352 _glfw.hints.window.decorated = value ? GLFW_TRUE : GLFW_FALSE; 353 return; 354 case GLFW_FOCUSED: 355 _glfw.hints.window.focused = value ? GLFW_TRUE : GLFW_FALSE; 356 return; 357 case GLFW_AUTO_ICONIFY: 358 _glfw.hints.window.autoIconify = value ? GLFW_TRUE : GLFW_FALSE; 359 return; 360 case GLFW_FLOATING: 361 _glfw.hints.window.floating = value ? GLFW_TRUE : GLFW_FALSE; 362 return; 363 case GLFW_MAXIMIZED: 364 _glfw.hints.window.maximized = value ? GLFW_TRUE : GLFW_FALSE; 365 return; 366 case GLFW_VISIBLE: 367 _glfw.hints.window.visible = value ? GLFW_TRUE : GLFW_FALSE; 368 return; 369 case GLFW_POSITION_X: 370 _glfw.hints.window.xpos = value; 371 return; 372 case GLFW_POSITION_Y: 373 _glfw.hints.window.ypos = value; 374 return; 375 case GLFW_WIN32_KEYBOARD_MENU: 376 _glfw.hints.window.win32.keymenu = value ? GLFW_TRUE : GLFW_FALSE; 377 return; 378 case GLFW_WIN32_SHOWDEFAULT: 379 _glfw.hints.window.win32.showDefault = value ? GLFW_TRUE : GLFW_FALSE; 380 return; 381 case GLFW_COCOA_GRAPHICS_SWITCHING: 382 _glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE; 383 return; 384 case GLFW_SCALE_TO_MONITOR: 385 _glfw.hints.window.scaleToMonitor = value ? GLFW_TRUE : GLFW_FALSE; 386 return; 387 case GLFW_SCALE_FRAMEBUFFER: 388 case GLFW_COCOA_RETINA_FRAMEBUFFER: 389 _glfw.hints.window.scaleFramebuffer = value ? GLFW_TRUE : GLFW_FALSE; 390 return; 391 case GLFW_CENTER_CURSOR: 392 _glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE; 393 return; 394 case GLFW_FOCUS_ON_SHOW: 395 _glfw.hints.window.focusOnShow = value ? GLFW_TRUE : GLFW_FALSE; 396 return; 397 case GLFW_MOUSE_PASSTHROUGH: 398 _glfw.hints.window.mousePassthrough = value ? GLFW_TRUE : GLFW_FALSE; 399 return; 400 case GLFW_CLIENT_API: 401 _glfw.hints.context.client = value; 402 return; 403 case GLFW_CONTEXT_CREATION_API: 404 _glfw.hints.context.source = value; 405 return; 406 case GLFW_CONTEXT_VERSION_MAJOR: 407 _glfw.hints.context.major = value; 408 return; 409 case GLFW_CONTEXT_VERSION_MINOR: 410 _glfw.hints.context.minor = value; 411 return; 412 case GLFW_CONTEXT_ROBUSTNESS: 413 _glfw.hints.context.robustness = value; 414 return; 415 case GLFW_OPENGL_FORWARD_COMPAT: 416 _glfw.hints.context.forward = value ? GLFW_TRUE : GLFW_FALSE; 417 return; 418 case GLFW_CONTEXT_DEBUG: 419 _glfw.hints.context.debug = value ? GLFW_TRUE : GLFW_FALSE; 420 return; 421 case GLFW_CONTEXT_NO_ERROR: 422 _glfw.hints.context.noerror = value ? GLFW_TRUE : GLFW_FALSE; 423 return; 424 case GLFW_OPENGL_PROFILE: 425 _glfw.hints.context.profile = value; 426 return; 427 case GLFW_CONTEXT_RELEASE_BEHAVIOR: 428 _glfw.hints.context.release = value; 429 return; 430 case GLFW_REFRESH_RATE: 431 _glfw.hints.refreshRate = value; 432 return; 433 } 434 435 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint 0x%08X", hint); 436} 437 438GLFWAPI void glfwWindowHintString(int hint, const char* value) 439{ 440 assert(value != NULL); 441 442 _GLFW_REQUIRE_INIT(); 443 444 switch (hint) 445 { 446 case GLFW_COCOA_FRAME_NAME: 447 strncpy(_glfw.hints.window.ns.frameName, value, 448 sizeof(_glfw.hints.window.ns.frameName) - 1); 449 return; 450 case GLFW_X11_CLASS_NAME: 451 strncpy(_glfw.hints.window.x11.className, value, 452 sizeof(_glfw.hints.window.x11.className) - 1); 453 return; 454 case GLFW_X11_INSTANCE_NAME: 455 strncpy(_glfw.hints.window.x11.instanceName, value, 456 sizeof(_glfw.hints.window.x11.instanceName) - 1); 457 return; 458 case GLFW_WAYLAND_APP_ID: 459 strncpy(_glfw.hints.window.wl.appId, value, 460 sizeof(_glfw.hints.window.wl.appId) - 1); 461 return; 462 } 463 464 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window hint string 0x%08X", hint); 465} 466 467GLFWAPI void glfwDestroyWindow(GLFWwindow* handle) 468{ 469 _GLFW_REQUIRE_INIT(); 470 471 _GLFWwindow* window = (_GLFWwindow*) handle; 472 473 // Allow closing of NULL (to match the behavior of free) 474 if (window == NULL) 475 return; 476 477 // Clear all callbacks to avoid exposing a half torn-down window object 478 memset(&window->callbacks, 0, sizeof(window->callbacks)); 479 480 // The window's context must not be current on another thread when the 481 // window is destroyed 482 if (window == _glfwPlatformGetTls(&_glfw.contextSlot)) 483 glfwMakeContextCurrent(NULL); 484 485 _glfw.platform.destroyWindow(window); 486 487 // Unlink window from global linked list 488 { 489 _GLFWwindow** prev = &_glfw.windowListHead; 490 491 while (*prev != window) 492 prev = &((*prev)->next); 493 494 *prev = window->next; 495 } 496 497 _glfw_free(window->title); 498 _glfw_free(window); 499} 500 501GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle) 502{ 503 _GLFW_REQUIRE_INIT_OR_RETURN(0); 504 505 _GLFWwindow* window = (_GLFWwindow*) handle; 506 assert(window != NULL); 507 508 return window->shouldClose; 509} 510 511GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value) 512{ 513 _GLFW_REQUIRE_INIT(); 514 515 _GLFWwindow* window = (_GLFWwindow*) handle; 516 assert(window != NULL); 517 518 window->shouldClose = value; 519} 520 521GLFWAPI const char* glfwGetWindowTitle(GLFWwindow* handle) 522{ 523 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 524 525 _GLFWwindow* window = (_GLFWwindow*) handle; 526 assert(window != NULL); 527 528 return window->title; 529} 530 531GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) 532{ 533 assert(title != NULL); 534 535 _GLFW_REQUIRE_INIT(); 536 537 _GLFWwindow* window = (_GLFWwindow*) handle; 538 assert(window != NULL); 539 540 char* prev = window->title; 541 window->title = _glfw_strdup(title); 542 543 _glfw.platform.setWindowTitle(window, title); 544 _glfw_free(prev); 545} 546 547GLFWAPI void glfwSetWindowIcon(GLFWwindow* handle, 548 int count, const GLFWimage* images) 549{ 550 int i; 551 552 assert(count >= 0); 553 assert(count == 0 || images != NULL); 554 555 _GLFW_REQUIRE_INIT(); 556 557 _GLFWwindow* window = (_GLFWwindow*) handle; 558 assert(window != NULL); 559 560 if (count < 0) 561 { 562 _glfwInputError(GLFW_INVALID_VALUE, "Invalid image count for window icon"); 563 return; 564 } 565 566 for (i = 0; i < count; i++) 567 { 568 assert(images[i].pixels != NULL); 569 570 if (images[i].width <= 0 || images[i].height <= 0) 571 { 572 _glfwInputError(GLFW_INVALID_VALUE, 573 "Invalid image dimensions for window icon"); 574 return; 575 } 576 } 577 578 _glfw.platform.setWindowIcon(window, count, images); 579} 580 581GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) 582{ 583 if (xpos) 584 *xpos = 0; 585 if (ypos) 586 *ypos = 0; 587 588 _GLFW_REQUIRE_INIT(); 589 590 _GLFWwindow* window = (_GLFWwindow*) handle; 591 assert(window != NULL); 592 593 _glfw.platform.getWindowPos(window, xpos, ypos); 594} 595 596GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos) 597{ 598 _GLFW_REQUIRE_INIT(); 599 600 _GLFWwindow* window = (_GLFWwindow*) handle; 601 assert(window != NULL); 602 603 if (window->monitor) 604 return; 605 606 _glfw.platform.setWindowPos(window, xpos, ypos); 607} 608 609GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) 610{ 611 if (width) 612 *width = 0; 613 if (height) 614 *height = 0; 615 616 _GLFW_REQUIRE_INIT(); 617 618 _GLFWwindow* window = (_GLFWwindow*) handle; 619 assert(window != NULL); 620 621 _glfw.platform.getWindowSize(window, width, height); 622} 623 624GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) 625{ 626 assert(width >= 0); 627 assert(height >= 0); 628 629 _GLFW_REQUIRE_INIT(); 630 631 _GLFWwindow* window = (_GLFWwindow*) handle; 632 assert(window != NULL); 633 634 window->videoMode.width = width; 635 window->videoMode.height = height; 636 637 _glfw.platform.setWindowSize(window, width, height); 638} 639 640GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle, 641 int minwidth, int minheight, 642 int maxwidth, int maxheight) 643{ 644 _GLFW_REQUIRE_INIT(); 645 646 _GLFWwindow* window = (_GLFWwindow*) handle; 647 assert(window != NULL); 648 649 if (minwidth != GLFW_DONT_CARE && minheight != GLFW_DONT_CARE) 650 { 651 if (minwidth < 0 || minheight < 0) 652 { 653 _glfwInputError(GLFW_INVALID_VALUE, 654 "Invalid window minimum size %ix%i", 655 minwidth, minheight); 656 return; 657 } 658 } 659 660 if (maxwidth != GLFW_DONT_CARE && maxheight != GLFW_DONT_CARE) 661 { 662 if (maxwidth < 0 || maxheight < 0 || 663 maxwidth < minwidth || maxheight < minheight) 664 { 665 _glfwInputError(GLFW_INVALID_VALUE, 666 "Invalid window maximum size %ix%i", 667 maxwidth, maxheight); 668 return; 669 } 670 } 671 672 window->minwidth = minwidth; 673 window->minheight = minheight; 674 window->maxwidth = maxwidth; 675 window->maxheight = maxheight; 676 677 if (window->monitor || !window->resizable) 678 return; 679 680 _glfw.platform.setWindowSizeLimits(window, 681 minwidth, minheight, 682 maxwidth, maxheight); 683} 684 685GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom) 686{ 687 assert(numer != 0); 688 assert(denom != 0); 689 690 _GLFW_REQUIRE_INIT(); 691 692 _GLFWwindow* window = (_GLFWwindow*) handle; 693 assert(window != NULL); 694 695 if (numer != GLFW_DONT_CARE && denom != GLFW_DONT_CARE) 696 { 697 if (numer <= 0 || denom <= 0) 698 { 699 _glfwInputError(GLFW_INVALID_VALUE, 700 "Invalid window aspect ratio %i:%i", 701 numer, denom); 702 return; 703 } 704 } 705 706 window->numer = numer; 707 window->denom = denom; 708 709 if (window->monitor || !window->resizable) 710 return; 711 712 _glfw.platform.setWindowAspectRatio(window, numer, denom); 713} 714 715GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height) 716{ 717 if (width) 718 *width = 0; 719 if (height) 720 *height = 0; 721 722 _GLFW_REQUIRE_INIT(); 723 724 _GLFWwindow* window = (_GLFWwindow*) handle; 725 assert(window != NULL); 726 727 _glfw.platform.getFramebufferSize(window, width, height); 728} 729 730GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle, 731 int* left, int* top, 732 int* right, int* bottom) 733{ 734 if (left) 735 *left = 0; 736 if (top) 737 *top = 0; 738 if (right) 739 *right = 0; 740 if (bottom) 741 *bottom = 0; 742 743 _GLFW_REQUIRE_INIT(); 744 745 _GLFWwindow* window = (_GLFWwindow*) handle; 746 assert(window != NULL); 747 748 _glfw.platform.getWindowFrameSize(window, left, top, right, bottom); 749} 750 751GLFWAPI void glfwGetWindowContentScale(GLFWwindow* handle, 752 float* xscale, float* yscale) 753{ 754 if (xscale) 755 *xscale = 0.f; 756 if (yscale) 757 *yscale = 0.f; 758 759 _GLFW_REQUIRE_INIT(); 760 761 _GLFWwindow* window = (_GLFWwindow*) handle; 762 assert(window != NULL); 763 764 _glfw.platform.getWindowContentScale(window, xscale, yscale); 765} 766 767GLFWAPI float glfwGetWindowOpacity(GLFWwindow* handle) 768{ 769 _GLFW_REQUIRE_INIT_OR_RETURN(0.f); 770 771 _GLFWwindow* window = (_GLFWwindow*) handle; 772 assert(window != NULL); 773 774 return _glfw.platform.getWindowOpacity(window); 775} 776 777GLFWAPI void glfwSetWindowOpacity(GLFWwindow* handle, float opacity) 778{ 779 assert(opacity == opacity); 780 assert(opacity >= 0.f); 781 assert(opacity <= 1.f); 782 783 _GLFW_REQUIRE_INIT(); 784 785 _GLFWwindow* window = (_GLFWwindow*) handle; 786 assert(window != NULL); 787 788 if (opacity != opacity || opacity < 0.f || opacity > 1.f) 789 { 790 _glfwInputError(GLFW_INVALID_VALUE, "Invalid window opacity %f", opacity); 791 return; 792 } 793 794 _glfw.platform.setWindowOpacity(window, opacity); 795} 796 797GLFWAPI void glfwIconifyWindow(GLFWwindow* handle) 798{ 799 _GLFW_REQUIRE_INIT(); 800 801 _GLFWwindow* window = (_GLFWwindow*) handle; 802 assert(window != NULL); 803 804 _glfw.platform.iconifyWindow(window); 805} 806 807GLFWAPI void glfwRestoreWindow(GLFWwindow* handle) 808{ 809 _GLFW_REQUIRE_INIT(); 810 811 _GLFWwindow* window = (_GLFWwindow*) handle; 812 assert(window != NULL); 813 814 _glfw.platform.restoreWindow(window); 815} 816 817GLFWAPI void glfwMaximizeWindow(GLFWwindow* handle) 818{ 819 _GLFW_REQUIRE_INIT(); 820 821 _GLFWwindow* window = (_GLFWwindow*) handle; 822 assert(window != NULL); 823 824 if (window->monitor) 825 return; 826 827 _glfw.platform.maximizeWindow(window); 828} 829 830GLFWAPI void glfwShowWindow(GLFWwindow* handle) 831{ 832 _GLFW_REQUIRE_INIT(); 833 834 _GLFWwindow* window = (_GLFWwindow*) handle; 835 assert(window != NULL); 836 837 if (window->monitor) 838 return; 839 840 _glfw.platform.showWindow(window); 841 842 if (window->focusOnShow) 843 _glfw.platform.focusWindow(window); 844} 845 846GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) 847{ 848 _GLFW_REQUIRE_INIT(); 849 850 _GLFWwindow* window = (_GLFWwindow*) handle; 851 assert(window != NULL); 852 853 _glfw.platform.requestWindowAttention(window); 854} 855 856GLFWAPI void glfwHideWindow(GLFWwindow* handle) 857{ 858 _GLFW_REQUIRE_INIT(); 859 860 _GLFWwindow* window = (_GLFWwindow*) handle; 861 assert(window != NULL); 862 863 if (window->monitor) 864 return; 865 866 _glfw.platform.hideWindow(window); 867} 868 869GLFWAPI void glfwFocusWindow(GLFWwindow* handle) 870{ 871 _GLFW_REQUIRE_INIT(); 872 873 _GLFWwindow* window = (_GLFWwindow*) handle; 874 assert(window != NULL); 875 876 _glfw.platform.focusWindow(window); 877} 878 879GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) 880{ 881 _GLFW_REQUIRE_INIT_OR_RETURN(0); 882 883 _GLFWwindow* window = (_GLFWwindow*) handle; 884 assert(window != NULL); 885 886 switch (attrib) 887 { 888 case GLFW_FOCUSED: 889 return _glfw.platform.windowFocused(window); 890 case GLFW_ICONIFIED: 891 return _glfw.platform.windowIconified(window); 892 case GLFW_VISIBLE: 893 return _glfw.platform.windowVisible(window); 894 case GLFW_MAXIMIZED: 895 return _glfw.platform.windowMaximized(window); 896 case GLFW_HOVERED: 897 return _glfw.platform.windowHovered(window); 898 case GLFW_FOCUS_ON_SHOW: 899 return window->focusOnShow; 900 case GLFW_MOUSE_PASSTHROUGH: 901 return window->mousePassthrough; 902 case GLFW_TRANSPARENT_FRAMEBUFFER: 903 return _glfw.platform.framebufferTransparent(window); 904 case GLFW_RESIZABLE: 905 return window->resizable; 906 case GLFW_DECORATED: 907 return window->decorated; 908 case GLFW_FLOATING: 909 return window->floating; 910 case GLFW_AUTO_ICONIFY: 911 return window->autoIconify; 912 case GLFW_DOUBLEBUFFER: 913 return window->doublebuffer; 914 case GLFW_CLIENT_API: 915 return window->context.client; 916 case GLFW_CONTEXT_CREATION_API: 917 return window->context.source; 918 case GLFW_CONTEXT_VERSION_MAJOR: 919 return window->context.major; 920 case GLFW_CONTEXT_VERSION_MINOR: 921 return window->context.minor; 922 case GLFW_CONTEXT_REVISION: 923 return window->context.revision; 924 case GLFW_CONTEXT_ROBUSTNESS: 925 return window->context.robustness; 926 case GLFW_OPENGL_FORWARD_COMPAT: 927 return window->context.forward; 928 case GLFW_CONTEXT_DEBUG: 929 return window->context.debug; 930 case GLFW_OPENGL_PROFILE: 931 return window->context.profile; 932 case GLFW_CONTEXT_RELEASE_BEHAVIOR: 933 return window->context.release; 934 case GLFW_CONTEXT_NO_ERROR: 935 return window->context.noerror; 936 } 937 938 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib); 939 return 0; 940} 941 942GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value) 943{ 944 _GLFW_REQUIRE_INIT(); 945 946 _GLFWwindow* window = (_GLFWwindow*) handle; 947 assert(window != NULL); 948 949 value = value ? GLFW_TRUE : GLFW_FALSE; 950 951 switch (attrib) 952 { 953 case GLFW_AUTO_ICONIFY: 954 window->autoIconify = value; 955 return; 956 957 case GLFW_RESIZABLE: 958 window->resizable = value; 959 if (!window->monitor) 960 _glfw.platform.setWindowResizable(window, value); 961 return; 962 963 case GLFW_DECORATED: 964 window->decorated = value; 965 if (!window->monitor) 966 _glfw.platform.setWindowDecorated(window, value); 967 return; 968 969 case GLFW_FLOATING: 970 window->floating = value; 971 if (!window->monitor) 972 _glfw.platform.setWindowFloating(window, value); 973 return; 974 975 case GLFW_FOCUS_ON_SHOW: 976 window->focusOnShow = value; 977 return; 978 979 case GLFW_MOUSE_PASSTHROUGH: 980 window->mousePassthrough = value; 981 _glfw.platform.setWindowMousePassthrough(window, value); 982 return; 983 } 984 985 _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute 0x%08X", attrib); 986} 987 988GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle) 989{ 990 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 991 992 _GLFWwindow* window = (_GLFWwindow*) handle; 993 assert(window != NULL); 994 995 return (GLFWmonitor*) window->monitor; 996} 997 998GLFWAPI void glfwSetWindowMonitor(GLFWwindow* wh, 999 GLFWmonitor* mh, 1000 int xpos, int ypos, 1001 int width, int height, 1002 int refreshRate) 1003{ 1004 assert(width >= 0); 1005 assert(height >= 0); 1006 1007 _GLFW_REQUIRE_INIT(); 1008 1009 _GLFWwindow* window = (_GLFWwindow*) wh; 1010 _GLFWmonitor* monitor = (_GLFWmonitor*) mh; 1011 assert(window != NULL); 1012 1013 if (width <= 0 || height <= 0) 1014 { 1015 _glfwInputError(GLFW_INVALID_VALUE, 1016 "Invalid window size %ix%i", 1017 width, height); 1018 return; 1019 } 1020 1021 if (refreshRate < 0 && refreshRate != GLFW_DONT_CARE) 1022 { 1023 _glfwInputError(GLFW_INVALID_VALUE, 1024 "Invalid refresh rate %i", 1025 refreshRate); 1026 return; 1027 } 1028 1029 window->videoMode.width = width; 1030 window->videoMode.height = height; 1031 window->videoMode.refreshRate = refreshRate; 1032 1033 _glfw.platform.setWindowMonitor(window, monitor, 1034 xpos, ypos, width, height, 1035 refreshRate); 1036} 1037 1038GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer) 1039{ 1040 _GLFW_REQUIRE_INIT(); 1041 1042 _GLFWwindow* window = (_GLFWwindow*) handle; 1043 assert(window != NULL); 1044 1045 window->userPointer = pointer; 1046} 1047 1048GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle) 1049{ 1050 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1051 1052 _GLFWwindow* window = (_GLFWwindow*) handle; 1053 assert(window != NULL); 1054 1055 return window->userPointer; 1056} 1057 1058GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle, 1059 GLFWwindowposfun cbfun) 1060{ 1061 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1062 1063 _GLFWwindow* window = (_GLFWwindow*) handle; 1064 assert(window != NULL); 1065 1066 _GLFW_SWAP(GLFWwindowposfun, window->callbacks.pos, cbfun); 1067 return cbfun; 1068} 1069 1070GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle, 1071 GLFWwindowsizefun cbfun) 1072{ 1073 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1074 1075 _GLFWwindow* window = (_GLFWwindow*) handle; 1076 assert(window != NULL); 1077 1078 _GLFW_SWAP(GLFWwindowsizefun, window->callbacks.size, cbfun); 1079 return cbfun; 1080} 1081 1082GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle, 1083 GLFWwindowclosefun cbfun) 1084{ 1085 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1086 1087 _GLFWwindow* window = (_GLFWwindow*) handle; 1088 assert(window != NULL); 1089 1090 _GLFW_SWAP(GLFWwindowclosefun, window->callbacks.close, cbfun); 1091 return cbfun; 1092} 1093 1094GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle, 1095 GLFWwindowrefreshfun cbfun) 1096{ 1097 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1098 1099 _GLFWwindow* window = (_GLFWwindow*) handle; 1100 assert(window != NULL); 1101 1102 _GLFW_SWAP(GLFWwindowrefreshfun, window->callbacks.refresh, cbfun); 1103 return cbfun; 1104} 1105 1106GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle, 1107 GLFWwindowfocusfun cbfun) 1108{ 1109 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1110 1111 _GLFWwindow* window = (_GLFWwindow*) handle; 1112 assert(window != NULL); 1113 1114 _GLFW_SWAP(GLFWwindowfocusfun, window->callbacks.focus, cbfun); 1115 return cbfun; 1116} 1117 1118GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle, 1119 GLFWwindowiconifyfun cbfun) 1120{ 1121 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1122 1123 _GLFWwindow* window = (_GLFWwindow*) handle; 1124 assert(window != NULL); 1125 1126 _GLFW_SWAP(GLFWwindowiconifyfun, window->callbacks.iconify, cbfun); 1127 return cbfun; 1128} 1129 1130GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* handle, 1131 GLFWwindowmaximizefun cbfun) 1132{ 1133 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1134 1135 _GLFWwindow* window = (_GLFWwindow*) handle; 1136 assert(window != NULL); 1137 1138 _GLFW_SWAP(GLFWwindowmaximizefun, window->callbacks.maximize, cbfun); 1139 return cbfun; 1140} 1141 1142GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle, 1143 GLFWframebuffersizefun cbfun) 1144{ 1145 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1146 1147 _GLFWwindow* window = (_GLFWwindow*) handle; 1148 assert(window != NULL); 1149 1150 _GLFW_SWAP(GLFWframebuffersizefun, window->callbacks.fbsize, cbfun); 1151 return cbfun; 1152} 1153 1154GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* handle, 1155 GLFWwindowcontentscalefun cbfun) 1156{ 1157 _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 1158 1159 _GLFWwindow* window = (_GLFWwindow*) handle; 1160 assert(window != NULL); 1161 1162 _GLFW_SWAP(GLFWwindowcontentscalefun, window->callbacks.scale, cbfun); 1163 return cbfun; 1164} 1165 1166GLFWAPI void glfwPollEvents(void) 1167{ 1168 _GLFW_REQUIRE_INIT(); 1169 _glfw.platform.pollEvents(); 1170} 1171 1172GLFWAPI void glfwWaitEvents(void) 1173{ 1174 _GLFW_REQUIRE_INIT(); 1175 _glfw.platform.waitEvents(); 1176} 1177 1178GLFWAPI void glfwWaitEventsTimeout(double timeout) 1179{ 1180 _GLFW_REQUIRE_INIT(); 1181 assert(timeout == timeout); 1182 assert(timeout >= 0.0); 1183 assert(timeout <= DBL_MAX); 1184 1185 if (timeout != timeout || timeout < 0.0 || timeout > DBL_MAX) 1186 { 1187 _glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", timeout); 1188 return; 1189 } 1190 1191 _glfw.platform.waitEventsTimeout(timeout); 1192} 1193 1194GLFWAPI void glfwPostEmptyEvent(void) 1195{ 1196 _GLFW_REQUIRE_INIT(); 1197 _glfw.platform.postEmptyEvent(); 1198} 1199 1200[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.