package ast.ui;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Cursor;
public class MouseCursor {
public Cursor cursor;
/**
* Set Cursor to custom image
*/
public MouseCursor(){
//cusor = new Cursor(width, height, xHotspot, yHotspot, numImages, images, delays);
int size = 16;
IntBuffer buffer = getPointer(size);
try {
cursor = new Cursor(16, 16, 0, 0, 1, buffer, null);
} catch (LWJGLException e) {
e.printStackTrace();
}
}
/**
*
* @param size int size of icon
* @return Intbuffer pointer
*/
public static IntBuffer getPointer(int size)
{
Image c=Toolkit.getDefaultToolkit().getImage(("res/img/Cursor.png"));
BufferedImage biCursor=new BufferedImage(16,16,BufferedImage.TYPE_INT_ARGB);
while(!biCursor.createGraphics().drawImage(c,0,15,15,0,0,0,15,15,null))
try
{
Thread.sleep(0);
}
catch(InterruptedException e)
{
}
int[] data=biCursor.getRaster().getPixels(0,0,16,16,(int[])null);
IntBuffer ib=BufferUtils.createIntBuffer(16*16);
for(int i=0;i<data.length;i+=4)
ib.put(data[i] | data[i+1]<<8 | data[i+2]<<16 | data[i+3]<<24);
ib.flip();
return ib;
}
}