34 lines
977 B
Kotlin
34 lines
977 B
Kotlin
package net.shadowfacts.cacao.util
|
|
|
|
/**
|
|
* Helper class for Cacao colors.
|
|
*
|
|
* @author shadowfacts
|
|
* @param red The red component, from 0-255.
|
|
* @param green The green component, from 0-255.
|
|
* @param blue The blue component, from 0-255.
|
|
* @param alpha The alpha (i.e. transparency) component, from 0-255. (0 is transparent, 255 is opaque)
|
|
*/
|
|
data class Color(val red: Int, val green: Int, val blue: Int, val alpha: Int = 255) {
|
|
|
|
/**
|
|
* Constructs a color from the packed RGB color.
|
|
*/
|
|
constructor(rgb: Int, alpha: Int = 255): this(rgb shr 16, (rgb shr 8) and 255, rgb and 255, alpha)
|
|
|
|
/**
|
|
* The ARGB packed representation of this color.
|
|
*/
|
|
val argb: Int
|
|
get() = ((alpha and 255) shl 24) or ((red and 255) shl 16) or ((green and 255) shl 8) or (blue and 255)
|
|
|
|
companion object {
|
|
val CLEAR = Color(0, alpha = 0)
|
|
val WHITE = Color(0xffffff)
|
|
val BLACK = Color(0)
|
|
val RED = Color(0xff0000)
|
|
val GREEN = Color(0x00ff00)
|
|
val BLUE = Color(0x0000ff)
|
|
}
|
|
|
|
} |