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 { 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)) { if (withinBounds(x, y) || withinBounds(x + width, y) || withinBounds(x, y + height) || withinBounds(x + width, y + height)) {
return true return true
} }
// crossing at least one line
if (y in this.y .. this.y + height) { if (y in this.y .. this.y + height) {
if (x < this.x && x + width > this.x + this.width) { if (x < this.x && x + width > this.x + this.width) {
return true 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 { 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 scissor = false
var scissorPadding = DockProperty.EMPTY
var dock = Dock.NONE var dock = Dock.NONE
set(value) { set(value) {
if (field != value) { if (field != value) {
@ -461,11 +462,13 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (scissor) { if (scissor) {
val scale = minecraft.window.guiScale val scale = minecraft.window.guiScale
val (left, top, right, bottom) = scissorPadding
pushScissorRect( pushScissorRect(
(absoluteX * scale).toInt(), ((absoluteX + left) * scale).toInt(),
(absoluteY * scale).toInt(), ((absoluteY + top) * scale).toInt(),
(width * scale).toInt() + 1, ((width - right - left) * scale).toInt() + 1,
(height * 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)) { ) : 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) val scroll: DiscreteScrollBarPanel<out S> = DiscreteScrollBarPanel(screen, this, this::calculateMaxScroll, this::onScrolled, height = height)
var alignOnRight = true
var gridWidth: Int = gridWidth var gridWidth: Int = gridWidth
set(value) { set(value) {
if (field == value) if (field == value)
@ -183,7 +185,11 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
var x = 0 var x = 0
for (panel in sorted) { 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++ x++

View File

@ -33,27 +33,36 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
var renderScale: Int = calculateScale(width, height) var renderScale: Int = calculateScale(width, height)
) : EditablePanel<S>(screen, parent, x, y, width, height) { ) : EditablePanel<S>(screen, parent, x, y, width, height) {
init { 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) { override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
ExoSuitInventoryScreen.ENTITY_RECTANGLE.render(stack) 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 { companion object {