diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-01 03:42:51 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-03 21:05:51 +0200 |
commit | 5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (patch) | |
tree | a5b0a6fbc8878ae62bb2c3a01dbb255388353fda /src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt | |
parent | dff1f9c0e2b728dba902d72816104abccc61f511 (diff) | |
download | firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.gz firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.bz2 firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.zip |
[WIP] Remove LibGUI
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt index 30f280c..d1e223e 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt @@ -15,24 +15,31 @@ import io.github.notenoughupdates.moulconfig.gui.component.PanelComponent import io.github.notenoughupdates.moulconfig.observer.GetSetter -class FirmButtonComponent( +open class FirmButtonComponent( child: GuiComponent, + val isEnabled: GetSetter<Boolean> = GetSetter.constant(true), val action: Runnable, - val isEnabled: GetSetter<Boolean> = GetSetter.constant(true) ) : PanelComponent(child) { /* TODO: make use of vanillas built in nine slicer */ - val hoveredBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_highlighted.png")) - .cornerSize(5) - .cornerUv(5 / 200F, 5 / 20F) - .mode(NinePatch.Mode.STRETCHING) - .build() + val hoveredBg = + NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_highlighted.png")) + .cornerSize(5) + .cornerUv(5 / 200F, 5 / 20F) + .mode(NinePatch.Mode.STRETCHING) + .build() val unhoveredBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button.png")) .cornerSize(5) .cornerUv(5 / 200F, 5 / 20F) .mode(NinePatch.Mode.STRETCHING) .build() - val disabledBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_disabled.png")) + val disabledBg = + NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_disabled.png")) + .cornerSize(5) + .cornerUv(5 / 200F, 5 / 20F) + .mode(NinePatch.Mode.STRETCHING) + .build() + val activeBg = NinePatch.builder(MyResourceLocation("firmament", "textures/gui/sprites/widget/button_active.png")) .cornerSize(5) .cornerUv(5 / 200F, 5 / 20F) .mode(NinePatch.Mode.STRETCHING) @@ -59,12 +66,15 @@ class FirmButtonComponent( return false } + open fun getBackground(context: GuiImmediateContext): NinePatch<MyResourceLocation> = + if (!isEnabled.get()) disabledBg + else if (context.isHovered || isClicking) hoveredBg + else unhoveredBg + override fun render(context: GuiImmediateContext) { context.renderContext.pushMatrix() context.renderContext.drawNinePatch( - if (!isEnabled.get()) disabledBg - else if (context.isHovered || isClicking) hoveredBg - else unhoveredBg, + getBackground(context), 0f, 0f, context.width, context.height ) context.renderContext.translate(insets.toFloat(), insets.toFloat(), 0f) |