Color

Represents an RGBA color

Constructors

this
this(int red, int green, int blue, int alpha)

Construct a color with the given values. They should be in range 0 <= x <= 255, where 255 is maximum intensity and 0 is minimum intensity.

this
this(ubyte[] components)

Construct a color from components[0 .. 4]. It must have length of at least 4 and be in r, g, b, a order.

this
this(float r, float g, float b, float a)

Constructs a color from floating-point rgba components, each between 0 and 1.0.

this
this(ColorF colorF)

Constructs a color from a ColorF (floating-point)

Members

Enums

ColorBlendMixinStr
eponymoustemplate ColorBlendMixinStr(string colu32name, string destu32name)

this mixin can be used to alphablend two uint colors; colu32name is variable that holds color to blend, destu32name is variable that holds "current" color (from surface, for example). alpha value of destu32name doesn't matter. alpha value of colu32name means: 255 for replace color, 0 for keep destu32name.

Functions

alphaBlend
Color alphaBlend(Color fore)

Perform alpha-blending of fore to this color, return new color. WARNING! This function does blending in RGB space, and RGB space is not linear!

asWindowsColorRef
uint asWindowsColorRef()

Returns a value compatible with a Win32 COLORREF.

toBW
Color toBW()

Return black-and-white color

toCssString
string toCssString()

Makes a string that matches CSS syntax for websites

toRgbaHexString
string toRgbaHexString()

returns RRGGBBAA, even if a== 255

toString
string toString()

Makes a hex string RRGGBBAA (aa only present if it is not 255)

Static functions

black
Color black()
blue
Color blue()
brown
Color brown()

Static convenience functions for common color names

fromHsl
Color fromHsl(double h, double s, double l)

from hsl

fromIntegers
Color fromIntegers(int red, int green, int blue, int alpha)

Like the constructor, but this makes sure they are in range before casting. If they are out of range, it saturates: anything less than zero becomes zero and anything greater than 255 becomes 255.

fromNameString
Color fromNameString(string s)

Gets a color by name, iff the name is one of the static members listed above

fromString
Color fromString(const(char)[] s)

Reads a CSS style string to get the color. Understands #rrggbb, rgba(), hsl(), and rrggbbaa

fromWindowsColorRef
Color fromWindowsColorRef(uint cr)

Constructs a Color from a Win32 COLORREF.

gray
Color gray()
green
Color green()
magenta
Color magenta()
purple
Color purple()
red
Color red()
teal
Color teal()

Static convenience functions for common color names

transparent
Color transparent()
white
Color white()
yellow
Color yellow()

Static convenience functions for common color names

Unions

__anonymous
union __anonymous

The color components are available as a static array, individual bytes, and a uint inside this union.

Suggestion Box / Bug Report