Skip to content

Commit

Permalink
Finishing touches
Browse files Browse the repository at this point in the history
- Correctly scale gradients
- Updated German translations
  • Loading branch information
Motschen committed May 2, 2024
1 parent 853f137 commit 7c89dee
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
18 changes: 9 additions & 9 deletions src/main/java/eu/midnightdust/blur/Blur.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public static int getRotation() {
if (BlurConfig.rainbowMode) return RainbowColor.rotation;
return BlurConfig.gradientRotation;
}
public static boolean renderRotatedGradient(DrawContext context, int width, int height) {
if (getRotation() > 0) {
context.getMatrices().peek().getPositionMatrix().rotationZ(Math.toRadians(getRotation()));
context.getMatrices().peek().getPositionMatrix().setTranslation(width / 2f, height / 2f, 0); // Make the gradient's center the pivot point
context.getMatrices().peek().getPositionMatrix().scale(Math.sqrt((float) width*width + height*height) / height); // Scales the gradient to the maximum diagonal value needed
context.fillGradient(-width / 2, -height / 2, width / 2, height / 2, Blur.getBackgroundColor(false), Blur.getBackgroundColor(true)); // Actually draw the gradient
context.getMatrices().peek().getPositionMatrix().rotationZ(0);
return true;
} return false;
public static void renderRotatedGradient(DrawContext context, int width, int height) {
float diagonal = Math.sqrt((float) width*width + height*height);
int smallestDimension = Math.min(width, height);

context.getMatrices().peek().getPositionMatrix().rotationZ(Math.toRadians(getRotation()));
context.getMatrices().peek().getPositionMatrix().setTranslation(width / 2f, height / 2f, 0); // Make the gradient's center the pivot point
context.getMatrices().peek().getPositionMatrix().scale(diagonal / smallestDimension); // Scales the gradient to the maximum diagonal value needed
context.fillGradient(-width / 2, -height / 2, width / 2, height / 2, Blur.getBackgroundColor(false), Blur.getBackgroundColor(true)); // Actually draw the gradient
context.getMatrices().peek().getPositionMatrix().rotationZ(0);
}
}
3 changes: 1 addition & 2 deletions src/main/java/eu/midnightdust/blur/mixin/MixinInGameHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class MixinInGameHud {
this.client.gameRenderer.renderBlur(delta);
this.client.getFramebuffer().beginWrite(false);

if (Blur.prevScreenHasBackground && !Blur.renderRotatedGradient(context, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()))
context.fillGradient(0, 0, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight(), Blur.getBackgroundColor(false), Blur.getBackgroundColor(true));
if (Blur.prevScreenHasBackground) Blur.renderRotatedGradient(context, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
}
}
}
23 changes: 4 additions & 19 deletions src/main/java/eu/midnightdust/blur/mixin/MixinScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import eu.midnightdust.blur.Blur;

Expand Down Expand Up @@ -41,7 +39,7 @@ public abstract class MixinScreen {
this.client.gameRenderer.renderBlur(delta);
this.client.getFramebuffer().beginWrite(false);

if (Blur.prevScreenHasBackground && !Blur.renderRotatedGradient(context, width, height)) context.fillGradient(0, 0, width, height, Blur.getBackgroundColor(false), Blur.getBackgroundColor(true));
if (Blur.prevScreenHasBackground) Blur.renderRotatedGradient(context, width, height);
}
Blur.doTest = false; // Set the test state to completed, as tests will happen in the same tick.
}
Expand All @@ -62,22 +60,9 @@ public abstract class MixinScreen {
}
}

@ModifyConstant(
method = "renderInGameBackground",
constant = @Constant(intValue = -1072689136))
private int blur$getFirstBackgroundColor(int color) {
return Blur.getBackgroundColor(false);
}

@ModifyConstant(
method = "renderInGameBackground",
constant = @Constant(intValue = -804253680))
private int blur$getSecondBackgroundColor(int color) {
return Blur.getBackgroundColor(true);
}

@Inject(at = @At("HEAD"), method = "renderInGameBackground", cancellable = true)
public void blur$rotatedGradient(DrawContext context, CallbackInfo ci) {
if (Blur.renderRotatedGradient(context, width, height)) ci.cancel();
public void blur$rotatedGradient(DrawContext context, CallbackInfo ci) { // Replaces the default gradient with our rotated one
Blur.renderRotatedGradient(context, width, height);
ci.cancel();
}
}
2 changes: 1 addition & 1 deletion src/main/java/eu/midnightdust/blur/util/RainbowColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class RainbowColor {
public static float hue;
public static float hue2 = 0.35f;

public static void tick(MinecraftClient client) {
public static void tick(MinecraftClient ignoredClient) {
if (BlurConfig.rainbowMode) {
if (hue >= 1) hue = 0f;
hue += 0.01f;
Expand Down
24 changes: 18 additions & 6 deletions src/main/resources/assets/blur/lang/de_de.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
{
"blur.midnightconfig.title": "Blur Konfiguration",
"blur.midnightconfig.blurExclusions": "Blur-Ausnahmen",
"blur.midnightconfig.title": "Blur+ Konfiguration",
"blur.midnightconfig.category.animations": "Animationen",
"blur.midnightconfig.category.style": "Stil",
"blur.midnightconfig.category.screens": "Bildschirme",
"blur.midnightconfig.blurContainers": "Unschärfe in Containern",
"blur.midnightconfig.fadeTimeMillis": "Überblendzeit (in Millisekunden)",
"blur.midnightconfig.fadeOutTimeMillis": "Ausblendzeit (in milliseconds)",
"blur.midnightconfig.ease": "Geschmeidige Animation",
"blur.midnightconfig.fadeOutTimeMillis": "Ausblendzeit (in Millisekunden)",
"blur.midnightconfig.animationCurve": "Animationskurve",
"blur.midnightconfig.enum.Easing.FLAT": "Flach",
"blur.midnightconfig.enum.Easing.SINE": "Sinus",
"blur.midnightconfig.enum.Easing.QUAD": "Quadriert",
"blur.midnightconfig.enum.Easing.CUBIC": "Kubiert",
"blur.midnightconfig.enum.Easing.QUART": "Quart",
"blur.midnightconfig.enum.Easing.QUINT": "Quint",
"blur.midnightconfig.enum.Easing.EXPO": "Expo",
"blur.midnightconfig.enum.Easing.CIRC": "Kreis",
"blur.midnightconfig.enum.Easing.BACK": "Zurück",
"blur.midnightconfig.enum.Easing.ELASTIC": "Elastisch",
"blur.midnightconfig.radius": "Radius",
"blur.midnightconfig.rainbowMode": "Regenbogenmodus \uD83C\uDF08",
"blur.midnightconfig.useGradient": "Farbverlauf im Hintergrund",
"blur.midnightconfig.gradientStart": "Farbverlauf-Anfangsfarbe",
"blur.midnightconfig.gradientEnd": "Farbverlauf-Endfarbe",
"blur.midnightconfig.gradientStartAlpha": "Farbverlauf-Anfangstransparenz",
"blur.midnightconfig.gradientEndAlpha": "Farbverlauf-Endstransparenz",
"blur.midnightconfig.showScreenTitle": "Logge Bildschirmtitel"
"blur.midnightconfig.gradientRotation": "Farbverlauf-Rotation"
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"backryun",
"byquanton"
],
"description": "Various Enhancements to the blur effect behind Minecraft GUIs",
"description": "Various enhancements for the blur effect behind Minecraft GUIs",
"mixins": [
"mixins.blur.json"
],
"depends": {
"minecraft": ">1.20.4"
"minecraft": ">=1.20.5"
}
}

0 comments on commit 7c89dee

Please sign in to comment.