org.lwjgl.glfw.GLFW.glfwSetWindowIcon()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(279)

本文整理了Java中org.lwjgl.glfw.GLFW.glfwSetWindowIcon()方法的一些代码示例,展示了GLFW.glfwSetWindowIcon()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GLFW.glfwSetWindowIcon()方法的具体详情如下:
包路径:org.lwjgl.glfw.GLFW
类名称:GLFW
方法名:glfwSetWindowIcon

GLFW.glfwSetWindowIcon介绍

[英]Sets the icon for the specified window.

This function sets the icon of the specified window. If passed an array of candidate images, 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.

Notes:

  • This function must only be called from the main thread.
  • The specified image data is copied before this function returns.
  • macOS: The GLFW window has no icon, as it is not a document window, so this function does nothing. The dock icon will be the same as the application bundle's icon. For more information on bundles, see the Bundle Programming Guide in the Mac Developer Library.
  • 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 function always emits #GLFW_PLATFORM_ERROR.
    [中]设置指定窗口的图标。
    此函数用于设置指定窗口的图标。如果传递了一组候选图像,则会选择系统所需大小或最接近系统所需大小的图像。如果未指定图像,窗口将恢复为默认图标。
    像素为32位、小端、非预乘RGBA,即每个通道8位,红色通道优先。从左上角开始,它们被规范地排列为压缩的连续行。
    所需的图像大小因平台和系统设置而异。所选图像将根据需要重新缩放。好的尺寸包括16x16、32x32和48x48。
    笔记:
    *只能从主线程调用此函数。
    *此函数返回之前,将复制指定的图像数据。
    *macOS:GLFW窗口没有图标,因为它不是文档窗口,所以此函数不执行任何操作。dock图标将与应用程序包的图标相同。有关捆绑包的更多信息,请参阅Mac Developer库中的{$0$}。
    *Wayland:没有更改图标的现有协议,因此窗口将继承应用程序桌面文件中定义的图标。此函数始终发出#GLFW_平台_错误。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Set custom icons to the window of this application.
 */
protected void setWindowIcon(final AppSettings settings) {
  final Object[] icons = settings.getIcons();
  if (icons == null) return;
  final GLFWImage[] images = imagesToGLFWImages(icons);
  try (final GLFWImage.Buffer iconSet = GLFWImage.malloc(images.length)) {
    for (int i = images.length - 1; i >= 0; i--) {
      final GLFWImage image = images[i];
      iconSet.put(i, image);
    }
    glfwSetWindowIcon(window, iconSet);
  }
}

代码示例来源:origin: libgdx/libgdx

static void setIcon(long windowHandle, Pixmap[] images) {
  if (SharedLibraryLoader.isMac)
    return;
  GLFWImage.Buffer buffer = GLFWImage.malloc(images.length);
  Pixmap[] tmpPixmaps = new Pixmap[images.length];
  for (int i = 0; i < images.length; i++) {
    Pixmap pixmap = images[i];
    if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
      Pixmap rgba = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
      rgba.setBlending(Pixmap.Blending.None);
      rgba.drawPixmap(pixmap, 0, 0);
      tmpPixmaps[i] = rgba;
      pixmap = rgba;
    }
    GLFWImage icon = GLFWImage.malloc();
    icon.set(pixmap.getWidth(), pixmap.getHeight(), pixmap.getPixels());
    buffer.put(icon);
    icon.free();
  }
  buffer.position(0);
  GLFW.glfwSetWindowIcon(windowHandle, buffer);
  buffer.free();
  for (Pixmap pixmap : tmpPixmaps) {
    if (pixmap != null) {
      pixmap.dispose();
    }
  }
}

代码示例来源:origin: libgdx/libgdx

static void setIcon(long windowHandle, Pixmap[] images) {
  if (SharedLibraryLoader.isMac)
    return;
  GLFWImage.Buffer buffer = GLFWImage.malloc(images.length);
  Pixmap[] tmpPixmaps = new Pixmap[images.length];
  for (int i = 0; i < images.length; i++) {
    Pixmap pixmap = images[i];
    if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
      Pixmap rgba = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
      rgba.setBlending(Pixmap.Blending.None);
      rgba.drawPixmap(pixmap, 0, 0);
      tmpPixmaps[i] = rgba;
      pixmap = rgba;
    }
    GLFWImage icon = GLFWImage.malloc();
    icon.set(pixmap.getWidth(), pixmap.getHeight(), pixmap.getPixels());
    buffer.put(icon);
    icon.free();
  }
  buffer.position(0);
  GLFW.glfwSetWindowIcon(windowHandle, buffer);
  buffer.free();
  for (Pixmap pixmap : tmpPixmaps) {
    if (pixmap != null) {
      pixmap.dispose();
    }
  }
}

代码示例来源:origin: org.jmonkeyengine/jme3-lwjgl3

/**
 * Set custom icons to the window of this application.
 */
protected void setWindowIcon(final AppSettings settings) {
  final Object[] icons = settings.getIcons();
  if (icons == null) return;
  final GLFWImage[] images = imagesToGLFWImages(icons);
  try (final GLFWImage.Buffer iconSet = GLFWImage.malloc(images.length)) {
    for (int i = images.length - 1; i >= 0; i--) {
      final GLFWImage image = images[i];
      iconSet.put(i, image);
    }
    glfwSetWindowIcon(window, iconSet);
  }
}

代码示例来源:origin: sriharshachilakapati/SilenceEngine

glfwImage.pixels(data);
glfwSetWindowIcon(handle, glfwImages);

代码示例来源:origin: Renanse/Ardor3D

public void setIcon(final Image[] iconImages) {
  if (iconImages.length == 0) {
    throw new IllegalArgumentException("Must have at least one icon image.  Only the first is used.");
  }
  Image image = iconImages[0];
  if (image.getDataType() != PixelDataType.UnsignedByte) {
    throw new Ardor3dException("Your icon is in a format that could not be converted to UnsignedByte - RGBA");
  }
  if (image.getDataFormat() != ImageDataFormat.RGBA) {
    if (image.getDataFormat() != ImageDataFormat.RGB) {
      throw new Ardor3dException(
          "Your icon is in a format that could not be converted to UnsignedByte - RGBA");
    }
    image = _RGB888_to_RGBA8888(image);
  }
  final ByteBuffer iconData = image.getData(0);
  iconData.rewind();
  final GLFWImage img = GLFWImage.malloc();
  final GLFWImage.Buffer imagebf = GLFWImage.malloc(1);
  img.set(image.getWidth(), image.getHeight(), iconData);
  imagebf.put(0, img);
  GLFW.glfwSetWindowIcon(_windowId, imagebf);
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-lwjgl3

static void setIcon(long windowHandle, Pixmap[] images) {
  if (SharedLibraryLoader.isMac)
    return;
  GLFWImage.Buffer buffer = GLFWImage.malloc(images.length);
  Pixmap[] tmpPixmaps = new Pixmap[images.length];
  for (int i = 0; i < images.length; i++) {
    Pixmap pixmap = images[i];
    if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
      Pixmap rgba = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
      rgba.setBlending(Pixmap.Blending.None);
      rgba.drawPixmap(pixmap, 0, 0);
      tmpPixmaps[i] = rgba;
      pixmap = rgba;
    }
    GLFWImage icon = GLFWImage.malloc();
    icon.set(pixmap.getWidth(), pixmap.getHeight(), pixmap.getPixels());
    buffer.put(icon);
    icon.free();
  }
  buffer.position(0);
  GLFW.glfwSetWindowIcon(windowHandle, buffer);
  buffer.free();
  for (Pixmap pixmap : tmpPixmaps) {
    if (pixmap != null) {
      pixmap.dispose();
    }
  }
}

相关文章

GLFW类方法