Skip to content

Commit

Permalink
Fix scrollbar sprites.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Nov 27, 2023
1 parent f409837 commit 1b396ae
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ dependencies {

compileOnly("me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}")
} else if (project.runtime_itemlist_mod == "rei") {
implementation("dev.architectury:architectury-neoforge:10.0.16")
implementation("me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}")
} else {
compileOnly("me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}")
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/appeng/client/gui/style/Blitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
Expand Down Expand Up @@ -107,16 +109,20 @@ public static Blitter texture(String file, int referenceWidth, int referenceHeig
* Creates a blitter from a texture atlas sprite.
*/
public static Blitter sprite(TextureAtlasSprite sprite) {
// We use this convoluted method to convert from UV in the range of [0,1] back to pixel values with a
// fictitious reference size of a large integer. This is converted back to UV later when we actually blit.
final int refSize = Integer.MAX_VALUE / 2; // Don't use max int to prevent overflows after inexact conversions.
var atlas = (TextureAtlas) Minecraft.getInstance().getTextureManager().getTexture(sprite.atlasLocation());

return new Blitter(sprite.atlasLocation(), refSize, refSize)
return new Blitter(sprite.atlasLocation(), atlas.getWidth(), atlas.getHeight())
.src(
(int) (sprite.getU0() * refSize),
(int) (sprite.getV0() * refSize),
(int) ((sprite.getU1() - sprite.getU0()) * refSize),
(int) ((sprite.getV1() - sprite.getV0()) * refSize));
sprite.getX(),
sprite.getY(),
sprite.contents().width(),
sprite.contents().height());
}

public static Blitter guiSprite(ResourceLocation resourceLocation) {
var sprites = Minecraft.getInstance().getGuiSprites();
var sprite = sprites.getSprite(resourceLocation);
return sprite(sprite);
}

public Blitter copy() {
Expand Down
57 changes: 22 additions & 35 deletions src/main/java/appeng/client/gui/widgets/Scrollbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.mojang.blaze3d.platform.InputConstants;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -111,10 +112,10 @@ public void drawForegroundLayer(GuiGraphics guiGraphics, Rect2i bounds, Point mo
Blitter image;
if (this.getRange() == 0) {
yOffset = 0;
image = style.disabledBlitter();
image = Blitter.guiSprite(style.disabledSprite());
} else {
yOffset = getHandleYOffset();
image = style.enabledBlitter();
image = Blitter.guiSprite(style.enabledSprite());
}

image.dest(this.displayX, this.displayY + yOffset).blit(guiGraphics);
Expand Down Expand Up @@ -295,44 +296,30 @@ private void pageDown() {
}

public static final Style DEFAULT = Style.create(
new ResourceLocation("minecraft", "textures/gui/container/creative_inventory/tabs.png"),
12,
15,
232, 0,
244, 0);
new ResourceLocation("minecraft", "container/creative_inventory/scroller"),
new ResourceLocation("minecraft", "container/creative_inventory/scroller_disabled"));

public static final Style SMALL = Style.create(
AppEng.makeId("textures/guis/pattern_modes.png"),
7,
15,
242, 0,
249, 0);
AppEng.makeId("small_scroller"),
AppEng.makeId("small_scroller_disabled"));

/**
* @param handleWidth Width of the scrollbar handle sprite in the source texture.
* @param handleHeight Height of the scrollbar handle sprite in the source texture.
* @param texture Texture containing the scrollbar handle sprites.
* @param enabledBlitter Rectangle in the source texture that contains the sprite for an enabled handle.
* @param disabledBlitter Rectangle in the source texture that contains the sprite for a disabled handle.
*/
public record Style(
int handleWidth,
int handleHeight,
ResourceLocation texture,
Blitter enabledBlitter,
Blitter disabledBlitter) {
ResourceLocation enabledSprite,
ResourceLocation disabledSprite) {
public static Style create(
ResourceLocation texture,
int handleWidth,
int handleHeight,
int enabledSrcX, int enabledSrcY,
int disabledSrcX, int disabledSrcY) {
return new Style(
handleWidth,
handleHeight,
texture,
Blitter.texture(texture).src(enabledSrcX, enabledSrcY, handleWidth, handleHeight),
Blitter.texture(texture).src(disabledSrcX, disabledSrcY, handleWidth, handleHeight));
ResourceLocation enabledSprite,
ResourceLocation disabledSprite) {
return new Style(enabledSprite, disabledSprite);
}

public int handleWidth() {
var minecraft = Minecraft.getInstance();
return minecraft.getGuiSprites().getSprite(enabledSprite).contents().width();
}

public int handleHeight() {
var minecraft = Minecraft.getInstance();
return minecraft.getGuiSprites().getSprite(enabledSprite).contents().height();
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/ae2/textures/guis/pattern_modes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1b396ae

Please sign in to comment.