import a._ggez

class Color {
    [opaque, r, g, b, a]

    static def __call(r, g=nil, b=nil, a=1.0) = {
        if g is nil {
            if type(r) is Color {
                r
            } elif type(r) is List and r.len() == 3 {
                [r, g, b] = r
                opaque = _ggez::new_color(r, g, b, a)
                __malloc(Color, [opaque, r, g, b, a])
            } else {
                [r, g, b, a] = r
                opaque = _ggez::new_color(r, g, b, a)
                __malloc(Color, [opaque, r, g, b, a])
            }
        } else {
            opaque = _ggez::new_color(r, g, b, a)
            __malloc(Color, [opaque, r, g, b, a])
        }
    }

    def scale(self, r) = Color(
        self.r * r,
        self.g * r,
        self.b * r,
        self.a,
    )
}

BLACK = Color(0, 0, 0)
WHITE = Color(1, 1, 1)
RED = Color(1, 0, 0)
GREEN = Color(0, 1, 0)
BLUE = Color(0, 0, 1)