ScreenRectangle.java
net.minecraft.client.gui.navigation.ScreenRectangle
信息
- 全限定名:net.minecraft.client.gui.navigation.ScreenRectangle
- 类型:public record
- 包:net.minecraft.client.gui.navigation
- 源码路径:src/main/java/net/minecraft/client/gui/navigation/ScreenRectangle.java
- 起始行号:L11
- 职责:
TODO
字段/常量
EMPTY- 类型:
ScreenRectangle - 修饰符:
private static final - 源码定位:
L12 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ScreenRectangle(int x, int y, int width, int height) @ L14
- 构造器名:ScreenRectangle
- 源码定位:L14
- 修饰符:public
参数:
- x: int
- y: int
- width: int
- height: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static ScreenRectangle empty() @ L18
- 方法名:empty
- 源码定位:L18
- 返回类型:ScreenRectangle
- 修饰符:public static
参数:
- 无
说明:
TODO
public static ScreenRectangle of(ScreenAxis primaryAxis, int primaryIndex, int secondaryIndex, int primaryLength, int secondaryLength) @ L22
- 方法名:of
- 源码定位:L22
- 返回类型:ScreenRectangle
- 修饰符:public static
参数:
- primaryAxis: ScreenAxis
- primaryIndex: int
- secondaryIndex: int
- primaryLength: int
- secondaryLength: int
说明:
TODO
public ScreenRectangle step(ScreenDirection direction) @ L29
- 方法名:step
- 源码定位:L29
- 返回类型:ScreenRectangle
- 修饰符:public
参数:
- direction: ScreenDirection
说明:
TODO
public int getLength(ScreenAxis axis) @ L33
- 方法名:getLength
- 源码定位:L33
- 返回类型:int
- 修饰符:public
参数:
- axis: ScreenAxis
说明:
TODO
public int getBoundInDirection(ScreenDirection direction) @ L40
- 方法名:getBoundInDirection
- 源码定位:L40
- 返回类型:int
- 修饰符:public
参数:
- direction: ScreenDirection
说明:
TODO
public ScreenRectangle getBorder(ScreenDirection direction) @ L45
- 方法名:getBorder
- 源码定位:L45
- 返回类型:ScreenRectangle
- 修饰符:public
参数:
- direction: ScreenDirection
说明:
TODO
public boolean overlaps(ScreenRectangle other) @ L53
- 方法名:overlaps
- 源码定位:L53
- 返回类型:boolean
- 修饰符:public
参数:
- other: ScreenRectangle
说明:
TODO
public boolean overlapsInAxis(ScreenRectangle other, ScreenAxis axis) @ L57
- 方法名:overlapsInAxis
- 源码定位:L57
- 返回类型:boolean
- 修饰符:public
参数:
- other: ScreenRectangle
- axis: ScreenAxis
说明:
TODO
public int getCenterInAxis(ScreenAxis axis) @ L65
- 方法名:getCenterInAxis
- 源码定位:L65
- 返回类型:int
- 修饰符:public
参数:
- axis: ScreenAxis
说明:
TODO
public ScreenRectangle intersection(ScreenRectangle other) @ L69
- 方法名:intersection
- 源码定位:L69
- 返回类型:ScreenRectangle
- 修饰符:public
参数:
- other: ScreenRectangle
说明:
TODO
public boolean intersects(ScreenRectangle other) @ L77
- 方法名:intersects
- 源码定位:L77
- 返回类型:boolean
- 修饰符:public
参数:
- other: ScreenRectangle
说明:
TODO
public boolean encompasses(ScreenRectangle other) @ L81
- 方法名:encompasses
- 源码定位:L81
- 返回类型:boolean
- 修饰符:public
参数:
- other: ScreenRectangle
说明:
TODO
public int top() @ L85
- 方法名:top
- 源码定位:L85
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int bottom() @ L89
- 方法名:bottom
- 源码定位:L89
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int left() @ L93
- 方法名:left
- 源码定位:L93
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int right() @ L97
- 方法名:right
- 源码定位:L97
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean containsPoint(int x, int y) @ L101
- 方法名:containsPoint
- 源码定位:L101
- 返回类型:boolean
- 修饰符:public
参数:
- x: int
- y: int
说明:
TODO
public ScreenRectangle transformAxisAligned(Matrix3x2fc matrix) @ L105
- 方法名:transformAxisAligned
- 源码定位:L105
- 返回类型:ScreenRectangle
- 修饰符:public
参数:
- matrix: Matrix3x2fc
说明:
TODO
public ScreenRectangle transformMaxBounds(Matrix3x2fc matrix) @ L111
- 方法名:transformMaxBounds
- 源码定位:L111
- 返回类型:ScreenRectangle
- 修饰符:public
参数:
- matrix: Matrix3x2fc
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public record ScreenRectangle(ScreenPosition position, int width, int height) {
private static final ScreenRectangle EMPTY = new ScreenRectangle(0, 0, 0, 0);
public ScreenRectangle(int x, int y, int width, int height) {
this(new ScreenPosition(x, y), width, height);
}
public static ScreenRectangle empty() {
return EMPTY;
}
public static ScreenRectangle of(ScreenAxis primaryAxis, int primaryIndex, int secondaryIndex, int primaryLength, int secondaryLength) {
return switch (primaryAxis) {
case HORIZONTAL -> new ScreenRectangle(primaryIndex, secondaryIndex, primaryLength, secondaryLength);
case VERTICAL -> new ScreenRectangle(secondaryIndex, primaryIndex, secondaryLength, primaryLength);
};
}
public ScreenRectangle step(ScreenDirection direction) {
return new ScreenRectangle(this.position.step(direction), this.width, this.height);
}
public int getLength(ScreenAxis axis) {
return switch (axis) {
case HORIZONTAL -> this.width;
case VERTICAL -> this.height;
};
}
public int getBoundInDirection(ScreenDirection direction) {
ScreenAxis axis = direction.getAxis();
return direction.isPositive() ? this.position.getCoordinate(axis) + this.getLength(axis) - 1 : this.position.getCoordinate(axis);
}
public ScreenRectangle getBorder(ScreenDirection direction) {
int startFirst = this.getBoundInDirection(direction);
ScreenAxis orthogonalAxis = direction.getAxis().orthogonal();
int startSecond = this.getBoundInDirection(orthogonalAxis.getNegative());
int length = this.getLength(orthogonalAxis);
return of(direction.getAxis(), startFirst, startSecond, 1, length).step(direction);
}
public boolean overlaps(ScreenRectangle other) {
return this.overlapsInAxis(other, ScreenAxis.HORIZONTAL) && this.overlapsInAxis(other, ScreenAxis.VERTICAL);
}
public boolean overlapsInAxis(ScreenRectangle other, ScreenAxis axis) {
int thisLower = this.getBoundInDirection(axis.getNegative());
int otherLower = other.getBoundInDirection(axis.getNegative());
int thisHigher = this.getBoundInDirection(axis.getPositive());
int otherHigher = other.getBoundInDirection(axis.getPositive());
return Math.max(thisLower, otherLower) <= Math.min(thisHigher, otherHigher);
}
public int getCenterInAxis(ScreenAxis axis) {
return (this.getBoundInDirection(axis.getPositive()) + this.getBoundInDirection(axis.getNegative())) / 2;
}
public @Nullable ScreenRectangle intersection(ScreenRectangle other) {
int left = Math.max(this.left(), other.left());
int top = Math.max(this.top(), other.top());
int right = Math.min(this.right(), other.right());
int bottom = Math.min(this.bottom(), other.bottom());
return left < right && top < bottom ? new ScreenRectangle(left, top, right - left, bottom - top) : null;
}
public boolean intersects(ScreenRectangle other) {
return this.left() < other.right() && this.right() > other.left() && this.top() < other.bottom() && this.bottom() > other.top();
}
public boolean encompasses(ScreenRectangle other) {
return other.left() >= this.left() && other.top() >= this.top() && other.right() <= this.right() && other.bottom() <= this.bottom();
}
public int top() {
return this.position.y();
}
public int bottom() {
return this.position.y() + this.height;
}
public int left() {
return this.position.x();
}
public int right() {
return this.position.x() + this.width;
}
public boolean containsPoint(int x, int y) {
return x >= this.left() && x < this.right() && y >= this.top() && y < this.bottom();
}
public ScreenRectangle transformAxisAligned(Matrix3x2fc matrix) {
Vector2f topLeft = matrix.transformPosition(this.left(), this.top(), new Vector2f());
Vector2f bottomRight = matrix.transformPosition(this.right(), this.bottom(), new Vector2f());
return new ScreenRectangle(Mth.floor(topLeft.x), Mth.floor(topLeft.y), Mth.floor(bottomRight.x - topLeft.x), Mth.floor(bottomRight.y - topLeft.y));
}
public ScreenRectangle transformMaxBounds(Matrix3x2fc matrix) {
Vector2f topLeft = matrix.transformPosition(this.left(), this.top(), new Vector2f());
Vector2f topRight = matrix.transformPosition(this.right(), this.top(), new Vector2f());
Vector2f bottomLeft = matrix.transformPosition(this.left(), this.bottom(), new Vector2f());
Vector2f bottomRight = matrix.transformPosition(this.right(), this.bottom(), new Vector2f());
float minX = Math.min(Math.min(topLeft.x(), bottomLeft.x()), Math.min(topRight.x(), bottomRight.x()));
float maxX = Math.max(Math.max(topLeft.x(), bottomLeft.x()), Math.max(topRight.x(), bottomRight.x()));
float minY = Math.min(Math.min(topLeft.y(), bottomLeft.y()), Math.min(topRight.y(), bottomRight.y()));
float maxY = Math.max(Math.max(topLeft.y(), bottomLeft.y()), Math.max(topRight.y(), bottomRight.y()));
return new ScreenRectangle(Mth.floor(minX), Mth.floor(minY), Mth.ceil(maxX - minX), Mth.ceil(maxY - minY));
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ScreenPosition()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.ceil(), Mth.floor()
- 引用位置: