Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ public static void drawTexture(BufferBuilder buffer, float x, float y, int u, in
}

public static void drawTexture(ResourceLocation location, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1) {
Platform.setupDrawTex(location);
drawTexture(location, x0, y0, x1, y1, u0, v0, u1, v1, false);
}

public static void drawTexture(ResourceLocation location, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, boolean withBlend) {
Platform.setupDrawTex(location, withBlend);
drawTexture(x0, y0, x1, y1, u0, v0, u1, v1, 0);
}

Expand Down
35 changes: 32 additions & 3 deletions src/main/java/com/cleanroommc/modularui/drawable/UITexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.cleanroommc.modularui.screen.viewport.GuiContext;
import com.cleanroommc.modularui.theme.WidgetTheme;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.utils.GlStateManager;
import com.cleanroommc.modularui.utils.Interpolations;
import com.cleanroommc.modularui.utils.JsonHelper;
import com.cleanroommc.modularui.widget.sizer.Area;
Expand Down Expand Up @@ -45,6 +46,7 @@ static UITexture icon(String name, int x, int y) {
public final ResourceLocation location;
public final float u0, v0, u1, v1;
@Nullable public final ColorType colorType;
public final boolean nonOpaque;

/**
* Creates a drawable texture
Expand All @@ -57,6 +59,21 @@ static UITexture icon(String name, int x, int y) {
* @param colorType a function to get which color from a widget theme should be used to color this texture. Can be null.
*/
public UITexture(ResourceLocation location, float u0, float v0, float u1, float v1, @Nullable ColorType colorType) {
this(location, u0, v0, u1, v1, colorType, false);
}

/**
* Creates a drawable texture
*
* @param location location of the texture
* @param u0 x offset of the image (0-1)
* @param v0 y offset of the image (0-1)
* @param u1 x end offset of the image (0-1)
* @param v1 y end offset of the image (0-1)
* @param colorType a function to get which color from a widget theme should be used to color this texture. Can be null.
* @param nonOpaque whether the texture should draw with blend (if true) or not (if false).
*/
public UITexture(ResourceLocation location, float u0, float v0, float u1, float v1, @Nullable ColorType colorType, boolean nonOpaque) {
this.colorType = colorType;
boolean png = !location.getResourcePath().endsWith(".png");
boolean textures = !location.getResourcePath().startsWith("textures/");
Expand All @@ -70,6 +87,7 @@ public UITexture(ResourceLocation location, float u0, float v0, float u1, float
this.v0 = v0;
this.u1 = u1;
this.v1 = v1;
this.nonOpaque = nonOpaque;
}

public static Builder builder() {
Expand Down Expand Up @@ -137,7 +155,8 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
}

public void draw(float x, float y, float width, float height) {
GuiDraw.drawTexture(this.location, x, y, x + width, y + height, this.u0, this.v0, this.u1, this.v1);
GuiDraw.drawTexture(this.location, x, y, x + width, y + height, this.u0, this.v0, this.u1, this.v1, this.nonOpaque);
GlStateManager.disableBlend();
}

@Deprecated
Expand All @@ -151,7 +170,8 @@ public void drawSubArea(float x, float y, float width, float height, float uStar
} else {
Color.setGlColorOpaque(Color.WHITE.main);
}
GuiDraw.drawTexture(this.location, x, y, x + width, y + height, lerpU(uStart), lerpV(vStart), lerpU(uEnd), lerpV(vEnd));
GuiDraw.drawTexture(this.location, x, y, x + width, y + height, lerpU(uStart), lerpV(vStart), lerpU(uEnd), lerpV(vEnd), this.nonOpaque);
GlStateManager.disableBlend();
}

@Override
Expand Down Expand Up @@ -240,6 +260,7 @@ public static class Builder {
private String name;
private boolean tiled = false;
private ColorType colorType = null;
private boolean nonOpaque = false;

/**
* @param loc location of the image to draw
Expand Down Expand Up @@ -443,6 +464,14 @@ public Builder name(String name) {
return this;
}

/**
* Sets this texture as at least partially transparent, will not disable glBlend when drawing.
*/
public Builder nonOpaque() {
this.nonOpaque = true;
return this;
}

/**
* Creates the texture
*
Expand Down Expand Up @@ -490,7 +519,7 @@ private UITexture create() {
if (this.tiled) {
return new TiledUITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.iw, this.ih, this.colorType);
}
return new UITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType);
return new UITexture(this.location, this.u0, this.v0, this.u1, this.v1, this.colorType, this.nonOpaque);
}
throw new IllegalStateException();
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/cleanroommc/modularui/utils/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public static void setupDrawColor() {
}

public static void setupDrawTex(ResourceLocation texture) {
setupDrawTex();
setupDrawTex(texture, false);
}

public static void setupDrawTex(ResourceLocation texture, boolean withBlend) {
setupDrawTex(withBlend);
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
}

Expand All @@ -82,9 +86,17 @@ public static void setupDrawTex(int textureId) {
}

public static void setupDrawTex() {
setupDrawTex(false);
}

public static void setupDrawTex(boolean withBlend) {
GlStateManager.enableTexture2D();
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
if (withBlend) {
GlStateManager.enableBlend();
} else {
GlStateManager.disableBlend();
}
}

public static void setupDrawGradient() {
Expand Down