AbstractTextAreaWidget.java

net.minecraft.client.gui.components.AbstractTextAreaWidget

信息

  • 全限定名:net.minecraft.client.gui.components.AbstractTextAreaWidget
  • 类型:public abstract class
  • 包:net.minecraft.client.gui.components
  • 源码路径:src/main/java/net/minecraft/client/gui/components/AbstractTextAreaWidget.java
  • 起始行号:L14
  • 继承:AbstractScrollArea
  • 职责:

    TODO

字段/常量

  • BACKGROUND_SPRITES

    • 类型: WidgetSprites
    • 修饰符: private static final
    • 源码定位: L15
    • 说明:

      TODO

  • INNER_PADDING

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

  • DEFAULT_TOTAL_PADDING

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L19
    • 说明:

      TODO

  • showBackground

    • 类型: boolean
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

  • showDecorations

    • 类型: boolean
    • 修饰符: private
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

public AbstractTextAreaWidget(int x, int y, int width, int height, Component narration, AbstractScrollArea.ScrollbarSettings scrollbarSettings) @ L23

  • 构造器名:AbstractTextAreaWidget
  • 源码定位:L23
  • 修饰符:public

参数:

  • x: int
  • y: int
  • width: int
  • height: int
  • narration: Component
  • scrollbarSettings: AbstractScrollArea.ScrollbarSettings

说明:

TODO

public AbstractTextAreaWidget(int x, int y, int width, int height, Component narration, AbstractScrollArea.ScrollbarSettings scrollbarSettings, boolean showBackground, boolean showDecorations) @ L27

  • 构造器名:AbstractTextAreaWidget
  • 源码定位:L27
  • 修饰符:public

参数:

  • x: int
  • y: int
  • width: int
  • height: int
  • narration: Component
  • scrollbarSettings: AbstractScrollArea.ScrollbarSettings
  • showBackground: boolean
  • showDecorations: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) @ L42

  • 方法名:mouseClicked
  • 源码定位:L42
  • 返回类型:boolean
  • 修饰符:public

参数:

  • event: MouseButtonEvent
  • doubleClick: boolean

说明:

TODO

public boolean keyPressed(KeyEvent event) @ L48

  • 方法名:keyPressed
  • 源码定位:L48
  • 返回类型:boolean
  • 修饰符:public

参数:

  • event: KeyEvent

说明:

TODO

public void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L63

  • 方法名:extractWidgetRenderState
  • 源码定位:L63
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

protected void extractDecorations(GuiGraphicsExtractor graphics) @ L83

  • 方法名:extractDecorations
  • 源码定位:L83
  • 返回类型:void
  • 修饰符:protected

参数:

  • graphics: GuiGraphicsExtractor

说明:

TODO

protected int innerPadding() @ L86

  • 方法名:innerPadding
  • 源码定位:L86
  • 返回类型:int
  • 修饰符:protected

参数:

说明:

TODO

protected int totalInnerPadding() @ L90

  • 方法名:totalInnerPadding
  • 源码定位:L90
  • 返回类型:int
  • 修饰符:protected

参数:

说明:

TODO

public boolean isMouseOver(double mouseX, double mouseY) @ L94

  • 方法名:isMouseOver
  • 源码定位:L94
  • 返回类型:boolean
  • 修饰符:public

参数:

  • mouseX: double
  • mouseY: double

说明:

TODO

protected int scrollBarX() @ L104

  • 方法名:scrollBarX
  • 源码定位:L104
  • 返回类型:int
  • 修饰符:protected

参数:

说明:

TODO

protected int contentHeight() @ L109

  • 方法名:contentHeight
  • 源码定位:L109
  • 返回类型:int
  • 修饰符:protected

参数:

说明:

TODO

protected void extractBackground(GuiGraphicsExtractor graphics) @ L114

  • 方法名:extractBackground
  • 源码定位:L114
  • 返回类型:void
  • 修饰符:protected

参数:

  • graphics: GuiGraphicsExtractor

说明:

TODO

protected void extractBorder(GuiGraphicsExtractor graphics, int x, int y, int width, int height) @ L118

  • 方法名:extractBorder
  • 源码定位:L118
  • 返回类型:void
  • 修饰符:protected

参数:

  • graphics: GuiGraphicsExtractor
  • x: int
  • y: int
  • width: int
  • height: int

说明:

TODO

protected boolean withinContentAreaTopBottom(int top, int bottom) @ L123

  • 方法名:withinContentAreaTopBottom
  • 源码定位:L123
  • 返回类型:boolean
  • 修饰符:protected

参数:

  • top: int
  • bottom: int

说明:

TODO

protected abstract int getInnerHeight() @ L127

  • 方法名:getInnerHeight
  • 源码定位:L127
  • 返回类型:int
  • 修饰符:protected abstract

参数:

说明:

TODO

protected abstract void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L129

  • 方法名:extractContents
  • 源码定位:L129
  • 返回类型:void
  • 修饰符:protected abstract

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

protected int getInnerLeft() @ L131

  • 方法名:getInnerLeft
  • 源码定位:L131
  • 返回类型:int
  • 修饰符:protected

参数:

说明:

TODO

protected int getInnerTop() @ L135

  • 方法名:getInnerTop
  • 源码定位:L135
  • 返回类型:int
  • 修饰符:protected

参数:

说明:

TODO

public void playDownSound(SoundManager soundManager) @ L139

  • 方法名:playDownSound
  • 源码定位:L139
  • 返回类型:void
  • 修饰符:public

参数:

  • soundManager: SoundManager

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public abstract class AbstractTextAreaWidget extends AbstractScrollArea {
    private static final WidgetSprites BACKGROUND_SPRITES = new WidgetSprites(
        Identifier.withDefaultNamespace("widget/text_field"), Identifier.withDefaultNamespace("widget/text_field_highlighted")
    );
    private static final int INNER_PADDING = 4;
    public static final int DEFAULT_TOTAL_PADDING = 8;
    private boolean showBackground = true;
    private boolean showDecorations = true;
 
    public AbstractTextAreaWidget(int x, int y, int width, int height, Component narration, AbstractScrollArea.ScrollbarSettings scrollbarSettings) {
        super(x, y, width, height, narration, scrollbarSettings);
    }
 
    public AbstractTextAreaWidget(
        int x,
        int y,
        int width,
        int height,
        Component narration,
        AbstractScrollArea.ScrollbarSettings scrollbarSettings,
        boolean showBackground,
        boolean showDecorations
    ) {
        this(x, y, width, height, narration, scrollbarSettings);
        this.showBackground = showBackground;
        this.showDecorations = showDecorations;
    }
 
    @Override
    public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
        boolean scrolling = this.updateScrolling(event);
        return super.mouseClicked(event, doubleClick) || scrolling;
    }
 
    @Override
    public boolean keyPressed(KeyEvent event) {
        boolean isUp = event.isUp();
        boolean isDown = event.isDown();
        if (isUp || isDown) {
            double previousScrollAmount = this.scrollAmount();
            this.setScrollAmount(this.scrollAmount() + (isUp ? -1 : 1) * this.scrollRate());
            if (previousScrollAmount != this.scrollAmount()) {
                return true;
            }
        }
 
        return super.keyPressed(event);
    }
 
    @Override
    public void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        if (this.visible) {
            if (this.showBackground) {
                this.extractBackground(graphics);
            }
 
            graphics.enableScissor(this.getX() + 1, this.getY() + 1, this.getX() + this.width - 1, this.getY() + this.height - 1);
            graphics.pose().pushMatrix();
            graphics.pose().translate(0.0F, (float)(-this.scrollAmount()));
            this.extractContents(graphics, mouseX, mouseY, a);
            graphics.pose().popMatrix();
            graphics.disableScissor();
            this.extractScrollbar(graphics, mouseX, mouseY);
            if (this.showDecorations) {
                this.extractDecorations(graphics);
            }
        }
    }
 
    protected void extractDecorations(GuiGraphicsExtractor graphics) {
    }
 
    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() + this.scrollbarWidth()
            && mouseY < this.getBottom();
    }
 
    @Override
    protected int scrollBarX() {
        return this.getRight();
    }
 
    @Override
    protected int contentHeight() {
        return this.getInnerHeight() + this.totalInnerPadding();
    }
 
    protected void extractBackground(GuiGraphicsExtractor graphics) {
        this.extractBorder(graphics, this.getX(), this.getY(), this.getWidth(), this.getHeight());
    }
 
    protected void extractBorder(GuiGraphicsExtractor graphics, int x, int y, int width, int height) {
        Identifier sprite = BACKGROUND_SPRITES.get(this.isActive(), this.isFocused());
        graphics.blitSprite(RenderPipelines.GUI_TEXTURED, sprite, 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 extractContents(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a);
 
    protected int getInnerLeft() {
        return this.getX() + this.innerPadding();
    }
 
    protected int getInnerTop() {
        return this.getY() + this.innerPadding();
    }
 
    @Override
    public void playDownSound(SoundManager soundManager) {
    }
}

引用的其他类