AbstractScrollArea.java

net.minecraft.client.gui.components.AbstractScrollArea

信息

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

    TODO

字段/常量

  • SCROLLBAR_WIDTH

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

      TODO

  • SCROLLBAR_MIN_HEIGHT

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

      TODO

  • SCROLLER_SPRITE

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

      TODO

  • SCROLLER_BACKGROUND_SPRITE

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

      TODO

  • scrollbarSettings

    • 类型: AbstractScrollArea.ScrollbarSettings
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • scrollAmount

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

      TODO

  • scrolling

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.components.AbstractScrollArea.ScrollbarSettings
    • 类型: record
    • 修饰符: public
    • 源码定位: L151
    • 说明:

      TODO

构造器

public AbstractScrollArea(int x, int y, int width, int height, Component message, AbstractScrollArea.ScrollbarSettings scrollbarSettings) @ L24

  • 构造器名:AbstractScrollArea
  • 源码定位:L24
  • 修饰符:public

参数:

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

说明:

TODO

方法

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

public boolean mouseScrolled(double mx, double my, double scrollX, double scrollY) @ L29

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

参数:

  • mx: double
  • my: double
  • scrollX: double
  • scrollY: double

说明:

TODO

public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) @ L39

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

参数:

  • event: MouseButtonEvent
  • dx: double
  • dy: double

说明:

TODO

public void onRelease(MouseButtonEvent event) @ L59

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

参数:

  • event: MouseButtonEvent

说明:

TODO

public double scrollAmount() @ L64

  • 方法名:scrollAmount
  • 源码定位:L64
  • 返回类型:double
  • 修饰符:public

参数:

说明:

TODO

public void setScrollAmount(double scrollAmount) @ L68

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

参数:

  • scrollAmount: double

说明:

TODO

public boolean updateScrolling(MouseButtonEvent event) @ L72

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

参数:

  • event: MouseButtonEvent

说明:

TODO

protected boolean isOverScrollbar(double x, double y) @ L77

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

参数:

  • x: double
  • y: double

说明:

TODO

public void refreshScrollAmount() @ L81

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

参数:

说明:

TODO

public int maxScrollAmount() @ L85

  • 方法名:maxScrollAmount
  • 源码定位:L85
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

protected boolean scrollable() @ L89

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

参数:

说明:

TODO

public int scrollbarWidth() @ L93

  • 方法名:scrollbarWidth
  • 源码定位:L93
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

protected int scrollerHeight() @ L97

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

参数:

说明:

TODO

protected int scrollBarX() @ L101

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

参数:

说明:

TODO

public int scrollBarY() @ L105

  • 方法名:scrollBarY
  • 源码定位:L105
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

protected void extractScrollbar(GuiGraphicsExtractor graphics, int mouseX, int mouseY) @ L111

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

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int

说明:

TODO

protected abstract int contentHeight() @ L140

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

参数:

说明:

TODO

protected double scrollRate() @ L142

  • 方法名:scrollRate
  • 源码定位:L142
  • 返回类型:double
  • 修饰符:protected

参数:

说明:

TODO

public static AbstractScrollArea.ScrollbarSettings defaultSettings(int scrollRate) @ L146

  • 方法名:defaultSettings
  • 源码定位:L146
  • 返回类型:AbstractScrollArea.ScrollbarSettings
  • 修饰符:public static

参数:

  • scrollRate: int

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public abstract class AbstractScrollArea extends AbstractWidget {
    public static final int SCROLLBAR_WIDTH = 6;
    private static final int SCROLLBAR_MIN_HEIGHT = 32;
    private static final Identifier SCROLLER_SPRITE = Identifier.withDefaultNamespace("widget/scroller");
    private static final Identifier SCROLLER_BACKGROUND_SPRITE = Identifier.withDefaultNamespace("widget/scroller_background");
    private final AbstractScrollArea.ScrollbarSettings scrollbarSettings;
    private double scrollAmount;
    private boolean scrolling;
 
    public AbstractScrollArea(int x, int y, int width, int height, Component message, AbstractScrollArea.ScrollbarSettings scrollbarSettings) {
        super(x, y, width, height, message);
        this.scrollbarSettings = scrollbarSettings;
    }
 
    @Override
    public boolean mouseScrolled(double mx, double my, double scrollX, double scrollY) {
        if (!this.visible) {
            return false;
        } else {
            this.setScrollAmount(this.scrollAmount() - scrollY * this.scrollRate());
            return true;
        }
    }
 
    @Override
    public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) {
        if (this.scrolling) {
            if (event.y() < this.getY()) {
                this.setScrollAmount(0.0);
            } else if (event.y() > this.getBottom()) {
                this.setScrollAmount(this.maxScrollAmount());
            } else {
                double max = Math.max(1, this.maxScrollAmount());
                int barHeight = this.scrollerHeight();
                double yDragScale = Math.max(1.0, max / (this.height - barHeight));
                this.setScrollAmount(this.scrollAmount() + dy * yDragScale);
            }
 
            return true;
        } else {
            return super.mouseDragged(event, dx, dy);
        }
    }
 
    @Override
    public void onRelease(MouseButtonEvent event) {
        this.scrolling = false;
    }
 
    public double scrollAmount() {
        return this.scrollAmount;
    }
 
    public void setScrollAmount(double scrollAmount) {
        this.scrollAmount = Mth.clamp(scrollAmount, 0.0, (double)this.maxScrollAmount());
    }
 
    public boolean updateScrolling(MouseButtonEvent event) {
        this.scrolling = this.scrollable() && this.isValidClickButton(event.buttonInfo()) && this.isOverScrollbar(event.x(), event.y());
        return this.scrolling;
    }
 
    protected boolean isOverScrollbar(double x, double y) {
        return x >= this.scrollBarX() && x <= this.scrollBarX() + this.scrollbarWidth() && y >= this.getY() && y < this.getBottom();
    }
 
    public void refreshScrollAmount() {
        this.setScrollAmount(this.scrollAmount);
    }
 
    public int maxScrollAmount() {
        return Math.max(0, this.contentHeight() - this.height);
    }
 
    protected boolean scrollable() {
        return this.maxScrollAmount() > 0;
    }
 
    public int scrollbarWidth() {
        return this.scrollbarSettings.scrollbarWidth();
    }
 
    protected int scrollerHeight() {
        return Mth.clamp((int)((float)(this.height * this.height) / this.contentHeight()), 32, this.height - 8);
    }
 
    protected int scrollBarX() {
        return this.getRight() - this.scrollbarWidth();
    }
 
    public int scrollBarY() {
        return this.maxScrollAmount() == 0
            ? this.getY()
            : Math.max(this.getY(), (int)this.scrollAmount * (this.height - this.scrollerHeight()) / this.maxScrollAmount() + this.getY());
    }
 
    protected void extractScrollbar(GuiGraphicsExtractor graphics, int mouseX, int mouseY) {
        int scrollbarX = this.scrollBarX();
        int scrollerHeight = this.scrollerHeight();
        int scrollerY = this.scrollBarY();
        if (!this.scrollable() && this.scrollbarSettings.disabledScrollerSprite() != null) {
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED, this.scrollbarSettings.backgroundSprite(), scrollbarX, this.getY(), this.scrollbarWidth(), this.getHeight()
            );
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED, this.scrollbarSettings.disabledScrollerSprite(), scrollbarX, this.getY(), this.scrollbarWidth(), scrollerHeight
            );
            if (this.isOverScrollbar(mouseX, mouseY)) {
                graphics.requestCursor(CursorTypes.NOT_ALLOWED);
            }
        }
 
        if (this.scrollable()) {
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED, this.scrollbarSettings.backgroundSprite(), scrollbarX, this.getY(), this.scrollbarWidth(), this.getHeight()
            );
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED, this.scrollbarSettings.scrollerSprite(), scrollbarX, scrollerY, this.scrollbarWidth(), scrollerHeight
            );
            if (this.isOverScrollbar(mouseX, mouseY)) {
                graphics.requestCursor(this.scrolling ? CursorTypes.RESIZE_NS : CursorTypes.POINTING_HAND);
            }
        }
    }
 
    protected abstract int contentHeight();
 
    protected double scrollRate() {
        return this.scrollbarSettings.scrollRate();
    }
 
    public static AbstractScrollArea.ScrollbarSettings defaultSettings(int scrollRate) {
        return new AbstractScrollArea.ScrollbarSettings(SCROLLER_SPRITE, null, SCROLLER_BACKGROUND_SPRITE, 6, 32, scrollRate, true);
    }
 
    @OnlyIn(Dist.CLIENT)
    public record ScrollbarSettings(
        Identifier scrollerSprite,
        @Nullable Identifier disabledScrollerSprite,
        Identifier backgroundSprite,
        int scrollbarWidth,
        int scrollbarMinHeight,
        int scrollRate,
        boolean resizingScrollbar
    ) {
    }
}

引用的其他类