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

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

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

GLFW.glfwCreateCursor介绍

[英]Creates a new custom cursor image that can be set for a window with #glfwSetCursor. The cursor can be destroyed with #glfwDestroyCursor. Any remaining cursors are destroyed by #glfwTerminate.

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 cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image. Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down.

Note
  • This function must only be called from the main thread.
  • The specified image data is copied before this function returns.
    [中]创建一个新的自定义光标图像,可以为带有#glfwSetCursor的窗口设置该图像。可以使用#glfwDestroyCursor销毁光标。任何剩余的游标都将被#glfweterminate销毁。
    像素为32位、小端、非预乘RGBA,即每个通道8位,红色通道优先。从左上角开始,它们被规范地排列为压缩的连续行。
    相对于光标图像的左上角,以像素为单位指定光标热点。与GLFW中的所有其他坐标系一样,X轴指向右侧,Y轴指向下方。
    #####注
    *只能从主线程调用此函数。
    *此函数返回之前,将复制指定的图像数据。

代码示例

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

private long createGlfwCursor(JmeCursor jmeCursor) {
  GLFWImage glfwImage = new GLFWImage(BufferUtils.createByteBuffer(GLFWImage.SIZEOF));
  // TODO: currently animated cursors are not supported
  IntBuffer imageData = jmeCursor.getImagesData();
  ByteBuffer buf = BufferUtils.createByteBuffer(imageData.capacity() * 4);
  buf.asIntBuffer().put(imageData);
  glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);
  return glfwCreateCursor(glfwImage, jmeCursor.getXHotSpot(), jmeCursor.getYHotSpot());
}

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

private static long[] createGlfwCursor(final JmeCursor jmeCursor) {
  long[] cursorArray = new long[jmeCursor.getNumImages()];
  for (int i = 0; i < jmeCursor.getNumImages(); i++) {
    final ByteBuffer buffer = transformCursorImage(jmeCursor.getImagesData(), jmeCursor.getWidth(), jmeCursor.getHeight(), i);
    final GLFWImage glfwImage = new GLFWImage(BufferUtils.createByteBuffer(GLFWImage.SIZEOF));
    glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buffer);
    final int hotspotX = jmeCursor.getXHotSpot();
    final int hotspotY = jmeCursor.getHeight() - jmeCursor.getYHotSpot();
    cursorArray[i] = glfwCreateCursor(glfwImage, hotspotX, hotspotY);
  }
  return cursorArray;
}

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

Lwjgl3Cursor(Lwjgl3Window window, Pixmap pixmap, int xHotspot, int yHotspot) {
  this.window = window;
  if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
    throw new GdxRuntimeException("Cursor image pixmap is not in RGBA8888 format.");
  }
  if ((pixmap.getWidth() & (pixmap.getWidth() - 1)) != 0) {
    throw new GdxRuntimeException(
        "Cursor image pixmap width of " + pixmap.getWidth() + " is not a power-of-two greater than zero.");
  }
  if ((pixmap.getHeight() & (pixmap.getHeight() - 1)) != 0) {
    throw new GdxRuntimeException("Cursor image pixmap height of " + pixmap.getHeight()
        + " is not a power-of-two greater than zero.");
  }
  if (xHotspot < 0 || xHotspot >= pixmap.getWidth()) {
    throw new GdxRuntimeException("xHotspot coordinate of " + xHotspot
        + " is not within image width bounds: [0, " + pixmap.getWidth() + ").");
  }
  if (yHotspot < 0 || yHotspot >= pixmap.getHeight()) {
    throw new GdxRuntimeException("yHotspot coordinate of " + yHotspot
        + " is not within image height bounds: [0, " + pixmap.getHeight() + ").");
  }
  this.pixmapCopy = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
  this.pixmapCopy.drawPixmap(pixmap, 0, 0);
  glfwImage = GLFWImage.malloc();
  glfwImage.width(pixmapCopy.getWidth());
  glfwImage.height(pixmapCopy.getHeight());
  glfwImage.pixels(pixmapCopy.getPixels());
  glfwCursor = GLFW.glfwCreateCursor(glfwImage, xHotspot, yHotspot);
  cursors.add(this);
}

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

Lwjgl3Cursor(Lwjgl3Window window, Pixmap pixmap, int xHotspot, int yHotspot) {
  this.window = window;
  if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
    throw new GdxRuntimeException("Cursor image pixmap is not in RGBA8888 format.");
  }
  if ((pixmap.getWidth() & (pixmap.getWidth() - 1)) != 0) {
    throw new GdxRuntimeException(
        "Cursor image pixmap width of " + pixmap.getWidth() + " is not a power-of-two greater than zero.");
  }
  if ((pixmap.getHeight() & (pixmap.getHeight() - 1)) != 0) {
    throw new GdxRuntimeException("Cursor image pixmap height of " + pixmap.getHeight()
        + " is not a power-of-two greater than zero.");
  }
  if (xHotspot < 0 || xHotspot >= pixmap.getWidth()) {
    throw new GdxRuntimeException("xHotspot coordinate of " + xHotspot
        + " is not within image width bounds: [0, " + pixmap.getWidth() + ").");
  }
  if (yHotspot < 0 || yHotspot >= pixmap.getHeight()) {
    throw new GdxRuntimeException("yHotspot coordinate of " + yHotspot
        + " is not within image height bounds: [0, " + pixmap.getHeight() + ").");
  }
  this.pixmapCopy = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
  this.pixmapCopy.drawPixmap(pixmap, 0, 0);
  glfwImage = GLFWImage.malloc();
  glfwImage.width(pixmapCopy.getWidth());
  glfwImage.height(pixmapCopy.getHeight());
  glfwImage.pixels(pixmapCopy.getPixels());
  glfwCursor = GLFW.glfwCreateCursor(glfwImage, xHotspot, yHotspot);
  cursors.add(this);
}

代码示例来源:origin: nifty-gui/nifty-gui

public Lwjgl3MouseCursor(final long glfwWindow, @Nonnull final String cursorImageFilename, final int hotspotX,
  final int hotspotY, @Nonnull final NiftyResourceLoader resourceLoader) throws IOException {
 this.glfwWindow = glfwWindow;
 ImageLoader imageLoader = ImageLoaderFactory.createImageLoader(cursorImageFilename);
 InputStream imageStream = resourceLoader.getResourceAsStream(cursorImageFilename);
 if (imageStream == null) {
  throw new IOException("Cannot find / load mouse cursor image file: [" + cursorImageFilename + "].");
 }
 try {
  ByteBuffer imageData = imageLoader.loadAsByteBufferARGB(imageStream, true);
  imageData.rewind();
  GLFWImage image = new GLFWImage(imageData);
  cursor = glfwCreateCursor(image, hotspotX, hotspotY);
 } finally {
  try {
   imageStream.close();
  } catch (IOException e) {
   log.log(Level.INFO, "An error occurred while closing the InputStream used to load mouse cursor image: " + "["
     + cursorImageFilename + "].", e);
  }
 }
}

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

glfwImage.pixels(data);
handle = glfwCreateCursor(glfwImage, xHot, yHot);

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

@Override
public void setCursor(final MouseCursor cursor) {
  if (cursor == MouseCursor.SYSTEM_DEFAULT || cursor == null) {
    GLFW.glfwSetCursor(_canvas.getWindowId(), 0);
    return;
  }
  final GLFWImage glfwImage = GLFWImage.create();
  glfwImage.set(cursor.getWidth(), cursor.getHeight(), cursor.getImage().getData(0));
  final long cptr = GLFW.glfwCreateCursor(glfwImage, cursor.getHotspotX(), cursor.getHotspotY());
  GLFW.glfwSetCursor(_canvas.getWindowId(), cptr);
}

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

private long[] createGlfwCursor(JmeCursor jmeCursor) {
  long[] cursorArray = new long[jmeCursor.getNumImages()];
  for (int i = 0; i < jmeCursor.getNumImages(); i++) {
    ByteBuffer buf = transformCursorImage(jmeCursor.getImagesData(), jmeCursor.getWidth(), jmeCursor.getHeight(), i);
    GLFWImage glfwImage = new GLFWImage(BufferUtils.createByteBuffer(GLFWImage.SIZEOF));
    glfwImage.set(jmeCursor.getWidth(), jmeCursor.getHeight(), buf);
    int hotspotX = jmeCursor.getXHotSpot();
    int hotspotY = jmeCursor.getHeight() - jmeCursor.getYHotSpot();
    cursorArray[i] = glfwCreateCursor(glfwImage, hotspotX, hotspotY);
  }
  return cursorArray;
}

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

Lwjgl3Cursor(Lwjgl3Window window, Pixmap pixmap, int xHotspot, int yHotspot) {
  this.window = window;
  if (pixmap.getFormat() != Pixmap.Format.RGBA8888) {
    throw new GdxRuntimeException("Cursor image pixmap is not in RGBA8888 format.");
  }
  if ((pixmap.getWidth() & (pixmap.getWidth() - 1)) != 0) {
    throw new GdxRuntimeException(
        "Cursor image pixmap width of " + pixmap.getWidth() + " is not a power-of-two greater than zero.");
  }
  if ((pixmap.getHeight() & (pixmap.getHeight() - 1)) != 0) {
    throw new GdxRuntimeException("Cursor image pixmap height of " + pixmap.getHeight()
        + " is not a power-of-two greater than zero.");
  }
  if (xHotspot < 0 || xHotspot >= pixmap.getWidth()) {
    throw new GdxRuntimeException("xHotspot coordinate of " + xHotspot
        + " is not within image width bounds: [0, " + pixmap.getWidth() + ").");
  }
  if (yHotspot < 0 || yHotspot >= pixmap.getHeight()) {
    throw new GdxRuntimeException("yHotspot coordinate of " + yHotspot
        + " is not within image height bounds: [0, " + pixmap.getHeight() + ").");
  }
  this.pixmapCopy = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Pixmap.Format.RGBA8888);
  this.pixmapCopy.drawPixmap(pixmap, 0, 0);
  glfwImage = GLFWImage.malloc();
  glfwImage.width(pixmapCopy.getWidth());
  glfwImage.height(pixmapCopy.getHeight());
  glfwImage.pixels(pixmapCopy.getPixels());
  glfwCursor = GLFW.glfwCreateCursor(glfwImage, xHotspot, yHotspot);
  cursors.add(this);
}

相关文章

GLFW类方法