diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-16 18:41:19 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-16 18:41:19 +0200 |
commit | eb389dbabde11a291eb3a040316d09722789e7d6 (patch) | |
tree | bf03eb97a96e04c7302f7c3b9338cc42ccda6f00 /src/main/java/cc | |
parent | 82ce1a72e26a3ced45949ab459592b97b39b334f (diff) | |
download | OneConfig-eb389dbabde11a291eb3a040316d09722789e7d6.tar.gz OneConfig-eb389dbabde11a291eb3a040316d09722789e7d6.tar.bz2 OneConfig-eb389dbabde11a291eb3a040316d09722789e7d6.zip |
hover states
Diffstat (limited to 'src/main/java/cc')
4 files changed, 34 insertions, 14 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index 2dbf181..36cd13f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -42,11 +42,11 @@ public class ConfigCheckbox extends BasicOption { e.printStackTrace(); } } + color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_600, OneConfigConfig.GRAY_400, hover, 40f); if (percentOn != 1f) { // performance RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, color, 6f); RenderManager.drawHollowRoundRect(vg, x, y + 4, 23.5f, 23.5f, OneConfigConfig.GRAY_300, 6f, 1f); // the 0.5f is to make it look better ok } - color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_600, OneConfigConfig.GRAY_400, hover, 40f); RenderManager.drawString(vg, name, x + 32, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 50f)); if (percentOn != 0 && percentOn != 1f) { @@ -56,6 +56,7 @@ public class ConfigCheckbox extends BasicOption { RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, OneConfigConfig.BLUE_500, 6f); RenderManager.drawSvg(vg, SVGs.CHECKBOX_TICK, x, y + 4, 24, 24); } + if(percentOn != 0 && hover) RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, OneConfigConfig.BLUE_600, 6f, 2f); NanoVG.nvgGlobalAlpha(vg, 1f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java index afe1888..599c094 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -4,6 +4,7 @@ import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; +import cc.polyfrost.oneconfig.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.nanovg.NanoVG; @@ -13,6 +14,8 @@ import java.lang.reflect.Field; public class ConfigDualOption extends BasicOption { private float percentMove = 0f; private final String left, right; + int colorSelected; + int colorUnselected; public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { super(field, parent, name, size); @@ -34,15 +37,18 @@ public class ConfigDualOption extends BasicOption { } catch (IllegalAccessException ignored) { } if (!isEnabled()) NanoVG.nvgGlobalAlpha(vg, 0.5f); + boolean hovered = InputUtils.isAreaHovered(x + 226, y, 256, 32) && isEnabled(); + colorSelected = ColorUtils.smoothColor(colorSelected, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, hovered, 40f); + colorUnselected = ColorUtils.smoothColor(colorUnselected, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 40f); RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, OneConfigConfig.GRAY_500, 12f); + RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, colorUnselected, 12f); int x1 = (int) (x + 228 + (percentMove * 128)); - RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, OneConfigConfig.BLUE_600, 10f); + RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, colorSelected, 10f); RenderManager.drawString(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE_90, 12f, Fonts.MEDIUM); RenderManager.drawString(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE_90, 12f, Fonts.MEDIUM); NanoVG.nvgGlobalAlpha(vg, 1); - if (InputUtils.isAreaClicked(x + 226, y, 256, 32) && isEnabled()) { + if (hovered && InputUtils.isClicked()) { toggled = !toggled; try { set(toggled); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 187d58d..233a29d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -12,7 +12,8 @@ import org.lwjgl.nanovg.NanoVG; import java.lang.reflect.Field; public class ConfigSwitch extends BasicOption { - private int color; + private int colorEnabled; + private int colorDisabled; private float percentOn = 0f; public ConfigSwitch(Field field, Object parent, String name, int size) { @@ -28,12 +29,13 @@ public class ConfigSwitch extends BasicOption { } catch (IllegalAccessException ignored) { } int x2 = x + 3 + (int) (percentOn * 18); - color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_400, OneConfigConfig.BLUE_500, toggled, 20f); - if (color == -15123643) { - color = OneConfigConfig.GRAY_400; - } + boolean hovered = InputUtils.isAreaHovered(x, y, 42, 32); + colorDisabled = ColorUtils.smoothColor(colorDisabled, OneConfigConfig.GRAY_400, OneConfigConfig.GRAY_300, hovered, 40f); + colorEnabled = ColorUtils.smoothColor(colorEnabled, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, !hovered, 40f); if (!isEnabled()) NanoVG.nvgGlobalAlpha(vg, 0.5f); - RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, color, 12f); + RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, colorDisabled, 12f); + if (percentOn != 0) + RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, ColorUtils.setAlpha(colorEnabled, (int) (255 * percentOn)), 12f); RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, OneConfigConfig.WHITE, 9f); RenderManager.drawString(vg, name, x + 50, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java index e721f16..938e830 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -8,6 +8,7 @@ import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; +import cc.polyfrost.oneconfig.utils.ColorUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.nanovg.NanoVG; @@ -18,6 +19,8 @@ public class ConfigUniSelector extends BasicOption { private final String[] options; private float percentMove = 1f; private int previous = -1; + private int colorLeft; + private int colorRight; public ConfigUniSelector(Field field, Object parent, String name, int size, String[] options) { super(field, parent, name, size); @@ -50,10 +53,18 @@ public class ConfigUniSelector extends BasicOption { } ScissorManager.resetScissor(vg, scissor); - RenderManager.drawSvg(vg, SVGs.CHEVRON_LEFT, x + 231, y + 7, 18, 18, OneConfigConfig.BLUE_400); - RenderManager.drawSvg(vg, SVGs.CHEVRON_RIGHT, x + 455, y + 7, 18, 18, OneConfigConfig.BLUE_400); + boolean hoveredLeft = InputUtils.isAreaHovered(x + 231, y + 7, 18, 18) && selected > 0 && isEnabled(); + boolean hoveredRight = InputUtils.isAreaHovered(x + 455, y + 7, 18, 18) && selected < options.length - 1 && isEnabled(); + colorLeft = ColorUtils.smoothColor(colorLeft, OneConfigConfig.BLUE_500, OneConfigConfig.BLUE_400, hoveredLeft, 40f); + colorRight = ColorUtils.smoothColor(colorRight, OneConfigConfig.BLUE_500, OneConfigConfig.BLUE_400, hoveredRight, 40f); - if (InputUtils.isAreaClicked(x + 231, y + 7, 18, 18) && selected > 0 && isEnabled()) { + if (selected <= 0 && isEnabled()) NanoVG.nvgGlobalAlpha(vg, 0.5f); + RenderManager.drawSvg(vg, SVGs.CHEVRON_LEFT, x + 231, y + 7, 18, 18, colorLeft); + if (isEnabled()) NanoVG.nvgGlobalAlpha(vg, selected >= options.length - 1 ? 0.5f : 1f); + RenderManager.drawSvg(vg, SVGs.CHEVRON_RIGHT, x + 455, y + 7, 18, 18, colorRight); + if (isEnabled()) NanoVG.nvgGlobalAlpha(vg, 1f); + + if (hoveredLeft && InputUtils.isClicked()) { previous = selected; selected -= 1; try { @@ -61,7 +72,7 @@ public class ConfigUniSelector extends BasicOption { } catch (IllegalAccessException ignored) { } percentMove = selected < previous ? 0f : 1f; - } else if (InputUtils.isAreaClicked(x + 455, y + 7, 18, 18) && selected < options.length - 1 && isEnabled()) { + } else if (hoveredRight && InputUtils.isClicked()) { previous = selected; selected += 1; try { |