浏览代码

Implemented SetIcon.

Brucey 5 年之前
父节点
当前提交
5641c7e180
共有 2 个文件被更改,包括 64 次插入2 次删除
  1. 2 0
      glfwwindow.mod/common.bmx
  2. 62 2
      glfwwindow.mod/glfwwindow.bmx

+ 2 - 0
glfwwindow.mod/common.bmx

@@ -23,6 +23,7 @@ SuperStrict
 
 Import GLFW.GLFWSystem
 Import GLFW.GLFWMonitor
+Import BRL.Pixmap
 
 Extern
 
@@ -56,6 +57,7 @@ Extern
 	Function bmx_glfw_glfwSetWindowAttrib(window:Byte Ptr, attrib:Int, value:Int)="glfwSetWindowAttrib"
 	Function bmx_glfw_glfwGetWindowMonitor:Byte Ptr(window:Byte Ptr)="glfwGetWindowMonitor"
 	Function bmx_glfw_glfwSetWindowMonitor(window:Byte Ptr, monitor:Byte Ptr, xpos:Int, ypos:Int, width:Int, height:Int, refreshRate:Int)="glfwSetWindowMonitor"
+	Function bmx_glfw_glfwSetWindowIcon(window:Byte Ptr, count:Int, images:Byte Ptr)="glfwSetWindowIcon"
 
 	Function bmx_glfw_glfwMakeContextCurrent(window:Byte Ptr)="glfwMakeContextCurrent"
 	Function bmx_glfw_glfwSwapBuffers(window:Byte Ptr)="glfwSwapBuffers"

+ 62 - 2
glfwwindow.mod/glfwwindow.bmx

@@ -156,8 +156,42 @@ Type TGLFWWindow
 		MemFree(t)
 	End Method
 	
-	'Method SetIcon()
-	'End Method
+	Rem
+	bbdoc: Sets the icon for the window.
+	about: If passed an array of candidate pixmaps, those of or closest to the sizes desired by the system are
+	selected.  If no images are specified, the window reverts to its default icon.
+
+	The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight bits per channel with the red channel first.
+	They are arranged canonically as packed sequential rows, starting from the top-left corner.
+
+	The desired image sizes varies depending on platform and system settings.
+	The selected images will be rescaled as needed.  Good sizes include 16x16, 32x32 and 48x48.
+	
+	> On macOS the GLFW window has no icon, as it is not a document window, so this method does nothing.  The dock icon will be the same as the application bundle's icon.
+	
+	> On Wayland there is no existing protocol to change an icon, the window will thus inherit the one defined in the application's desktop file. This method always emits #GLFW_PLATFORM_ERROR.
+	End Rem
+	Method SetIcon(pixmaps:TPixmap[])
+		If pixmaps.length = 0 Then
+			bmx_glfw_glfwSetWindowIcon(windowPtr, 0, Null)
+		Else
+			Local images:SGLFWimage[pixmaps.length]
+			
+			Local pixs:TPixmap[pixmaps.length] ' cache
+			For Local i:Int = 0 Until pixmaps.length
+				Local pix:TPixmap = pixmaps[i]
+				If pix.format <> PF_RGBA8888 Then
+					pix = pix.Convert(PF_RGBA8888)
+				End If
+				pixs[i] = pix
+				
+				images[i] = New SGLFWimage(pix.width, pix.height, pix.pixels)
+			Next
+			
+			bmx_glfw_glfwSetWindowIcon(windowPtr, pixmaps.length, images)
+			pixs = Null ' refer to cache - prevent compiler optimizing it away because we don't reference it otherwise after the loop
+		End If
+	End Method
 	
 	Rem
 	bbdoc: Retrieves the position, in screen coordinates, of the upper-left corner of the content area of the window.
@@ -649,6 +683,32 @@ Private
 
 End Type
 
+Rem
+bbdoc: Image data.
+about: This describes a single 2D image.
+See the documentation for each related function what the expected pixel format is.
+End Rem
+Struct SGLFWimage
+	Rem
+	bbdoc: The width, in pixels, of this image.
+	End Rem
+	Field width:Int
+	Rem
+	bbdoc: The height, in pixels, of this image.
+	End Rem
+	Field height:Int
+	Rem
+	bbdoc: The pixel data of this image, arranged left-to-right, top-to-bottom.
+	End Rem
+	Field pixels:Byte Ptr
+	
+	Method New(width:Int, height:Int, pixels:Byte Ptr)
+		Self.width = width
+		Self.height = height
+		Self.pixels = pixels
+	End Method
+End Struct
+
 Private
 
 Extern