本文整理了Java中org.lwjgl.glfw.GLFW.glfwCreateCursor()
方法的一些代码示例,展示了GLFW.glfwCreateCursor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GLFW.glfwCreateCursor()
方法的具体详情如下:
包路径:org.lwjgl.glfw.GLFW
类名称: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.
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!