Skip to content

Commit

Permalink
more stuff, sliders and toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
twenty48lol committed Dec 5, 2024
1 parent 94d40b8 commit 60a5bc4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/dev/blend/module/impl/client/ThemeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import dev.blend.module.api.Category
import dev.blend.module.api.ModuleInfo
import dev.blend.value.impl.ColorValue
import dev.blend.value.impl.ModeValue
import dev.blend.value.impl.NumberValue
import java.awt.Color

@ModuleInfo(
Expand All @@ -16,7 +17,8 @@ object ThemeModule: Module() {

val accent = ColorValue("Accent", this, Color(0, 160, 255))
val secondary = ColorValue("Secondary", this, Color(160, 0, 255))
// val theme = ModeValue("Theme", this, arrayOf("Dark", "Light"))
val theme = ModeValue("Theme", this, arrayOf("Dark", "Light"))
val gradientSpeed = NumberValue("Speed", this, 500.0, 200.0, 2000.0, 100.0)

override fun onEnable() {
this.set(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ class ModuleComponent(
it.x = x
it.y = y + veryRealHeight
it.width = width
it.render(mouseX, mouseY)
veryRealHeight += it.height
if (it.value.visibility()) {
it.render(mouseX, mouseY)
veryRealHeight += it.height
}
}
expandAnimation.animate(
if (expanded) veryRealHeight else initialHeight
Expand Down Expand Up @@ -103,10 +105,20 @@ class ModuleComponent(
}

override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean {
components.forEach {
if (it.release(mouseX, mouseY, mouseButton)) {
return true
}
}
return false
}

override fun key(key: Int, scancode: Int, modifiers: Int): Boolean {
components.forEach {
if (it.key(key, scancode, modifiers)) {
return true
}
}
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BooleanValueComponent(
) {

private val toggleAnimation = SineOutAnimation()
private val clickAnimation = SineOutAnimation()
private val toggleDependentAnimation = SineOutAnimation()

override fun init() {

Expand All @@ -30,17 +30,16 @@ class BooleanValueComponent(
val pillY = y + (height / 2.0)
val indicatorRadius = 6.0
val indicatorOffset = 1.0
val indicatorX = (pillX - ((indicatorRadius / 2) + indicatorOffset)) - ((pillWidth - (indicatorRadius + (indicatorOffset * 2.0))) * toggleAnimation.get())
val indicatorX = (pillX - (pillWidth - indicatorRadius + (indicatorOffset * 2.0))) + (pillWidth - (indicatorRadius + (indicatorOffset * 2.0))) * toggleAnimation.get()

val pillColor = ColorUtil.mixColors(ThemeHandler.gray, ThemeHandler.getPrimary(), toggleAnimation.get())
val outline = ColorUtil.applyOpacity(ThemeHandler.getContrast(), toggleAnimation.get())
with(DrawUtil) {
drawString(value.name, x + padding, y + (height / 2.0), 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT)
roundedRect(pillX, pillY, pillWidth, pillHeight, pillHeight / 2.0, pillColor, Alignment.CENTER_RIGHT)
roundedRect(indicatorX, pillY, indicatorRadius + ((indicatorRadius / 3.0) * clickAnimation.get()), indicatorRadius, indicatorRadius / 2.0, ThemeHandler.getContrast(), Alignment.CENTER)
roundedRect(indicatorX, pillY, indicatorRadius + ((indicatorRadius / 3.0) * toggleDependentAnimation.get()), indicatorRadius, indicatorRadius / 2.0, ThemeHandler.getContrast(), Alignment.CENTER)
}
toggleAnimation.animate(if (value.get()) 1.0 else 0.0)
clickAnimation.animate(if (toggleAnimation.finished) 0.0 else 1.0)
toggleDependentAnimation.animate(if (toggleAnimation.finished) 0.0 else 1.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 @@ -3,30 +3,66 @@ 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.render.Alignment
import dev.blend.util.render.ColorUtil
import dev.blend.util.render.DrawUtil
import dev.blend.value.impl.NumberValue

class NumberValueComponent(
parent: ModuleComponent,
override val value: NumberValue
): AbstractValueComponent(
parent, value, height = 20.0
parent, value, height = 30.0
) {

private val dragAnimation = CubicOutAnimation()
private val dragDependentAnimation = SineOutAnimation()
private val selectAnimation = SineOutAnimation()
private var held = false

override fun init() {

}

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 sliderW = width - (padding * 2.0)
val sliderH = 2.0
val sliderX = x + padding
val sliderY = (y + height) - (padding * 2.0)
val dragIndicator = 6.0 + (selectAnimation.get() * 2.0)
val holdIndicator = 4.0
// (value - min) / (max - min)
// (15 - 10) / (20 - 10) = 0.5
val relativeValue = (value.get().toDouble() - value.min.toDouble()) / (value.max.toDouble() - value.min.toDouble())
val relativeMouseX = (mouseX - sliderX) / ((sliderX + sliderW) - sliderX)
if (held) {
value.set(value.min.toDouble() + relativeMouseX * (value.max.toDouble() - value.min.toDouble()))
}

val heldColor = ColorUtil.mixColors(ThemeHandler.getTextColor(), ThemeHandler.getPrimary(), selectAnimation.get())
with(DrawUtil) {
drawString(value.name, x + padding, y + padding, 8, ThemeHandler.getTextColor(), Alignment.CENTER_LEFT)
drawString(value.toString(), (x + width) - padding, y + padding, 8, heldColor, Alignment.CENTER_RIGHT)
roundedRect(sliderX, sliderY, sliderW, sliderH, sliderH / 2.0, ThemeHandler.getContrast(), Alignment.CENTER_LEFT)
roundedRect(sliderX, sliderY, dragAnimation.get(), sliderH, sliderH / 2.0, ThemeHandler.getPrimary(), Alignment.CENTER_LEFT)
roundedRect(sliderX + dragAnimation.get(), sliderY, dragIndicator + (dragDependentAnimation.get() * 3.0), dragIndicator, dragIndicator / 2.0, ThemeHandler.getContrast(), Alignment.CENTER)
roundedRect(sliderX + dragAnimation.get() , sliderY, holdIndicator + (dragDependentAnimation.get() * 3.0), holdIndicator, holdIndicator / 2.0, heldColor, Alignment.CENTER)
}
dragAnimation.duration = 100.0
dragAnimation.animate(relativeValue * sliderW)
dragDependentAnimation.animate(if (dragAnimation.finished) 0.0 else 1.0)
selectAnimation.animate(if (held) 1.0 else 0.0)
}

override fun click(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean {
held = true
return false
}

override fun release(mouseX: Double, mouseY: Double, mouseButton: Int): Boolean {
held = false
return false
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/dev/blend/util/render/ColorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ object ColorUtil {
@JvmStatic
fun mixColors(primary: Color, secondary: Color, factor: Double): Color {
val otherFactor = 1.0 - factor
val redFactor = (primary.red * factor + secondary.red * otherFactor).toInt()
val greenFactor = (primary.green * factor + secondary.green * otherFactor).toInt()
val blueFactor = (primary.blue * factor + secondary.blue * otherFactor).toInt()
val redFactor = (primary.red * otherFactor + secondary.red * factor).toInt()
val greenFactor = (primary.green * otherFactor + secondary.green * factor).toInt()
val blueFactor = (primary.blue * otherFactor + secondary.blue * factor).toInt()
return Color(redFactor, greenFactor, blueFactor)
}
@JvmStatic
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/dev/blend/util/render/DrawUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ object DrawUtil: IAccessor {
private fun postRender() {
RenderSystem.disableCull()
RenderSystem.disableDepthTest()
RenderSystem.defaultBlendFunc()
// RenderSystem.enableBlend()
// RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE)
RenderSystem.enableBlend()
// RenderSystem.defaultBlendFunc()
// RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA)
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE)
}
private fun alignX(x: Number, width: Number, alignment: Alignment): Float {
return when (alignment) {
Expand Down

0 comments on commit 60a5bc4

Please sign in to comment.