StretchingRectangleElement
This commit is contained in:
parent
c28c66b56b
commit
65c36e44fa
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client.render
|
|||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
|
||||||
|
|
||||||
class SkinGrid(
|
class SkinGrid(
|
||||||
val texture: ResourceLocation,
|
val texture: ResourceLocation,
|
||||||
@ -63,6 +64,13 @@ fun ResourceLocation.element(
|
|||||||
textureHeight: Float = 256f
|
textureHeight: Float = 256f
|
||||||
) = SkinElement(this, x, y, w, h, textureWidth, textureHeight)
|
) = SkinElement(this, x, y, w, h, textureWidth, textureHeight)
|
||||||
|
|
||||||
|
fun ResourceLocation.pixel(
|
||||||
|
x: Float,
|
||||||
|
y: Float,
|
||||||
|
textureWidth: Float = 256f,
|
||||||
|
textureHeight: Float = 256f
|
||||||
|
) = SkinElement(this, x, y, 1f, 1f, textureWidth, textureHeight)
|
||||||
|
|
||||||
class SkinElement @JvmOverloads constructor(
|
class SkinElement @JvmOverloads constructor(
|
||||||
val texture: ResourceLocation,
|
val texture: ResourceLocation,
|
||||||
val x: Float,
|
val x: Float,
|
||||||
@ -234,3 +242,44 @@ class SkinElement @JvmOverloads constructor(
|
|||||||
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
|
winding: UVWindingOrder = UVWindingOrder.U0_V0_U1_V1
|
||||||
) = renderRawPartial(stack, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), winding)
|
) = renderRawPartial(stack, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), winding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StretchingRectangleElement(
|
||||||
|
val topLeft: SkinElement,
|
||||||
|
val topRight: SkinElement,
|
||||||
|
val bottomLeft: SkinElement,
|
||||||
|
val bottomRight: SkinElement,
|
||||||
|
val left: SkinElement,
|
||||||
|
val right: SkinElement,
|
||||||
|
val top: SkinElement,
|
||||||
|
val bottom: SkinElement,
|
||||||
|
val middle: SkinElement,
|
||||||
|
val padding: DockProperty = DockProperty.EMPTY
|
||||||
|
) {
|
||||||
|
fun render(
|
||||||
|
stack: PoseStack,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float,
|
||||||
|
height: Float,
|
||||||
|
) {
|
||||||
|
val bgWidth = width - topLeft.w.coerceAtMost(bottomLeft.w) - topRight.w.coerceAtMost(bottomRight.w) - padding.left - padding.right
|
||||||
|
val bgHeight = height - topLeft.h.coerceAtMost(bottomLeft.h) - topRight.h.coerceAtMost(bottomRight.h) - padding.top - padding.bottom
|
||||||
|
|
||||||
|
if (bgWidth > 0 && bgHeight > 0) {
|
||||||
|
middle.render(stack, x + topLeft.w + padding.left, y + topLeft.h + padding.top, bgWidth, bgHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
top.render(stack, x + topLeft.w, y, width = width - topLeft.w - topRight.w)
|
||||||
|
bottom.render(stack, x + bottomLeft.w, y + height - bottom.h, width = width - bottomLeft.w - bottomRight.w)
|
||||||
|
|
||||||
|
left.render(stack, x, y + topLeft.h, height = height - topLeft.h - bottomLeft.h)
|
||||||
|
right.render(stack, x + width - right.h, y + topRight.h, height = height - topRight.h - bottomRight.h)
|
||||||
|
|
||||||
|
topLeft.render(stack, x, y)
|
||||||
|
topRight.render(stack, x + width - topRight.w, y)
|
||||||
|
|
||||||
|
bottomLeft.render(stack, x, y + height - bottomLeft.h)
|
||||||
|
bottomRight.render(stack, x + width - bottomRight.w, y + height - bottomLeft.h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,11 @@ import kotlin.math.max
|
|||||||
data class ScreenPos(val x: Float, val y: Float)
|
data class ScreenPos(val x: Float, val y: Float)
|
||||||
|
|
||||||
@JvmRecord
|
@JvmRecord
|
||||||
data class DockProperty @JvmOverloads constructor(val left: Float = 0f, val top: Float = 0f, val right: Float = 0f, val bottom: Float = 0f)
|
data class DockProperty @JvmOverloads constructor(val left: Float = 0f, val top: Float = 0f, val right: Float = 0f, val bottom: Float = 0f) {
|
||||||
|
companion object {
|
||||||
|
val EMPTY = DockProperty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class Dock {
|
enum class Dock {
|
||||||
NONE, LEFT, RIGHT, TOP, BOTTOM, FILL
|
NONE, LEFT, RIGHT, TOP, BOTTOM, FILL
|
||||||
@ -127,7 +131,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
field = value
|
field = value
|
||||||
parent?.needsInvalidation = true
|
parent?.needsInvalidation = true
|
||||||
}
|
}
|
||||||
var dockMargin = DockProperty()
|
var dockMargin = DockProperty.EMPTY
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field != value) {
|
if (field != value) {
|
||||||
parent?.needsInvalidation = true
|
parent?.needsInvalidation = true
|
||||||
@ -135,7 +139,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
|
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
var dockPadding = DockProperty()
|
var dockPadding = DockProperty.EMPTY
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field != value) {
|
if (field != value) {
|
||||||
parent?.needsInvalidation = true
|
parent?.needsInvalidation = true
|
||||||
|
@ -79,30 +79,30 @@ open class FramePanel(
|
|||||||
if (isActive) {
|
if (isActive) {
|
||||||
width = frameTabPosition.active_width
|
width = frameTabPosition.active_width
|
||||||
height = frameTabPosition.active_height
|
height = frameTabPosition.active_height
|
||||||
window_background.render(stack, 2f, 2f, width - 4, height - 2)
|
RECTANGLE.middle.render(stack, 2f, 2f, width - 4, height - 2)
|
||||||
} else {
|
} else {
|
||||||
width = frameTabPosition.width
|
width = frameTabPosition.width
|
||||||
height = frameTabPosition.height
|
height = frameTabPosition.height
|
||||||
tab_background.render(stack, 2f, 2f, width - 4, height - 2)
|
tabBackground.render(stack, 2f, 2f, width - 4, height - 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
top_window_border.renderW(stack, 3f, 0f, width - 6)
|
RECTANGLE.top.renderW(stack, 3f, 0f, width - 6)
|
||||||
left_window_border.renderH(stack, 0f, 3f, (height - if (isActive) if (initial) 2 else 4 else 3))
|
RECTANGLE.left.renderH(stack, 0f, 3f, (height - if (isActive) if (initial) 2 else 4 else 3))
|
||||||
|
|
||||||
right_window_border.renderH(stack, width - right_window_border.w, 3f, (height - if (isActive) 4 else 3))
|
RECTANGLE.right.renderH(stack, width - RECTANGLE.right.w, 3f, (height - if (isActive) 4 else 3))
|
||||||
|
|
||||||
top_left_window_corner.render(stack, 0f, 0f)
|
RECTANGLE.topLeft.render(stack, 0f, 0f)
|
||||||
top_right_window_corner.render(stack, width - top_right_window_corner.w, 0f)
|
RECTANGLE.topRight.render(stack, width - RECTANGLE.topRight.w, 0f)
|
||||||
|
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
if (!initial) {
|
if (!initial) {
|
||||||
tab_left_connection.render(stack, 0f, height - tab_left_connection.h - 1)
|
tabLeftConnection.render(stack, 0f, height - tabLeftConnection.h - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
tab_right_connection.render(
|
tabRightConnection.render(
|
||||||
stack,
|
stack,
|
||||||
width - tab_right_connection.w,
|
width - tabRightConnection.w,
|
||||||
height - tab_left_connection.h - 1
|
height - tabLeftConnection.h - 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,29 +238,7 @@ open class FramePanel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
// background
|
RECTANGLE.render(stack, width = width, height = height)
|
||||||
// RenderSystem.disableDepthTest();
|
|
||||||
val bgWidth = width - 4
|
|
||||||
val bgHeight = height - 4
|
|
||||||
|
|
||||||
// background
|
|
||||||
if (bgWidth > 0 && bgHeight > 0) {
|
|
||||||
window_background.render(stack, 3f, 3f, bgWidth, bgHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
// borders
|
|
||||||
left_window_border.render(stack, 0f, 4f, 3f, height - 8)
|
|
||||||
right_window_border.renderRaw(stack, width - 3, 4f, 3f, height - 6)
|
|
||||||
top_window_border.renderRaw(stack, 4f, 0f, width - 8, 3f)
|
|
||||||
bottom_window_border.renderRaw(stack, 4f, height - 3, width - 8, 3f)
|
|
||||||
|
|
||||||
// corners
|
|
||||||
top_left_window_corner.renderRaw(stack)
|
|
||||||
top_right_window_corner.renderRaw(stack, x = width - 6)
|
|
||||||
bottom_left_window_corner.renderRaw(stack, y = height - 6)
|
|
||||||
bottom_right_window_corner.renderRaw(stack, x = width - 6, y = height - 6)
|
|
||||||
|
|
||||||
// RenderSystem.enableDepthTest();
|
|
||||||
|
|
||||||
// title
|
// title
|
||||||
RenderSystem.depthFunc(GL30.GL_ALWAYS)
|
RenderSystem.depthFunc(GL30.GL_ALWAYS)
|
||||||
@ -282,17 +260,21 @@ open class FramePanel(
|
|||||||
const val PADDING = 8f
|
const val PADDING = 8f
|
||||||
const val PADDING_TOP = 14f
|
const val PADDING_TOP = 14f
|
||||||
|
|
||||||
val top_left_window_corner = WidgetLocation.WIDGETS.element(x = 18f, y = 0f, w = 6f, h = 6f)
|
val RECTANGLE = StretchingRectangleElement(
|
||||||
val top_right_window_corner = WidgetLocation.WIDGETS.element(x = 24f, y = 0f, w = 6f, h = 6f)
|
topLeft = WidgetLocation.WIDGETS.element(x = 18f, y = 0f, w = 6f, h = 6f),
|
||||||
val left_window_border = WidgetLocation.WIDGETS.element(x = 18f, y = 4f, w = 3f, h = 5f)
|
topRight = WidgetLocation.WIDGETS.element(x = 24f, y = 0f, w = 6f, h = 6f),
|
||||||
val right_window_border = WidgetLocation.WIDGETS.element(x = 27f, y = 3f, w = 3f, h = 5f)
|
left = WidgetLocation.WIDGETS.element(x = 18f, y = 4f, w = 3f, h = 5f),
|
||||||
val top_window_border = WidgetLocation.WIDGETS.element(x = 22f, y = 0f, w = 5f, h = 3f)
|
right = WidgetLocation.WIDGETS.element(x = 25f, y = 3f, w = 5f, h = 5f),
|
||||||
val window_background = WidgetLocation.WIDGETS.element(x = 30f, y = 12f, w = 6f, h = 6f)
|
top = WidgetLocation.WIDGETS.element(x = 22f, y = 0f, w = 5f, h = 3f),
|
||||||
val tab_right_connection = WidgetLocation.WIDGETS.element(x = 30f, y = 0f, w = 3f, h = 5f)
|
bottomLeft = WidgetLocation.WIDGETS.element(x = 18f, y = 6f, w = 6f, h = 6f),
|
||||||
val tab_left_connection = WidgetLocation.WIDGETS.element(x = 33f, y = 0f, w = 3f, h = 5f)
|
bottomRight = WidgetLocation.WIDGETS.element(x = 24f, y = 6f, w = 6f, h = 6f),
|
||||||
val tab_background = WidgetLocation.WIDGETS.element(x = 30f, y = 6f, w = 6f, h = 6f)
|
bottom = WidgetLocation.WIDGETS.element(x = 21f, y = 9f, w = 5f, h = 3f),
|
||||||
val bottom_left_window_corner = WidgetLocation.WIDGETS.element(x = 18f, y = 6f, w = 6f, h = 6f)
|
middle = WidgetLocation.WIDGETS.element(x = 30f, y = 12f, w = 6f, h = 6f),
|
||||||
val bottom_right_window_corner = WidgetLocation.WIDGETS.element(x = 24f, y = 6f, w = 6f, h = 6f)
|
padding = DockProperty(-3f, -3f, -3f, -3f)
|
||||||
val bottom_window_border = WidgetLocation.WIDGETS.element(x = 21f, y = 9f, w = 5f, h = 3f)
|
)
|
||||||
|
|
||||||
|
val tabRightConnection = WidgetLocation.WIDGETS.element(x = 30f, y = 0f, w = 3f, h = 5f)
|
||||||
|
val tabLeftConnection = WidgetLocation.WIDGETS.element(x = 33f, y = 0f, w = 3f, h = 5f)
|
||||||
|
val tabBackground = WidgetLocation.WIDGETS.element(x = 30f, y = 6f, w = 6f, h = 6f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user