/newcode/src/com/prupe/mcpatcher/hd/BorderedTexture.java

https://bitbucket.org/SevenBits/mcpatcher · Java · 122 lines · 106 code · 16 blank · 0 comment · 7 complexity · b1ebf524edfa1fab1b3a775b3c6c84fe MD5 · raw file

  1. package com.prupe.mcpatcher.hd;
  2. import com.prupe.mcpatcher.MCLogger;
  3. import com.prupe.mcpatcher.MCPatcherUtils;
  4. import net.minecraft.src.TextureAtlasSprite;
  5. public class BorderedTexture extends TextureAtlasSprite {
  6. private static final MCLogger logger = MCLogger.getLogger(MCPatcherUtils.MIPMAP);
  7. private float minU;
  8. private float maxU;
  9. private float minV;
  10. private float maxV;
  11. private float scaledWidth;
  12. private float scaledHeight;
  13. private int tilesheetWidth;
  14. private int tilesheetHeight;
  15. private int x0;
  16. private int y0;
  17. private String tilesheet;
  18. int border;
  19. public static TextureAtlasSprite create(String tilesheet, String name) {
  20. if (AAHelper.useAAForTexture(tilesheet)) {
  21. return new BorderedTexture(tilesheet, name);
  22. } else {
  23. return new TextureAtlasSprite(name);
  24. }
  25. }
  26. private BorderedTexture(String tilesheet, String name) {
  27. super(name);
  28. this.tilesheet = tilesheet;
  29. }
  30. @Override
  31. public void init(int tilesheetWidth, int tilesheetHeight, int x0, int y0, boolean flipped) {
  32. super.init(tilesheetWidth, tilesheetHeight, x0, y0, flipped);
  33. this.tilesheetWidth = tilesheetWidth;
  34. this.tilesheetHeight = tilesheetHeight;
  35. this.x0 = x0;
  36. this.y0 = y0;
  37. setBorderWidth(border);
  38. }
  39. @Override
  40. public float getMinU() {
  41. return minU;
  42. }
  43. @Override
  44. public float getMaxU() {
  45. return maxU;
  46. }
  47. @Override
  48. public float getInterpolatedU(double u) {
  49. return border > 0 ? minU + (float) u * scaledWidth : super.getInterpolatedU(u);
  50. }
  51. @Override
  52. public float getMinV() {
  53. return minV;
  54. }
  55. @Override
  56. public float getMaxV() {
  57. return maxV;
  58. }
  59. @Override
  60. public float getInterpolatedV(double v) {
  61. return border > 0 ? minV + (float) v * scaledHeight : super.getInterpolatedV(v);
  62. }
  63. @Override
  64. public void copy(TextureAtlasSprite stitched) {
  65. if (stitched instanceof BorderedTexture) {
  66. BorderedTexture bordered = (BorderedTexture) stitched;
  67. tilesheetWidth = bordered.tilesheetWidth;
  68. tilesheetHeight = bordered.tilesheetHeight;
  69. x0 = bordered.x0;
  70. y0 = bordered.y0;
  71. tilesheet = bordered.tilesheet;
  72. border = bordered.border;
  73. }
  74. }
  75. void setBorderWidth(int border) {
  76. this.border = border;
  77. int width = getWidth();
  78. int height = getHeight();
  79. if (width <= 0 || height <= 0) {
  80. x0 = y0 = 0;
  81. minU = maxU = minV = maxV = 0.0f;
  82. scaledWidth = scaledHeight = 0.0f;
  83. return;
  84. }
  85. logger.finer("setBorderWidth(%s, %s, %d): %dx%d -> %dx%d",
  86. tilesheet, getIconName(), border, width - 2 * border, height - 2 * border, width, height
  87. );
  88. if (border > 0) {
  89. x0 += border;
  90. y0 += border;
  91. width -= 2 * border;
  92. height -= 2 * border;
  93. minU = (float) x0 / (float) tilesheetWidth;
  94. maxU = (float) (x0 + width) / (float) tilesheetWidth;
  95. minV = (float) y0 / (float) tilesheetHeight;
  96. maxV = (float) (y0 + height) / (float) tilesheetHeight;
  97. } else {
  98. minU = super.getMinU();
  99. maxU = super.getMaxU();
  100. minV = super.getMinV();
  101. maxV = super.getMaxV();
  102. }
  103. scaledWidth = (maxU - minU) / 16.0f;
  104. scaledHeight = (maxV - minV) / 16.0f;
  105. }
  106. }