浏览代码

Cocoa: Added glfwGetCocoaView native access function

Resolves #2235

Co-authored-by: mightgoyardstill <[email protected]>
Doug Binks 1 年之前
父节点
当前提交
1fb7f0e120
共有 5 个文件被更改,包括 40 次插入0 次删除
  1. 1 0
      CONTRIBUTORS.md
  2. 1 0
      README.md
  3. 6 0
      docs/news.md
  4. 17 0
      include/GLFW/glfw3native.h
  5. 15 0
      src/cocoa_window.m

+ 1 - 0
CONTRIBUTORS.md

@@ -154,6 +154,7 @@ video tutorials.
  - Jonathan Mercier
  - Marcel Metz
  - Liam Middlebrook
+ - mightgoyardstill
  - Ave Milia
  - Icyllis Milica
  - Jonathan Miller

+ 1 - 0
README.md

@@ -180,6 +180,7 @@ information on what to include when reporting a bug.
  - [Win32] Added a version info resource to the GLFW DLL
  - [Win32] Made hidden helper window use its own window class
  - [Win32] Bugfix: The foreground lock timeout was overridden, ignoring the user
+ - [Cocoa] Added `glfwGetCocoaView` native access function (#2235)
  - [Cocoa] Moved main menu creation to GLFW initialization time (#1649)
  - [Cocoa] Bugfix: Touching event queue from secondary thread before main thread
    would abort (#1649)

+ 6 - 0
docs/news.md

@@ -7,6 +7,12 @@
 
 ### New features in version 3.4 {#features_34}
 
+#### Cocoa NSView native access function {#native_cocoa_nsview_34}
+
+GLFW now provides the @ref glfwGetCocoaView native access function
+for returning the Cocoa NSView.
+
+
 #### Runtime platform selection {#runtime_platform_34}
 
 GLFW now supports being compiled for multiple backends and selecting between

+ 17 - 0
include/GLFW/glfw3native.h

@@ -286,6 +286,23 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
  *  @ingroup native
  */
 GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window);
+
+/*! @brief Returns the `NSView` of the specified window.
+ *
+ *  @return The `NSView` of the specified window, or `nil` if an
+ *  [error](@ref error_handling) occurred.
+ *
+ *  @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
+ *  GLFW_PLATFORM_UNAVAILABLE.
+ *
+ *  @thread_safety This function may be called from any thread.  Access is not
+ *  synchronized.
+ *
+ *  @since Added in version 3.4.
+ *
+ *  @ingroup native
+ */
+GLFWAPI id glfwGetCocoaView(GLFWwindow* window);
 #endif
 
 #if defined(GLFW_EXPOSE_NATIVE_NSGL)

+ 15 - 0
src/cocoa_window.m

@@ -2053,5 +2053,20 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
     return window->ns.object;
 }
 
+GLFWAPI id glfwGetCocoaView(GLFWwindow* handle)
+{
+    _GLFWwindow* window = (_GLFWwindow*) handle;
+    _GLFW_REQUIRE_INIT_OR_RETURN(nil);
+
+    if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA)
+    {
+        _glfwInputError(GLFW_PLATFORM_UNAVAILABLE,
+                        "Cocoa: Platform not initialized");
+        return nil;
+    }
+
+    return window->ns.view;
+}
+
 #endif // _GLFW_COCOA