OneColor
Learn more about OneColor, OneConfig's way of processing colors
Why?
OneColor exists for many reasons.
Firstly, there are limitations when converting RGB to HSB and vice versa. We wanted to have HSB color selectors because they are much more usable than a few RGB sliders. Rendering uses ARGB though, so we have to convert! This means multiple conversions for RGB to HSB every tick, and there can be miscalculations with this.
Secondly, we wanted to have a more lightweight alternative to java.awt.Color
. While it's not bad for performance, it contains a lot of code that isn't strictly necessary, so we built a more lightweight alternative. There are many similarities to Color
in terms of methods and language for parity, but they are different under the hood.
Lastly, we wanted to support chroma natively. So, we have a data bit, which controls the speed of the chroma, along with favorites, and the getRGB()
methods will return these chroma colors instantly.
So, in a nutshell, we made OneColor for performance and accuracy.
OneColor's structure
OneColor stores color as a short[]
array, creating an int rgba
every time the color is changed (upon instantiation). They are used with the @Color Config element, are used widely throughout OneConfig's codebase and are fully integrated with java.awt.Color
and .
Creating a OneColor
Creating a OneColor is very easy! Here are some of the methods you can use:
Hex
OneColor also has full support for hex strings. You can create a OneColor from a parsed hex, or get the hex of a OneColor easily.
The hex parser has auto-completion features, and supports a variety of hexes even if they are malformed:
If the hex is less than 6 characters, 0s are appended.
If the hex is 3 characters long, it is understood as a 3-digit RGB hex and is repeated appropriately.
E.g. CF2 -> CCFF22.
If the hex is 1 character long, it is repeated across the R, G and B fields.
E.g. C -> CCCCCC.
The alpha will be fetched from the hex color if it is 8 characters long (RRGGBBAA).
Last updated