fix for GitHub issue #115 (GoogleCode issue #638) as discussed at http://hub.jmonkeyengine.org/forum/topic/proposed-fix-for-issue-638
This commit is contained in:
parent
701da19757
commit
b200db1a3c
@ -56,9 +56,11 @@ import javax.imageio.ImageIO;
|
|||||||
* @creation Jun 5, 2012 9:45:58 AM
|
* @creation Jun 5, 2012 9:45:58 AM
|
||||||
*/
|
*/
|
||||||
public class CursorLoader implements AssetLoader {
|
public class CursorLoader implements AssetLoader {
|
||||||
|
final private static int FDE_OFFSET = 6; // first directory entry offset
|
||||||
|
|
||||||
private boolean isIco;
|
private boolean isIco;
|
||||||
private boolean isAni;
|
private boolean isAni;
|
||||||
|
private boolean isCur; // .cur format if true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and return a cursor file of one of the following format: .ani, .cur and .ico.
|
* Loads and return a cursor file of one of the following format: .ani, .cur and .ico.
|
||||||
@ -70,15 +72,16 @@ public class CursorLoader implements AssetLoader {
|
|||||||
|
|
||||||
isIco = false;
|
isIco = false;
|
||||||
isAni = false;
|
isAni = false;
|
||||||
|
isCur = false;
|
||||||
|
|
||||||
isIco = ((AssetKey) info.getKey()).getExtension().equals("ico");
|
isIco = ((AssetKey) info.getKey()).getExtension().equals("ico");
|
||||||
if (!isIco) {
|
if (!isIco) {
|
||||||
isIco = ((AssetKey) info.getKey()).getExtension().equals("cur");
|
isCur = ((AssetKey) info.getKey()).getExtension().equals("cur");
|
||||||
if (!isIco) {
|
if (!isCur) {
|
||||||
isAni = ((AssetKey) info.getKey()).getExtension().equals("ani");
|
isAni = ((AssetKey) info.getKey()).getExtension().equals("ani");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isAni && !isIco) {
|
if (!isAni && !isIco && !isCur) {
|
||||||
throw new IllegalArgumentException("Cursors supported are .ico, .cur or .ani");
|
throw new IllegalArgumentException("Cursors supported are .ico, .cur or .ani");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ public class CursorLoader implements AssetLoader {
|
|||||||
byte[] icoimages = new byte[0]; // new byte [0] facilitates read()
|
byte[] icoimages = new byte[0]; // new byte [0] facilitates read()
|
||||||
|
|
||||||
if (isAni) {
|
if (isAni) {
|
||||||
CursorImageData ciDat = new CursorImageData();
|
CursorLoader.CursorImageData ciDat = new CursorLoader.CursorImageData();
|
||||||
int numIcons = 0;
|
int numIcons = 0;
|
||||||
int jiffy = 0;
|
int jiffy = 0;
|
||||||
// not using those but keeping references for now.
|
// not using those but keeping references for now.
|
||||||
@ -209,7 +212,7 @@ public class CursorLoader implements AssetLoader {
|
|||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown format.");
|
throw new IllegalArgumentException("Unknown format.");
|
||||||
}
|
}
|
||||||
} else if (isIco) {
|
} else if (isCur || isIco) {
|
||||||
DataInputStream in = new DataInputStream(inStream);
|
DataInputStream in = new DataInputStream(inStream);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
byte[] buffer = new byte[16384];
|
byte[] buffer = new byte[16384];
|
||||||
@ -221,13 +224,30 @@ public class CursorLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage bi[] = parseICOImage(icoimages);
|
BufferedImage bi[] = parseICOImage(icoimages);
|
||||||
CursorImageData cid = new CursorImageData(bi, 0, 0, 0, 0);
|
int hotSpotX = 0;
|
||||||
|
int hotSpotY = 0;
|
||||||
|
CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, 0, hotSpotX, hotSpotY, 0);
|
||||||
|
if (isCur) {
|
||||||
|
/*
|
||||||
|
* Per http://msdn.microsoft.com/en-us/library/ms997538.aspx
|
||||||
|
* every .cur file should provide hotspot coordinates.
|
||||||
|
*/
|
||||||
|
hotSpotX = icoimages[FDE_OFFSET + 4]
|
||||||
|
+ icoimages[FDE_OFFSET + 5] * 255;
|
||||||
|
hotSpotY = icoimages[FDE_OFFSET + 6]
|
||||||
|
+ icoimages[FDE_OFFSET + 7] * 255;
|
||||||
|
cid.xHotSpot = hotSpotX;
|
||||||
|
/*
|
||||||
|
* Flip the Y-coordinate.
|
||||||
|
*/
|
||||||
|
cid.yHotSpot = cid.height - 1 - hotSpotY;
|
||||||
|
}
|
||||||
cid.completeCursor();
|
cid.completeCursor();
|
||||||
|
|
||||||
return setJmeCursor(cid);
|
return setJmeCursor(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JmeCursor setJmeCursor(CursorImageData cid) {
|
private JmeCursor setJmeCursor(CursorLoader.CursorImageData cid) {
|
||||||
JmeCursor jmeCursor = new JmeCursor();
|
JmeCursor jmeCursor = new JmeCursor();
|
||||||
|
|
||||||
// set cursor's params.
|
// set cursor's params.
|
||||||
@ -255,7 +275,6 @@ public class CursorLoader implements AssetLoader {
|
|||||||
|
|
||||||
BufferedImage[] bi;
|
BufferedImage[] bi;
|
||||||
// Check resource type field.
|
// Check resource type field.
|
||||||
int FDE_OFFSET = 6; // first directory entry offset
|
|
||||||
int DE_LENGTH = 16; // directory entry length
|
int DE_LENGTH = 16; // directory entry length
|
||||||
int BMIH_LENGTH = 40; // BITMAPINFOHEADER length
|
int BMIH_LENGTH = 40; // BITMAPINFOHEADER length
|
||||||
|
|
||||||
@ -653,7 +672,7 @@ public class CursorLoader implements AssetLoader {
|
|||||||
if (rate == 0) {
|
if (rate == 0) {
|
||||||
rate = jiffy;
|
rate = jiffy;
|
||||||
}
|
}
|
||||||
CursorImageData cid = new CursorImageData(bi, rate, hotspotx, hotspoty, type);
|
CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, rate, hotspotx, hotspoty, type);
|
||||||
if (width == 0) {
|
if (width == 0) {
|
||||||
this.width = cid.width;
|
this.width = cid.width;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user