112 lines
3.6 KiB
Java
112 lines
3.6 KiB
Java
package net.minecraft.client.gui.components;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.renderer.RenderType;
|
|
import net.minecraft.client.sounds.SoundManager;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public abstract class AbstractTextAreaWidget extends AbstractScrollArea {
|
|
private static final WidgetSprites BACKGROUND_SPRITES = new WidgetSprites(
|
|
ResourceLocation.withDefaultNamespace("widget/text_field"), ResourceLocation.withDefaultNamespace("widget/text_field_highlighted")
|
|
);
|
|
private static final int INNER_PADDING = 4;
|
|
|
|
public AbstractTextAreaWidget(int i, int j, int k, int l, Component component) {
|
|
super(i, j, k, l, component);
|
|
}
|
|
|
|
@Override
|
|
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
|
boolean bl = this.updateScrolling(mouseX, mouseY, button);
|
|
return super.mouseClicked(mouseX, mouseY, button) || bl;
|
|
}
|
|
|
|
@Override
|
|
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
|
boolean bl = keyCode == 265;
|
|
boolean bl2 = keyCode == 264;
|
|
if (bl || bl2) {
|
|
double d = this.scrollAmount();
|
|
this.setScrollAmount(this.scrollAmount() + (bl ? -1 : 1) * this.scrollRate());
|
|
if (d != this.scrollAmount()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return super.keyPressed(keyCode, scanCode, modifiers);
|
|
}
|
|
|
|
@Override
|
|
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
|
if (this.visible) {
|
|
this.renderBackground(guiGraphics);
|
|
guiGraphics.enableScissor(this.getX() + 1, this.getY() + 1, this.getX() + this.width - 1, this.getY() + this.height - 1);
|
|
guiGraphics.pose().pushPose();
|
|
guiGraphics.pose().translate(0.0, -this.scrollAmount(), 0.0);
|
|
this.renderContents(guiGraphics, mouseX, mouseY, partialTick);
|
|
guiGraphics.pose().popPose();
|
|
guiGraphics.disableScissor();
|
|
this.renderDecorations(guiGraphics);
|
|
}
|
|
}
|
|
|
|
protected void renderDecorations(GuiGraphics guiGraphics) {
|
|
this.renderScrollbar(guiGraphics);
|
|
}
|
|
|
|
protected int innerPadding() {
|
|
return 4;
|
|
}
|
|
|
|
protected int totalInnerPadding() {
|
|
return this.innerPadding() * 2;
|
|
}
|
|
|
|
@Override
|
|
public boolean isMouseOver(double mouseX, double mouseY) {
|
|
return this.active && this.visible && mouseX >= this.getX() && mouseY >= this.getY() && mouseX < this.getRight() + 6 && mouseY < this.getBottom();
|
|
}
|
|
|
|
@Override
|
|
protected int scrollBarX() {
|
|
return this.getRight();
|
|
}
|
|
|
|
@Override
|
|
protected int contentHeight() {
|
|
return this.getInnerHeight() + this.totalInnerPadding();
|
|
}
|
|
|
|
protected void renderBackground(GuiGraphics guiGraphics) {
|
|
this.renderBorder(guiGraphics, this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
|
}
|
|
|
|
protected void renderBorder(GuiGraphics guiGraphics, int x, int y, int width, int height) {
|
|
ResourceLocation resourceLocation = BACKGROUND_SPRITES.get(this.isActive(), this.isFocused());
|
|
guiGraphics.blitSprite(RenderType::guiTextured, resourceLocation, x, y, width, height);
|
|
}
|
|
|
|
protected boolean withinContentAreaTopBottom(int top, int bottom) {
|
|
return bottom - this.scrollAmount() >= this.getY() && top - this.scrollAmount() <= this.getY() + this.height;
|
|
}
|
|
|
|
protected abstract int getInnerHeight();
|
|
|
|
protected abstract void renderContents(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick);
|
|
|
|
protected int getInnerLeft() {
|
|
return this.getX() + this.innerPadding();
|
|
}
|
|
|
|
protected int getInnerTop() {
|
|
return this.getY() + this.innerPadding();
|
|
}
|
|
|
|
@Override
|
|
public void playDownSound(SoundManager handler) {
|
|
}
|
|
}
|