From 68d5b433918b8f35fc6870443e7c702b1b7120e9 Mon Sep 17 00:00:00 2001 From: twenty48 Date: Fri, 6 Dec 2024 10:29:09 +0530 Subject: [PATCH] cooler animations, DropdownGUI updates, ColorValue fixes and more. --- .../dropdown/components/CategoryComponent.kt | 9 ++++---- .../ui/dropdown/components/ModuleComponent.kt | 21 +++++++++---------- .../components/values/ColorValueComponent.kt | 7 ++++++- .../components/values/ModeValueComponent.kt | 5 ++++- .../components/values/NumberValueComponent.kt | 5 ++--- .../dev/blend/util/animations/Animations.kt | 2 ++ src/main/kotlin/dev/blend/value/Value.kt | 2 +- .../kotlin/dev/blend/value/impl/ColorValue.kt | 6 +++++- 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt index e1df1ff..318b2f3 100644 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt +++ b/src/main/kotlin/dev/blend/ui/dropdown/components/CategoryComponent.kt @@ -18,6 +18,7 @@ class CategoryComponent( val components = mutableListOf() private val expandAnimation = SineOutAnimation() + private val expandToggleAnimation = SineOutAnimation() private val initialHeight = height; private var expanded = true @@ -54,18 +55,18 @@ class CategoryComponent( it.height } } - expandAnimation.animate( - if (expanded) veryRealHeight else initialHeight - ) DrawUtil.resetScissor() DrawUtil.restore() - if (canAnimateExpansion()) { this.height = expandAnimation.get() } else { expandAnimation.set(veryRealHeight) this.height = veryRealHeight } + expandAnimation.animate( + if (expanded) veryRealHeight else initialHeight + ) + expandToggleAnimation.animate(if (expanded) 1.0 else 0.0) } override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt index 41321cd..71399d4 100644 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt +++ b/src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt @@ -27,7 +27,9 @@ class ModuleComponent( val components = mutableListOf() val expandAnimation = SineOutAnimation() - private val expandAnimation2 = SineOutAnimation() + private val toggleAnimation = SineOutAnimation() + private val lastElementAnimation = SineOutAnimation() + private val expandToggleAnimation = SineOutAnimation() private val initialHeight = height private var expanded = false private var last = false @@ -53,13 +55,7 @@ class ModuleComponent( override fun render(mouseX: Int, mouseY: Int) { DrawUtil.save() DrawUtil.intersectScissor(x, y, width, height) - if (module.get()) { - if (last) { - DrawUtil.roundedRect(x, y, width, initialHeight, doubleArrayOf(0.0, 0.0, 5.0, 5.0), ColorUtil.applyOpacity(ThemeHandler.getPrimary(), 0.75)) - } else { - DrawUtil.rect(x, y, width, initialHeight, ColorUtil.applyOpacity(ThemeHandler.getPrimary(), 0.75)) - } - } + DrawUtil.roundedRect(x, y, width, initialHeight, doubleArrayOf(0.0, 0.0, lastElementAnimation.get(), lastElementAnimation.get()), ColorUtil.applyOpacity(ThemeHandler.getPrimary(), toggleAnimation.get())) DrawUtil.drawString(module.name, x + (width / 2), y + (initialHeight / 2), 12, ThemeHandler.getTextColor(), Alignment.CENTER) var veryRealHeight = initialHeight @@ -72,9 +68,6 @@ class ModuleComponent( veryRealHeight += it.height } } - expandAnimation.animate( - if (expanded) veryRealHeight else initialHeight - ) DrawUtil.restore() // if (canAnimateExpansion()) { @@ -84,6 +77,12 @@ class ModuleComponent( // this.height = veryRealHeight // } last = parent.components.last() == this && !expanded + expandAnimation.animate( + if (expanded) veryRealHeight else initialHeight + ) + expandToggleAnimation.animate(if (expanded) 1.0 else 0.0) + toggleAnimation.animate(if (module.get()) 0.75 else 0.0) + lastElementAnimation.animate(if (last) 5.0 else 0.0) } override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt index af54d98..a9cbb45 100644 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt +++ b/src/main/kotlin/dev/blend/ui/dropdown/components/values/ColorValueComponent.kt @@ -18,7 +18,12 @@ class ColorValueComponent( } override fun render(mouseX: Int, mouseY: Int) { - DrawUtil.drawString(value.name, x + 5.0, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) + val offset = 5.0 + with(DrawUtil) { + drawString(value.name, x + 5.0, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) + roundedRect(x + (width - offset), y + (height / 2.0), 20.0, height - (offset * 2.0), 2.0, value.get(), Alignment.CENTER_RIGHT) + roundedRect(x + (width - offset), y + (height / 2.0), 20.0, height - (offset * 2.0), 2.0, 1.0, ThemeHandler.getContrast(), Alignment.CENTER_RIGHT) + } } override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt index 0df7636..9d7745a 100644 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt +++ b/src/main/kotlin/dev/blend/ui/dropdown/components/values/ModeValueComponent.kt @@ -19,7 +19,10 @@ class ModeValueComponent( } override fun render(mouseX: Int, mouseY: Int) { - DrawUtil.drawString(value.name, x + 5.0, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) + with(DrawUtil) { + drawString(value.name, x + padding, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT) + drawString(value.get(), (x + width) - padding, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_RIGHT) + } } override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean { diff --git a/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt b/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt index 441e8bd..d5290c6 100644 --- a/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt +++ b/src/main/kotlin/dev/blend/ui/dropdown/components/values/NumberValueComponent.kt @@ -3,8 +3,7 @@ package dev.blend.ui.dropdown.components.values import dev.blend.handler.impl.ThemeHandler import dev.blend.ui.dropdown.components.AbstractValueComponent import dev.blend.ui.dropdown.components.ModuleComponent -import dev.blend.util.animations.CubicOutAnimation -import dev.blend.util.animations.SineOutAnimation +import dev.blend.util.animations.* import dev.blend.util.render.Alignment import dev.blend.util.render.ColorUtil import dev.blend.util.render.DrawUtil @@ -17,7 +16,7 @@ class NumberValueComponent( parent, value, height = 30.0 ) { - private val dragAnimation = CubicOutAnimation() + private val dragAnimation = LinearAnimation() private val dragDependentAnimation = SineOutAnimation() private val selectAnimation = SineOutAnimation() private var held = false diff --git a/src/main/kotlin/dev/blend/util/animations/Animations.kt b/src/main/kotlin/dev/blend/util/animations/Animations.kt index e413529..ed97a7f 100644 --- a/src/main/kotlin/dev/blend/util/animations/Animations.kt +++ b/src/main/kotlin/dev/blend/util/animations/Animations.kt @@ -13,3 +13,5 @@ class SineOutAnimation(duration: Double = 200.0): AbstractAnimation( { x -> sin( class SineInOutAnimation(duration: Double = 200.0): AbstractAnimation( { x -> -(cos(PI * x) - 1) / 2 }, duration) class CubicOutAnimation(duration: Double = 200.0): AbstractAnimation( { x -> 1 - (1 - x).pow(3.0) }, duration) + +class ExpoOutAnimation(duration: Double = 200.0): AbstractAnimation( { x -> if (x == 1.0) 1.0 else 1.0 - 2.0.pow(-10.0 * x) }, duration) diff --git a/src/main/kotlin/dev/blend/value/Value.kt b/src/main/kotlin/dev/blend/value/Value.kt index 21090f3..468676c 100644 --- a/src/main/kotlin/dev/blend/value/Value.kt +++ b/src/main/kotlin/dev/blend/value/Value.kt @@ -9,12 +9,12 @@ abstract class Value( private val defaultValue: T, var visibility: () -> Boolean, ): ValueHolder() { + protected var value: T = defaultValue init { parent.values.add(this) } - public var value = defaultValue open fun get(): T { return value } diff --git a/src/main/kotlin/dev/blend/value/impl/ColorValue.kt b/src/main/kotlin/dev/blend/value/impl/ColorValue.kt index 5e09d21..6c93ed6 100644 --- a/src/main/kotlin/dev/blend/value/impl/ColorValue.kt +++ b/src/main/kotlin/dev/blend/value/impl/ColorValue.kt @@ -17,6 +17,10 @@ class ColorValue( var saturation: Float = 0.0f var brightness: Float = 1.0f + init { + set(defaultValue) + } + fun set(hsb: FloatArray) { set(hsb[0], hsb[1], hsb[2]) } @@ -31,7 +35,7 @@ class ColorValue( return Color.getHSBColor(hue, saturation, brightness) } override fun set(value: Color) { - val hsb = floatArrayOf() + val hsb = floatArrayOf(1f, 1f, 1f) set(Color.RGBtoHSB(value.red, value.green, value.blue, hsb)) } override fun getJsonObject(): JsonObject {