@@ -19,14 +19,18 @@ package com.lambda.gui.impl.clickgui.core
1919
2020import com.lambda.graphics.animation.Animation.Companion.exp
2121import com.lambda.gui.component.HAlign
22+ import com.lambda.gui.component.core.FilledRect
23+ import com.lambda.gui.component.core.FilledRect.Companion.rect
24+ import com.lambda.gui.component.core.FilledRect.Companion.rectBehind
2225import com.lambda.gui.component.layout.Layout
2326import com.lambda.gui.component.window.Window
2427import com.lambda.gui.impl.clickgui.module.ModuleLayout
25- import com.lambda.gui.impl.clickgui.module.settings .SettingLayout
28+ import com.lambda.gui.impl.clickgui.module.setting .SettingLayout
2629import com.lambda.module.modules.client.ClickGui
2730import com.lambda.util.math.MathUtils.toInt
2831import com.lambda.util.math.Vec2d
2932import com.lambda.util.math.lerp
33+ import com.lambda.util.math.multAlpha
3034import com.lambda.util.math.setAlpha
3135import com.lambda.util.math.transform
3236import java.awt.Color
@@ -152,4 +156,69 @@ abstract class AnimatedChild(
152156 outlineRect
153157 ).forEach(Layout ::destroy)
154158 }
159+
160+ companion object {
161+ fun AnimatedChild.animatedBackground (
162+ enableProgress : () -> Double = { hoverAnimation }
163+ ) = rectBehind(titleBar) {
164+ // base rect with lowest y to avoid children overlying
165+ onUpdate {
166+ val enableAnimation = enableProgress()
167+
168+ rect = this @animatedBackground.rect.shrink(shrink)
169+ shade = ClickGui .backgroundShade
170+
171+ val openRev = 1.0 - openAnimation // 1.0 <-> 0.0
172+ val openRevSigned = openRev * 2 - 1 // 1.0 <-> -1.0
173+ val enableRev = 1.0 - enableAnimation // 1.0 <-> 0.0
174+
175+ var progress = enableAnimation
176+
177+ // hover: +0.1 to alpha if minimized, -0.1 to alpha if maximized and enabled
178+ progress + = hoverAnimation * ClickGui .moduleHoverAccent *
179+ lerp(enableAnimation, 1.0 , openRevSigned)
180+
181+ // +0.4 to alpha if opened and disabled
182+ progress + = openAnimation * ClickGui .moduleOpenAccent * enableRev
183+
184+ // interpolate and set the color
185+ setColor(
186+ lerp(progress,
187+ ClickGui .moduleDisabledColor,
188+ ClickGui .moduleEnabledColor
189+ ).multAlpha(showAnimation)
190+ )
191+
192+ setRadius(hoverAnimation)
193+
194+ if (isLast && ClickGui .autoResize) {
195+ leftBottomRadius = ClickGui .roundRadius - (ClickGui .padding + shrink)
196+ rightBottomRadius = leftBottomRadius
197+ }
198+ }
199+
200+ rect { // hover fx
201+ onUpdate {
202+ val base = this @rect.owner as FilledRect
203+
204+ position = base.position
205+ size = base.size
206+ shade = base.shade
207+
208+ setRadius(
209+ base.leftTopRadius,
210+ base.rightTopRadius,
211+ base.rightBottomRadius,
212+ base.leftBottomRadius
213+ )
214+
215+ val hoverColor = Color .WHITE .setAlpha(
216+ ClickGui .moduleHoverAccent * hoverAnimation * (1.0 - openAnimation) * showAnimation
217+ )
218+
219+ setColorH(hoverColor.setAlpha(0.0 ), hoverColor)
220+ }
221+ }
222+ }
223+ }
155224}
0 commit comments