diff --git a/src/main/kotlin/net/shadowfacts/asmr/TestCacaoScreen.kt b/src/main/kotlin/net/shadowfacts/asmr/TestCacaoScreen.kt index 15aa5ea..2f5a506 100644 --- a/src/main/kotlin/net/shadowfacts/asmr/TestCacaoScreen.kt +++ b/src/main/kotlin/net/shadowfacts/asmr/TestCacaoScreen.kt @@ -8,8 +8,8 @@ import net.shadowfacts.cacao.Window import net.shadowfacts.cacao.geometry.Axis import net.shadowfacts.cacao.geometry.Size import net.shadowfacts.cacao.util.Color -import net.shadowfacts.cacao.util.NinePatchTexture -import net.shadowfacts.cacao.util.Texture +import net.shadowfacts.cacao.util.texture.NinePatchTexture +import net.shadowfacts.cacao.util.texture.Texture import net.shadowfacts.cacao.view.* import net.shadowfacts.cacao.view.button.DropdownButton @@ -26,8 +26,7 @@ class TestCacaoScreen: CacaoScreen() { val red = stack.addArrangedSubview(TextureView(Texture(Identifier("textures/block/birch_log_top.png"), 0, 0, 16, 16)).apply { intrinsicContentSize = Size(50.0, 50.0) }) - val buttonNinePatch = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 66), 3, 3, 194, 14) - val green = stack.addArrangedSubview(NinePatchView(buttonNinePatch).apply { + val green = stack.addArrangedSubview(NinePatchView(NinePatchTexture.PANEL_BG).apply { intrinsicContentSize = Size(75.0, 100.0) }) val blue = stack.addArrangedSubview(View().apply { diff --git a/src/main/kotlin/net/shadowfacts/cacao/util/RenderHelper.kt b/src/main/kotlin/net/shadowfacts/cacao/util/RenderHelper.kt index a3f2e64..8d7c807 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/util/RenderHelper.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/util/RenderHelper.kt @@ -8,6 +8,7 @@ import net.minecraft.client.render.VertexFormats import net.minecraft.client.sound.PositionedSoundInstance import net.minecraft.sound.SoundEvent import net.shadowfacts.cacao.geometry.Rect +import net.shadowfacts.cacao.util.texture.Texture import org.lwjgl.opengl.GL11 /** diff --git a/src/main/kotlin/net/shadowfacts/cacao/util/NinePatchTexture.kt b/src/main/kotlin/net/shadowfacts/cacao/util/texture/NinePatchTexture.kt similarity index 72% rename from src/main/kotlin/net/shadowfacts/cacao/util/NinePatchTexture.kt rename to src/main/kotlin/net/shadowfacts/cacao/util/texture/NinePatchTexture.kt index 89dea70..d922c24 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/util/NinePatchTexture.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/util/texture/NinePatchTexture.kt @@ -1,4 +1,6 @@ -package net.shadowfacts.cacao.util +package net.shadowfacts.cacao.util.texture + +import net.minecraft.util.Identifier /** * Helper class that represents a texture that can be divided into nine pieces (4 corners, 4 edges, and the center) @@ -15,12 +17,20 @@ package net.shadowfacts.cacao.util */ data class NinePatchTexture(val texture: Texture, val cornerWidth: Int, val cornerHeight: Int, val centerWidth: Int, val centerHeight: Int) { + companion object { + val PANEL_BG = NinePatchTexture(Texture(Identifier("textures/gui/demo_background.png"), 0, 0), 5, 5, 238, 156) + + val BUTTON_BG = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 66), 3, 3, 194, 14) + val BUTTON_HOVERED_BG = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 86), 3, 3, 194, 14) + val BUTTON_DISABLED_BG = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 46), 3, 3, 194, 14) + } + // Corners val topLeft by lazy { texture } val topRight by lazy { - Texture(texture.location, texture.u + cornerWidth + centerWidth, texture.v, texture.width, texture.height) + Texture(texture.location, texture.u + cornerWidth + centerWidth, texture.v, texture.width, texture.height) } val bottomLeft by lazy { Texture(texture.location, texture.u, texture.v + cornerHeight + centerHeight, texture.width, texture.height) diff --git a/src/main/kotlin/net/shadowfacts/cacao/util/Texture.kt b/src/main/kotlin/net/shadowfacts/cacao/util/texture/Texture.kt similarity index 93% rename from src/main/kotlin/net/shadowfacts/cacao/util/Texture.kt rename to src/main/kotlin/net/shadowfacts/cacao/util/texture/Texture.kt index b1fd37e..1840fd7 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/util/Texture.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/util/texture/Texture.kt @@ -1,4 +1,4 @@ -package net.shadowfacts.cacao.util +package net.shadowfacts.cacao.util.texture import net.minecraft.util.Identifier diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/NinePatchView.kt b/src/main/kotlin/net/shadowfacts/cacao/view/NinePatchView.kt index c5d5c4d..9c6cf21 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/NinePatchView.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/NinePatchView.kt @@ -2,7 +2,7 @@ package net.shadowfacts.cacao.view import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Rect -import net.shadowfacts.cacao.util.NinePatchTexture +import net.shadowfacts.cacao.util.texture.NinePatchTexture import net.shadowfacts.cacao.util.RenderHelper import net.shadowfacts.cacao.util.properties.ResettableLazyProperty diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/TextureView.kt b/src/main/kotlin/net/shadowfacts/cacao/view/TextureView.kt index 155f29a..ffab001 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/TextureView.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/TextureView.kt @@ -2,7 +2,7 @@ package net.shadowfacts.cacao.view import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.util.RenderHelper -import net.shadowfacts.cacao.util.Texture +import net.shadowfacts.cacao.util.texture.Texture /** * A helper class for drawing a [Texture] in a view. diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt b/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt index 36f4098..ca428c0 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt @@ -1,11 +1,9 @@ package net.shadowfacts.cacao.view.button -import net.minecraft.util.Identifier import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.util.MouseButton -import net.shadowfacts.cacao.util.NinePatchTexture +import net.shadowfacts.cacao.util.texture.NinePatchTexture import net.shadowfacts.cacao.util.RenderHelper -import net.shadowfacts.cacao.util.Texture import net.shadowfacts.cacao.view.NinePatchView import net.shadowfacts.cacao.view.View import net.shadowfacts.kiwidsl.dsl @@ -23,12 +21,6 @@ import net.shadowfacts.kiwidsl.dsl */ abstract class AbstractButton>(val content: View, val padding: Double = 4.0): View() { - companion object { - val DEFAULT_BG = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 66), 3, 3, 194, 14) - val HOVERED_BG = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 86), 3, 3, 194, 14) - val DISABLED_BG = NinePatchTexture(Texture(Identifier("textures/gui/widgets.png"), 0, 46), 3, 3, 194, 14) - } - /** * The function that handles when this button is clicked. * The parameter is the type of the concrete button implementation that was used. @@ -50,19 +42,19 @@ abstract class AbstractButton>(val content: View, val * If a [backgroundColor] is specified, it will be drawn behind the background View and thus not visible * unless the background view is not fully opaque. */ - var background: View? = NinePatchView(DEFAULT_BG) + var background: View? = NinePatchView(NinePatchTexture.BUTTON_BG) /** * The background to draw when the button is hovered over by the mouse. * If `null`, the normal [background] will be used. * @see background */ - var hoveredBackground: View? = NinePatchView(HOVERED_BG) + var hoveredBackground: View? = NinePatchView(NinePatchTexture.BUTTON_HOVERED_BG) /** * The background to draw when the button is [disabled]. * If `null`, the normal [background] will be used. * @see background */ - var disabledBackground: View? = NinePatchView(DISABLED_BG) + var disabledBackground: View? = NinePatchView(NinePatchTexture.BUTTON_DISABLED_BG) override fun wasAdded() { solver.dsl { diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/button/DropdownButton.kt b/src/main/kotlin/net/shadowfacts/cacao/view/button/DropdownButton.kt index 3ae8123..d100ccf 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/button/DropdownButton.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/button/DropdownButton.kt @@ -6,8 +6,8 @@ import net.shadowfacts.cacao.geometry.Axis import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Rect import net.shadowfacts.cacao.util.MouseButton -import net.shadowfacts.cacao.util.NinePatchTexture -import net.shadowfacts.cacao.util.Texture +import net.shadowfacts.cacao.util.texture.NinePatchTexture +import net.shadowfacts.cacao.util.texture.Texture import net.shadowfacts.cacao.util.properties.ResettableLazyProperty import net.shadowfacts.cacao.view.NinePatchView import net.shadowfacts.cacao.view.StackView @@ -89,7 +89,7 @@ class DropdownButton( private fun showDropdown() { val dropdownWindow = window.screen.addWindow(Window()) - val dropdownBackground = dropdownWindow.addView(NinePatchView(DEFAULT_BG).apply { + val dropdownBackground = dropdownWindow.addView(NinePatchView(NinePatchTexture.BUTTON_BG).apply { zIndex = -1.0 }) val stack = dropdownWindow.addView(StackView(Axis.VERTICAL, StackView.Distribution.LEADING)) @@ -100,8 +100,8 @@ class DropdownButton( val contentView = createView(value) val button = stack.addArrangedSubview(Button(contentView, padding).apply { background = null - hoveredBackground = DropdownItemBackgroundView(index == 0, index == last, HOVERED_BG) - disabledBackground = DropdownItemBackgroundView(index == 0, index == last, DISABLED_BG) + hoveredBackground = DropdownItemBackgroundView(index == 0, index == last, NinePatchTexture.BUTTON_HOVERED_BG) + disabledBackground = DropdownItemBackgroundView(index == 0, index == last, NinePatchTexture.BUTTON_DISABLED_BG) disabled = value == this@DropdownButton.value handler = { dropdownWindow.removeFromScreen() diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/button/ToggleButton.kt b/src/main/kotlin/net/shadowfacts/cacao/view/button/ToggleButton.kt index 24766af..020b17b 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/button/ToggleButton.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/button/ToggleButton.kt @@ -4,7 +4,7 @@ import net.minecraft.util.Identifier import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Size import net.shadowfacts.cacao.util.MouseButton -import net.shadowfacts.cacao.util.Texture +import net.shadowfacts.cacao.util.texture.Texture import net.shadowfacts.cacao.view.TextureView /**