ActiveTextCollector.java
net.minecraft.client.gui.ActiveTextCollector
信息
- 全限定名:net.minecraft.client.gui.ActiveTextCollector
- 类型:public interface
- 包:net.minecraft.client.gui
- 源码路径:src/main/java/net/minecraft/client/gui/ActiveTextCollector.java
- 起始行号:L25
- 职责:
TODO
字段/常量
-
PERIOD_PER_SCROLLED_PIXEL- 类型:
double - 修饰符:
package-private - 源码定位:
L26 - 说明:
TODO
- 类型:
-
MIN_SCROLL_PERIOD- 类型:
double - 修饰符:
package-private - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.ActiveTextCollector.ClickableStyleFinder- 类型:
class - 修饰符:
public static - 源码定位:
L120 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.ActiveTextCollector.Parameters- 类型:
record - 修饰符:
public - 源码定位:
L177 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
ActiveTextCollector.Parameters defaultParameters() @ L29
- 方法名:defaultParameters
- 源码定位:L29
- 返回类型:ActiveTextCollector.Parameters
- 修饰符:package-private
参数:
- 无
说明:
TODO
void defaultParameters(ActiveTextCollector.Parameters newParameters) @ L31
- 方法名:defaultParameters
- 源码定位:L31
- 返回类型:void
- 修饰符:package-private
参数:
- newParameters: ActiveTextCollector.Parameters
说明:
TODO
default void accept(int x, int y, FormattedCharSequence text) @ L33
- 方法名:accept
- 源码定位:L33
- 返回类型:void
- 修饰符:default
参数:
- x: int
- y: int
- text: FormattedCharSequence
说明:
TODO
default void accept(int x, int y, Component text) @ L37
- 方法名:accept
- 源码定位:L37
- 返回类型:void
- 修饰符:default
参数:
- x: int
- y: int
- text: Component
说明:
TODO
default void accept(TextAlignment alignment, int anchorX, int y, ActiveTextCollector.Parameters parameters, Component text) @ L41
- 方法名:accept
- 源码定位:L41
- 返回类型:void
- 修饰符:default
参数:
- alignment: TextAlignment
- anchorX: int
- y: int
- parameters: ActiveTextCollector.Parameters
- text: Component
说明:
TODO
void accept(TextAlignment alignment, int anchorX, int y, ActiveTextCollector.Parameters parameters, FormattedCharSequence text) @ L45
- 方法名:accept
- 源码定位:L45
- 返回类型:void
- 修饰符:package-private
参数:
- alignment: TextAlignment
- anchorX: int
- y: int
- parameters: ActiveTextCollector.Parameters
- text: FormattedCharSequence
说明:
TODO
default void accept(TextAlignment alignment, int anchorX, int y, Component text) @ L47
- 方法名:accept
- 源码定位:L47
- 返回类型:void
- 修饰符:default
参数:
- alignment: TextAlignment
- anchorX: int
- y: int
- text: Component
说明:
TODO
default void accept(TextAlignment alignment, int anchorX, int y, FormattedCharSequence text) @ L51
- 方法名:accept
- 源码定位:L51
- 返回类型:void
- 修饰符:default
参数:
- alignment: TextAlignment
- anchorX: int
- y: int
- text: FormattedCharSequence
说明:
TODO
void acceptScrolling(Component message, int centerX, int left, int right, int top, int bottom, ActiveTextCollector.Parameters parameters) @ L55
- 方法名:acceptScrolling
- 源码定位:L55
- 返回类型:void
- 修饰符:package-private
参数:
- message: Component
- centerX: int
- left: int
- right: int
- top: int
- bottom: int
- parameters: ActiveTextCollector.Parameters
说明:
TODO
default void acceptScrolling(Component message, int centerX, int left, int right, int top, int bottom) @ L57
- 方法名:acceptScrolling
- 源码定位:L57
- 返回类型:void
- 修饰符:default
参数:
- message: Component
- centerX: int
- left: int
- right: int
- top: int
- bottom: int
说明:
TODO
default void acceptScrollingWithDefaultCenter(Component message, int left, int right, int top, int bottom) @ L61
- 方法名:acceptScrollingWithDefaultCenter
- 源码定位:L61
- 返回类型:void
- 修饰符:default
参数:
- message: Component
- left: int
- right: int
- top: int
- bottom: int
说明:
TODO
default void defaultScrollingHelper(Component message, int centerX, int left, int right, int top, int bottom, int lineWidth, int lineHeight, ActiveTextCollector.Parameters parameters) @ L65
- 方法名:defaultScrollingHelper
- 源码定位:L65
- 返回类型:void
- 修饰符:default
参数:
- message: Component
- centerX: int
- left: int
- right: int
- top: int
- bottom: int
- lineWidth: int
- lineHeight: int
- parameters: ActiveTextCollector.Parameters
说明:
TODO
static void findElementUnderCursor(GuiTextRenderState text, float testX, float testY, Consumer<Style> output) @ L84
- 方法名:findElementUnderCursor
- 源码定位:L84
- 返回类型:void
- 修饰符:static
参数:
- text: GuiTextRenderState
- testX: float
- testY: float
- output: Consumer
说明:
TODO
static boolean isPointInRectangle(float x, float y, float left, float top, float right, float bottom) @ L115
- 方法名:isPointInRectangle
- 源码定位:L115
- 返回类型:boolean
- 修饰符:static
参数:
- x: float
- y: float
- left: float
- top: float
- right: float
- bottom: float
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public interface ActiveTextCollector {
double PERIOD_PER_SCROLLED_PIXEL = 0.5;
double MIN_SCROLL_PERIOD = 3.0;
ActiveTextCollector.Parameters defaultParameters();
void defaultParameters(ActiveTextCollector.Parameters newParameters);
default void accept(int x, int y, FormattedCharSequence text) {
this.accept(TextAlignment.LEFT, x, y, this.defaultParameters(), text);
}
default void accept(int x, int y, Component text) {
this.accept(TextAlignment.LEFT, x, y, this.defaultParameters(), text.getVisualOrderText());
}
default void accept(TextAlignment alignment, int anchorX, int y, ActiveTextCollector.Parameters parameters, Component text) {
this.accept(alignment, anchorX, y, parameters, text.getVisualOrderText());
}
void accept(TextAlignment alignment, int anchorX, int y, ActiveTextCollector.Parameters parameters, FormattedCharSequence text);
default void accept(TextAlignment alignment, int anchorX, int y, Component text) {
this.accept(alignment, anchorX, y, text.getVisualOrderText());
}
default void accept(TextAlignment alignment, int anchorX, int y, FormattedCharSequence text) {
this.accept(alignment, anchorX, y, this.defaultParameters(), text);
}
void acceptScrolling(Component message, int centerX, int left, int right, int top, int bottom, ActiveTextCollector.Parameters parameters);
default void acceptScrolling(Component message, int centerX, int left, int right, int top, int bottom) {
this.acceptScrolling(message, centerX, left, right, top, bottom, this.defaultParameters());
}
default void acceptScrollingWithDefaultCenter(Component message, int left, int right, int top, int bottom) {
this.acceptScrolling(message, (left + right) / 2, left, right, top, bottom);
}
default void defaultScrollingHelper(
Component message, int centerX, int left, int right, int top, int bottom, int lineWidth, int lineHeight, ActiveTextCollector.Parameters parameters
) {
int textTop = (top + bottom - lineHeight) / 2 + 1;
int availableMessageWidth = right - left;
if (lineWidth > availableMessageWidth) {
int maxPosition = lineWidth - availableMessageWidth;
double time = Util.getMillis() / 1000.0;
double period = Math.max(maxPosition * 0.5, 3.0);
double alpha = Math.sin((Math.PI / 2) * Math.cos((Math.PI * 2) * time / period)) / 2.0 + 0.5;
double pos = Mth.lerp(alpha, 0.0, (double)maxPosition);
ActiveTextCollector.Parameters localParameters = parameters.withScissor(left, right, top, bottom);
this.accept(TextAlignment.LEFT, left - (int)pos, textTop, localParameters, message.getVisualOrderText());
} else {
int textX = Mth.clamp(centerX, left + lineWidth / 2, right - lineWidth / 2);
this.accept(TextAlignment.CENTER, textX, textTop, message);
}
}
static void findElementUnderCursor(GuiTextRenderState text, float testX, float testY, Consumer<Style> output) {
ScreenRectangle bounds = text.bounds();
if (bounds != null && bounds.containsPoint((int)testX, (int)testY)) {
Vector2fc localMousePos = text.pose.invert(new Matrix3x2f()).transformPosition(new Vector2f(testX, testY));
final float localMouseX = localMousePos.x();
final float localMouseY = localMousePos.y();
text.ensurePrepared()
.visit(
new Font.GlyphVisitor() {
@Override
public void acceptGlyph(TextRenderable.Styled glyph) {
this.acceptActiveArea(glyph);
}
@Override
public void acceptEmptyArea(EmptyArea empty) {
this.acceptActiveArea(empty);
}
private void acceptActiveArea(ActiveArea glyph) {
if (ActiveTextCollector.isPointInRectangle(
localMouseX, localMouseY, glyph.activeLeft(), glyph.activeTop(), glyph.activeRight(), glyph.activeBottom()
)) {
output.accept(glyph.style());
}
}
}
);
}
}
static boolean isPointInRectangle(float x, float y, float left, float top, float right, float bottom) {
return x >= left && x < right && y >= top && y < bottom;
}
@OnlyIn(Dist.CLIENT)
public static class ClickableStyleFinder implements ActiveTextCollector {
private static final ActiveTextCollector.Parameters INITIAL = new ActiveTextCollector.Parameters(new Matrix3x2f());
private final Font font;
private final int testX;
private final int testY;
private ActiveTextCollector.Parameters defaultParameters = INITIAL;
private boolean includeInsertions;
private @Nullable Style result;
private final Consumer<Style> styleScanner = style -> {
if (style.getClickEvent() != null || this.includeInsertions && style.getInsertion() != null) {
this.result = style;
}
};
public ClickableStyleFinder(Font font, int testX, int testY) {
this.font = font;
this.testX = testX;
this.testY = testY;
}
@Override
public ActiveTextCollector.Parameters defaultParameters() {
return this.defaultParameters;
}
@Override
public void defaultParameters(ActiveTextCollector.Parameters newParameters) {
this.defaultParameters = newParameters;
}
@Override
public void accept(TextAlignment alignment, int anchorX, int y, ActiveTextCollector.Parameters parameters, FormattedCharSequence text) {
int leftX = alignment.calculateLeft(anchorX, this.font, text);
GuiTextRenderState renderState = new GuiTextRenderState(
this.font, text, parameters.pose(), leftX, y, ARGB.white(parameters.opacity()), 0, true, true, parameters.scissor()
);
ActiveTextCollector.findElementUnderCursor(renderState, this.testX, this.testY, this.styleScanner);
}
@Override
public void acceptScrolling(Component message, int centerX, int left, int right, int top, int bottom, ActiveTextCollector.Parameters parameters) {
int lineWidth = this.font.width(message);
int lineHeight = 9;
this.defaultScrollingHelper(message, centerX, left, right, top, bottom, lineWidth, lineHeight, parameters);
}
public ActiveTextCollector.ClickableStyleFinder includeInsertions(boolean flag) {
this.includeInsertions = flag;
return this;
}
public @Nullable Style result() {
return this.result;
}
}
@OnlyIn(Dist.CLIENT)
public record Parameters(Matrix3x2fc pose, float opacity, @Nullable ScreenRectangle scissor) {
public Parameters(Matrix3x2fc pose) {
this(pose, 1.0F, null);
}
public ActiveTextCollector.Parameters withPose(Matrix3x2fc pose) {
return new ActiveTextCollector.Parameters(pose, this.opacity, this.scissor);
}
public ActiveTextCollector.Parameters withScale(float scale) {
return this.withPose(this.pose.scale(scale, scale, new Matrix3x2f()));
}
public ActiveTextCollector.Parameters withOpacity(float opacity) {
return this.opacity == opacity ? this : new ActiveTextCollector.Parameters(this.pose, opacity, this.scissor);
}
public ActiveTextCollector.Parameters withScissor(ScreenRectangle scissor) {
return scissor.equals(this.scissor) ? this : new ActiveTextCollector.Parameters(this.pose, this.opacity, scissor);
}
public ActiveTextCollector.Parameters withScissor(int left, int right, int top, int bottom) {
ScreenRectangle newScissor = new ScreenRectangle(left, top, right - left, bottom - top).transformAxisAligned(this.pose);
if (this.scissor != null) {
newScissor = Objects.requireNonNullElse(this.scissor.intersection(newScissor), ScreenRectangle.empty());
}
return this.withScissor(newScissor);
}
}
}引用的其他类
-
- 引用位置:
方法调用/构造调用 - 关联成员:
Font.GlyphVisitor(), GlyphVisitor()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
ScreenRectangle(), ScreenRectangle.empty()
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
GuiTextRenderState()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.white()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.clamp(), Mth.lerp()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.getMillis()
- 引用位置: