Colour constructor aliases for scripting


#1

The Colour class has a bunch of constructors which are discriminated by differentiating between float and uint8 args. Well, some programming languages (including PILS) don’t support this distinction, so I suggest the following addition to the Colour class.

Note: I renamed the float alpha to opacity/opaqueness (english not being my native language, I am not sure which is more appropriate, so I did one of each - this should of course be changed). Perhaps this should be applied to the regular construtors too? (But I’m not judge of juce-style.)

It compiles with VC9, I didn’t test other compilers and I didn’t make test runs.

juce_Colour.h

[code] /** Creates an opaque colour using 8-bit red, green and blue values

    Scrpting-friendly constructor alias.
*/
static const Colour fromRGB (const uint8 red,
                             const uint8 green,
                             const uint8 blue) throw();

/** Creates a colour using 8-bit red, green, blue and alpha values.

    Scrpting-friendly constructor alias.
*/
static const Colour fromRGBA(const uint8 red,
                             const uint8 green,
                             const uint8 blue,
                             const uint8 alpha) throw();

/** Creates a colour from 8-bit red, green, and blue values, and a floating-point opacity.

    Scrpting-friendly constructor alias.
*/
static const Colour fromRGBO(const uint8 red,
                             const uint8 green,
                             const uint8 blue,
                             const float opacity) throw();

/** Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.

    Scrpting-friendly constructor alias.
*/
static const Colour fromHSBA(const float hue,
                             const float saturation,
                             const float brightness,
                             const uint8 alpha) throw();

/** Creates a colour using floating point hue, saturation, brightness and opaqueness values.

    Scrpting-friendly constructor alias.
*/
static const Colour fromHSBO(const float hue,
                             const float saturation,
                             const float brightness,
                             const float opaqueness) throw();[/code]

juce_Colour.cpp:

[code]const Colour Colour::fromRGB (const uint8 red,
const uint8 green,
const uint8 blue) throw()
{
return Colour(red, green, blue);
}

const Colour Colour::fromRGBA (const uint8 red,
const uint8 green,
const uint8 blue,
const uint8 alpha) throw()
{
return Colour(red, green, blue, alpha);
}

const Colour Colour::fromRGBO(const uint8 red,
const uint8 green,
const uint8 blue,
const float opacity) throw()
{
return Colour(red, green, blue, opacity);
}

const Colour Colour::fromHSBA(const float hue,
const float saturation,
const float brightness,
const uint8 alpha) throw()
{
return Colour(hue, saturation, brightness, alpha);
}

const Colour Colour::fromHSBO(const float hue,
const float saturation,
const float brightness,
const float opaqueness) throw()
{
return Colour(hue, saturation, brightness, opaqueness);
}[/code]


#2

Ok. I wouldn’t normally add anything like this just for a reason like supporting other language wrappers, but having this kind of constructor could lead to more readable code, so I’ll throw something along these lines in there.