Make EntityRendererPanel clip 1 pixel on each side

This commit is contained in:
DBotThePony 2022-09-13 18:20:41 +07:00
parent 0d45f0b612
commit 85ebbbf905
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 44 additions and 23 deletions

View File

@ -415,10 +415,12 @@ data class ScissorRect(val x: Int, val y: Int, val width: Int, val height: Int)
}
fun cross(x: Int, y: Int, width: Int, height: Int): Boolean {
// corssing any of rect points
if (withinBounds(x, y) || withinBounds(x + width, y) || withinBounds(x, y + height) || withinBounds(x + width, y + height)) {
return true
}
// crossing at least one line
if (y in this.y .. this.y + height) {
if (x < this.x && x + width > this.x + this.width) {
return true
@ -429,7 +431,8 @@ data class ScissorRect(val x: Int, val y: Int, val width: Int, val height: Int)
}
}
return false
// final test: check if scissor rect is completely inside provided rect
return this.x in x .. x + width && this.y in y .. y + height
}
fun crossScaled(x: Float, y: Float, width: Float, height: Float): Boolean {

View File

@ -179,6 +179,7 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
// Обрезать отрисовку потомков?
var scissor = false
var scissorPadding = DockProperty.EMPTY
var dock = Dock.NONE
set(value) {
if (field != value) {
@ -461,11 +462,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (scissor) {
val scale = minecraft.window.guiScale
val (left, top, right, bottom) = scissorPadding
pushScissorRect(
(absoluteX * scale).toInt(),
(absoluteY * scale).toInt(),
(width * scale).toInt() + 1,
(height * scale).toInt() + 1,
((absoluteX + left) * scale).toInt(),
((absoluteY + top) * scale).toInt(),
((width - right - left) * scale).toInt() + 1,
((height - bottom - top) * scale).toInt() + 1,
)
}

View File

@ -34,6 +34,8 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
) : EditablePanel<S>(screen, parent, x, y, gridWidth * (SQUARE_THIN.width + 2f), gridHeight * (SQUARE_THIN.height + 2f)) {
val scroll: DiscreteScrollBarPanel<out S> = DiscreteScrollBarPanel(screen, this, this::calculateMaxScroll, this::onScrolled, height = height)
var alignOnRight = true
var gridWidth: Int = gridWidth
set(value) {
if (field == value)
@ -183,7 +185,11 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
var x = 0
for (panel in sorted) {
panel.setPos((gridWidth - x - 1) * 26f, y * 26f)
if (alignOnRight) {
panel.setPos((gridWidth - x - 1) * 26f, y * 26f)
} else {
panel.setPos(x * 26f, y * 26f)
}
x++

View File

@ -33,27 +33,36 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
var renderScale: Int = calculateScale(width, height)
) : EditablePanel<S>(screen, parent, x, y, width, height) {
init {
scissor = true
dockPadding = DockProperty(1f, 1f, 1.5f, 1f)
}
val canvas = object : EditablePanel<S>(screen, this@EntityRendererPanel) {
init {
dock = Dock.FILL
scissor = true
}
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
if (entity.isDeadOrDying) {
return
}
val renderX = absoluteX.toInt() + width.toInt() / 2
val renderY = absoluteY.toInt() + (height * 0.9f).toInt()
InventoryScreen.renderEntityInInventory(
renderX,
renderY,
renderScale,
renderX - mouseX,
absoluteY + height * 0.15f - mouseY,
entity
)
}
}
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
ExoSuitInventoryScreen.ENTITY_RECTANGLE.render(stack)
if (entity.isDeadOrDying) {
return
}
val renderX = absoluteX.toInt() + width.toInt() / 2
val renderY = absoluteY.toInt() + (height * 0.9f).toInt()
InventoryScreen.renderEntityInInventory(
renderX,
renderY,
renderScale,
renderX - mouseX,
absoluteY + height * 0.15f - mouseY,
entity
)
}
companion object {