Skip to content

Commit

Permalink
Fix AdaptableUITexture uv (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune committed Sep 7, 2024
1 parent 4758eb3 commit a670dd3
Showing 1 changed file with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,43 @@ public void drawStretched(float x, float y, float width, float height) {
float uBl = this.bl * 1f / this.imageWidth, uBr = this.br * 1f / this.imageWidth;
float vBt = this.bt * 1f / this.imageHeight, vBb = this.bb * 1f / this.imageHeight;
float x1 = x + width, y1 = y + height;
float uInnerStart = this.u0 + uBl, vInnerStart = this.v0 + vBt, uInnerEnd = this.u1 - uBr, vInnerEnd = this.v1 - vBb;

if ((this.bl > 0 || this.br > 0) && this.bt <= 0 && this.bb <= 0) {
// left border
GuiDraw.drawTexture(x, y, x + this.bl, y1, this.u0, this.v0, this.u0 + uBl, this.v1);
GuiDraw.drawTexture(x, y, x + this.bl, y1, this.u0, this.v0, uInnerStart, this.v1);
// right border
GuiDraw.drawTexture(x1 - this.br, y, x1, y1, this.u1 - uBr, this.v0, this.u1, this.v1);
GuiDraw.drawTexture(x1 - this.br, y, x1, y1, uInnerEnd, this.v0, this.u1, this.v1);
// center
GuiDraw.drawTexture(x + this.bl, y, x1 - this.br, y1, uBl, this.v0, this.u1 - uBr, this.v1);
GuiDraw.drawTexture(x + this.bl, y, x1 - this.br, y1, uInnerStart, this.v0, uInnerEnd, this.v1);
} else if (this.bl <= 0 && this.br <= 0) {
// top border
GuiDraw.drawTexture(x, y, x1, y + this.bt, this.u0, this.v0, this.u1, this.v0 + vBt);
GuiDraw.drawTexture(x, y, x1, y + this.bt, this.u0, this.v0, this.u1, vInnerStart);
// bottom border
GuiDraw.drawTexture(x, y1 - this.bb, x1, y1, this.u0, this.v1 - vBb, this.u1, this.v1);
GuiDraw.drawTexture(x, y1 - this.bb, x1, y1, this.u0, vInnerEnd, this.u1, this.v1);
// center
GuiDraw.drawTexture(x, y + this.bt, x1, y1 - this.bb, this.u0, vBt, this.u1, this.v1 - vBb);
GuiDraw.drawTexture(x, y + this.bt, x1, y1 - this.bb, this.u0, vInnerStart, this.u1, vInnerEnd);
} else {
// top left corner
GuiDraw.drawTexture(x, y, x + this.bl, y + this.bt, this.u0, this.v0, this.u0 + uBl, this.v0 + vBt);
GuiDraw.drawTexture(x, y, x + this.bl, y + this.bt, this.u0, this.v0, uInnerStart, vInnerStart);
// top right corner
GuiDraw.drawTexture(x1 - this.br, y, x1, y + this.bt, this.u1 - uBr, this.v0, this.u1, vBt);
GuiDraw.drawTexture(x1 - this.br, y, x1, y + this.bt, uInnerEnd, this.v0, this.u1, vInnerStart);
// bottom left corner
GuiDraw.drawTexture(x, y1 - this.bb, x + this.bl, y1, this.u0, this.v1 - vBb, uBl, this.v1);
GuiDraw.drawTexture(x, y1 - this.bb, x + this.bl, y1, this.u0, vInnerEnd, uInnerStart, this.v1);
// bottom right corner
GuiDraw.drawTexture(x1 - this.br, y1 - this.bb, x1, y1, this.u1 - uBr, this.v1 - vBb, this.u1, this.v1);
GuiDraw.drawTexture(x1 - this.br, y1 - this.bb, x1, y1, uInnerEnd, vInnerEnd, this.u1, this.v1);

// left border
GuiDraw.drawTexture(x, y + this.bt, x + this.bl, y1 - this.bb, this.u0, vBt, uBl, this.v1 - vBb);
GuiDraw.drawTexture(x, y + this.bt, x + this.bl, y1 - this.bb, this.u0, vInnerStart, uInnerStart, vInnerEnd);
// top border
GuiDraw.drawTexture(x + this.bl, y, x1 - this.br, y + this.bt, uBl, this.v0, this.u1 - uBl, vBt);
GuiDraw.drawTexture(x + this.bl, y, x1 - this.br, y + this.bt, uInnerStart, this.v0, uInnerEnd, vInnerStart);
// right border
GuiDraw.drawTexture(x1 - this.br, y + this.bt, x1, y1 - this.bb, this.u1 - uBr, vBt, this.u1, this.v1 - vBb);
GuiDraw.drawTexture(x1 - this.br, y + this.bt, x1, y1 - this.bb, uInnerEnd, vInnerStart, this.u1, vInnerEnd);
// bottom border
GuiDraw.drawTexture(x + this.bl, y1 - this.bb, x1 - this.br, y1, uBl, this.v1 - vBb, this.u1 - uBl, this.v1);
GuiDraw.drawTexture(x + this.bl, y1 - this.bb, x1 - this.br, y1, uInnerStart, vInnerEnd, uInnerEnd, this.v1);

// center
GuiDraw.drawTexture(x + this.bl, y + this.bt, x1 - this.br, y1 - this.bb, uBl, vBt, this.u1 - uBr, this.v1 - vBb);
GuiDraw.drawTexture(x + this.bl, y + this.bt, x1 - this.br, y1 - this.bb, uInnerStart, vInnerStart, uInnerEnd, vInnerEnd);
}
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
Expand All @@ -108,45 +109,46 @@ public void drawTiled(float x, float y, float width, float height) {
float uBl = this.bl * 1f / this.imageWidth, uBr = this.br * 1f / this.imageWidth;
float vBt = this.bt * 1f / this.imageHeight, vBb = this.bb * 1f / this.imageHeight;
float x1 = x + width, y1 = y + height;
float uInnerStart = this.u0 + uBl, vInnerStart = this.v0 + vBt, uInnerEnd = this.u1 - uBr, vInnerEnd = this.v1 - vBb;

int tw = (int) (this.imageWidth * (this.u1 - this.u0));
int th = (int) (this.imageHeight * (this.v1 - this.v0));

if ((this.bl > 0 || this.br > 0) && this.bt <= 0 && this.bb <= 0) {
// left border
GuiDraw.drawTiledTexture(x, y, this.bl, height, this.u0, this.v0, this.u0 + uBl, this.v1, this.bl, th, 0);
GuiDraw.drawTiledTexture(x, y, this.bl, height, this.u0, this.v0, uInnerStart, this.v1, this.bl, th, 0);
// right border
GuiDraw.drawTiledTexture(x1 - this.br, y, this.br, height, this.u1 - uBr, this.v0, this.u1, this.v1, this.br, th, 0);
GuiDraw.drawTiledTexture(x1 - this.br, y, this.br, height, uInnerEnd, this.v0, this.u1, this.v1, this.br, th, 0);
// center
GuiDraw.drawTiledTexture(x + this.bl, y, width - this.bl - this.br, height, uBl, this.v0, this.u1 - uBr, this.v1, tw - this.bl - this.br, th, 0);
GuiDraw.drawTiledTexture(x + this.bl, y, width - this.bl - this.br, height, uInnerStart, this.v0, uInnerEnd, this.v1, tw - this.bl - this.br, th, 0);
} else if (this.bl <= 0 && this.br <= 0) {
// top border
GuiDraw.drawTiledTexture(x, y, width, this.bt, this.u0, this.v0, this.u1, this.v0 + vBt, tw, this.bt, 0);
GuiDraw.drawTiledTexture(x, y, width, this.bt, this.u0, this.v0, this.u1, vInnerStart, tw, this.bt, 0);
// bottom border
GuiDraw.drawTiledTexture(x, y1 - this.bb, width, this.bb, this.u0, this.v1 - vBb, this.u1, this.v1, tw, this.bb, 0);
GuiDraw.drawTiledTexture(x, y1 - this.bb, width, this.bb, this.u0, vInnerEnd, this.u1, this.v1, tw, this.bb, 0);
// center
GuiDraw.drawTiledTexture(x, y + this.bt, width, height - this.bt - this.bb, this.u0, vBt, this.u1, this.v1 - vBb, tw, th - this.bt - this.bb, 0);
GuiDraw.drawTiledTexture(x, y + this.bt, width, height - this.bt - this.bb, this.u0, vInnerStart, this.u1, vInnerEnd, tw, th - this.bt - this.bb, 0);
} else {
// top left corner
GuiDraw.drawTiledTexture(x, y, this.bl, this.bt, this.u0, this.v0, this.u0 + uBl, this.v0 + vBt, this.bl, this.bt, 0);
GuiDraw.drawTiledTexture(x, y, this.bl, this.bt, this.u0, this.v0, uInnerStart, vInnerStart, this.bl, this.bt, 0);
// top right corner
GuiDraw.drawTiledTexture(x1 - this.br, y, this.br, this.bt, this.u1 - uBr, this.v0, this.u1, vBt, this.br, this.bt, 0);
GuiDraw.drawTiledTexture(x1 - this.br, y, this.br, this.bt, uInnerEnd, this.v0, this.u1, vInnerStart, this.br, this.bt, 0);
// bottom left corner
GuiDraw.drawTiledTexture(x, y1 - this.bb, this.bl, this.bb, this.u0, this.v1 - vBb, uBl, this.v1, this.bl, this.bb, 0);
GuiDraw.drawTiledTexture(x, y1 - this.bb, this.bl, this.bb, this.u0, vInnerEnd, uInnerStart, this.v1, this.bl, this.bb, 0);
// bottom right corner
GuiDraw.drawTiledTexture(x1 - this.br, y1 - this.bb, this.br, this.bb, this.u1 - uBr, this.v1 - vBb, this.u1, this.v1, this.br, this.bb, 0);
GuiDraw.drawTiledTexture(x1 - this.br, y1 - this.bb, this.br, this.bb, uInnerEnd, vInnerEnd, this.u1, this.v1, this.br, this.bb, 0);

// left border
GuiDraw.drawTiledTexture(x, y + this.bt, this.bl, height - this.bt - this.bb, this.u0, vBt, uBl, this.v1 - vBb, this.bl, th - this.bt - this.bb, 0);
GuiDraw.drawTiledTexture(x, y + this.bt, this.bl, height - this.bt - this.bb, this.u0, vInnerStart, uInnerStart, vInnerEnd, this.bl, th - this.bt - this.bb, 0);
// top border
GuiDraw.drawTiledTexture(x + this.bl, y, width - this.bl - this.br, this.bt, uBl, this.v0, this.u1 - uBr, vBt, tw - this.bl - this.bb, this.bt, 0);
GuiDraw.drawTiledTexture(x + this.bl, y, width - this.bl - this.br, this.bt, uInnerStart, this.v0, uInnerEnd, vInnerStart, tw - this.bl - this.bb, this.bt, 0);
// right border
GuiDraw.drawTiledTexture(x1 - this.br, y + this.bt, this.br, height - this.bt - this.bb, this.u1 - uBr, vBt, this.u1, this.v1 - vBb, this.br, th - this.bt - this.bb, 0);
GuiDraw.drawTiledTexture(x1 - this.br, y + this.bt, this.br, height - this.bt - this.bb, uInnerEnd, vInnerStart, this.u1, vInnerEnd, this.br, th - this.bt - this.bb, 0);
// bottom border
GuiDraw.drawTiledTexture(x + this.bl, y1 - this.bb, width - this.bl - this.br, this.bb, uBl, this.v1 - vBb, this.u1 - uBr, this.v1, tw - this.bl - this.br, this.bb, 0);
GuiDraw.drawTiledTexture(x + this.bl, y1 - this.bb, width - this.bl - this.br, this.bb, uInnerStart, vInnerEnd, uInnerEnd, this.v1, tw - this.bl - this.br, this.bb, 0);

// center
GuiDraw.drawTiledTexture(x + this.bl, y + this.bt, width - this.bl - this.br, height - this.bt - this.bb, uBl, vBt, this.u1 - uBr, this.v1 - vBb, tw - this.bl - this.br, th - this.bt - this.bb, 0);
GuiDraw.drawTiledTexture(x + this.bl, y + this.bt, width - this.bl - this.br, height - this.bt - this.bb, uInnerStart, vInnerStart, uInnerEnd, vInnerEnd, tw - this.bl - this.br, th - this.bt - this.bb, 0);
}
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
Expand Down

0 comments on commit a670dd3

Please sign in to comment.