|
| 1 | +package alexiil.mods.load.json; |
| 2 | + |
| 3 | +public class ImageRender { |
| 4 | + public final String resourceLocation; |
| 5 | + public final EPosition positionType; |
| 6 | + public final EType type; |
| 7 | + public final Area texture; |
| 8 | + public final Area position; |
| 9 | + public final String colour; |
| 10 | + public final String text; |
| 11 | + |
| 12 | + public ImageRender(String resourceLocation, EPosition positionType, EType type, Area texture, Area position, String colour, String text) { |
| 13 | + this.resourceLocation = resourceLocation; |
| 14 | + this.positionType = positionType; |
| 15 | + this.type = type; |
| 16 | + this.texture = texture; |
| 17 | + this.position = position; |
| 18 | + this.colour = colour; |
| 19 | + this.text = text; |
| 20 | + } |
| 21 | + |
| 22 | + public ImageRender(String resourceLocation, EPosition positionType, EType type, Area texture, Area position) { |
| 23 | + this(resourceLocation, positionType, type, texture, position, null, null); |
| 24 | + } |
| 25 | + |
| 26 | + public int transformX(int screenWidth) { |
| 27 | + return positionType.transformX(position.x, screenWidth - position.width); |
| 28 | + } |
| 29 | + |
| 30 | + public int transformY(int screenWidth) { |
| 31 | + return positionType.transformY(position.y, screenWidth - position.height); |
| 32 | + } |
| 33 | + |
| 34 | + public int getColour() { |
| 35 | + if (colour == null) |
| 36 | + return 0xFFFFFF; |
| 37 | + else { |
| 38 | + try { |
| 39 | + return Integer.parseInt(colour, 16); |
| 40 | + } |
| 41 | + catch (NumberFormatException nfe) { |
| 42 | + return 0xFFFFFF; |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + private float getColourPart(int bitStart) { |
| 48 | + return ((getColour() >> bitStart) & 0xFF) / 256F; |
| 49 | + } |
| 50 | + |
| 51 | + public float getRed() { |
| 52 | + return getColourPart(16); |
| 53 | + } |
| 54 | + |
| 55 | + public float getGreen() { |
| 56 | + return getColourPart(8); |
| 57 | + } |
| 58 | + |
| 59 | + public float getBlue() { |
| 60 | + return getColourPart(0); |
| 61 | + } |
| 62 | +} |
0 commit comments