Files
OpenOnyx/src/openonyx/ui/internal/CheckboxControl.java
T

94 lines
3.0 KiB
Java

package openonyx.ui.internal;
import openonyx.history.internal.BooleanSetting;
import openonyx.render.Render2D;
import openonyx.render.group_d.Animation;
import openonyx.render.group_d.Easings;
import openonyx.theme.ThemeManager;
import openonyx.ui.MaterialIcons;
import openonyx.ui.RenderContext;
import openonyx.ui.UiSupport_545;
public class CheckboxControl extends SettingControl {
private static final float j = 13.0F;
private static final float m = 15.0F;
private final Animation animation;
private final BooleanSetting booleanSetting;
private boolean i;
private boolean f;
private final UiSupport_545 uiSupport_545 = new UiSupport_545();
@Override
protected float L(RenderContext renderContext) {
return this.A();
}
private float m() {
return this.f + this.e - 15.0F;
}
private float B() {
return this.I() - 7.5F;
}
@Override
public void update(RenderContext renderContext) {
super.update(renderContext);
if (!this.i) {
this.i = true;
this.f = this.booleanSetting.getValue();
this.animation.set(this.f ? 1.0F : 0.0F);
}
if (this.booleanSetting.getValue() != this.f) {
this.f = this.booleanSetting.getValue();
this.animation.animateTo(this.f ? 1.0F : 0.0F, 200.0F, Easings.EASING2);
}
this.animation.update(renderContext.i);
this.uiSupport_545.L(renderContext.i, this.h, this.H);
}
public CheckboxControl(BooleanSetting booleanSetting) {
super(booleanSettingx);
this.animation = new Animation(0.0F);
this.booleanSetting = booleanSettingx;
}
@Override
public boolean mouseClicked(float f, float g, int i) {
if (this.i() && ix == 0 && this.contains(fx, g)) {
this.booleanSetting.toggle();
return true;
} else {
return false;
}
}
@Override
protected void d(RenderContext renderContext, float k) {
CheckboxControl checkboxControl1 = this;
Render2D render2D = renderContext.render2D;
float h = checkboxControl1.m();
float fx = checkboxControl1.B();
float g = checkboxControl1.animation.getValue();
checkboxControl1.L(renderContext, h - 10.0F - checkboxControl1.f);
checkboxControl1.uiSupport_545.L(render2D, h - 6.0F, fx - 6.0F, 27.0F, 27.0F, Float.MAX_VALUE, checkboxControl1.L(renderContext.palette().onSurface()));
if (g > 0.01F) {
float ix = (1.0F - g) * 15.0F / 2.0F;
render2D.roundedRect(h + ix, fx + ix, 15.0F - ix * 2.0F, 15.0F - ix * 2.0F, 4.0F, checkboxControl1.L(renderContext.palette().primary()));
}
if (g < 0.99F) {
render2D.roundedOutline(h, fx, 15.0F, 15.0F, 4.0F, 1.5F, checkboxControl1.L(renderContext.palette().onSurfaceVariant()));
}
if (g > 0.15F) {
float jx = Math.clamp((g - 0.15F) / 0.85F, 0.0F, 1.0F);
MaterialIcons.d(
render2D, h + 7.5F, fx + 7.5F, 13.0F * (0.7F + 0.3F * jx), checkboxControl1.L(ThemeManager.withAlpha(renderContext.palette().onPrimary(), jx))
);
}
}
}