-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reset button for color interval slider
- Loading branch information
Showing
6 changed files
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/com/goby56/wakes/config/gui/TexturedButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.goby56.wakes.config.gui; | ||
|
||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class TexturedButton extends ButtonWidget { | ||
private final Identifier texture; | ||
private final int textureWidth; | ||
private final int textureHeight; | ||
protected TexturedButton(int width, int height, PressAction onPress, Identifier texture, int texWidth, int texHeight) { | ||
super(0, 0, width, height, Text.empty(), onPress, DEFAULT_NARRATION_SUPPLIER); | ||
this.texture = texture; | ||
this.textureWidth = texWidth; | ||
this.textureHeight = texHeight; | ||
} | ||
|
||
public static Builder builder(ButtonWidget.PressAction onPress) { | ||
return new Builder(onPress); | ||
} | ||
|
||
@Override | ||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { | ||
super.renderWidget(context, mouseX, mouseY, delta); | ||
int tw = this.textureWidth; | ||
int th = this.textureHeight; | ||
int x = this.getX() + this.getWidth() / 2 - this.textureWidth / 2; | ||
int y = this.getY() + this.getHeight() / 2 - this.textureHeight / 2; | ||
context.drawTexture(this.texture, x, y, 0, 0, tw, th, tw, th); | ||
} | ||
|
||
public static class Builder { | ||
private final ButtonWidget.PressAction onPress; | ||
private int width = 30; | ||
private int height = 30; | ||
private Identifier texture; | ||
private int textureWidth = 20; | ||
private int textureHeight = 20; | ||
|
||
public Builder(ButtonWidget.PressAction onPress) { | ||
this.onPress = onPress; | ||
} | ||
|
||
public Builder dimension(int width, int height) { | ||
this.width = width; | ||
this.height = height; | ||
return this; | ||
} | ||
|
||
public Builder texture(Identifier texture, int width, int height) { | ||
this.texture = texture; | ||
this.textureWidth = width; | ||
this.textureHeight = height; | ||
return this; | ||
} | ||
|
||
public TexturedButton build() { | ||
if (this.texture == null) { | ||
throw new IllegalStateException("Texture not set"); | ||
} else { | ||
return new TexturedButton(this.width, this.height, this.onPress, this.texture, this.textureWidth, this.textureHeight); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.