diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-01 17:37:49 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-01 17:37:49 +0100 |
commit | e48cd4479f832cdd341ab0a289d1b4a88ab21a3c (patch) | |
tree | 01f38d4575287612f1720b6f1f294ea91d15e617 /src/main/java/cc/polyfrost/oneconfig/utils | |
parent | d109fac644fb9be7424f35fa24eb0ad32331e799 (diff) | |
download | OneConfig-e48cd4479f832cdd341ab0a289d1b4a88ab21a3c.tar.gz OneConfig-e48cd4479f832cdd341ab0a289d1b4a88ab21a3c.tar.bz2 OneConfig-e48cd4479f832cdd341ab0a289d1b4a88ab21a3c.zip |
OC-53 should be done but had to push + color utils changed again
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java | 140 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/utils/color/ColorUtils.java (renamed from src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java) | 82 |
2 files changed, 145 insertions, 77 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java new file mode 100644 index 0000000..c2a1fec --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java @@ -0,0 +1,140 @@ +package cc.polyfrost.oneconfig.utils.color; + + +import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.core.OneColor; + +import java.awt.*; + +import static cc.polyfrost.oneconfig.config.OneConfigConfig.*; + +public class ColorPalette { + /** + * Always returns transparent. + */ + public static final ColorPalette TRANSPARENT = new ColorPalette(OneConfigConfig.TRANSPARENT, OneConfigConfig.TRANSPARENT, OneConfigConfig.TRANSPARENT); + /** + * <h1>Primary Color Scheme</h1> Normal: Primary 600,<br> Hover: Primary 700,<br> Clicked: Primary 700 (80%) + */ + public static final ColorPalette PRIMARY = new ColorPalette(PRIMARY_600, PRIMARY_700, PRIMARY_700_80); + /** + * <h1>Secondary Color Scheme</h1> Normal: Gray 500,<br> Hover: Gray 400,<br> Clicked: Gray 400 (80%) + */ + public static final ColorPalette SECONDARY = new ColorPalette(OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, OneConfigConfig.GRAY_400_80); + /** + * <h1>Secondary (Transparent) Color Scheme</h1> Normal: Transparent,<br> Hover: Gray rgba(229, 229, 229, 77),<br> Clicked: Gray rgba(229, 229, 229, 51) + */ + public static final ColorPalette SECONDARY_TRANSPARENT = new ColorPalette(OneConfigConfig.TRANSPARENT, new Color(229, 229, 229, 77).getRGB(), new Color(229, 229, 229, 51).getRGB()); + /** + * <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%) + * <h2>NOTICE this returns the text colors as it is always transparent.</h2> + */ + public static final ColorPalette TERTIARY = new ColorPalette(WHITE_90, WHITE, WHITE_80); + /** + * <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%) + */ + public static final ColorPalette PRIMARY_DESTRUCTIVE = new ColorPalette(ERROR_700, ERROR_600, ERROR_600_80); + /** + * <h1>Secondary Destructive Color Scheme</h1> Normal: Gray 500,<br> Hover: Error 800,<br> Clicked: Error 800 (80%) + */ + public static final ColorPalette SECONDARY_DESTRUCTIVE = new ColorPalette(OneConfigConfig.GRAY_500, ERROR_800, ERROR_800_80); + /** + * <h1>Tertiary Destructive Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=Error 300),<br> Clicked: Transparent (Text=Error 300 80%) + * <h2>NOTICE this returns the text colors as it is always transparent.</h2> + */ + public static final ColorPalette TERTIARY_DESTRUCTIVE = new ColorPalette(WHITE_90, ERROR_300, ERROR_300_80); + + + + + private final int colorNormal; + private final int colorHovered; + private final int colorPressed; + private final float[] colorNormalf; + private final float[] colorHoveredf; + private final float[] colorPressedf; + + /** <h1>Create a new ColorPalette.</h1> + * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. + * <br> This method takes integers in ARGB format, like many other classes, such as {@link OneColor} and {@link Color}. + * @param colorNormal the color of the element when it is not hovered or pressed. + * @param colorHovered the color of the element when it is hovered. + * @param colorPressed the color of the element when it is pressed. + */ + public ColorPalette(int colorNormal, int colorHovered, int colorPressed) { + this.colorNormal = colorNormal; + this.colorHovered = colorHovered; + this.colorPressed = colorPressed; + this.colorNormalf = new float[]{ColorUtils.getRed(colorNormal) / 255f, ColorUtils.getGreen(colorNormal) / 255f, ColorUtils.getBlue(colorNormal) / 255f, ColorUtils.getAlpha(colorNormal) / 255f}; + this.colorHoveredf = new float[]{ColorUtils.getRed(colorHovered) / 255f, ColorUtils.getGreen(colorHovered) / 255f, ColorUtils.getBlue(colorHovered) / 255f, ColorUtils.getAlpha(colorHovered) / 255f}; + this.colorPressedf = new float[]{ColorUtils.getRed(colorPressed) / 255f, ColorUtils.getGreen(colorPressed) / 255f, ColorUtils.getBlue(colorPressed) / 255f, ColorUtils.getAlpha(colorPressed) / 255f}; + } + /** <h1>Create a new ColorPalette.</h1> + * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. + * <br> This method takes {@link OneColor} in ARGB format. + * @param colorNormal the color of the element when it is not hovered or pressed. + * @param colorHovered the color of the element when it is hovered. + * @param colorPressed the color of the element when it is pressed. + */ + public ColorPalette(OneColor colorNormal, OneColor colorHovered, OneColor colorPressed) { + this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB()); + } + + /** <h1>Create a new ColorPalette.</h1> + * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. + * <br> This method takes {@link Color} in ARGB format. + * @param colorNormal the color of the element when it is not hovered or pressed. + * @param colorHovered the color of the element when it is hovered. + * @param colorPressed the color of the element when it is pressed. + */ + public ColorPalette(Color colorNormal, Color colorHovered, Color colorPressed) { + this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB()); + } + + /** <h1>Create a new ColorPalette.</h1> + * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. + * <br> This method takes float arrays of the color between 0f and 1f, in [R, G, B, A] format. + * @param colorNormal the color of the element when it is not hovered or pressed. + * @param colorHovered the color of the element when it is hovered. + * @param colorPressed the color of the element when it is pressed. + */ + public ColorPalette(float[] colorNormal, float[] colorHovered, float[] colorPressed) { + this.colorNormalf = colorNormal; + this.colorHoveredf = colorHovered; + this.colorPressedf = colorPressed; + this.colorNormal = ColorUtils.getColor(colorNormal[0], colorNormal[1], colorNormal[2], colorNormal[3]); + this.colorHovered = ColorUtils.getColor(colorHovered[0], colorHovered[1], colorHovered[2], colorHovered[3]); + this.colorPressed = ColorUtils.getColor(colorPressed[0], colorPressed[1], colorPressed[2], colorPressed[3]); + } + + /** Return the color of the element when it is not hovered or pressed in ARGB format. */ + public int getNormalColor() { + return colorNormal; + } + + /** Return the color of the element when it is hovered in ARGB format. */ + public int getHoveredColor() { + return colorHovered; + } + + /** Return the color of the element when it is pressed in ARGB format. */ + public int getPressedColor() { + return colorPressed; + } + + /** Return the color of the element when it is not hovered or pressed in a float array (r,g,b,a). */ + public float[] getNormalColorf() { + return colorNormalf; + } + + /** Return the color of the element when it is hovered in a float array (r,g,b,a). */ + public float[] getHoveredColorf() { + return colorHoveredf; + } + + /** Return the color of the element when it is pressed in a float array (r,g,b,a). */ + public float[] getPressedColorf() { + return colorPressedf; + } + +} diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorUtils.java index 127b200..a419766 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorUtils.java @@ -1,91 +1,19 @@ -package cc.polyfrost.oneconfig.utils; +package cc.polyfrost.oneconfig.utils.color; -import cc.polyfrost.oneconfig.config.OneConfigConfig; - -import java.awt.*; +import cc.polyfrost.oneconfig.utils.MathUtils; /** * A class to help with color manipulation. */ public final class ColorUtils { - /** - * Always returns transparent. - */ - public static final int TRANSPARENT = -10; - /** - * <h1>Primary Color Scheme</h1> Normal: Primary 600,<br> Hover: Primary 700,<br> Clicked: Primary 700 (80%) - */ - public static final int PRIMARY = 1; - /** - * <h1>Secondary Color Scheme</h1> Normal: Gray 500,<br> Hover: Gray 400,<br> Clicked: Gray 400 (80%) - */ - public static final int SECONDARY = 2; - /** - * <h1>Secondary (Transparent) Color Scheme</h1> Normal: Transparent,<br> Hover: Gray rgba(229, 229, 229, 77),<br> Clicked: Gray rgba(229, 229, 229, 51) - */ - public static final int SECONDARY_TRANSPARENT = 0; - /** - * <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%) - * <h2>NOTICE this returns the text colors as it is always transparent.</h2> - */ - public static final int TERTIARY = 3; - /** - * <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%) - */ - public static final int PRIMARY_DESTRUCTIVE = -1; - /** - * <h1>Secondary Destructive Color Scheme</h1> Normal: Gray 500,<br> Hover: Error 800,<br> Clicked: Error 800 (80%) - */ - public static final int SECONDARY_DESTRUCTIVE = -2; - /** - * <h1>Tertiary Destructive Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=Error 300),<br> Clicked: Transparent (Text=Error 300 80%) - * <h2>NOTICE this returns the text colors as it is always transparent.</h2> - */ - public static final int TERTIARY_DESTRUCTIVE = -3; - - public static int getColor(int currentColor, int colorPalette, boolean hover, boolean click) { + public static int getColor(int currentColor, ColorPalette colorPalette, boolean hover, boolean click) { float[] color = splitColor(currentColor); - if (colorPalette == TRANSPARENT) { - return OneConfigConfig.TRANSPARENT; - } if (click) { - switch (colorPalette) { - case PRIMARY_DESTRUCTIVE: - return OneConfigConfig.ERROR_600_80; - case SECONDARY_DESTRUCTIVE: - return OneConfigConfig.ERROR_800_80; - case TERTIARY_DESTRUCTIVE: - return OneConfigConfig.ERROR_300_80; - case TERTIARY: - return OneConfigConfig.WHITE_80; - default: - case SECONDARY: - return OneConfigConfig.GRAY_400_80; - case SECONDARY_TRANSPARENT: - return new Color(0.9f, 0.9f, 0.9f, 0.2f).getRGB(); - case PRIMARY: - return OneConfigConfig.PRIMARY_700_80; - } + return colorPalette.getPressedColor(); } - switch (colorPalette) { - case SECONDARY_TRANSPARENT: // Formally -2 - return getColorComponents(color, new float[]{0f, 0f, 0f, 0f}, new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f); - case PRIMARY: // Formally 1 - return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_700), splitColor(OneConfigConfig.PRIMARY_600), hover, 20f); - default: - case SECONDARY: // Formally 0 - return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover, 20f); - case TERTIARY: - return getColorComponents(color, splitColor(OneConfigConfig.WHITE_90), splitColor(OneConfigConfig.WHITE), hover, 20f); - case PRIMARY_DESTRUCTIVE: - return getColorComponents(color, splitColor(OneConfigConfig.ERROR_700), splitColor(OneConfigConfig.ERROR_600), hover, 20f); - case SECONDARY_DESTRUCTIVE: - return getColorComponents(color, splitColor(OneConfigConfig.ERROR_800), splitColor(OneConfigConfig.GRAY_500), !hover, 20f); - case TERTIARY_DESTRUCTIVE: - return getColorComponents(color, splitColor(OneConfigConfig.WHITE_90), splitColor(OneConfigConfig.ERROR_300), hover, 20f); - } + return getColorComponents(color, colorPalette.getNormalColorf(), colorPalette.getHoveredColorf(), hover, 20f); } /** |