github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/raylib/external/glfw/src/null_window.c (about)

     1  //========================================================================
     2  // GLFW 3.4 - www.glfw.org
     3  //------------------------------------------------------------------------
     4  // Copyright (c) 2016 Google Inc.
     5  // Copyright (c) 2016-2019 Camilla Löwy <elmindreda@glfw.org>
     6  //
     7  // This software is provided 'as-is', without any express or implied
     8  // warranty. In no event will the authors be held liable for any damages
     9  // arising from the use of this software.
    10  //
    11  // Permission is granted to anyone to use this software for any purpose,
    12  // including commercial applications, and to alter it and redistribute it
    13  // freely, subject to the following restrictions:
    14  //
    15  // 1. The origin of this software must not be misrepresented; you must not
    16  //    claim that you wrote the original software. If you use this software
    17  //    in a product, an acknowledgment in the product documentation would
    18  //    be appreciated but is not required.
    19  //
    20  // 2. Altered source versions must be plainly marked as such, and must not
    21  //    be misrepresented as being the original software.
    22  //
    23  // 3. This notice may not be removed or altered from any source
    24  //    distribution.
    25  //
    26  //========================================================================
    27  // It is fine to use C99 in this file because it will not be built with VS
    28  //========================================================================
    29  
    30  #include "internal.h"
    31  
    32  #include <stdlib.h>
    33  
    34  static void applySizeLimits(_GLFWwindow* window, int* width, int* height)
    35  {
    36      if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE)
    37      {
    38          const float ratio = (float) window->numer / (float) window->denom;
    39          *height = (int) (*width / ratio);
    40      }
    41  
    42      if (window->minwidth != GLFW_DONT_CARE)
    43          *width = _glfw_max(*width, window->minwidth);
    44      else if (window->maxwidth != GLFW_DONT_CARE)
    45          *width = _glfw_min(*width, window->maxwidth);
    46  
    47      if (window->minheight != GLFW_DONT_CARE)
    48          *height = _glfw_min(*height, window->minheight);
    49      else if (window->maxheight != GLFW_DONT_CARE)
    50          *height = _glfw_max(*height, window->maxheight);
    51  }
    52  
    53  static void fitToMonitor(_GLFWwindow* window)
    54  {
    55      GLFWvidmode mode;
    56      _glfwGetVideoModeNull(window->monitor, &mode);
    57      _glfwGetMonitorPosNull(window->monitor,
    58                             &window->null.xpos,
    59                             &window->null.ypos);
    60      window->null.width = mode.width;
    61      window->null.height = mode.height;
    62  }
    63  
    64  static void acquireMonitor(_GLFWwindow* window)
    65  {
    66      _glfwInputMonitorWindow(window->monitor, window);
    67  }
    68  
    69  static void releaseMonitor(_GLFWwindow* window)
    70  {
    71      if (window->monitor->window != window)
    72          return;
    73  
    74      _glfwInputMonitorWindow(window->monitor, NULL);
    75  }
    76  
    77  static int createNativeWindow(_GLFWwindow* window,
    78                                const _GLFWwndconfig* wndconfig,
    79                                const _GLFWfbconfig* fbconfig)
    80  {
    81      if (window->monitor)
    82          fitToMonitor(window);
    83      else
    84      {
    85          if (wndconfig->xpos == GLFW_ANY_POSITION && wndconfig->ypos == GLFW_ANY_POSITION)
    86          {
    87              window->null.xpos = 17;
    88              window->null.ypos = 17;
    89          }
    90          else
    91          {
    92              window->null.xpos = wndconfig->xpos;
    93              window->null.ypos = wndconfig->ypos;
    94          }
    95  
    96          window->null.width = wndconfig->width;
    97          window->null.height = wndconfig->height;
    98      }
    99  
   100      window->null.visible = wndconfig->visible;
   101      window->null.decorated = wndconfig->decorated;
   102      window->null.maximized = wndconfig->maximized;
   103      window->null.floating = wndconfig->floating;
   104      window->null.transparent = fbconfig->transparent;
   105      window->null.opacity = 1.f;
   106  
   107      return GLFW_TRUE;
   108  }
   109  
   110  
   111  //////////////////////////////////////////////////////////////////////////
   112  //////                       GLFW platform API                      //////
   113  //////////////////////////////////////////////////////////////////////////
   114  
   115  GLFWbool _glfwCreateWindowNull(_GLFWwindow* window,
   116                                 const _GLFWwndconfig* wndconfig,
   117                                 const _GLFWctxconfig* ctxconfig,
   118                                 const _GLFWfbconfig* fbconfig)
   119  {
   120      if (!createNativeWindow(window, wndconfig, fbconfig))
   121          return GLFW_FALSE;
   122  
   123      if (ctxconfig->client != GLFW_NO_API)
   124      {
   125          if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API ||
   126              ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
   127          {
   128              if (!_glfwInitOSMesa())
   129                  return GLFW_FALSE;
   130              if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
   131                  return GLFW_FALSE;
   132          }
   133          else if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
   134          {
   135              if (!_glfwInitEGL())
   136                  return GLFW_FALSE;
   137              if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
   138                  return GLFW_FALSE;
   139          }
   140  
   141          if (!_glfwRefreshContextAttribs(window, ctxconfig))
   142              return GLFW_FALSE;
   143      }
   144  
   145      if (wndconfig->mousePassthrough)
   146          _glfwSetWindowMousePassthroughNull(window, GLFW_TRUE);
   147  
   148      if (window->monitor)
   149      {
   150          _glfwShowWindowNull(window);
   151          _glfwFocusWindowNull(window);
   152          acquireMonitor(window);
   153  
   154          if (wndconfig->centerCursor)
   155              _glfwCenterCursorInContentArea(window);
   156      }
   157      else
   158      {
   159          if (wndconfig->visible)
   160          {
   161              _glfwShowWindowNull(window);
   162              if (wndconfig->focused)
   163                  _glfwFocusWindowNull(window);
   164          }
   165      }
   166  
   167      return GLFW_TRUE;
   168  }
   169  
   170  void _glfwDestroyWindowNull(_GLFWwindow* window)
   171  {
   172      if (window->monitor)
   173          releaseMonitor(window);
   174  
   175      if (_glfw.null.focusedWindow == window)
   176          _glfw.null.focusedWindow = NULL;
   177  
   178      if (window->context.destroy)
   179          window->context.destroy(window);
   180  }
   181  
   182  void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title)
   183  {
   184  }
   185  
   186  void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images)
   187  {
   188  }
   189  
   190  void _glfwSetWindowMonitorNull(_GLFWwindow* window,
   191                                 _GLFWmonitor* monitor,
   192                                 int xpos, int ypos,
   193                                 int width, int height,
   194                                 int refreshRate)
   195  {
   196      if (window->monitor == monitor)
   197      {
   198          if (!monitor)
   199          {
   200              _glfwSetWindowPosNull(window, xpos, ypos);
   201              _glfwSetWindowSizeNull(window, width, height);
   202          }
   203  
   204          return;
   205      }
   206  
   207      if (window->monitor)
   208          releaseMonitor(window);
   209  
   210      _glfwInputWindowMonitor(window, monitor);
   211  
   212      if (window->monitor)
   213      {
   214          window->null.visible = GLFW_TRUE;
   215          acquireMonitor(window);
   216          fitToMonitor(window);
   217      }
   218      else
   219      {
   220          _glfwSetWindowPosNull(window, xpos, ypos);
   221          _glfwSetWindowSizeNull(window, width, height);
   222      }
   223  }
   224  
   225  void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos)
   226  {
   227      if (xpos)
   228          *xpos = window->null.xpos;
   229      if (ypos)
   230          *ypos = window->null.ypos;
   231  }
   232  
   233  void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos)
   234  {
   235      if (window->monitor)
   236          return;
   237  
   238      if (window->null.xpos != xpos || window->null.ypos != ypos)
   239      {
   240          window->null.xpos = xpos;
   241          window->null.ypos = ypos;
   242          _glfwInputWindowPos(window, xpos, ypos);
   243      }
   244  }
   245  
   246  void _glfwGetWindowSizeNull(_GLFWwindow* window, int* width, int* height)
   247  {
   248      if (width)
   249          *width = window->null.width;
   250      if (height)
   251          *height = window->null.height;
   252  }
   253  
   254  void _glfwSetWindowSizeNull(_GLFWwindow* window, int width, int height)
   255  {
   256      if (window->monitor)
   257          return;
   258  
   259      if (window->null.width != width || window->null.height != height)
   260      {
   261          window->null.width = width;
   262          window->null.height = height;
   263          _glfwInputWindowSize(window, width, height);
   264          _glfwInputFramebufferSize(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              releaseMonitor(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              acquireMonitor(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_KEY_SPACE || scancode > GLFW_KEY_LAST)
   572      {
   573          _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode);
   574          return NULL;
   575      }
   576  
   577      switch (scancode)
   578      {
   579          case GLFW_KEY_APOSTROPHE:
   580              return "'";
   581          case GLFW_KEY_COMMA:
   582              return ",";
   583          case GLFW_KEY_MINUS:
   584          case GLFW_KEY_KP_SUBTRACT:
   585              return "-";
   586          case GLFW_KEY_PERIOD:
   587          case GLFW_KEY_KP_DECIMAL:
   588              return ".";
   589          case GLFW_KEY_SLASH:
   590          case GLFW_KEY_KP_DIVIDE:
   591              return "/";
   592          case GLFW_KEY_SEMICOLON:
   593              return ";";
   594          case GLFW_KEY_EQUAL:
   595          case GLFW_KEY_KP_EQUAL:
   596              return "=";
   597          case GLFW_KEY_LEFT_BRACKET:
   598              return "[";
   599          case GLFW_KEY_RIGHT_BRACKET:
   600              return "]";
   601          case GLFW_KEY_KP_MULTIPLY:
   602              return "*";
   603          case GLFW_KEY_KP_ADD:
   604              return "+";
   605          case GLFW_KEY_BACKSLASH:
   606          case GLFW_KEY_WORLD_1:
   607          case GLFW_KEY_WORLD_2:
   608              return "\\";
   609          case GLFW_KEY_0:
   610          case GLFW_KEY_KP_0:
   611              return "0";
   612          case GLFW_KEY_1:
   613          case GLFW_KEY_KP_1:
   614              return "1";
   615          case GLFW_KEY_2:
   616          case GLFW_KEY_KP_2:
   617              return "2";
   618          case GLFW_KEY_3:
   619          case GLFW_KEY_KP_3:
   620              return "3";
   621          case GLFW_KEY_4:
   622          case GLFW_KEY_KP_4:
   623              return "4";
   624          case GLFW_KEY_5:
   625          case GLFW_KEY_KP_5:
   626              return "5";
   627          case GLFW_KEY_6:
   628          case GLFW_KEY_KP_6:
   629              return "6";
   630          case GLFW_KEY_7:
   631          case GLFW_KEY_KP_7:
   632              return "7";
   633          case GLFW_KEY_8:
   634          case GLFW_KEY_KP_8:
   635              return "8";
   636          case GLFW_KEY_9:
   637          case GLFW_KEY_KP_9:
   638              return "9";
   639          case GLFW_KEY_A:
   640              return "a";
   641          case GLFW_KEY_B:
   642              return "b";
   643          case GLFW_KEY_C:
   644              return "c";
   645          case GLFW_KEY_D:
   646              return "d";
   647          case GLFW_KEY_E:
   648              return "e";
   649          case GLFW_KEY_F:
   650              return "f";
   651          case GLFW_KEY_G:
   652              return "g";
   653          case GLFW_KEY_H:
   654              return "h";
   655          case GLFW_KEY_I:
   656              return "i";
   657          case GLFW_KEY_J:
   658              return "j";
   659          case GLFW_KEY_K:
   660              return "k";
   661          case GLFW_KEY_L:
   662              return "l";
   663          case GLFW_KEY_M:
   664              return "m";
   665          case GLFW_KEY_N:
   666              return "n";
   667          case GLFW_KEY_O:
   668              return "o";
   669          case GLFW_KEY_P:
   670              return "p";
   671          case GLFW_KEY_Q:
   672              return "q";
   673          case GLFW_KEY_R:
   674              return "r";
   675          case GLFW_KEY_S:
   676              return "s";
   677          case GLFW_KEY_T:
   678              return "t";
   679          case GLFW_KEY_U:
   680              return "u";
   681          case GLFW_KEY_V:
   682              return "v";
   683          case GLFW_KEY_W:
   684              return "w";
   685          case GLFW_KEY_X:
   686              return "x";
   687          case GLFW_KEY_Y:
   688              return "y";
   689          case GLFW_KEY_Z:
   690              return "z";
   691      }
   692  
   693      return NULL;
   694  }
   695  
   696  int _glfwGetKeyScancodeNull(int key)
   697  {
   698      return 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