cursors = new Cursor[3];
int cursorImageCount = 1;
int cursorWidth = Math.min(64, Cursor.getMaxCursorSize());
int cursorHeight = cursorWidth;
IntBuffer cursorImages;
IntBuffer cursorDelays;
// Create a single cursor
// ==================================
cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
cursorDelays = null;
for(int j=0; j<cursorWidth; j++) {
for(int l=0; l<cursorHeight; l++) {
cursorImages.put(0xffffffff);
}
}
cursorImages.flip();
cursors[0] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
// ----------------------------------
// Create 3 piece animation
// ==================================
cursorImageCount = 3;
cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
cursorDelays = ByteBuffer.allocateDirect(cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
for(int i=0; i<cursorImageCount; i++) {
// make a colored square with a chocolate center
int offColor = 0x00000000;
int onColor = 0xffff0000;
// change color according to cursor
if(i == 1) {
onColor = 0xff00ff00;
} else if (i == 2) {
onColor = 0xff0000ff;
}
// calculate size of center
int centerSize = (cursorWidth / 5) * (i + 1);
int centerLeft = cursorWidth / 2 - centerSize / 2;
int centerRight = cursorWidth / 2 + centerSize / 2;
// go!
for(int j=0; j<cursorWidth; j++) {
for(int l=0; l<cursorHeight; l++) {
if(j >= centerLeft && j < centerRight && l >= centerLeft && l < centerRight) {
cursorImages.put(offColor);
} else {
cursorImages.put(onColor);
}
}
}
}
cursorDelays.put(2000).put(2000).put(2000);
cursorDelays.flip();
cursorImages.flip();
cursors[1] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
// ----------------------------------
// Create a 20 piece animation
// ==================================
cursorImageCount = 20;
cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
cursorDelays = ByteBuffer.allocateDirect(cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer();
cursorDelays.put(
new int[] {
100, 100, 100, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100, 100, 100,
100, 100, 100, 100, 100
});
float step = 0xffffffff / 20.0f;
for(int i=0; i<cursorImageCount; i++) {
for(int j=0; j<cursorWidth; j++) {
for(int l=0; l<cursorHeight; l++) {
cursorImages.put((int)step);
}
}
step += step;
}
cursorImages.flip();
cursorDelays.flip();
cursors[2] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
// ----------------------------------
Mouse.setNativeCursor(cursors[0]);
}