Skip to content

Commit

Permalink
cooler animations, DropdownGUI updates, ColorValue fixes and more.
Browse files Browse the repository at this point in the history
  • Loading branch information
twenty48lol committed Dec 6, 2024
1 parent 60a5bc4 commit 68d5b43
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CategoryComponent(

val components = mutableListOf<ModuleComponent>()
private val expandAnimation = SineOutAnimation()
private val expandToggleAnimation = SineOutAnimation()
private val initialHeight = height;
private var expanded = true

Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 10 additions & 11 deletions src/main/kotlin/dev/blend/ui/dropdown/components/ModuleComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class ModuleComponent(

val components = mutableListOf<AbstractValueComponent>()
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
Expand All @@ -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
Expand All @@ -72,9 +68,6 @@ class ModuleComponent(
veryRealHeight += it.height
}
}
expandAnimation.animate(
if (expanded) veryRealHeight else initialHeight
)
DrawUtil.restore()

// if (canAnimateExpansion()) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/dev/blend/util/animations/Animations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/blend/value/Value.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ abstract class Value<T>(
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
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/dev/blend/value/impl/ColorValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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 {
Expand Down

0 comments on commit 68d5b43

Please sign in to comment.